• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Dropped Item is destroyed overtime?

Status
Not open for further replies.
Level 4
Joined
Jul 3, 2006
Messages
61
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?
 
Level 24
Joined
Jun 26, 2006
Messages
3,406
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?
 
Level 4
Joined
Jul 3, 2006
Messages
61
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.
 
Level 3
Joined
Aug 17, 2006
Messages
38
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.

Code:
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.

Code:
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
 
Status
Not open for further replies.
Top