Is there a way to count the number of players in a game? I need to because then I can enable/disable triggers based on the number of players in order to balance the game.
Have you tried to set a player group to all active players, then count the number of players in the group?
There is a fault with this method, I believe. If a player is alt-tabbed during the loading screen (for any length of time), that player won't be added to the Active Players Group. I am uncertain if this has been patched, or whether it is testable through the map editor (ie: testing unpublished maps).
Back in Starcraft 1, you would simply create a unit for each Human player, and if that player didn't 'exist', his units would be removed on map initialisation. Not sure on a 100% fool proof method to reliably get all active players.
That is rather strange. Someone should test it out and confirm it. If I'm not mistaken, it may be possible to check if player slots are used or not as well. That way you could just count the number of used player slots, with the condition of course that the person using the slot is a human and not AI.
I have confirmed this. In my "Initialize Players" action, I loop from 1 to 14 (max number of players in my map) and check to see if Status of Player is not Left The Game AND Status of Player is not Unused. I'm not 100% sure that fixes it, but so far I've not seen the problem since making that change.
FYI this means you can never rely on "Active Players" built-in group. I keep player data in arrays of records and have a lot of loops because I want things to be in order, but if you don't care about order then just create a corrected Player Group that represents the "truly active" players and assign players into this group at the beginning of the game using a similar method that my Initialize Players action uses.
Well I would make a variable that would be called something like AmmountOfPlayers and the just Pick all Active Players and then modify the variable +1.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Is there a way to count the number of players in a game? I need to because then I can enable/disable triggers based on the number of players in order to balance the game.
@N33b: Go
Have you tried to set a player group to all active players, then count the number of players in the group?
@FuzzYD: Go
nope, but good idea, I'm trying it right now
There is a fault with this method, I believe. If a player is alt-tabbed during the loading screen (for any length of time), that player won't be added to the Active Players Group. I am uncertain if this has been patched, or whether it is testable through the map editor (ie: testing unpublished maps).
Back in Starcraft 1, you would simply create a unit for each Human player, and if that player didn't 'exist', his units would be removed on map initialisation. Not sure on a 100% fool proof method to reliably get all active players.
@Nardival: Go
That is rather strange. Someone should test it out and confirm it. If I'm not mistaken, it may be possible to check if player slots are used or not as well. That way you could just count the number of used player slots, with the condition of course that the person using the slot is a human and not AI.
I have confirmed this. In my "Initialize Players" action, I loop from 1 to 14 (max number of players in my map) and check to see if Status of Player is not Left The Game AND Status of Player is not Unused. I'm not 100% sure that fixes it, but so far I've not seen the problem since making that change.
FYI this means you can never rely on "Active Players" built-in group. I keep player data in arrays of records and have a lot of loops because I want things to be in order, but if you don't care about order then just create a corrected Player Group that represents the "truly active" players and assign players into this group at the beginning of the game using a similar method that my Initialize Players action uses.
Well I would make a variable that would be called something like AmmountOfPlayers and the just Pick all Active Players and then modify the variable +1.