foreach doesnt work
#1

Used on the /backup system
PHP код:
CMD:bk(playeridparams[])
{
    new 
string[128];
       if(!
IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playeridCOLOR_GREY"You are not allowed to use this command.");
    if(!
IsALeo(playerid) && !IsMedic(playerid)) return SendClientMessage(playeridCOLOR_GREY"You are not a government official.");
    if(
sscanf(params"s[128]"params)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /backup [LEO/MEDIC]");
    if(!
strcmp(params"leo"true))
    {
        if(
Backup[playerid] == 1) return SendClientMessage(playeridCOLOR_GREY"You have already requested for police backup.");
        
Backup[playerid] = 1;
        foreach(new 
Player)
        {
            if(
IsACop(i) || IsSASD(i) || IsFBI(i))
            {
                
SetPlayerMarkerForPlayer(iplayerid0x0000FFFF);
                
format(stringsizeof(string), "[Central Dispatch]: %s %s is requesting immediate backup, his coordinates have been marked on your GPS."RPFRN(playerid), RPN(playerid));
                
SendClientMessage(iCOLOR_RADIOstring);
                
printf("The number is %d.",i);
                return 
1;
            }
        }
    }
    if(!
strcmp(params"medic"true))
    {
        if(
Backup[playerid] == 2) return SendClientMessage(playeridCOLOR_GREY"You have already requested for medical assistance.");
        
Backup[playerid] = 2;
        foreach(new 
Player)
        {
            if(
IsMedic(i))
            {
                
SetPlayerMarkerForPlayer(iplayerid0xFF3366FF);
                
format(stringsizeof(string), "[Central Dispatch]: %s %s is requesting medical assistance, his coordinates have been marked on your GPS."RPFRN(playerid), RPN(playerid));
                
SendClientMessage(iCOLOR_RADIOstring);
                
printf("The number is %d.",i);
                return 
1;
            }
        }
    }
    return 
1;

I debugged it with printf - ID is 0 (aka nobody)
Reply
#2

Try using this instead:


PHP код:
foreach(Playeri)
{
//your code

Reply
#3

Quote:
Originally Posted by Akbaig
Посмотреть сообщение
Try using this instead:


PHP код:
foreach(Playeri)
{
//your code

Won't compile
I have already updated my includes
Reply
#4

Damn I get it now..

You've used the

PHP код:
return 1
in the loop.. which disables the loop to repeat.
Reply
#5

Quote:
Originally Posted by Akbaig
Посмотреть сообщение
Damn I get it now..

You've used the

PHP код:
return 1
in the loop.. which disables the loop to repeat.
stupid me, thanks
Reply
#6

Quote:
Originally Posted by Akbaig
Посмотреть сообщение
Try using this instead:


PHP код:
foreach(Playeri)
{
//your code

For future reference...

Don't use this! That's an outdated format! Your current code is fine, but as mentioned above (and as you fixed) you are returning prematurely.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)