Treasure Chest
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Treasure Chest
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
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Re: Treasure Chest
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
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):
In the mob script:
[/strike]
in the npc script for your chest:
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 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.
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");
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
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
Code: Select all
GetNPCById(npcid):setStatus(STATUS_DISAPPEAR)
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.
Last edited by TeoTwawki on Thu Aug 03, 2017 11:14 pm, edited 3 times in total.
Hi, I run The Demiurge server.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
DO NOT PRIVATE MESSAGE ME ABOUT BUGSPLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Re: Treasure Chest
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!
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Re: Treasure Chest
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
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
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:
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.
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
Hi, I run The Demiurge server.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
DO NOT PRIVATE MESSAGE ME ABOUT BUGSPLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Re: Treasure Chest
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
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.
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.
Hi, I run The Demiurge server.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding
DO NOT PRIVATE MESSAGE ME ABOUT BUGSPLS USE [ code ] CODE TAGS [ /code ] WHEN POSTING CODE
-
- Posts: 36
- Joined: Sat Feb 21, 2015 10:08 am
Re: Treasure Chest
Ahh yes they were all zeros. Working now thanks for your assistance on this one.