SA-MP Forums Archive
Player loops - 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)
+--- Thread: Player loops (/showthread.php?tid=503943)



Player loops - Garr - 01.04.2014

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?


Re: Player loops - Sascha - 01.04.2014

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



Re: Player loops - Garr - 02.04.2014

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?


Re: Player loops - Polki - 02.04.2014

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.


Re: Player loops - Garr - 02.04.2014

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.


Re: Player loops - SickAttack - 02.04.2014

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
    }
}



Re: Player loops - RajatPawar - 02.04.2014

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
}



Re: Player loops - BroZeus - 02.04.2014

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
}