• 🏆 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] Problem with an attack order trigger

Status
Not open for further replies.
Level 6
Joined
Apr 5, 2013
Messages
154
I'm using this trigger for a zombie map, where every 3.00 seconds the zombies attack a nearby player that is ALIVE. The problem here is that the zombies will still choose to attack units/locations where a dead player is if its closer than a live one. Help would be appreciated, every time I try to return to this map I just can't seem to work it out.
  • OrderZombieAttack
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: call RemoveLocation (udg_EP)
      • 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
              • (PlayerUnit[(Integer A)] is alive) Equal to True
            • Then - Actions
              • Custom script: call RemoveLocation (udg_EP_PLAYER[bj_forLoopAIndex])
              • Set EP_PLAYER[(Integer A)] = (Position of PlayerUnit[(Integer A)])
            • Else - Actions
      • Unit Group - Pick every unit in ALLZombies and do (Actions)
        • Loop - Actions
          • Set EP = (Position of (Picked unit))
          • -------- Player 1 --------
          • Set PLAYERNUMBER = 1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[5])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 2 --------
          • Set PLAYERNUMBER = 2
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[5])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 3 --------
          • Set PLAYERNUMBER = 3
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[5])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 4 --------
          • Set PLAYERNUMBER = 4
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[5])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 5 --------
          • Set PLAYERNUMBER = 5
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 6 --------
          • Set PLAYERNUMBER = 6
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Player 7 --------
          • Set PLAYERNUMBER = 7
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[1])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[2])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[3])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[4])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[6])
                  • (Distance between EP and EP_PLAYER[PLAYERNUMBER]) Less than (Distance between EP and EP_PLAYER[7])
            • Then - Actions
              • Unit - Order (Picked unit) to Attack PlayerUnit[PLAYERNUMBER]
            • Else - Actions
          • -------- Idiot Corner --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Idiot Corner <gen> contains (Picked unit)) Equal to True
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units in Idiot Corner <gen>) and do (Actions)
                • Loop - Actions
                  • Unit - Order (Picked unit) to Attack-Move To (Center of REAL <gen>)
            • Else - Actions
 
Create 2 variables:
  • int (integer)
  • real (real
Before ZombieGroup enumerarion
set real = 99999
set int = 0
Inside ZombieGroup enumeration
Loop from 1 to 10
---- If (Distance between UnitPostion and EP_PLAYER[LoopInt] < real AND PlayerUnit[LoopInt] Is Alive) Then
---- ---- set real = Distance between UnitPostion and EP_PLAYER[LoopInt]
---- ---- set int = LoopInt

If (int != 0) Then
---- Attack PLayerUnit[int]

set int = 0
set real = 99999
 
Level 6
Joined
Apr 5, 2013
Messages
154
Should this be about right? It still doesn't work, and i've even made a trigger to check if the units that are being targeted are dead or alive, and they're dead.
  • OrderZombieAttack
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: call RemoveLocation (udg_EP)
      • 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
              • (PlayerUnit[(Integer A)] is alive) Equal to True
            • Then - Actions
              • Custom script: call RemoveLocation (udg_EP_PLAYER[bj_forLoopAIndex])
              • Set EP_PLAYER[(Integer A)] = (Position of PlayerUnit[(Integer A)])
            • Else - Actions
      • Set Int = 0
      • Set Real = 999999.00
      • Unit Group - Pick every unit in ALLZombies and do (Actions)
        • Loop - Actions
          • Set EP = (Position of (Picked unit))
          • 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
                  • And - All (Conditions) are true
                    • Conditions
                      • (Distance between EP and EP_PLAYER[(Integer A)]) Less than Real
                      • (PlayerUnit[(Integer A)] is alive) Equal to True
                • Then - Actions
                  • Set Real = (Distance between EP and EP_PLAYER[(Integer A)])
                  • Set Int = (Integer A)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Int Not equal to 0
                    • Then - Actions
                      • Unit - Order (Picked unit) to Attack PlayerUnit[(Integer A)]
                    • Else - Actions
                • Else - Actions
          • -------- Idiot Corner --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Idiot Corner <gen> contains (Picked unit)) Equal to True
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units in Idiot Corner <gen>) and do (Actions)
                • Loop - Actions
                  • Unit - Order (Picked unit) to Attack-Move To (Center of REAL <gen>)
            • Else - Actions
 
Reset 'int' and 'real' for each picked unit.

How is 'Idiot Corner' related? If (Picked Unit) is inside respective region, no loop checks need to be done.

'And - All Conditions' block can be removed. Just normaly have 2 conditions there.

The concept with saving and removing unit locations seems kind of messy, and is not working properly, by the way. (not removed when unit is dead)
I would recommend to make 2 simple loops, one at trigger start that creates locations for alive playerunits, and one at end of trigger which removes them again.
 
Status
Not open for further replies.
Top