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. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. 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.

Spawned units move back to their spawn location after combat

Discussion in 'World Editor Help Zone' started by Qrom Bellascream, Jul 28, 2017.

  1. Qrom Bellascream

    Qrom Bellascream

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

    A]mun

    Joined:
    Dec 4, 2007
    Messages:
    767
    Resources:
    0
    Resources:
    0
    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.
     
  3. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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)".
     
  4. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    Why are the waits inside the loop bad? I'm intrigued, but i'll make it like you said, using the trigger run action.
     
  5. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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).
     
  6. DaneTheBeast

    DaneTheBeast

    Joined:
    Dec 11, 2014
    Messages:
    585
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Waits in loops don't work, there's nothing more to it, it just doesn't work, you'll need another solution
     
  7. NightStalker

    NightStalker

    Joined:
    Apr 21, 2013
    Messages:
    1,193
    Resources:
    5
    Icons:
    4
    Spells:
    1
    Resources:
    5
    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. ^^
     
  8. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,815
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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 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.
     
  9. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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.
     
  10. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    The gameplay constant change didn't work, and having the units moving in being players is kind of essential. Any idea if a "neutral" player would work?
     
  11. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    Nevermind, removing the computer players and making them allied with the real players through triggers worked, and their units function perfectly now too. Thanks Kaijyuu!
     
  12. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    And yet another problem surfaces... The attacking units are no longer casting spells...
     
  13. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,815
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    That is likely because they have no AI. Empty/user slots do not have AI.

    They have to be computer controlled, preferably with running AI, to cast abilities.
     
  14. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    Hmm... Would changing the "Guard Return Time" constant change anything? Since atm it's either working movement with no spells or spells and the guard position returning
     
  15. Kaijyuu

    Kaijyuu

    Joined:
    Jun 2, 2004
    Messages:
    848
    Resources:
    0
    Resources:
    0
    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.
     
  16. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    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: Jul 30, 2017
  17. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,815
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Have you tried removing guarding duty from the created units?
     
  18. Qrom Bellascream

    Qrom Bellascream

    Joined:
    Apr 5, 2013
    Messages:
    150
    Resources:
    0
    Resources:
    0
    Is that in the Unit tab? Or is it even in the trigger menu?
     
  19. HappyTauren

    HappyTauren

    Joined:
    Nov 3, 2006
    Messages:
    8,408
    Resources:
    87
    Models:
    61
    Icons:
    23
    Packs:
    1
    Tutorials:
    2
    Resources:
    87
    Even if you do this the 'most correct way' (by using a custom variable instad of bj_forLoopIndexA/B), waits are still inaccurate, and it adds up in loops.
     
  20. Qrom Bellascream

    Qrom Bellascream

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