• 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.

Removing an event from a trigger in game

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
I have a spell idea that I think would require an action that allows you to remove an event from a trigger.

IDEA: Stun-shield. Creates a buff on a target unit. Any unit that attacks the buffed unit will be stunned for 3 seconds. There is only one hero who can cast it in my campaign, so it doesn't have to be MUI or anything. There will only ever be 1 unit in the game (at a time) that has the shield on them.

To work, I plan on having two triggers:

Trigger #1: fires when the shield buff is applied to a unit. Adds the event "Unit X is attacked" to Trigger #2.

Trigger #2: Fires when that unit is attacked. Summons an invisible unit to thunderbolt the attacker.

My problem, is how to remove that event when the spell is cast on a second unit? For example, if the spell is cast on a footman, Trigger #2 will fire when that specific footman is attacked. But then the hero casts it on a rifleman. Now I want to the first buff to go away (that's easy to do), but I also want the Event in Trigger #2 to be removed. Is there any way using JASS or custom code to remove an event from a trigger that was put there before?

I could just store the shielded unit as a variable and put a condition in Trigger #2 (does unitX = attacked unit). But if the hero casts the shield on 20 or 40 or 60 units in a given game then Trigger #2 would have 60 events. That could get messy I'd think.

I hope this makes sense, please ask questions if I can clarify.
 
Sadly, you can't remove events specifically. The only way to release the event data is by destroying the actual trigger.

There are a couple of ways to approach this problem. First, there is a generic "unit is attacked" event (I think Daffa meant this--there is no generic "unit takes damage" event). With that, you can detect when any unit is attacked and check if he has the buff. The only issue is that units can do pseudo attacks, where the attack event is fired when the unit doesn't actually deal damage (the unit starts the animation but quickly cancels it). This could be considered a potential bug with your spell. :(

A different option is to use a damage detection system. If you already have one in your map, you can just use that. Just note that this means the thing can fire off of multiple things, such as 0 damage events (you can add a filter for that) or spells.

A third option would be to use an orb system to detect if a unit is attacked.

Eh, there might be some more options too. If you need more information on any one, feel free to post. You'll likely have to make a lot of checks, but it will be worth it in the end.
 
Level 14
Joined
Aug 30, 2004
Messages
909
Thanks for all the options! I've been doing this for a while and hadn't thought of several of those. I'm impressed.

This is a very large campaign and this is only one small spell, so I think the most efficient method is to use the general "A unit is attacked" and put a delay into the counterattack to be sure I don't preemptively stun a unit before it gets its attack off. I can turn the trigger off when the spell is not in use as well, so that will save some of the calculations. I can do a simple condition to check if the attacking unit is melee, so I don't think I'll need a range detector.

Thanks again everyone.
 
Status
Not open for further replies.
Top