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

[Trigger] Custom attack spell

Status
Not open for further replies.

sentrywiz

S

sentrywiz

I have a unit without attack. he gains an "attack" spell, that i wish to be cast when a player "right clicks" an enemy unit.

Here's the trigger, but it causes a crash each time. idk what's wrong.

  • test attack
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Target unit of issued order) belongs to an enemy of (Owner of (Ordered unit))) Equal to True
    • Actions
      • Unit - Order (Ordered unit) to Night Elf Druid Of The Talon - Faerie Fire (Target unit of issued order)
p.s - the spell's id is faerie fire. just so you know
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
The problem is an endless loop.
Unit is issued targeting order (event)
Give unit new target order (order cast fairy fire)
Unit is issued targeting order (fired by fairy fire)
Give unit new target order (order new fairy fire)
Unit is issued targeting order
Give unit new target order
etc.
This keeps going on until it eventually crashes the game.

What BloodDrunk meant is this:
Unit is issued targeting order
turn off trigger
Give unit new target order (now it should not trigger the event of this trigger again)
turn on trigger
 
Level 18
Joined
May 11, 2012
Messages
2,103
Yeah, as Nichilus said, this trigger keeps reoccuring infinitely many times.
As this trigger reacts to a unit ordering something, when your unit does that order, since the trigger is on, the event will react to that order, that trigger will reorder the unit to do the same thing. When the trigger reorders the unit to do that, as the unit does that order again, the event will run again et cetera.

To fix this, just put action Turn off this trigger before the action that orders the unit, and then after that ordering action put action that turns this trigger back on.

That way, when the trigger reacts to the order, it will first turn off this trigger, order the unit to do that action (now when the trigger is off, the event won't react to that order), and turn the trigger back on.
 

sentrywiz

S

sentrywiz

Yeah, as Nichilus said, this trigger keeps reoccuring infinitely many times.
As this trigger reacts to a unit ordering something, when your unit does that order, since the trigger is on, the event will react to that order, that trigger will reorder the unit to do the same thing. When the trigger reorders the unit to do that, as the unit does that order again, the event will run again et cetera.

To fix this, just put action Turn off this trigger before the action that orders the unit, and then after that ordering action put action that turns this trigger back on.

That way, when the trigger reacts to the order, it will first turn off this trigger, order the unit to do that action (now when the trigger is off, the event won't react to that order), and turn the trigger back on.

Ooh ok. i knew it was a loop, but didn't understand why.
thanks for the explanation. i will try the suggestion now

EDIT: works as intended. thanks guys. +rep
 
Status
Not open for further replies.
Top