Command isn't working
#1

Hello this is my command, but when ever I write /frisk (playerid) it says "You are not cop!" even if I have cop skin...
Also 1 warning:
pawn Код:
warning 219: local variable "x" shadows a variable at a preceding level
how to fix it?

pawn Код:
if(strcmp(cmd, "/frisk", true) == 0)
    {
        if(!IsPlayerCop(playerid))
        {
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTGREEN, "Usage: /frisk [PlayerID]");
            tmp = strtok(cmdtext, idx);
            new otherplayer = strval(tmp); // giveplayerid
            new Count, x; // warning line
            new string[128], string2[64];
            new WeapName[24], slot, weap, ammo;
           
            if(IsPlayerConnected(otherplayer) && otherplayer != INVALID_PLAYER_ID)
            {
                format(string2,sizeof(string2),"_______|- %s's Weapons -|_______", otherplayer);
                SendClientMessage(playerid,COLOR_LIGHTGREEN,string2);
                for(slot = 0; slot < 14; slot++)
                {
                GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                if( ammo != 0 && weap != 0)
                Count++;
                }
                if(Count < 1)
                return SendClientMessage(playerid,COLOR_LIGHTGREEN,"No Weapons found!");
                if(Count >= 1)
                {
                    for (slot = 0; slot < 14; slot++)
                    {
                    GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                    if( ammo != 0 && weap != 0)
                    {
                    GetWeaponName(weap, WeapName, sizeof(WeapName));
                    if(ammo == 65535 || ammo == 1)
                    format(string,sizeof(string),"%s%s (1)",string, WeapName);
                    else format(string,sizeof(string),"%s%s (%d)",string, WeapName, ammo);
                    x++;
                    if(x >= 5)
                    {
                    SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                    x = 0;
                    format(string, sizeof(string), "");
                    }
                    else format(string, sizeof(string), "%s,  ", string);
                    }
                    }
                    if(x <= 4 && x > 0)
                    {
                    string[strlen(string)-3] = '.';
                    SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                    }
                }
                return 1;
            }
            else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"Invalid player ID");
        }
        else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"You are not cop!");
    }
    return 0;
}
Reply
#2

You have another variable called x. Just change the one in the command to x2 or something
Also I suggest you to use zcmd, it's better and easier
Reply
#3

Quote:
Originally Posted by Reera
Посмотреть сообщение
You have another variable called x. Just change the one in the command to x2 or something
Also I suggest you to use zcmd, it's better and easier
True, oh-well, he might not understand what you mean.

Fixed Code
pawn Код:
if(strcmp(cmd, "/frisk", true) == 0)
    {
        if(!IsPlayerCop(playerid))
        {
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTGREEN, "Usage: /frisk [PlayerID]");
            tmp = strtok(cmdtext, idx);
            new otherplayer = strval(tmp); // giveplayerid
            new Count, items; // warning line
            new string[128], string2[64];
            new WeapName[24], slot, weap, ammo;
           
            if(IsPlayerConnected(otherplayer) && otherplayer != INVALID_PLAYER_ID)
            {
                format(string2,sizeof(string2),"_______|- %s's Weapons -|_______", otherplayer);
                SendClientMessage(playerid,COLOR_LIGHTGREEN,string2);
                for(slot = 0; slot < 14; slot++)
                {
                    GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                    if( ammo != 0 && weap != 0)
                    Count++;
                }
                if(Count < 1) return SendClientMessage(playerid,COLOR_LIGHTGREEN,"No Weapons found!");
                if(Count >= 1)
                {
                    for (slot = 0; slot < 14; slot++)
                    {
                        GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                        if( ammo != 0 && weap != 0)
                        {
                            GetWeaponName(weap, WeapName, sizeof(WeapName));
                            if(ammo == 65535 || ammo == 1)
                            format(string,sizeof(string),"%s%s (1)",string, WeapName);
                            else format(string,sizeof(string),"%s%s (%d)",string, WeapName, ammo);
                            items++;
                            if(items >= 5)
                            {
                                SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                                items = 0;
                                format(string, sizeof(string), "");
                            }
                            else format(string, sizeof(string), "%s,  ", string);
                        }
                    }
                    if(items <= 4 && items > 0)
                    {
                        string[strlen(string)-3] = '.';
                        SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                    }
                }
                return 1;
            }
            else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"Invalid player ID");
        }
        else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"You are not cop!");
    }
    return 0;
}
Reply
#4

Okay warning is fixed, thank you, but what about message always saying "you are not a cop" when I write /frisk..
I have skin 280 and is defined as cops skin under "stock IsPlayerCop" how to fix that?
Reply
#5

Since you're using else return, just remove the !Exclamation Mark.

This
pawn Код:
if(IsPlayerCop(playerid))
Reply
#6

Ty, but now it says "Usage: /frisk playerid" at any ID I entered :S
Reply
#7

anyone please ? :/
Reply
#8

Bump
Reply
#9

Just so we're on the exact same page, can you show us the code?
ED: I mean, has it changed since?
Reply
#10

This is current code
pawn Код:
if(strcmp(cmd, "/frisk", true) == 0)
    {
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_LIGHTGREEN, "Usage: /frisk [PlayerID]");
        tmp = strtok(cmdtext, idx);
        new otherplayer = strval(tmp); // giveplayerid
        new Count, items;
        new string[128], string2[64];
        new WeapName[24], slot, weap, ammo;
       
        if(IsPlayerCop(playerid))
        {
            if(IsPlayerConnected(otherplayer) && otherplayer != INVALID_PLAYER_ID)
            {
                format(string2,sizeof(string2),"_______|- %s's Weapons -|_______", otherplayer);
                SendClientMessage(playerid,COLOR_LIGHTGREEN,string2);
                for(slot = 0; slot < 14; slot++)
                {
                    GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                    if( ammo != 0 && weap != 0)
                    Count++;
                }
                if(Count < 1) return SendClientMessage(playerid,COLOR_LIGHTGREEN,"No Weapons found!");
                if(Count >= 1)
                {
                    for (slot = 0; slot < 14; slot++)
                    {
                        GetPlayerWeaponData(otherplayer, slot, weap, ammo);
                        if( ammo != 0 && weap != 0)
                        {
                            GetWeaponName(weap, WeapName, sizeof(WeapName));
                            if(ammo == 65535 || ammo == 1)
                            format(string,sizeof(string),"%s%s (1)",string, WeapName);
                            else format(string,sizeof(string),"%s%s (%d)",string, WeapName, ammo);
                            items++;
                            if(items >= 5)
                            {
                                SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                                items = 0;
                                format(string, sizeof(string), "");
                            }
                            else format(string, sizeof(string), "%s,  ", string);
                        }
                    }
                    if(items <= 4 && items > 0)
                    {
                        string[strlen(string)-3] = '.';
                        SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
                    }
                }
                return 1;
            }
            else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"Invalid player ID");
        }
        else return SendClientMessage(playerid,COLOR_LIGHTGREEN,"You are not cop!");
    }
    return 0;
}
The problem is, whenever I write "/frisk (ID)" it will say "Usage: /frisk (id)" I don't know what should cause this problem, can anyone help please? :/
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)