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

How to make "When a unit takes damage..."

Status
Not open for further replies.
Usually theese systems are based on the concept of creating a trigger for each unit on the map, registering a specific "unit takes damage" event to them, and then destroying the trigger once the specific unit dies. Since it is risky to destroy a trigger while it is being used (will cause crash), there is usually a delay of about 20 seconds before the trigger is actually destroyed.
 
Level 4
Joined
Aug 5, 2011
Messages
99
  • Untitled Trigger 001
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Trigger - Add to (some_trigger) the event (Unit - (Triggering unit) Takes damage)
this might be enough for you?
 
^Well, actually the only problem with that is the fact that it will cause a ton of performance problems :/
When a unit leaves the map, the trigger event registration wouldn't get destroyed, and thus, you would have thousands of events registered to one trigger throughout the course of the game.
That's why Bribe's DamageEngine destroys and recreates the DamageEvent trigger every time 15 units are deindexed. (Meaning 15 units leave the map)

It also has some other features like Recursion safety and such.
If you were to damage a unit inside a trigger registered to a Damage event, you would cause the game to crash due to an infinite loop.
That's why Bribe provides you with a boolean that allows you to turn off the damage system, deal the damage, then turn it back on.
 
If you don't have that many units dying in your map, or not many new units placed, the performance loss from the damage event leak is negligable.

Just saying, in my first WiF versions, i used the method heleskiller suggessted, and even after four hours of playing with thousands of units trained, there was no notable effect on performance. It is ofcourse still advisable to use a "real" system in most such cases, since things may add upp as you add more systems and cause you problems.
 
Level 6
Joined
Jun 19, 2010
Messages
143
Destroy Trigger=call DisableTrigger() ? but it means turn off a trigger in GUI, how'd it cause the problem? When not using the trigger we turn it off. Similarly, I think we can DisableTrigger at the beginning of action function & condition function pr at the end of those functions. This is up to us. We can even disable it right after CreateTrigger & Event call. Correct me if I'm wrong at some points.
 
helekiller's method works just fine, no need for a complicated system if you don't need it.

Adding to a trigger the triggering unit takes damage does not effect performance for it does not leak however it does leak in a way, but it does add to a loop which when hits 8191 I think will cause wc3 to auto shutdown. There is ways to get around that without having to destroy triggers/events, the only problem here is how to deal with event leaks.
 
Status
Not open for further replies.
Top