[DEFNAME respawning_loot_settings]
RESPAWN_CUSTOM_LOOT_TIME = 10 //secs
/////////////////////////////////////////////////////
//// EVENTS/TYPEDEF e_eventhandler_respawn_loot
//// -our event handler for ON=@ PickUp_Self/DropOn_Self/TIMER
//// @ PickUp_Self - checks contents of container, when empty use TIMERF to call f_loopback_timer to trigger our @Timer event
//// @ DropOn_Self - prevents adding items to the container
//// @ TIMER - if container empty calls f_Load_Loot passing in a list created from TAG.loot
/////////////////////////////////////////////////////
[TYPEDEF e_eventhandler_respawn_loot] //loot handler
ON=@PickUp_Self
//when an item is removed from container reset our timer
//we have -1 because COUNT still considers the current object to still be in the container
IF ((<I.COUNT> - 1)== 0) //only fire if no other items are left
TIMERF <dDEF.RESPAWN_CUSTOM_LOOT_TIME> f_loopback_timer
ENDIF
UPDATE
ON=@DropOn_Self
//prevent droping things into this container
return 1
ON=@TIMER
//if container is empty add new loot based on stored template(s) above or previous
IF (<I.COUNT> == 0)
//turn TAG.loot into a list then pass into function
// f_Load_Loot expects a list
f_Load_Loot <EXPLODE +,<TAG.loot>>
ENDIF
/////////////////////////////////////////////////////
//// FUNCTION f_loopback_timer
//// -loopback to call @TIMER
//// -without this loopback, timers that reach zero will auto decay the object.
//// If that item is static -> error object timer elapsed without decay
//// error is thrown. This prevents that error.
/////////////////////////////////////////////////////
[FUNCTION f_loopback_timer]
//call this items TIMER event
I.TRIGGER @TIMER
/////////////////////////////////////////////////////
//// FUNCTION f_Load_Loot <args>
//// Param <args> - must be a list
//// -takes a list of items and adds each item to the calling container's contents
//// -updates nearby clients so tooltip shows correctly
/////////////////////////////////////////////////////
[FUNCTION f_Load_Loot]
//a list is passed in, loop through and add each item
FOR 0 <EVAL (<ARGV> - 1)>
SERV.NEWITEM <ARGV[<LOCAL._FOR>]>
NEW.CONT=<UID>
ENDFOR
UPDATE
/////////////////////////////////////////////////////
//// ITEM i_metal_chest_rloot
/////////////////////////////////////////////////////
[ITEMDEF i_metal_chest_rloot] //A - our item ref
ID = i_chest_metal //B - what our item looks & feels like
TAG.loot = poor_gold_pile+poor_pouch //C - the loot this item respawns, can have mutiple items seperated by a +
ON=@Create
EVENTS +e_eventhandler_respawn_loot
I.TRIGGER @TIMER