Help with one thing :D - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with one thing :D (
/showthread.php?tid=196753)
Help with one thing :D -
WillyP - 06.12.2010
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..
Re: Help with one thing :D -
Mauzen - 06.12.2010
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 ;)
}
Re: Help with one thing :D -
Scenario - 06.12.2010
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...
Re: Help with one thing :D -
WillyP - 06.12.2010
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
Re: Help with one thing :D -
SkizzoTrick - 06.12.2010
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
Re: Help with one thing :D -
WillyP - 06.12.2010
Wait. I don't get it. Would I put both parts of the code in one place? They just look the same to me..
Re: Help with one thing :D -
SkizzoTrick - 06.12.2010
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
Re: Help with one thing :D -
WillyP - 06.12.2010
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.
Re: Help with one thing :D -
Mauzen - 06.12.2010
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.
Re: Help with one thing :D -
WillyP - 06.12.2010
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?