Help with one thing :D
#1

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..
Reply
#2

You can simple count how many players are spawned with a loop, then divide it by the players that are online:

pawn Код:
// 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 ;)
}
Reply
#3

You could do;

pawn Код:
#un def MAX_PLAYERS
#define MAX_PLAYERS YOUR_MAX_PLAYERS
Then when the half of your new MAX_PLAYERS are spawned, do what you gotta' do...
Reply
#4

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
You can simple count how many players are spawned with a loop, then divide it by the players that are online:

pawn Код:
// 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 ;)
}
Thanks for this
Reply
#5

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
You can simple count how many players are spawned with a loop, then divide it by the players that are online:

pawn Код:
// 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 ;)
}
I never knew how to use the counts and i learnt everything from this little post,thanks
Reply
#6

Wait. I don't get it. Would I put both parts of the code in one place? They just look the same to me..
Reply
#7

Quote:
Originally Posted by [FU]Victious
Посмотреть сообщение
Wait. I don't get it. Would I put both parts of the code in one place? They just look the same to me..
I don't think so,both of them are doing the same thing
I would put the seconds one xD
Reply
#8

Hmm, maybe OPC, then a timer or smth.. I'm confused because there's two things I need to be doing, which looks more like only 1 thing, but it isn't.
Reply
#9

Quote:
Originally Posted by SkizzoTrick
Посмотреть сообщение
I never knew how to use the counts and i learnt everything from this little post,thanks
No problem



Yes, both parts belong together. The first one just counts how many players are online, the second how many players are spawned. The last if check needs both values, so you have to use them together.
Reply
#10

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
No problem



Yes, both parts belong together. The first one just counts how many players are online, the second how many players are spawned. The last if check needs both values, so you have to use them together.
As a timer?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)