SA-MP Forums Archive
Multiple Command Parameters - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multiple Command Parameters (/showthread.php?tid=359105)



Multiple Command Parameters - zT KiNgKoNg - 12.07.2012

Hello im a new script for ultra-gaming and i would like to know how i can make
multiple parameters with SAMP include only and no other includes
please post the code if you know thanks


Re: Multiple Command Parameters - ReneG - 13.07.2012

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new
        index,
        cmd[20];
    cmd = strtok(cmdtext, index);
    if (strcmp(cmd, "/heal", true) == 0)
    {
        new
            tmp[20],
            id;
        tmp = strtok(cmdtext, index);
        if (strlen(tmp))
        {
            id = strval(tmp);
            if (IsPlayerConnected(id))
            {
                SetPlayerHealth(id, 100.0);
                SendClientMessage(id, 0x00FF00AA, "You have been healed");
                SendClientMessage(playerid, 0x00FF00AA, "Player healed");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "Player not found");
            }
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
        }
        return 1;
    }
    return 0;
}
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
This is from the sa-mp wiki.

ZCMD, YCMD, with sscanf are preferred for a reason.

That code turns into this.
pawn Код:
CMD:heal(playerid, params[])
{
    new
        targetid;
   
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /heal [playerid]");
   
    SetPlayerHealth(targetid, 100.0);
    return 1;
}
That's why you shouldn't use the default sa-mp functions to process commands.