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

[Solved] Moving Unit Group to XY Location

Status
Not open for further replies.
Level 12
Joined
May 7, 2008
Messages
327
EDIT: Case closed, you can find the solution by reading the thread.


Hi gang,


I've been stuck on this problem of mine for a while and I guess I need help again :)

What I'm trying to accomplish is that after a certain period of time, I select every unit owned by player 1 and moving them in a certain region.

I want to do this for every player, however every players gets moved to a different region.

Example below:

  • MovePlayers
    • Events
    • Conditions
    • Actions
      • Set VariableSet RedRegion = (Center of RedPlayer <gen>)
      • Set VariableSet BlueRegion = (Center of BluePlayer <gen>)
      • Set VariableSet TealRegion = (Center of TealPlayer <gen>)
      • Set VariableSet PurpleRegion = (Center of PurplePlayer <gen>)
      • Set VariableSet YellowRegion = (Center of YellowPlayer <gen>)
      • Set VariableSet GreenRegion = (Center of GreenPlayer <gen>)
      • -------- - --------
      • Set VariableSet Player1Charge = (Units owned by Player 1 (Red) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player2Charge = (Units owned by Player 2 (Blue) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player3Charge = (Units owned by Player 3 (Teal) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player4Charge = (Units owned by Player 4 (Purple) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player5Charge = (Units owned by Player 5 (Yellow) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player7Charge = (Units owned by Player 7 (Green) matching (((Picked unit) is A structure) Equal to False).)
      • -------- - --------
      • Set VariableSet Point = (Center of KingMoveCinematic <gen>
      • Unit Group - Pick every unit in Player1Charge and do (Unit - Move (Picked unit) instantly to RedRegion, facing Point)
      • Unit Group - Pick every unit in Player2Charge and do (Unit - Move (Picked unit) instantly to BlueRegion, facing Point)
      • Unit Group - Pick every unit in Player3Charge and do (Unit - Move (Picked unit) instantly to TealRegion, facing Point)
      • Unit Group - Pick every unit in Player4Charge and do (Unit - Move (Picked unit) instantly to PurpleRegion, facing Point)
      • Unit Group - Pick every unit in Player5Charge and do (Unit - Move (Picked unit) instantly to YellowRegion, facing Point)
      • Unit Group - Pick every unit in Player7Charge and do (Unit - Move (Picked unit) instantly to GreenRegion, facing Point)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_RedRegion)
      • Custom script: call RemoveLocation(udg_BlueRegion)
      • Custom script: call RemoveLocation(udg_TealRegion)
      • Custom script: call RemoveLocation(udg_PurpleRegion)
      • Custom script: call RemoveLocation(udg_YellowRegion)
      • Custom script: call RemoveLocation(udg_GreenRegion)
      • -------- - --------
      • Custom script: call DestroyGroup(udg_Player1Charge)
      • Custom script: call DestroyGroup(udg_Player2Charge)
      • Custom script: call DestroyGroup(udg_Player3Charge)
      • Custom script: call DestroyGroup(udg_Player4Charge)
      • Custom script: call DestroyGroup(udg_Player5Charge)
      • Custom script: call DestroyGroup(udg_Player7Charge)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_Point)
      • -------- - --------
      • Custom script: call DestroyTrigger(GetTriggeringTrigger())

This works, however it moves buildings too, which I don't want. I only need units like Footman, Knights, Heroes, etc (anything other than towers or buildings basically).

Tried giving the buildings mechanical classification, doesn't work either, they still get moved.
 
Last edited by a moderator:
Level 25
Joined
Sep 26, 2009
Messages
2,378
You would need a region array. Set regions into the array in such order that the index in the array matches player's number.
E.g. "regions[1] = RedPlayer <gen>", since player's 1 Red's index is "1".

Then you would use a loop mechanism or a player group to iterate over each player
  • Pick every unit belonging to picked player
  • Order each unit to move to center of regions[picked_player's_index]
 
Level 12
Joined
May 7, 2008
Messages
327
You would need a region array. Set regions into the array in such order that the index in the array matches player's number.
E.g. "regions[1] = RedPlayer <gen>", since player's 1 Red's index is "1".

Then you would use a loop mechanism or a player group to iterate over each player
  • Pick every unit belonging to picked player
  • Order each unit to move to center of regions[picked_player's_index]

Thanks for the reply. I've did as you suggested, but I'm not sure if I did it the right way.

The buildings get moved just like before, and I get an error for clearing region array leak which I don't know how to clean precisely.

  • RegionArray
    • Events
    • Conditions
    • Actions
      • Set VariableSet RegionArray[1] = RedPlayer <gen>
      • Set VariableSet RegionArray[2] = BluePlayer <gen>
      • Set VariableSet RegionArray[3] = TealPlayer <gen>
      • Set VariableSet RegionArray[4] = PurplePlayer <gen>
      • Set VariableSet RegionArray[5] = YellowPlayer <gen>
      • Set VariableSet RegionArray[7] = GreenPlayer <gen>
      • -------- - --------
      • Set VariableSet Player1Charge = (Units owned by Player 1 (Red) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player2Charge = (Units owned by Player 2 (Blue) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player3Charge = (Units owned by Player 3 (Teal) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player4Charge = (Units owned by Player 4 (Purple) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player5Charge = (Units owned by Player 5 (Yellow) matching (((Picked unit) is A structure) Equal to False).)
      • Set VariableSet Player7Charge = (Units owned by Player 7 (Green) matching (((Picked unit) is A structure) Equal to False).)
      • -------- - --------
      • Unit Group - Pick every unit in Player1Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[1]), facing Point)
      • Unit Group - Pick every unit in Player2Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[2]), facing Point)
      • Unit Group - Pick every unit in Player3Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[3]), facing Point)
      • Unit Group - Pick every unit in Player4Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[4]), facing Point)
      • Unit Group - Pick every unit in Player5Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[5]), facing Point)
      • Unit Group - Pick every unit in Player7Charge and do (Unit - Move (Picked unit) instantly to (Center of RegionArray[7]), facing Point)
      • -------- - --------
      • Custom script: call RemoveLocation(udg_RegionArray[ 1 ])
      • Custom script: call RemoveLocation(udg_Point)
      • -------- - --------
      • Custom script: call DestroyGroup(udg_Player1Charge)
      • Custom script: call DestroyGroup(udg_Player2Charge)
      • Custom script: call DestroyGroup(udg_Player3Charge)
      • Custom script: call DestroyGroup(udg_Player4Charge)
      • Custom script: call DestroyGroup(udg_Player5Charge)
      • Custom script: call DestroyGroup(udg_Player7Charge)
      • -------- - --------
Tried with the ''units owned by x player'' in lets say player1charge group and still the buildings get moved.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
ok, I missed the part with moving structures - That happens because in your condition you use "(Picked unit) is A structure", but there is no (Picked unit) - it should actually be "(Matching unit) is A structure".

Why your code fails to "clean region leak" is because the "RemoveLocation" function accepts an object of type "point" as its parameter, but what you are giving it is an object of type "region"

As for the triggers, here I assumed that you may want to do more with same set of players (1,2,3,4,5,7), so I created and initialized a player group at map initialization, same with the region array:
  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Add Player 1 (Red) to PlayerGroup
      • Player Group - Add Player 2 (Blue) to PlayerGroup
      • Player Group - Add Player 3 (Teal) to PlayerGroup
      • Player Group - Add Player 4 (Purple) to PlayerGroup
      • Player Group - Add Player 5 (Yellow) to PlayerGroup
      • Player Group - Add Player 7 (Green) to PlayerGroup
      • Set VariableSet RegionsArray[1] = Red Player <gen>
      • Set VariableSet RegionsArray[2] = Blue Player <gen>
      • Set VariableSet RegionsArray[3] = Teal Player <gen>
      • Set VariableSet RegionsArray[4] = Purple Player <gen>
      • Set VariableSet RegionsArray[5] = Yellow Player <gen>
      • Set VariableSet RegionsArray[7] = Green Player <gen>

The actual trigger that moves units can then be simplified to the following:
  • MoveToRegions
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet loc = (Center of RegionsArray[(Player number of (Picked player))])
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Picked player) matching (((Matching unit) is A structure) Equal to False).) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to loc
          • Custom script: call RemoveLocation(udg_loc)
 
Level 12
Joined
May 7, 2008
Messages
327
ok, I missed the part with moving structures - That happens because in your condition you use "(Picked unit) is A structure", but there is no (Picked unit) - it should actually be "(Matching unit) is A structure".

Why your code fails to "clean region leak" is because the "RemoveLocation" function accepts an object of type "point" as its parameter, but what you are giving it is an object of type "region"

As for the triggers, here I assumed that you may want to do more with same set of players (1,2,3,4,5,7), so I created and initialized a player group at map initialization, same with the region array:
  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Add Player 1 (Red) to PlayerGroup
      • Player Group - Add Player 2 (Blue) to PlayerGroup
      • Player Group - Add Player 3 (Teal) to PlayerGroup
      • Player Group - Add Player 4 (Purple) to PlayerGroup
      • Player Group - Add Player 5 (Yellow) to PlayerGroup
      • Player Group - Add Player 7 (Green) to PlayerGroup
      • Set VariableSet RegionsArray[1] = Red Player <gen>
      • Set VariableSet RegionsArray[2] = Blue Player <gen>
      • Set VariableSet RegionsArray[3] = Teal Player <gen>
      • Set VariableSet RegionsArray[4] = Purple Player <gen>
      • Set VariableSet RegionsArray[5] = Yellow Player <gen>
      • Set VariableSet RegionsArray[7] = Green Player <gen>

The actual trigger that moves units can then be simplified to the following:
  • MoveToRegions
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet loc = (Center of RegionsArray[(Player number of (Picked player))])
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Picked player) matching (((Matching unit) is A structure) Equal to False).) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to loc
          • Custom script: call RemoveLocation(udg_loc)

Thanks for the quick and awesome reply, I appreciate the help! I will test this out and edit once I confirm that it's working :p

EDIT:

Did everything as you wrote down, but weird thing is only heroes get moved instantly, units are left behind for some reason. I also thought what if I train another unit after map initialization, does the code you provided register them afterwards and move them to the desired place?

Also, I have to move my units facing a certain point in a random spot in xy region, since they are supposed to encounter undead armies in my cinematic :p

  • Move Units Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Add Player 1 (Red) to PlayerGroup
      • Player Group - Add Player 2 (Blue) to PlayerGroup
      • Player Group - Add Player 3 (Teal) to PlayerGroup
      • Player Group - Add Player 4 (Purple) to PlayerGroup
      • Player Group - Add Player 5 (Yellow) to PlayerGroup
      • Player Group - Add Player 7 (Green) to PlayerGroup
      • -------- - --------
      • Set VariableSet RegionArray[1] = RedPlayer <gen>
      • Set VariableSet RegionArray[2] = BluePlayer <gen>
      • Set VariableSet RegionArray[3] = TealPlayer <gen>
      • Set VariableSet RegionArray[4] = PurplePlayer <gen>
      • Set VariableSet RegionArray[5] = YellowPlayer <gen>
      • Set VariableSet RegionArray[7] = GreenPlayer <gen>

  • Move Units
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet loc = (Random point in RegionArray[(Player number of (Picked player))])
          • Set VariableSet Point = (Center of Low HP King 1 <gen>)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Picked player) matching (((Matching unit) is A structure) Equal to False).) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to loc, facing Point
              • Custom script: call RemoveLocation(udg_loc)
              • Custom script: call RemoveLocation(udg_Point)
So to summarize the following problems as of now:

1) only Heroes get moved instantly
 
Last edited by a moderator:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
In the Move Units trigger you're removing the locations inside of the Pick every unit function. Take the very last 2 Actions and move them to BELOW the Pick every unit function, so they're not inside of it.

Once you Remove loc it no longer exists. So the first (Picked unit) gets moved there, then loc gets removed, and then the rest of the (Picked units) try to move to loc but it no longer exists.
 
Last edited:
Level 12
Joined
May 7, 2008
Messages
327
In the Move Units trigger you're removing the locations inside of the Pick every unit function. Take the very last 2 Actions and move them to BELOW the Pick every unit function, so they're not inside of it.

Oh, I didn't even spot that was the problem, works now!


EDIT: it seems that the unit still get grouped after moving instantly at the center of the region instead of random points, any solution to that?


  • Move Units
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet loc = (Random point in RegionArray[(Player number of (Picked player))])
          • Set VariableSet Point = (Center of Low HP King 1 <gen>)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by (Picked player) matching (((Matching unit) is A structure) Equal to False).) and do (Actions)
            • Loop - Actions
              • Unit - Move (Picked unit) instantly to loc, facing Point
          • Custom script: call RemoveLocation(udg_loc)
          • Custom script: call RemoveLocation(udg_Point)

 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Currently you're setting loc once for each PLAYER in PlayerGroup. If you want loc to be a random spot for each UNIT then move it to inside of the Pick every unit function. If you do this then you'll want to move the Remove loc action back to where it originally was. The rule is whenever you Set a Point (location) you need to Remove it before Setting it again, unless you plan on keeping that Point around all game.

In other words:
Move the Set Variable loc action to inside of the Pick every unit function as the very first action.
Move the Remove loc action to inside of the Pick every unit function as the very last action.
 
Last edited:
Level 12
Joined
May 7, 2008
Messages
327
Currently you're setting loc once for each PLAYER in PlayerGroup. If you want loc to be a random spot for each UNIT then move it to inside of the Pick every unit function. If you do this then you'll actually want to move the Remove loc action back to where it originally was. The rule is whenever you Set a Point (location) you need to Remove it before Setting it again, unless you plan on keeping that Point around all game.

In other words:
Move the Set Variable loc action to inside of the Pick every unit function as the very first action.
Move the Remove loc action to inside of the Pick every unit function as the very last action.

Everything works as of now, thanks for that Uncle and of course Nichilus!

Here's a small picture of what I'm working on before I case this thread as solved :p



[CASE CLOSED]
 
Status
Not open for further replies.
Top