Player loops
#1

I'm not sure on how to check through all the players and if something is true, code executes, can somebody help me with what I'd do?

I've basically made a command, where if typed a player variable is set to 1. When the server starts a timer is set to execute in 30 minutes. At the 30 minute mark, all players with the variable set to 1 will be teleported. How do I loop through the players to check if the variable is equal to one?
Reply
#2

pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i) && variable[i] == 1)
    {
        //yourbtimer
    }
}
Reply
#3

That's exactly what I wanted, thank you, though I have another question.

Say I've done what you have done, how do I check if there's atleast 5 people with the variable equal to 1 before the action happens?
Reply
#4

Hello,

For 5 people use the script :

PHP код:
for(new i=0i<5 i++)
{
    if(
IsPlayerConnected(i) && variable[i] == 1)
    {
        
//yourbtimer
    
}

i'm not sure.
Reply
#5

Nah, you don't understand what I said.

I want the loop to loop through EVERY player with a variable set to 1. BUT if only 3 people have the variable 1, it doesn't execute. It only executes if atleast 4 players have it.
Reply
#6

pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(Variable[i] == 1 && GeneralVariable >= 4) // IsPlayerConnected(i) isn't necessary, for each player that has Variable[playerid] = 1; do GeneralVariable++; and if the player that had Variable[playerid] = 1; is then set to 0 do GeneralVariable--;
    {
        // Timer
    }
}
Reply
#7

pawn Код:
static _count = 0 ;

for( new i = 0 ; i < MAX_PLAYERS ; i++ )
{
      if( IsPlayerConnected( i ) && ( your_variable[ i ] == 1 ) )
                       _count++;
      else continue;
}

if( _count > 4 )
{
     // Atleast 5 people with the variable turned one.
}

else
{
     // Nope
}
Reply
#8

get foreach.inc whoch can be found here http://pastebin.com/iUFrMNtY
then do like this-
pawn Код:
foreach (new i : Player)
{
    //now in i will be the each and every player id come
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)