• 🏆 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] Get units to attack nearest unit without returning to spawn point

Status
Not open for further replies.
Level 4
Joined
Feb 9, 2010
Messages
48
Greetings,

I need to create following mechanics, where over time, at every 'Demonic Sundering' unit, a group of neutral-hostile units will spawn, and will go attack nearest non-neutral-hostile control point. After they destroy the CP, they will be again issues to attack nearest non-neutral-hostile control point.

The trigger when demons spawn:
  • Demonic Sunderings spawning demons
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) the text: |cffff0000WARNING:|...
      • Sound - Play CoVQuestFailed <gen>
      • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Demonic Sundering))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set TempLoc = (Position of (Picked unit))
          • Set TempReal = 100000000.00
          • Set Temp_Group = (Units in (Playable map area) matching ((((Unit-type of (Matching unit)) Equal to Control Point (15g)) or (((Unit-type of (Matching unit)) Equal to Control Point (20g)) or (((Unit-type of (Matching unit)) Equal to Control Point (25g)) or ((Unit-type of (Match
          • Unit Group - Pick every unit in Temp_Group and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of (Picked unit)) Not equal to Neutral Hostile
                • Then - Actions
                  • Set TempPos = (Position of (Picked unit))
                  • Set TempReal2 = (Distance between TempLoc and TempPos)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TempReal2 Less than TempReal
                    • Then - Actions
                      • Custom script: call RemoveLocation (udg_TempPos2)
                      • Set TempPos2 = (Position of (Picked unit))
                      • Set TempReal = TempReal2
                    • Else - Actions
                  • Custom script: call RemoveLocation (udg_TempPos)
                • Else - Actions
          • Custom script: call DestroyGroup (udg_Temp_Group)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 2) Equal to 1
            • Then - Actions
              • Unit - Create 1 Vozhal Warrior [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Warrior [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Stalker [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Stalker [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Stalker [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Demoness [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Demoness [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
            • Else - Actions
              • Unit - Create 1 Vozhal Warrior [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Warrior [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Warrior [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Voidwalker [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Voidwalker [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Sorcerer [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
              • Unit - Create 1 Vozhal Sorcerer [lvl 1 ruptures] for Neutral Hostile at TempLoc facing Default building facing degrees
              • AI - Ignore (Last created unit)'s guard position
              • Unit - Set the custom value of (Last created unit) to 2
              • Unit - Order (Last created unit) to Attack-Move To TempPos2
          • Custom script: call RemoveLocation (udg_TempLoc)
          • -------- TempPos2 = Location of nearest CP --------
          • Custom script: call RemoveLocation (udg_TempPos2)
      • Custom script: call DestroyGroup (udg_TempGroup)
The trigger when CP is killed by one of the spawnt demons:
  • CP dies by Demons
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Custom value of (Killing unit)) Equal to 2
      • (Owner of (Killing unit)) Equal to Neutral Hostile
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Control Point (15g)
          • (Unit-type of (Triggering unit)) Equal to Control Point (20g)
          • (Unit-type of (Triggering unit)) Equal to Control Point (25g)
          • (Unit-type of (Triggering unit)) Equal to Control Point (35g)
          • And - All (Conditions) are true
            • Conditions
              • ((Triggering unit) is A structure) Equal to True
              • ((Triggering unit) is An Ancient) Equal to True
              • ((Triggering unit) is A sapper) Equal to True
              • ((Triggering unit) is A town-hall-type unit) Equal to True
    • Actions
      • Set TempLoc = (Position of (Triggering unit))
      • Set TempGroup = (Units within 1000.00 of TempLoc matching (((Owner of (Matching unit)) Equal to Neutral Hostile) and ((Custom value of (Matching unit)) Equal to 2)))
      • Set TempReal = 100000000.00
      • Set Temp_Group = (Units in (Playable map area) matching ((((Unit-type of (Matching unit)) Equal to Control Point (15g)) or (((Unit-type of (Matching unit)) Equal to Control Point (20g)) or (((Unit-type of (Matching unit)) Equal to Control Point (25g)) or ((Unit-type of (Match
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Picked unit)) Not equal to Neutral Hostile
            • Then - Actions
              • Set TempPos = (Position of (Picked unit))
              • Set TempReal2 = (Distance between TempLoc and TempPos)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempReal2 Less than TempReal
                • Then - Actions
                  • Custom script: call RemoveLocation (udg_TempPos2)
                  • Set TempPos2 = (Position of (Picked unit))
                  • Set TempReal = TempReal2
                • Else - Actions
              • Custom script: call RemoveLocation (udg_TempPos)
            • Else - Actions
      • Custom script: call DestroyGroup (udg_Temp_Group)
      • Custom script: call RemoveLocation (udg_TempLoc)
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • AI - Ignore (Picked unit)'s guard position
          • Unit - Order (Picked unit) to Attack-Move To TempPos2
      • Custom script: call DestroyGroup (udg_TempGroup)
      • Custom script: call RemoveLocation (udg_TempPos2)
The problem I have here is that the units will return to their spawn location after taking few shots/attacks from players. Despite me using the action 'AI - ignore unit's guard position', the units will proceed to return to their spawn location.

I cannot change the 'Guard Distance' in settings to infinite, as I also have creep camps in map, and I need them to stay on point instead of chasing after the player for whole map. I had hopes the AI - Ignore guard position will help me out, but it was unsuccesful.

Any ideas how to fix the problem?
 
Level 4
Joined
Feb 9, 2010
Messages
48
Periodicly order the units to attack the nearest ControlPoint. Each second, for example.

Then, obviously they will attack the nearest control point, and then automatcialy, when one is destroyed, they will also attack the next closest one.
If I did that, the map would lag as hell, as every second around ~30 units would do group to find nearest CP to get the attack-move command. No, that's not an option.


do not use neutral hostile for new spawned units (stationary creep camps are fine)
use other free slot instead
make neutral hostile and this new owner of spawned groups ally

I'm planning to use every player spot for players. Or do you mean that I should spawn them as Player1 units, issue the command, and then change owner?
 
You mean looping through 30 units each second is no option? It's nothing.

I had this problem before and found that even this was not enough. What i ended up doing was using a player slot for the creeps, because neutral hostile units usually insist on guarding no matter what and i don't think you can get rid of this.
 
Status
Not open for further replies.
Top