Wanting to make /radio (Need to use foreach?)
#1

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?
Reply
#2

Use either foreach or a simple for loop. Whatever you like! (I'd prefer foreach - it's faster)
Reply
#3

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);

Reply
#4

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


Forum Jump:


Users browsing this thread: 2 Guest(s)