SA-MP Forums Archive
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(playeridparams[])
{
    new 
string[256], text[128];
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    if(
sscanf(params"s[128]"text)) return SendClientMessage(playerid, -1"USAGE: /radio [text]");
    foreach(new 
iPlayer)
    {
        if(
PlayerInfo[i][pTeam] == 1)
        {
            
format(stringsizeof(string), "[Team 1]%s: %s"nametext);
            
SendClientMessage(i, -1string);
        }
        else if(
PlayerInfo[i][pTeam] == 2)
        {
            
format(stringsizeof(string), "[Team 2]%s: %s"nametext);
            
SendClientMessage(i, -1string);
        }
        else if(
PlayerInfo[i][pTeam] == 3)
        {
            
format(stringsizeof(string), "[Team 3]%s: %s"nametext);
            
SendClientMessage(i, -1string);
        }
    }
    return 
1;

PHP код:
CMD:r(playeridparams[])
{
    return 
cmd_radio(playeridparams);




Re: Wanting to make /radio (Need to use foreach?) - arjanforgames - 14.07.2013

I will try the code tomorrow. Time to sleep now.
Thanks.