Looping - 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: Looping (
/showthread.php?tid=467933)
Looping -
AnonScripter - 05.10.2013
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.
Re: Looping -
Konstantinos - 05.10.2013
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
Re: Looping -
AnonScripter - 05.10.2013
i don't understand why u put "!"
Re: Looping -
Konstantinos - 05.10.2013
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;
Re: Looping -
TomatoRage - 05.10.2013
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;
Re: Looping -
DanishHaq - 05.10.2013
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
Re: Looping -
AnonScripter - 07.10.2013
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;"