Search Unity

Teams choose

Discussion in 'Scripting' started by AgainstTime, May 5, 2010.

  1. AgainstTime

    AgainstTime

    Joined:
    Apr 14, 2010
    Posts:
    84
    Hey, I'm developing a mmo game , and I wanted to ask you how to random choose whether the player goes to red team/blue team depending on the players ammount.
    psuedo codes will be awesome.
     
  2. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Well, you could do something like this:
    Code (csharp):
    1.  
    2. var probability = redPlayers / totalPlayers : float;
    3. if (Random.value > probability)
    4.     // the player gets the red color
    5. else
    6.     // the player gets the blue color
    7.  
    This means that if there is a similar number of players in both teams, the new player will go to any team absolutely randomly. However, if in one of the teams there are more players, the probability to get into this team is less (and if the number differs a lot, the probability is very small).
     
  3. AgainstTime

    AgainstTime

    Joined:
    Apr 14, 2010
    Posts:
    84
    thank you.