Hello all, long time dabbler first time forum poster here, I have a question for finding a variable for trigger use. I have a funny asymmetric melee style map I'm making with different spawn locations with unique base mechanics.
I need to find the player who spawned at each base for trigger purposes. I have very dodgy methods at the moment, like detecting initial worker movement, but that wont work for some of the funnier bases without mineral patches (other means of income). The locations are assigned randomly, so lobby things will not work
How do I get the player (or none) that spawned at a particular Start Location?
When you think something like this, you must create a variable as a table (a matrix with 1 dimension). I called it "PlayerStartLocations".
What you may know is that Start Locations are a certain type of points.
Events Game - Map initialization
Local variables i = 0 <Integer> radius = 10 <Integer(Constant)> points = No Point <Point[4]> groups = (Empty unit group) <Unit Group[4]>
Conditions
Actions General - Action Group: "init points" Actions Variable - Set points[1] = Start location 001 Variable - Set points[2] = Start location 002 Variable - Set points[3] = Start location 003 Variable - Set points[4] = Start location 004 General - For each integer i from 1 to 4 with increment 1, do (Actions) Actions Unit Group - Add all units in (Any units in (Region(points[i], radius)) owned by player Any Player matching Excludes : Dead, Hidden, Missile, with at most Any Amount) to groups[i] General - If (Conditions) then do (Actions) else do (Actions) If (Number of Living units in groups[i]) > 0 Then Variable - Set PlayerStartLocations[i] = (Owner of (Random Living unit from groups[i])) Else
To explain what this does :
- For each points (= start locations), find any units around the point within 10 squares.
- If the unit group has at least 1 unit, we get the unit to retrieve its owner.
Thanks for the reply. Works great! I had a similar idea but wasn't sure if there was a straight up function to get the starting location in a much simpler way.
I might just set my starting units/orders and locations manually (but still random) anyway, due to unique cases
I imagined that you would do something with player's units, so I opened it for you.
However, if you want something even shorter than that (and that's something I utterly forgotten in the answer), you can use the function expecting a point instead :
Player - Start location of player
Which simplifies the previous script :
Player Group - Pick each player in (Active Players) and do (Actions) Actions Variable - Set PlayerStartLocations[(Picked player)] = (Start location of player (Picked player))
Note 1 : Whether the order it gets from the pick order, the table stays in order since the index P is player P.
Note 2 : No player = No point.
Note 3 : If this returns an error because the Start location has no player, insert a "if" that checks "No point" from the returned value.
Combine and replace some of the previous script with this loop, and you will get a stronger one.
Hello all, long time dabbler first time forum poster here, I have a question for finding a variable for trigger use. I have a funny asymmetric melee style map I'm making with different spawn locations with unique base mechanics.
I need to find the player who spawned at each base for trigger purposes. I have very dodgy methods at the moment, like detecting initial worker movement, but that wont work for some of the funnier bases without mineral patches (other means of income). The locations are assigned randomly, so lobby things will not work
How do I get the player (or none) that spawned at a particular Start Location?
Hello,
Let's take a 4 players example :
1 -> 4
2 -> 2
3 -> 1
4 -> 3
When you think something like this, you must create a variable as a table (a matrix with 1 dimension). I called it "PlayerStartLocations".
What you may know is that Start Locations are a certain type of points.
To explain what this does :
- For each points (= start locations), find any units around the point within 10 squares.
- If the unit group has at least 1 unit, we get the unit to retrieve its owner.
- We save the integer.
- A 0-value means no player on the location.
Have a good day !
In reply to Phosphatidylinositol_:
Thanks for the reply. Works great! I had a similar idea but wasn't sure if there was a straight up function to get the starting location in a much simpler way.
I might just set my starting units/orders and locations manually (but still random) anyway, due to unique cases
I imagined that you would do something with player's units, so I opened it for you.
However, if you want something even shorter than that (and that's something I utterly forgotten in the answer), you can use the function expecting a point instead :
Player - Start location of player
Which simplifies the previous script :
Note 1 : Whether the order it gets from the pick order, the table stays in order since the index P is player P.
Note 2 : No player = No point.
Note 3 : If this returns an error because the Start location has no player, insert a "if" that checks "No point" from the returned value.
Combine and replace some of the previous script with this loop, and you will get a stronger one.
Have a nice day.