Additional parameters in sscanf, is it possible?
#3

Well, there are multiple ways of doing this. One way to go about this is to use strcmp for each parameter that DOESN'T require additional parameters.

Example:
pawn Код:
CMD:accept(playerid, params[])
{
    if(!strcmp(params, "hire", true))
    {
        // Player used /accept hire
    }
    else if(!strcmp(params, "interview", true))
    {
        // Player used /accept interview
    }
    else if(!strcmp(params, "gag", true))
    {
        // Player used /accept gag
    }
    else if(!strcmp(params, "tie", true))
    {
        // Player used /accept tie
    }
    else if(!strcmp(params, "ticket", true))
    {
        // Player used /accept ticket
    }
Then you can add on the choices that DO require additional parameters, like so:
pawn Код:
CMD:accept(playerid, params[])
{
    if(sscanf(params, "'hire'"(params, "hire", true))
    {
        // Player used /accept hire
    }
    else if(!strcmp(params, "interview", true))
    {
        // Player used /accept interview
    }
    else if(!strcmp(params, "gag", true))
    {
        // Player used /accept gag
    }
    else if(!strcmp(params, "tie", true))
    {
        // Player used /accept tie
    }
    else if(!strcmp(params, "ticket", true))
    {
        // Player used /accept ticket
    }
    else // Command requires additional parameters.
    {
        new id;
        if(sscanf(params, "'namechange'i", id)) return SCM(playerid, COLOR_GREY, "USAGE: /accept namechange [id]");
        if(id == INVALID_PLAYER_ID || !IsPlayerConnected(id)) return SendClientMessageF(playerid, COLOR_GREY, "Invalid Player ID.");
        if(RequestNameChange[id] != 1) return SCM(playerid, COLOR_GREY, "That player is not requesting a name change.");
This line in particular:
pawn Код:
if(sscanf(params, "'namechange'i", id)) return SCM(playerid, COLOR_GREY, "USAGE: /accept namechange [id]");
Will return false when the player types "/accept namechange [id]", where '[id]' is a numerical parameter. You can essentially do this with each choice, but strcmp is the best option for choices that don't require more than 1 parameter.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)