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

[Trigger] i need help with a trigger, trying to cancle an action when...

Status
Not open for further replies.
Level 4
Joined
Apr 19, 2009
Messages
42
so heres the build

Events
Unit - A unit Beginds casting an ability

Conditions
And - All (Conditions) are true
Conditions
((Triggering unit) is in (Units of type Footman)) Equal to True
(((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
(Ability being cast) Equal to Battle Roar

Actions
Wait 120.00 seconds
Create 1 Footman for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees


i wanna know how to make it so when triggering unit exits a regrion is cancles the stuff under actions
 
Level 1
Joined
Jun 2, 2009
Messages
2
I'm guessing your problem is the Wait 120.00 seconds since the hero/unit may have left the region. I suggest you use If/Endif after the Wait to see if the unit is there still. And you should set the Triggering unit into a temp variable and its location to a temp loc to prevent leaks.

  • Events
  • Unit - A unit Begins casting an ability
  • Conditions
  • And - All (Conditions) are true
  • Conditions
  • ((Triggering unit) is in (Units of type Footman)) Equal to True
  • (((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
  • (Ability being cast) Equal to Battle Roar
  • Actions
  • Wait 120.00 seconds
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
  • ((Triggering unit) is in (Units of type Footman)) Equal to True
  • (((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
  • (Ability being cast) Equal to Battle Roar
    • Then - Actions
  • Create 1 Footman for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
    • Else - Actions
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I'm going to build this up slowly, in a few steps.

First of all: trigger tags!

(trigger tags are actually better than what you did, since I think you've written the whole code, now if you right click the trigger name above "event" inside the trigger editor, you can use "copy as text", then paste it here and add [trigger ] - [/trigger] around it).

  • Trigger
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • And - All (Conditions) are true
      • Conditions
        • ((Triggering unit) is in (Units of type Footman)) Equal to True
        • (((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
        • (Ability being cast) Equal to Battle Roar
  • Actions
    • Wait 120.00 seconds
    • Unit - Create 1 Footman for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
Right, now we can continue...

Then: Remove the leak!


  • Trigger
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • And - All (Conditions) are true
      • Conditions
        • ((Triggering unit) is in (Units of type Footman)) Equal to True
        • (((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
        • (Ability being cast) Equal to Battle Roar
  • Actions
    • Wait 120.00 seconds
    • Set TempLoc = (Position of (Triggering unit))
    • Unit - Create 1 Footman for Player 1 (Red) at TempLoc facing Default building facing degrees
    • Custom script: call RemoveLocation(udg_TempLoc)
allright, this trigger won't cause lag anymore now, great...
Now what do we want? We want to check if the casting unit is in a certain region, then we shall check that.

But: we can't do that yet, because we will need to set a variable to the casting unit and the created unit...
Otherwise we cannot recall them anymore


  • Trigger (actions only)
  • Actions
    • Set Caster[Player number of (Owner of Triggering Unit)] = Casting Unit
    • Wait 120.00 seconds
    • Set TempLoc = (Position of (Triggering unit))
    • Unit - Create 1 Footman for Player 1 (Red) at TempLoc facing Default building facing degrees
    • Set Summon[Player number of (Owner of Triggering Unit)] = Last Created Unit
    • Custom script: call RemoveLocation(udg_TempLoc)
Let's check the status:
  • We've got trigger tags to make it more clear
  • We've removed the leaks, to avoid lag
  • We've set a few variables to the units, that way we can recall them in other triggers

Hmm... the last point is interesting... "recall them in other triggers", so we can create a trigger and we can check the status of those units.
Let's do that, shall we?

First, create a trigger (name it to whatever you want)

Now... how do we check the status of every unit assigned to the variable "caster[player number]"?
It would take a lot of triggers if we would add the actual condition we need in the conditions-part of the trigger, so we won't do that ;)

  • Check
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (amount of players), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Region 2 contains Caster[(Player number of (Player((Integer A))))]) Equal to False
              • Caster[(Player number of (Player((Integer A))))] Not equal to No unit
            • Then - Actions
            • Else - Actions
All right, set the "(amount of players)" in the for each integer A to the last player that can use this ability (if red, blue and brown can use it, the integer needs to be "12").

Notes:
  • "Region contains unit" can be found in the list with boolean conditions
  • "(Player number of (Player((Integer A))))" can be found: first just use "Player Number", then where the "(Triggering Player)" is, use "Conversion - Convert Player Index to Player"

Now we know exactly when the casting unit leaves the region, we will add the last things.


  • Next Trigger
  • Check
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Playable map area) contains Caster[(Player number of (Player((Integer A))))]) Equal to False
              • Caster[(Player number of (Player((Integer A))))] Not equal to No unit
            • Then - Actions
              • Unit - Remove Summon[Player number of (Player((Integer A))))] from the game
              • Set Caster[(Player number of (Player((Integer A))))]) = No unit
            • Else - Actions
This speaks for itself, we need to remove the summoned unit and the casting unit isn't the casting unit anymore.

Complete Triggers:


  • Trigger
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • And - All (Conditions) are true
      • Conditions
        • ((Triggering unit) is in (Units of type Footman)) Equal to True
        • (((Triggering unit) is in (Units in Region 1)) Equal to True) or (((Triggering unit) is in (Units in Region 2)) Equal to True)
        • (Ability being cast) Equal to Battle Roar
  • Actions
    • Set Caster[Player number of (Owner of Triggering Unit)] = Casting Unit
    • Wait 120.00 seconds
    • Set TempLoc = (Position of (Triggering unit))
    • Unit - Create 1 Footman for Player 1 (Red) at TempLoc facing Default building facing degrees
    • Set Summon[Player number of (Owner of Triggering Unit)] = Last Created Unit
    • Custom script: call RemoveLocation(udg_TempLoc)
  • Next Trigger
  • Check
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Playable map area) contains Caster[(Player number of (Player((Integer A))))]) Equal to False
              • Caster[(Player number of (Player((Integer A))))] Not equal to No unit
            • Then - Actions
              • Unit - Remove Summon[Player number of (Player((Integer A))))] from the game
              • Set Caster[(Player number of (Player((Integer A))))]) = No unit
            • Else - Actions
If you still didn't understand everything, or if this post was too long for you to read, I will explain further, or make it shorter :)
 
Status
Not open for further replies.
Top