Page 1 of 1
Treasure Chest
Posted: Wed May 17, 2017 9:20 am
by dragonarmor
So I've searched the forums and i'm not really coming up with anything on this. What i'd like to do is have certain mobs spawn a treasure chest or pyrix upon death and have custom loot inside. If someone could at least point me in the right direction it would be much appreciated. Thank you
Re: Treasure Chest
Posted: Thu May 18, 2017 12:14 pm
by dragonarmor
Basically I'm just looking for an onMobDeath function I can use to spawn chests. I can figure out the rest. Any help is appreciated.
Re: Treasure Chest
Posted: Thu May 18, 2017 3:39 pm
by TeoTwawki
Updated
While retail has multiple chests in a single zone being shared by lots of mobs, if you just have a few specific ones this is rather easy.
Make sure status.lua is required (in
both scripts):
Code: Select all
require("scripts/globals/status");
In the mob script:
Code: Select all
function onMobDeath(mob, player, isKiller)
local npcid = put_ID_here
local timestamp = os.time()
if (isKiller) then -- this check ensures its only running once per
GetNPCById(npcid):setLocalVar(npcid, timestamp) -- Timestamp the NPC
GetNPCById(npcid):setPos(mob:getXpos(), mob:getYPos(), mob:getYPos()); -- Set chest position to where mob died.
GetNPCById(npcid):setStatus(STATUS_NORMAL) -- Spawn it!
end
-- This part hits every member of all parties in the alliance
player:setLocalVar(npcid, timestamp) -- Timestamp the players
end
Code: Select all
function onMobDeath(mob, player, isKiller)
if (isKiller) then -- this check ensures its only running once per
local npcid = put_ID_here
local timestamp = os.time()
GetNPCById(npcid):setLocalVar(npcid, timestamp)
for member, player in player:getAlliance() do
member:setLocalVar(npcid, timestamp)
end
-- Spawn it!
GetNPCById(npcid):setStatus(STATUS_NORMAL)
end
end
[/strike]
in the npc script for your chest:
Code: Select all
function onTrigger(player,npc)
-- comparing these variables prevents wrong people opening the box
if (player:getLocalVar(npc:getId()) == npc:getLocalVar(npc:getId()) then
player:startEvent( whatever the event ID is goes here )
end
You'll also need onEventFinish code to handle your event. This will only work in zones that actually have retail treasure box events, like abyssea. You will need
Code: Select all
GetNPCById(npcid):setStatus(STATUS_DISAPPEAR)
at the end of the event to despawn the box.
If you are looking for a dynamic system to do what retails does, I am workin on it (slowly, lots of real life/offline distractions these days) and will have it in the project when its usable.
Re: Treasure Chest
Posted: Thu May 18, 2017 3:51 pm
by dragonarmor
That is exactly the info I needed. Thanks a lot! All the work you guys do on this project is amazing keep up the good work!
Re: Treasure Chest
Posted: Thu Aug 03, 2017 10:11 am
by dragonarmor
I cannot seem to get the chest to spawn. i'm getting this error:
lua:22: attempt to call a table value
function onMobDeath(mob, player, isKiller)
if (isKiller) then -- this check ensures its only running once per
local npcId = 17216140
local timestamp = os.time()
GetNPCByID(npcId):setLocalVar(npcId, timestamp)
for member, player in player:getAlliance() do <<<-- THIS line 22 error
member:setLocalVar(npcId, timestamp)
end
-- Spawn it!
GetNPCByID(npcId):setStatus(STATUS_NORMAL)
end
end
Re: Treasure Chest
Posted: Thu Aug 03, 2017 7:36 pm
by TeoTwawki
My bad.
We changed some onMobDeath things several times and it used to be called killer before "isKiller" came about, and the come now runs once per alliance member natively and I didn't update from my old version proper.. So lets try:
Code: Select all
function onMobDeath(mob, player, isKiller)
local npcid = put_ID_here
local timestamp = os.time()
if (isKiller) then -- this check ensures its only running once per
GetNPCById(npcid):setLocalVar(npcid, timestamp) -- Timestamp the NPC
GetNPCById(npcid):setStatus(STATUS_NORMAL) -- Spawn it!
end
-- This part hits every member of all parties in the alliance
player:setLocalVar(npcid, timestamp) -- Timestamp the players
end
I think the error you got was because I used "player" when player was already your baseentity. But this version get rid of the need for using getAlliance inside a for loop anyway.
Re: Treasure Chest
Posted: Thu Aug 03, 2017 8:13 pm
by dragonarmor
Well I don't get any errors this time but no chest pops. here is my code
Code: Select all
-----------------------------------
-- Area: South Gustaberg
-- MOB: Land Crab
-----------------------------------
require("scripts/globals/fieldsofvalor");
require("scripts/globals/status");
-----------------------------------
-- onMobDeath
-----------------------------------
function onMobDeath(mob, player, isKiller)
local npcid = 17216156
local timestamp = os.time()
if (isKiller) then -- this check ensures its only running once per
GetNPCByID(npcid):setLocalVar(npcid, timestamp) -- Timestamp the NPC
GetNPCByID(npcid):setStatus(STATUS_NORMAL) -- Spawn it!
end
-- This part hits every member of all parties in the alliance
player:setLocalVar(npcid, timestamp) -- Timestamp the players
end
Re: Treasure Chest
Posted: Thu Aug 03, 2017 11:02 pm
by TeoTwawki
whats the position of the NPC? if its all zero for pos data in the database it will be unable to be spawned. I always forget people new to this won't know these things
Show me your sql line for this npc, just to be sure.
If you want a dynamic location (wherever mob died) that can be done with an addition script command but the database still has to be non zero.
Re: Treasure Chest
Posted: Fri Aug 04, 2017 9:31 am
by dragonarmor
Ahh yes they were all zeros. Working now thanks for your assistance on this one.