| 03-22-2008, 02:16 AM | #1 |
Currently, I want a way to detect damage on "all units." What I've got so far is putting every unit into a unit group and then setting that as a unit variable. However, whenever I use a trigger using "all units," the trigger never activates. Using GUI, I can see no "Damaged Unit;" could this be a problem? And also, is this leakless? If so, how can I prevent leaks? |
| 03-22-2008, 02:28 AM | #2 |
Basically you need to have a system which detects when a new unit enters to the map, create a new trigger with the respective event EVENT_UNIT_DAMAGED, and then add to those triggers an action so they can do something to the damaged units. As is this would leak events and triggers (something unavoidable), but any optimization could be done if you define more specifically how is your map and such. |
| 03-22-2008, 08:18 AM | #4 |
What are you even trying to do? In no way can I see what you posted working. The only thing I can see that doing is adding that EVENT_UNIT_DAMAGED event to the trigger for one (and only one) random unit on the map (whichever unit was the last unit in allunits_ug at 10.00 seconds elapsed gametime). Adding events to triggers doesn't work the way you think it does. As for the "leaks": it's the memory allocated for new events added to a trigger and/or memory allocated for TriggerActions and the triggers themselves. |
| 03-22-2008, 04:08 PM | #5 |
I see. How would I detect damage for any unit on the map then? (I've heard about dynamic triggers and vJASS, although frankly, I have no clue what either one is.) |
| 03-22-2008, 11:46 PM | #6 |
Trigger: Although the fact that u didnt do that in the first place makes me thing that u cant do that, but meh Also, why dont u just have one damage detection trigger, add some conditions to it to see what spell gets used, then make it runn the approptiate trigger. I think that why is better because you are adding only a third of the amount of events |
| 03-23-2008, 12:16 AM | #7 | |
Quote:
|
| 03-23-2008, 07:22 PM | #8 |
Well, I want to use detection to be able to replace "Unit is attacked" (as it can be easily abused), EX: If an archer shot an arrow at a guy 1200 away, the archer's 15% chance to cast Chain Lightning won't fire as soon as the archer attacks, rather, when the archer's arrow hits; and so that I can produce better effects with spells, EX: instead of stunning my target before a projectile even hits, I can stun the target when it takes damage by the projectile (and then make flashy effects if required). |
| 03-25-2008, 07:33 AM | #9 |
Try looking at emjlr3's on attack template, I think it does what you want. It kinda works like a " generic a unit is damaged event ". *Note that there is no Generic unit damage event. |
| 03-25-2008, 09:02 AM | #10 |
You want an attack detection not a damage detection in your case. |
| 03-25-2008, 12:51 PM | #11 | |
Quote:
The easiest way to do that is to have a single "damage detection" trigger and whenever a unit enters playable map area, add a unit takes damage event for that unit to that trigger. The problem with that is that you can't clean up events without destroying the whole trigger, so once units leave the game the event for them will stay in your trigger. Now, I'm not even sure if that's a performance issue at all, but generaly proper damage detection systems avoid this by making a new trigger for every unit and destroying that trigger when the unit dies. Once you do this, you have an equivalent of a generic unit takes damage event trigger. Now, the second part of the challenge is telling apart attack damage from spell damage. One way is to deal all your spell damage with triggers and before you deal it, set a global boolean variable to true, so when the damage detection trigger runs it checks that boolean to see if the damage was caused by a trigger or by another source (in this case, the only source left are attacks), and immediately sets the boolean to false. Another way is to give all units a passive ability that leaves a buff behind when they attack, like slow poison for example. Then, in the damage detect trigger, check if the unit has the buff, if it does then the damage was caused by an attack, then remove the buff. A third method would be to keep track of who's attacking whom and who's casting spells on whom and when damage is dealt, check if the damage source's last action was an attack or a spell cast (might work incorrectly with projectile spells and attacks that take some time to reach the target). |
| 03-28-2008, 08:33 PM | #12 |
I suppose I can't detect whenever a unit enters the map and store it in an array (and then every once in a while, clear the arrays of all dead units)? And how would I make a trigger that makes other triggers? It's cool how far the community's modding capabilities have advanced. |
| 05-14-2008, 05:45 PM | #15 |
You are using WEU's "Any unit takes damage" ... |
