Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. function onPlayerRequestSpawn( player )
  2. {
  3.     // pointless to enforce a certain team because there aren't enough players on the server
  4.     if(GetPlayers() < 2)
  5.         return 1;
  6.  
  7.     // array to store teams
  8.     playerTeams <- [];
  9.     local tmpPlayer;
  10.  
  11.     // quick loop to count players on each team
  12.     for(local i = 0; i < GetMaxPlayers(); ++i)
  13.     {
  14.         tmpPlayer = FindPlayer(i);
  15.  
  16.         // check if player is valid
  17.         if(!tmpPlayer)
  18.             continue;
  19.  
  20.         // check if player is spawned or not
  21.         // pointless to check the team of an unspawned player
  22.         if(!tmpPlayer.IsSpawned)
  23.             continue;  
  24.  
  25.         // check against local player
  26.         if(tmpPlayer == player)
  27.             continue;
  28.  
  29.         if(playerTeams[tmpPlayer.Team])
  30.             ++playerTeams[tmpPlayer.Team];
  31.         else
  32.             playerTeams[tmpPlayer.Team] = 1;
  33.     }
  34.  
  35.     // check if the array is empty or not
  36.     if(playerTeams.len() < 1)
  37.         return 1;
  38.  
  39.     // sort using a lambda expression
  40.     playerTeams.sort(@(a,b) a <=> b);
  41.  
  42.     // grab the first item off the array
  43.     local first_team = playerTeams[0];
  44.    
  45.     // switch for efficiency. do your code here
  46.     switch(first_team)
  47.     {
  48.         case 0:
  49.             break;
  50.  
  51.         case 1:
  52.             break;
  53.  
  54.         case 2:
  55.             break;
  56.     }
  57.  
  58.     // return 0, we didn't process the spawn anyway
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement