params inside of a param
#1

I am able to get the params to work properly now, but I'm getting a sscanf error. This is the command:

pawn Код:
CMD:reboot(playerid, params[])
{
    new szOption[9];
    if(gPlayerData[playerid][EP_ADMINLVL] < 4)
        return 0;
    if(sscanf(params, "s[9]I", szOption))
        return SendClientMessage(playerid, COLOR_YELLOW, "SYNTAX: /reboot [option] | OPTIONS: start, stop, postpone");

    if(!strcmp(szOption, "start", true))
    {
        new iMinutes;
        if(sscanf(params, "{s[9]}i", iMinutes))
            return SendClientMessage(playerid, COLOR_YELLOW, "SYNTAX: /reboot start [minutes]");
        if(RebootPending == 1)
            return SendClientMessage(playerid, COLOR_ORANGE, "SERVER: There is already a reboot pending.");
        if(iMinutes <= 0)
            return SendClientMessage(playerid, COLOR_ORANGE, "SERVER: You need to specify a time greater than 0.");

        new szString[128];
        format(szString, sizeof(szString), "SERVER: %s %s has just initiated a server reboot. It will begin in %d minutes.", GetAdminRank(playerid), gPlayerData[playerid][EP_ADMINNAME], iMinutes);
        SendClientMessageToAll(COLOR_ORANGE, szString);
        defer Reboot(iMinutes);
        RebootTimer = defer Reboot(iMinutes);
        RebootMinutesTotal = iMinutes;
        RebootPending = 1;
    }
    else if(!strcmp(szOption, "stop", true))
    {
        if(RebootPending != 1)
            return SendClientMessage(playerid, COLOR_ORANGE, "SERVER: There currently is not a reboot pending.");

        new szString[128];
        format(szString, sizeof(szString), "SERVER: %s %s has stopped the reboot timer, the server will not be rebooted!", GetAdminRank(playerid), gPlayerData[playerid][EP_ADMINNAME]);
        SendMessageToAll(COLOR_LRED, szString);
        stop RebootTimer;
        RebootPending = 0;
    }
    else if(!strcmp(szOption, "postpone", true))
    {
        new iMinutes;
        if(sscanf(params, "{s[9]}i", iMinutes))
            return SendClientMessage(playerid, COLOR_YELLOW, "SYNTAX: /reboot postpone [minutes]");
        if(RebootPending != 1)
            return SendClientMessage(playerid, COLOR_ORANGE, "SERVER: There currently is not a reboot pending.");
        if(iMinutes <= 0)
            return SendClientMessage(playerid, COLOR_ORANGE, "SERVER: You need to specify a time greater than 0.");

        RebootMinutesTotal = RebootMinutesTotal+iMinutes;

        new szString[128];
        format(szString, sizeof(szString), "SERVER: %s %s has postpone the server reboot an extra %d minutes. The reboot will begin in %d minutes.", GetAdminRank(playerid), gPlayerData[playerid][EP_ADMINNAME], iMinutes, RebootMinutesTotal);
        SendMessageToAll(COLOR_LRED, szString);
        defer Reboot(RebootMinutesTotal);
        RebootTimer = defer Reboot(RebootMinutesTotal);
    }
    return 1;
}
This is the error:

Код:
sscanf warning: Format specifier does not match parameter count.
Reply
#2

Situation updated. Please check the main post!
Reply
#3

you have if(sscanf(params, "{s[9]}i", iMinutes)) but you only state 1 parameter but your format specifier states you should have 2 params.
Reply
#4

Quote:
Originally Posted by vital2k
Посмотреть сообщение
you have if(sscanf(params, "{s[9]}i", iMinutes)) but you only state 1 parameter but your format specifier states you should have 2 params.
With that line, it shouldn't give me an error because the first specifier isn't being saved.

And with this line:

pawn Код:
if(sscanf(params, "s[9]I", szOption))
It doesn't let me enter the minutes param of /reboot start without the optional "I" specifier.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
There is no default value for the "I".
Doesn't seem to make a difference when I set one, unless I'm doing it incorrectly...

pawn Код:
if(sscanf(params, "s[9]I(0)", szOption))
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
Now there's no variable in which to store the "I" parameter.
Why do I need to store that parameter? I don't use it unless the first param is start or postpone...
Reply
#7

Quote:

if(sscanf(params, "s[9]I", szOption))

Quote:

if(sscanf(params, "{s[9]}i", iMinutes))

Why you do this?
the string shouldn't be "start" "stop" and "postpone"?
You must specify the variables to store the 2 parameters.
Anyway wouldn't be much better using only once sscanf function and the use the string array and the time variable in the function instead of recalling sscanf each time?
Reply
#8

I'm not sure that it matters, but anyways, I've gotten it down to one sscanf line and used other means to send the syntax message if necessary. Thanks for the help.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Because you tell sscanf to get it, you might not use it but it still wants to try and save it because that's what you told it to do.
Okay, I'm about to leave for work but when I get home I'll try fiddling with it a little more. Thanks for the responses.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)