Dcmd question.
#1

Hey, I'm trying to make like a command for example: /v [name] in dcmd.

Actually what I'm making is a /creategun [gunname] command, however I can't seem to get it working.

pawn Code:
dcmd_creategun(playerid, params[])
{
    new id[64];
    if(sscanf(params,"s",id))
    {
        SendClientMessage(playerid,COLOR_YELLOW,"Usage: /creategun [GunName]");
        SendClientMessage(playerid,COLOR_YELLOW,"Deagle[3], Shotgun[1]");
        SendClientMessage(playerid,COLOR_YELLOW,"MP5[4], Sniper[7]");
    }
    else
    {
        if(sscanf(params,"deagle",id))
        {
            if(PlayerAccount[playerid][WeaponPackages] >= 3)
            {
                GivePlayerWeapon(playerid,24,100);
                PlayerAccount[playerid][WeaponPackages] -= 3;
            }
            else
            {
                SendClientMessage(playerid,COLOR_YELLOW,"Not Enough Weapon Packages");
            }
        }
}
I guess I'm doing something wrong at this:
pawn Code:
if(sscanf(params,"deagle",id))
Reply
#2

If your only ever expecting a single string input from the command, get rid of the sscanf altogether.

Remove your id variable.

Replace if(sscanf(params,"s",id)) with a param null check.

Replace if(sscanf(params,"deagle",id)) with a simple strcmp check.
Reply
#3

Mhm okay, I don't really get what you mean by Replace if(sscanf(params,"deagle",id)) with a simple strcmp check.

Like:
pawn Code:
if(strcmp(params,"deagle"))
It gives a error so I guess it's not like that, could you maybe help me a little more, I would be very grateful, thanks.
Reply
#4

Well you could do something like this:

pawn Code:
stock equal(string[], compare[], bool:ignorecase = true) {
    if(strlen(string) == strlen(compare) && strcmp(string, compare, ignorecase) == 0) return true;
    return false;
}
if(equal(params,"deagle"))
Reply
#5

Working now Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)