Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onPlayerRequestSpawn( player )
- {
- // pointless to enforce a certain team because there aren't enough players on the server
- if(GetPlayers() < 2)
- return 1;
- // array to store teams
- playerTeams <- [];
- local tmpPlayer;
- // quick loop to count players on each team
- for(local i = 0; i < GetMaxPlayers(); ++i)
- {
- tmpPlayer = FindPlayer(i);
- // check if player is valid
- if(!tmpPlayer)
- continue;
- // check if player is spawned or not
- // pointless to check the team of an unspawned player
- if(!tmpPlayer.IsSpawned)
- continue;
- // check against local player
- if(tmpPlayer == player)
- continue;
- if(playerTeams[tmpPlayer.Team])
- ++playerTeams[tmpPlayer.Team];
- else
- playerTeams[tmpPlayer.Team] = 1;
- }
- // check if the array is empty or not
- if(playerTeams.len() < 1)
- return 1;
- // sort using a lambda expression
- playerTeams.sort(@(a,b) a <=> b);
- // grab the first item off the array
- local first_team = playerTeams[0];
- // switch for efficiency. do your code here
- switch(first_team)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- }
- // return 0, we didn't process the spawn anyway
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement