• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Can you detect item destruction

Status
Not open for further replies.
Level 10
Joined
Dec 11, 2009
Messages
234
Run a periodic timer that checks item life with GetWidgetLife, maybe something like this:

JASS:
function onUpdate takes nothing returns nothing
    local real life = GetWidgetLife(itm)
    if life < 0.405 then // maybe it should be "<=", I'm not sure
        // Item was destroyed
            // ...
            // ...
            // ...

    elseif life < BlzGetItemIntegerField(itm, ITEM_IF_MAX_HIT_POINTS)
        // Item was damaged
            // ...
            // ...
            // ...
    endif
endfunction

call TimerStart(updateTimer, 0.1, true, function onUpdate)

If there are multiple items, you need to add them to a list and iterate through it.
 
Level 18
Joined
Jan 1, 2018
Messages
728
Items are widgets, so you should be able to use this widget event:
constant widgetevent EVENT_WIDGET_DEATH = ConvertWidgetEvent(89)
But... there's no TriggerRegisterWidgetEvent... wtf Blizzard?

Luckily, there is also this native:
native TriggerRegisterDeathEvent takes trigger whichTrigger, widget whichWidget returns event
 
Status
Not open for further replies.
Top