06.12.2010, 18:21
Hey, can I use variables to check if a player is spawned, then if more than 50% of the server is spawned, do some cool stuff ? I know how to do it, except the percentage part..
// Get the amount of online players first
new onlineplayers = 0;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i)) onlineplayers ++;
}
new counter = 0;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerSpawned(i)) counter ++; // Replace IsPlayerSpawned with the method you use to check it
}
if((float(counter) / float(onlineplayers)) > 0.5)
{
// More than 50% spawned, do something cool here ;)
}
#un def MAX_PLAYERS
#define MAX_PLAYERS YOUR_MAX_PLAYERS
You can simple count how many players are spawned with a loop, then divide it by the players that are online:
pawn Код:
|
You can simple count how many players are spawned with a loop, then divide it by the players that are online:
pawn Код:
|
I never knew how to use the counts and i learnt everything from this little post,thanks
|