Currently I am thinking about this. When a unit drops an item, and nobody would take it up then the item would be destroyed automaticly in 60 seconds. But I can't find any trigger / idea to get such a trigger. Does anyone has an idea for this?
just have a trigger with the event every 60 seconds and action remove all items in playable map area. or have it so that when you type in something it does the same thing in 60 seconds?
I want to create a timer for every item dropped and then deleted. If I would use every 60 seconds, and a unit just dropped an item it would dissapear, and the chance of grabbing it is gone then.
Well, you could use this code. It needs vexorian's cscache system (part of the caster system).
This trigger (ItemCleaner) sets up the timer when the item is dropped. Just change the "60." to whatever time you want.
function CleanItemNow takes nothing returns nothing
local timer t = GetExpiredTimer()
local item it = GetAttachedItem(t, "killitem")
call CleanAttachedVars(it)
call RemoveItem(it)
set it = null
call CleanAttachedVars(t)
call DestroyTimer(t)
set t = null
endfunction
function Trig_ItemCleaner_Actions takes nothing returns nothing
local timer t = CreateTimer()
local item it = GetManipulatedItem()
// prepare new one
call AttachObject(t, "killitem", it)
call AttachObject(it, "killtimer", t)
call TimerStart(t, 60., false, function CleanItemNow)
set it = null
set t = null
endfunction
//===========================================================================
function InitTrig_ItemCleaner takes nothing returns nothing
set gg_trg_ItemCleaner = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ItemCleaner, EVENT_PLAYER_UNIT_DROP_ITEM)
call TriggerAddAction(gg_trg_ItemCleaner, function Trig_ItemCleaner_Actions)
endfunction
And this trigger (ItemCleanerStop) stops the timer once the item gets picked back up.
function Trig_ItemCleanerStop_Actions takes nothing returns nothing
local item it = GetManipulatedItem()
local timer t
// remove previous timer
set t = GetAttachedTimer(it, "killtimer")
if (t != null) then
call CleanAttachedVars(t)
call DestroyTimer(t)
set t = null
endif
set it = null
endfunction
//===========================================================================
function InitTrig_ItemCleanerStop takes nothing returns nothing
set gg_trg_ItemCleanerStop = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_ItemCleanerStop, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(gg_trg_ItemCleanerStop, function Trig_ItemCleanerStop_Actions)
endfunction