Im making a kinda risk map in sc2 editor, i have placed cities around the map. how can i randomly split these cities among the players when the game starts?
Basically, you need to use Change Owner for every unit in a certain region.
Actually the question is not complete. There are many options for solving this issue and it all depends on how the units are located on the map, whether there is an AI player on the map and what his number is, the players will start at the starting points or you will distribute units to them. This will greatly change the structure of the algorithm. Therefore, it is desirable to give either a detailed description, or a diagram, or a screen (I don’t know how to put the whole map), or the map itself.
Roughly, the code algorithm would be similar to (below): link to Google Disk I wrote quickly, as there is a lot of text and code. No, there is a lot of code (shit!, sorry) and the structure of the algorithm from the question is not clear.
Global variables
- maxNumberPlayers The maximum player number in the game. If there are only players controlled by the User in the game, then this will mean the number of players in the game. If there is AI, then everything will depend on the settings of the GetUserPlayer function.
- currentPlayers_OfStartLocation Stores player numbers in order. There will be only 8 players, for example, it will be stored as 1, 2, 3, 4, 5, 6, 7, 8 (index 0 is not taken !).
- newPlayers_OfStartLocation Stores the new order of players, which will be returned in the GetNewPoint function. For example 5, 7, 3, 1, 2, 4, 8, 6 (index 0 is not taken !).
- currentPoints_OfStartLocation Stores the start points of the players in order - which start points were given when the map was initialized (index 0 is not taken !).
- newPoints_OfStartLocation Absolutely exactly the same order of storage of start points (index 0 is not taken !). Instead of changing the variable "newPlayers_OfStartLocation" with the GetNewPoint function, you can change this variable "newPoints_OfStartLocation" (change the position of the points, not the players).
- currentGroupPlayers A group of players that plays on a map.
- newGroupPlayers New group of players. More for order. Used in GetNewPoint and can act as a local variable there.
Action functions
- GetUserPlayer We fill in the group of players on the map "currentGroupPlayers" and calculate the maximum number of the player.
- WriteStartLocation We write down for each player in order in variables "currentPlayers_OfStartLocation" - its number "currentPoints_OfStartLocation" - its starting point
- GetNewPoint In order, for each player in the group will calculate the number of Random (random number of the player). If the number is calculated: - random is not equal to the player, - random is in the group of players on the map - random is not in a new group yet , then we write in variables - "newPlayers_OfStartLocation" - random number - "newPoints_OfStartLocation" - player's starting point (will not change) - add random to a new group "newGroupPlayers" - set the flag: we found the right random "_do" = true Thus, now the new player will have a different starting point (but does not mean that he will start at a different starting point when the map is initialized !!!).
- WriteUnits&StructuresToPlayer We list in order the indices (players) in the variables - "newPlayers_OfStartLocation" - player number (new random) - "newPoints_OfStartLocation" - player's starting point Create a region from the starting point of the player (index) Create a group of old player units (index) We list the units in the group and record them as the owner of the new player (newPlayers_OfStartLocation (index) !!!)
- Melee Initialization Running game conditions
- PrintCurrentInfo - PrintNewInfo Used for verification. Display information on starting points for each player from variables.
As you can see from everything above: - We only swap players. You can change the starting points. - It is possible not to calculate the starting points of the players, but to immediately give the players the numbers of the regions from the map, if they are created. The code will be different. - The number of global variables can be drastically reduced by converting them to local ones. Or passing parameters to functions. - Depending on whether you will have starting points for players (this algorithm will work), or they will not exist and you need to distribute units from the regions, you will have to change the code algorithm.
- If you need to add units from regions, then you can have an array of regions (regions themselves or names in a string) and distribute to players after shuffling them. Then, instead of starting points for ishroks, you will have regions stored.
so many thanks qmax! you did so much and really helped me along this projekt! it all works good now, i did some small changes but i would never have got here without you^^
Im making a kinda risk map in sc2 editor, i have placed cities around the map. how can i randomly split these cities among the players when the game starts?
Basically, you need to use Change Owner for every unit in a certain region.
Actually the question is not complete. There are many options for solving this issue and it all depends on how the units are located on the map, whether there is an AI player on the map and what his number is, the players will start at the starting points or you will distribute units to them.
This will greatly change the structure of the algorithm.
Therefore, it is desirable to give either a detailed description, or a diagram, or a screen (I don’t know how to put the whole map), or the map itself.
Roughly, the code algorithm would be similar to (below): link to Google Disk
I wrote quickly, as there is a lot of text and code. No, there is a lot of code (shit!, sorry) and the structure of the algorithm from the question is not clear.
Global variables
- maxNumberPlayers
The maximum player number in the game. If there are only players controlled by the User in the game, then this will mean the number of players in the game. If there is AI, then everything will depend on the settings of the GetUserPlayer function.
- currentPlayers_OfStartLocation
Stores player numbers in order. There will be only 8 players, for example, it will be stored as 1, 2, 3, 4, 5, 6, 7, 8 (index 0 is not taken !).
- newPlayers_OfStartLocation
Stores the new order of players, which will be returned in the GetNewPoint function. For example 5, 7, 3, 1, 2, 4, 8, 6 (index 0 is not taken !).
- currentPoints_OfStartLocation
Stores the start points of the players in order - which start points were given when the map was initialized (index 0 is not taken !).
- newPoints_OfStartLocation
Absolutely exactly the same order of storage of start points (index 0 is not taken !).
Instead of changing the variable "newPlayers_OfStartLocation" with the GetNewPoint function, you can change this variable "newPoints_OfStartLocation" (change the position of the points, not the players).
- currentGroupPlayers
A group of players that plays on a map.
- newGroupPlayers
New group of players. More for order. Used in GetNewPoint and can act as a local variable there.
Action functions
- GetUserPlayer
We fill in the group of players on the map "currentGroupPlayers" and calculate the maximum number of the player.
- WriteStartLocation
We write down for each player in order in variables
"currentPlayers_OfStartLocation" - its number
"currentPoints_OfStartLocation" - its starting point
- GetNewPoint
In order, for each player in the group will calculate the number of Random (random number of the player). If the number is calculated:
- random is not equal to the player,
- random is in the group of players on the map
- random is not in a new group yet
, then we write in variables
- "newPlayers_OfStartLocation" - random number
- "newPoints_OfStartLocation" - player's starting point (will not change)
- add random to a new group "newGroupPlayers"
- set the flag: we found the right random "_do" = true
Thus, now the new player will have a different starting point (but does not mean that he will start at a different starting point when the map is initialized !!!).
- WriteUnits&StructuresToPlayer
We list in order the indices (players) in the variables
- "newPlayers_OfStartLocation" - player number (new random)
- "newPoints_OfStartLocation" - player's starting point
Create a region from the starting point of the player (index)
Create a group of old player units (index)
We list the units in the group and record them as the owner of the new player (newPlayers_OfStartLocation (index) !!!)
- Melee Initialization
Running game conditions
- PrintCurrentInfo
- PrintNewInfo
Used for verification. Display information on starting points for each player from variables.
As you can see from everything above:
- We only swap players. You can change the starting points.
- It is possible not to calculate the starting points of the players, but to immediately give the players the numbers of the regions from the map, if they are created. The code will be different.
- The number of global variables can be drastically reduced by converting them to local ones. Or passing parameters to functions.
- Depending on whether you will have starting points for players (this algorithm will work), or they will not exist and you need to distribute units from the regions, you will have to change the code algorithm.
- If you need to add units from regions, then you can have an array of regions (regions themselves or names in a string) and distribute to players after shuffling them. Then, instead of starting points for ishroks, you will have regions stored.
In reply to qmax2250:
so many thanks qmax!
you did so much and really helped me along this projekt!
it all works good now, i did some small changes but i would never have got here without you^^
Not at all. It was an interesting experience.