Multiple Command Parameters
#1

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
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)