1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Problem with an attack order trigger

Discussion in 'Triggers & Scripts' started by Qrom Bellascream, Jan 4, 2018.

  1. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    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
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,226
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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
     
  3. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    I'll try it out
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,805
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Units have a decay time during which they still exist and have a location. As such you also need to test if they are alive as IcemanBo's trigger shows otherwise the zombies will try and attack the corpses.
     
  5. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    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
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,226
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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.