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

Seperate players into two teams?

Status
Not open for further replies.
Level 10
Joined
Nov 5, 2008
Messages
536
Oh, one more thing. I wonder if anyone has an effective way to seperate players into two teams. (player groups)

I use this trigger:

  • Team
    • Events
      • Game - Map initialization
    • Local Variables
      • Team1 = (Empty player group) <Player Group>
    • Conditions
    • Actions
      • Player Group - Add player 1 to Team1
      • Player Group - Add player 2 to Team1
      • Player Group - Add player 3 to Team1
      • Player Group - Add player 4 to Team1
      • Player Group - Add player 5 to Team1
      • Player Group - Add player 6 to Team1
      • Player Group - Add player 7 to Team1
      • Player - Make all players in Team1 treat each other as Ally With Shared Vision
Then a similar trigger for Team2.


It is not good at all because if there are fewer then 7 players they all get in the same team.

I wonder how I can make so 50% of the players get in one team (playergroup A) and 50% get in the other playergroup, no matther how many players who play the game. If there are 5 players, 3 in one team, 2 in the other. 14 players, 7 in team A and 7 in team B, etc.

Any suggestions?
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Well, you can use a construct like this:
  • n = (Number of players in (Active Players))
With (Number of Players) a function that counts the number of players in a Player Group, and the Player Group chosen being (Active Players).
Then just iterate through the group, place the first half into the first team, and the next into the second. If you need a more explicit implementation, just ask :)
 
Level 10
Joined
Nov 5, 2008
Messages
536
If you need a more explicit implementation, just ask :)

I think I need more explicit implementation :)

I don´t mind fighting with triggers so I learn it and become better. But this trigger is so important that I need it to function perfectly, like a clockwork! If I would make this from scratch, experience tells me that I would make something weird with it. And then I would have to come to this thread again and nag about what might be wrong..
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
No problemo. I use additional variables because I wasn't sure players are added ingame in order (being player 1, player 2, player 3 etc.). This trigger simply takes all playable players (no restrictions on their indexes).

  • Untitled Trigger 001
    • Events
      • Game - Map initialization
    • Local Variables
      • k = 1 <Integer>
      • p = 0 <Integer>
      • i = ((Number of players in (Active Players)) / 2) <Integer>
    • Conditions
    • Actions
      • Player Group - For each player p in (Active Players) do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • k <= i
            • Then
              • Player Group - Add player p to set1
            • Else
              • Player Group - Add player p to set2
 
I made a function in my map to do this:
JASS:
void gf_TeamSwitchPlayer (int lp_team, int lp_player) {
    if (lp_team == 1) {
        PlayerGroupRemove(gv_teamB, lp_player);
        PlayerGroupAdd(gv_teamA, lp_player);
    } else {
        PlayerGroupRemove(gv_teamA, lp_player);
        PlayerGroupAdd(gv_teamB, lp_player);
    }
    
    gf_TeamColorChange(gv_teamColorA, gv_teamColorB);
    libNtve_gf_SetPlayerGroupAlliance(gv_allPlayers, c_allianceEnemy);
    libNtve_gf_SetPlayerGroupAlliance(gv_teamA, c_allianceAlly);
    libNtve_gf_SetPlayerGroupAlliance(gv_teamB, c_allianceAlly);
    //DebugMsg("Team Changed");
}

It's a crappy function btw.
 
Status
Not open for further replies.
Top