Wanting to make /radio (Need to use foreach?) - 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: Wanting to make /radio (Need to use foreach?) (
/showthread.php?tid=450841)
Wanting to make /radio (Need to use foreach?) -
arjanforgames - 14.07.2013
I'd like to make a /radio command but do I need foreach to loop through all players with the same team?
If someone with PlayerInfo[playerid][pTeam] == 1 uses /r only people on pTeam 1 can see it.
So foreach or? Can I get some help?
Re: Wanting to make /radio (Need to use foreach?) -
Konstantinos - 14.07.2013
Use either foreach or a simple for loop. Whatever you like! (I'd prefer foreach - it's faster)
Re: Wanting to make /radio (Need to use foreach?) -
ThePhenix - 14.07.2013
Not tested:
I just did it:
PHP код:
CMD:radio(playerid, params[])
{
new string[256], text[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, -1, "USAGE: /radio [text]");
foreach(new i: Player)
{
if(PlayerInfo[i][pTeam] == 1)
{
format(string, sizeof(string), "[Team 1]%s: %s", name, text);
SendClientMessage(i, -1, string);
}
else if(PlayerInfo[i][pTeam] == 2)
{
format(string, sizeof(string), "[Team 2]%s: %s", name, text);
SendClientMessage(i, -1, string);
}
else if(PlayerInfo[i][pTeam] == 3)
{
format(string, sizeof(string), "[Team 3]%s: %s", name, text);
SendClientMessage(i, -1, string);
}
}
return 1;
}
PHP код:
CMD:r(playerid, params[])
{
return cmd_radio(playerid, params);
}
Re: Wanting to make /radio (Need to use foreach?) -
arjanforgames - 14.07.2013
I will try the code tomorrow. Time to sleep now.
Thanks.