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

Spawned units move back to their spawn location after combat

Status
Not open for further replies.
Level 6
Joined
Apr 5, 2013
Messages
154
I'm making a tower defense-esque map where you send your units to fight the AI's units headlong on a long road. But whenever the units are done fighting on the road, they stop moving towards the enemy's base and go back to their spawn location. Here's the script

  • Game Start
    • Events
      • Map initialization
    • Conditions
    • Actions
      • AI - Ignore the guard positions of all Player 5 (Yellow) units
      • AI - Ignore the guard positions of all Player 6 (Orange) units
      • AI - Ignore the guard positions of all Player 7 (Green) units
      • AI - Ignore the guard positions of all Player 8 (Pink) units
      • AI - Ignore the guard positions of all Player 9 (Gray) units
      • AI - Ignore the guard positions of all Player 9 (Gray) units
      • Wait 5.00 seconds
      • -------- WAVE 1 --------
      • Game - Display to (All players) the text: |c001CE6B9Wave 1: S...
      • Wait 5.00 seconds
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Satyr Swine for Player 9 (Gray) at (Center of Region 015 <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Attack-Move To (Center of EnemyAttackZone <gen>)
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Create 1 Wolf Pup for Player 9 (Gray) at (Center of Region 016 <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Attack-Move To (Center of EnemyAttackZone <gen>)
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Wait 2.00 seconds
          • Unit - Create 1 Satyr Swine for Player 9 (Gray) at (Center of Region 016 <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Attack-Move To (Center of EnemyAttackZone <gen>)
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Create 1 Wolf Pup for Player 9 (Gray) at (Center of Region 015 <gen>) facing Default building facing degrees
          • Unit - Order (Last created unit) to Attack-Move To (Center of EnemyAttackZone <gen>)
          • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Wait 2.00 seconds
I don't see anything wrong with it though, hopefully you guys will.
 
Level 21
Joined
Dec 4, 2007
Messages
1,478
Where are you referring to integer A?

Anyway, you probably have to increase the guard distance/guard return distance (something like that) in gameplay constants.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Side note: You have waits inside a loop. This is Bad (tm).

The easiest way to fix is simply unroll the loop, since you're not using Integer A. IE, just copy/paste it the appropriate number of times. If you want to reduce the amount of redundant code, you can put the spawn actions inside an empty trigger with no events or conditions, and then run it using "Trigger - Run (your trigger) (ignoring conditions)".
 
Level 11
Joined
Jun 2, 2004
Messages
849
I forget the full effects but I know that at the very least the loop variable won't be preserved. If you were to use Integer A anywhere else in the entire map, it will affect the loop with a wait in it too (potentially making it last forever, or end early, or such).
 
Level 19
Joined
Apr 21, 2013
Messages
1,194
You probably should remove the leaks created by the points.

  • Set tempLoc1 = (Center of Region 015 <gen>)
  • Unit - Create 1 Satyr Swine for Player 9 (Gray) at (tempLoc1) facing Default building facing degrees
  • call removeLocation(udg_tempLoc1)
remove the waits as well, and use no event triggers and run them from the main trigger as @Kaijyuu suggested. And change the Integer A with a variable as well. ^^
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Why are the waits inside the loop bad? I'm intrigued, but i'll make it like you said, using the trigger run action.
They are not bad. Just many people are confused as to what it means thanks to GUI.

Loops are flow control structures, they execute the body code from start until end and then repeat based on the loop structures. This means that a wait in a loop will run 1 iteration at a time then wait before the next iteration starts. Many people expect GUI loops to run the body actions in parallel and wait in parallel, they do not work like this.

Waits in loops don't work, there's nothing more to it, it just doesn't work, you'll need another solution
Waits in loops do work. Waits in pseudo calls do not work. This means that ForGroup and ForForce does not allow waits in their code argument function, but standard loop/endloop blocks do allow waits.
 
Level 11
Joined
Jun 2, 2004
Messages
849
So there you have it. Definitely don't use a wait in a "pick every x in blah" type loop, only use unique variables (like locals or otherwise unused globals, not Integer A/B) for regular for loops with waits.


For the original question, did making the guard distance in gameplay constants fix your issue? If not, you could also make it so the player isn't computer controlled, which will disable all AI.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Yeah when I said no AI I meant literally no AI. They'll still use autocast things but nothing the computer would cast normally (holy light, etc).

I usually solve the problem by using a computer controller and periodically reissuing the attack move order. Don't do it too often since the order will reset their attack swing timer if they happen to be attacking something.
 
Level 6
Joined
Apr 5, 2013
Messages
154
I tried using the attack move order, on a periodic timer of 2 seconds. It only picks couple of the units though, and most of them still go running back to their spawn point, here's the trigger
  • AttackMove
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 5 (Yellow) matching (((Triggering unit) is A structure) Equal to False)) and do (Unit - Order (Picked unit) to Attack-Move To (Center of Attack Hre <gen>))
      • Unit Group - Pick every unit in (Units owned by Player 6 (Orange) matching (((Triggering unit) is A structure) Equal to False)) and do (Unit - Order (Picked unit) to Attack-Move To (Center of Attack Hre <gen>))
      • Unit Group - Pick every unit in (Units owned by Player 7 (Green) matching (((Triggering unit) is A structure) Equal to False)) and do (Unit - Order (Picked unit) to Attack-Move To (Center of Attack Hre <gen>))
      • Unit Group - Pick every unit in (Units owned by Player 8 (Pink) matching (((Triggering unit) is A structure) Equal to False)) and do (Unit - Order (Picked unit) to Attack-Move To (Center of Attack Hre <gen>))
      • Unit Group - Pick every unit in (Units owned by Player 9 (Gray) matching (((Triggering unit) is A structure) Equal to False)) and do (Unit - Order (Picked unit) to Attack-Move To (Center of EnemyAttackZone <gen>))
 
Last edited:
There is no problems with waits in loops as long as you do not re-declare variables. Since the game automatically re-declare globals like GetTriggerUnits() (I assume they're globals, or functions that retrieve memory), you'll have to store them in locals, or globals if you're limited to GUI. That is the only problem with waits.


Well, waits is bad in general, but that is not related to loops.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Ok, Might've worded my last question a bit badly here's a better try; how do you remove the guard duty from an unit? Couldn't find it
Try some of the AI actions.
There is no problems with waits in loops as long as you do not re-declare variables. Since the game automatically re-declare globals like GetTriggerUnits() (I assume they're globals, or functions that retrieve memory), you'll have to store them in locals, or globals if you're limited to GUI. That is the only problem with waits.
They are actually stored on the stack already so have nothing to do with globals. Just there is a bug that some of them get corrupted after TriggerSleepAction.
 
Status
Not open for further replies.
Top