Looping
#1

would somebody give me a tutorial topic for looping all the players.
example:
when a player type /911 , it will message all the cops team that this player needs help

so i want it to make commands that calling all x team.
Reply
#2

pawn Код:
for( new i = 0; i < MAX_PLAYERS; i++ )
{
    if( !IsPlayerConnected( i ) || /* !IsCop( i ) .. or whaterver you're using to check if they're not cops */ ) continue;
    // send the message
}
https://sampwiki.blast.hk/wiki/Loops
https://sampwiki.blast.hk/wiki/Control_Structures#Loops
Reply
#3

i don't understand why u put "!"
Reply
#4

continue; skips it and it goes to the next i. If the player is not (!) connected OR the player is not (!) cop, then skip it.

Else.. do your code - send the message.

NOTE: You may use something like gTeam[playerid] for cops, it depends on your script. Let's say, it's that case and the team is 2 for cops. It'd be: if( !IsPlayerConnected( i ) || gTeam[ i ] != 2 ) continue;
Reply
#5

pawn Код:
#define TEAM_COP 1

forward SendClientMessageToAllCops(msg[]);

new gTeam[MAX_PLAYERS];
new HasLawEnforcementRadio[MAX_PLAYERS];

public OnPlayerRequestClass(playerid, classid)
{
     SetPlayerTeamFromClass(playerid,classid);

    SetPlayerTeamFromClass(playerid,classid)
    {
        if(GetPlayerSkin(playerid) == skin || GetPlayerSkin(playerid) == skin)
        {
            gTeam[playerid] = TEAM_COP;
        }
   }
}

OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == TEAM_COP)
        {
            HasLawEnforcementRadio[playerid] =1;
        }

}

public SendClientMessageToAllCops(msg[])
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
             if(HasLawEnforcementRadio[i] == 1)
             {
                  SendClientMessage(i,Anycolor you want,msg);
             }
        }
    }
}
check if i forgot something tell me

btw i will give you gift:
if you don't want them to kill each other
put this
pawn Код:
SetPlayerTeam(playerid,team id);
under
pawn Код:
HasLawEnforcementRadio[playerid] =1;
Reply
#6

Quote:
Originally Posted by AnonScripter
Посмотреть сообщение
i don't understand why u put "!"
The symbol of ! means 'not'. So basically:

pawn Код:
if(!IsPlayerAdmin(playerid)) // You're not an admin
if(IsPlayerAdmin(playerid)) // You are an admin
Reply
#7

Quote:
Originally Posted by TomatoRage
Посмотреть сообщение
pawn Код:
#define TEAM_COP 1

forward SendClientMessageToAllCops(msg[]);

new gTeam[MAX_PLAYERS];
new HasLawEnforcementRadio[MAX_PLAYERS];

public OnPlayerRequestClass(playerid, classid)
{
     SetPlayerTeamFromClass(playerid,classid);

    SetPlayerTeamFromClass(playerid,classid)
    {
        if(GetPlayerSkin(playerid) == skin || GetPlayerSkin(playerid) == skin)
        {
            gTeam[playerid] = TEAM_COP;
        }
   }
}

OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == TEAM_COP)
        {
            HasLawEnforcementRadio[playerid] =1;
        }

}

public SendClientMessageToAllCops(msg[])
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
             if(HasLawEnforcementRadio[i] == 1)
             {
                  SendClientMessage(i,Anycolor you want,msg);
             }
        }
    }
}
check if i forgot something tell me

btw i will give you gift:
if you don't want them to kill each other
put this
pawn Код:
SetPlayerTeam(playerid,team id);
under
pawn Код:
HasLawEnforcementRadio[playerid] =1;
thank you, i will try it.

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
The symbol of ! means 'not'. So basically:

pawn Код:
if(!IsPlayerAdmin(playerid)) // You're not an admin
if(IsPlayerAdmin(playerid)) // You are an admin
i know what "!" means, but i didn't notice the "continue;"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)