• 🏆 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!

Event - Item dies. Is it possible?

Status
Not open for further replies.

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
EVENT_WIDGET_DEATH and TriggerRegisterDeathEvent might help, as items are widgets. I don't know if there is a GUI event for that and if it works. I never used it.
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
As Jampion stated, you can use the following function/event native TriggerRegisterDeathEvent takes trigger whichTrigger, widget whichWidget returns event.
However, you have to specify which item is going to fire a trigger, and also there's no native getter in order to know who destroyed it.

A simple example:

When my map loads, a pre-placed item is going to be registered to another trigger (new event).
  • RegisterXItem
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- I'm going to use a preplaced item for this example, so I'll use a variable to point to it. --------
      • Set item = Claws of Attack +15 0000 <gen>
      • -------- EXTRA: By doing so, a preplaced item variable (gg_item_rawid_number) for a Claws of Attack is generated --------
      • -------- --------
      • -------- Now I'll add it to the XItemDied trigger. --------
      • Custom script: call TriggerRegisterDeathEvent(gg_trg_XItemDied, udg_item)
      • -------- NOTE: Triggers also have their global variable, just as the claws of attack item. However, they use the gg_trg_ prefix. --------
      • -------- See XItemDied trigger --------
When such item dies, I create a thunder clap effect at its position.
  • XItemDied
    • Events
    • Conditions
    • Actions
      • -------- I'm using a point (UDG) variable in order to store the position where the widget died --------
      • -------- GetTriggerWidget = Item/Unit/Destructible that just died. --------
      • Custom script: set udg_point = Location(GetWidgetX(GetTriggerWidget()), GetWidgetY(GetTriggerWidget()))
      • Special Effect - Create a special effect at point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_point)
You can also use other functions in order to register multiple items to that trigger, but remember that you can't remove them from an event/trigger with ease. The "event list" size grows as you add more items to a trigger. I'm not certain about performance issues caused by that specific event/scenario, so I can't say anything about it. I believe you should be fine anyway, as you wouldn't get past hundreds of registered items at once.
 
Status
Not open for further replies.
Top