Converting Command
#1

Okay I'm converting command /frisk from ZCMD to Strcmp.. don't ask why
So this command shows my weapons and so on..
But the problem is if I write /frisk (ANY ID) it will frisk me :/ it doesn't want to send me error message "Invalid player ID" what is wrong? :/

pawn Код:
if(strcmp(cmd,"/frisk",true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /frisk[playerid/PartOfName]");
                return 1;
            }
            if (id == INVALID_PLAYER_ID)
            {
                SendClientMessage(playerid, COLOR_WHITE, "Invalid player ID!");
                return 1;
            }
            if (IsPlayerInAnyVehicle(id))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This player is in vehicle!");
                return 1;
            }
            if (!IsPlayerInRangeOfPoint(id, 5.0, x, y, z))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This player is to far away");
                return 1;
            }
            // if is player connected...
            format(Str2, sizeof(Str2), "__________%s's Weapon Information___________", Name);
            SendClientMessage(playerid, COLOR_YELLOW, Str2);
            for(Slot = 0; Slot < 14; Slot++)
            {
                GetPlayerWeaponData(id, Slot, Weapon, Ammo);
                if( Ammo != 0 && Weapon != 0)
                CNT++;
            }
            if(CNT < 1)
            {
                SendClientMessage(playerid,0x33AA33AA,"No weapons found!");
                return 1;
            }
            if(CNT >= 1)
            {
                for (Slot = 0; Slot < 14; Slot++)
                {
                GetPlayerWeaponData(id, Slot, Weapon, Ammo);
                if( Ammo != 0 && Weapon != 0)
                {
                GetWeaponName(Weapon,WN, sizeof(WN));
                if(Ammo == 65535 || Ammo == 1)
                format(Str,sizeof(Str),"%s%s (1)",Str, WN);
                else format(Str,sizeof(Str),"%s%s (%d)",Str, WN, Ammo);
                X++;
                if(X >= 5)
                {
                    SendClientMessage(playerid, 0x33AA33AA, Str);
                    X = 0;
                    format(Str, sizeof(Str), "");
                }
                else format(Str, sizeof(Str), "%s,  ", Str);
                }
            }
            if(X <= 4 && X > 0)
            {
                Str[strlen(Str)-3] = '.';
                SendClientMessage(playerid, 0x33AA33AA, Str);
            }
            }
        }
        return 1;
    }
    return 0;
}
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=231496
Reply
#3

Well I'm not converting to ZCMD I'm converting from ZCMD TO STRCMP, and also I'm asking for help because I don't know what is wrong with command..
Reply
#4

Try like this
pawn Код:
if(strcmp(cmd,"/frisk",true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /frisk[playerid/PartOfName]");
                return 1;
            }
            if (IsPlayerInAnyVehicle(id))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This player is in vehicle!");
                return 1;
            }
            if (!IsPlayerInRangeOfPoint(id, 5.0, x, y, z))
            {
                SendClientMessage(playerid, COLOR_WHITE, "This player is to far away");
                return 1;
            }
            // if is player connected...
            format(Str2, sizeof(Str2), "__________%s's Weapon Information___________", Name);
            SendClientMessage(playerid, COLOR_YELLOW, Str2);
            for(Slot = 0; Slot < 14; Slot++)
            {
                GetPlayerWeaponData(id, Slot, Weapon, Ammo);
                if( Ammo != 0 && Weapon != 0)
                CNT++;
            }
            if(CNT < 1)
            {
                SendClientMessage(playerid,0x33AA33AA,"No weapons found!");
                return 1;
            }
            if(CNT >= 1)
            {
                for (Slot = 0; Slot < 14; Slot++)
                {
                GetPlayerWeaponData(id, Slot, Weapon, Ammo);
                if( Ammo != 0 && Weapon != 0)
                {
                GetWeaponName(Weapon,WN, sizeof(WN));
                if(Ammo == 65535 || Ammo == 1)
                format(Str,sizeof(Str),"%s%s (1)",Str, WN);
                else format(Str,sizeof(Str),"%s%s (%d)",Str, WN, Ammo);
                X++;
                if(X >= 5)
                {
                    SendClientMessage(playerid, 0x33AA33AA, Str);
                    X = 0;
                    format(Str, sizeof(Str), "");
                }
                else format(Str, sizeof(Str), "%s,  ", Str);
                }
            }
            if(X <= 4 && X > 0)
            {
                Str[strlen(Str)-3] = '.';
                SendClientMessage(playerid, 0x33AA33AA, Str);
            }
        }
        else
        {
            SendClientMessage(playerid, 0x33AA33AA, "No such a player");
            return 1;
        }
    }
    return 0;
}
Reply
#5

Umm now it says "USAGE: bla bla bla" at any ID I entered :/
some more help please
Reply
#6

pawn Код:
if(strcmp(cmd,"/frisk",true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:x, Float:y, Float:z;
        tmp = strtok(cmdtext, idx);
        GetPlayerPos(playerid, x, y, z);
       
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /frisk [playerid]");
            return 1;
        }
        if (!IsPlayerConnected(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "Invalid player ID!");
            return 1;
        }
        if (IsPlayerInAnyVehicle(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "This player is in vehicle!");
            return 1;
        }
        if (!IsPlayerInRangeOfPoint(tmp, 5.0, x, y, z))
        {
            SendClientMessage(playerid, COLOR_WHITE, "This player is to far away");
            return 1;
        }
        // if is player connected...
        format(Str2, sizeof(Str2), "__________%s's Weapon Information___________", Name);
        SendClientMessage(playerid, COLOR_YELLOW, Str2);
        for(Slot = 0; Slot < 14; Slot++)
        {
            GetPlayerWeaponData(tmp, Slot, Weapon, Ammo);
            if( Ammo != 0 && Weapon != 0)
            CNT++;
        }
        if(CNT < 1)
        {
            SendClientMessage(playerid,0x33AA33AA,"No weapons found!");
            return 1;
        }
        if(CNT >= 1)
        {
            for (Slot = 0; Slot < 14; Slot++)
            {
            GetPlayerWeaponData(tmp, Slot, Weapon, Ammo);
            if( Ammo != 0 && Weapon != 0)
            {
            GetWeaponName(Weapon,WN, sizeof(WN));
            if(Ammo == 65535 || Ammo == 1)
            format(Str,sizeof(Str),"%s%s (1)",Str, WN);
            else format(Str,sizeof(Str),"%s%s (%d)",Str, WN, Ammo);
            X++;
            if(X >= 5)
            {
                SendClientMessage(playerid, 0x33AA33AA, Str);
                X = 0;
                format(Str, sizeof(Str), "");
            }
            else format(Str, sizeof(Str), "%s,  ", Str);
            }
        }
        if(X <= 4 && X > 0)
        {
            Str[strlen(Str)-3] = '.';
            SendClientMessage(playerid, 0x33AA33AA, Str);
        }
        }
    }
    return 1;
}
Reply
#7

Thanks for try but I have defined those x,y,z, Weapon,Ammo etc etc :/
Anyone please ?
Reply
#8

lol, one question ?
what's "id" in your command ?
i just change all "id" to "tmp" and

Quote:

if(id == INVALID_PLAYER_ID)

to
pawn Код:
if(!IsPlayerConnected(tmp))
Reply
#9

Well this is "id"
pawn Код:
new id = strval(tmp);
Reply
#10

I never understand why people move backwards instead of forwards it's like African street justice a can of gas and a pack of matches should do the trick.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)