SA-MP Forums Archive
Please, how to make one command with two usages? Using ycmd sscanf2 - 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: Please, how to make one command with two usages? Using ycmd sscanf2 (/showthread.php?tid=484103)



Please, how to make one command with two usages? Using ycmd sscanf2 - Riwerry - 29.12.2013

Hello guys, I need to make this time command to have 2 usages. First usage I have done. It is /restart HOUR MIN but I want to make this command when player enters /restart SEC, when he just type one integer I want to make it for seconds. But dont know how to add it to the command. Code:

pawn Код:
YCMD:restart (playerid, params [], help)
{
    if (!IsPlayerAdmin (playerid)) return SendClientMessage (playerid, -1, "You must be main administrator to use this command!");
    new string [128];
    if (sscanf (params, "ii", restarth, restartm)) return SendClientMessage (playerid, -1, "You have entered wrong format of command. Use: /restart HOUR MINUTE");
    format (string, sizeof (string), "Administrator set server restart today, in time: %d:%d", restarth, restartm);
    SendClientMessageToAll (-1, string);
    SetTimer ("RLTimeRestart", 1000*60, false);
    return true;
}
Thx.


Re: Please, how to make one command with two usages? Using ycmd sscanf2 - Threshold - 29.12.2013

Give this a shot:
pawn Код:
YCMD:restart (playerid, params [], help)
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You must be main administrator to use this command!");
    new restarth, restartm, restarts;
    if(!sscanf(params, "ii", restarth, restartm))
    {
        new string[70];
        format(string, sizeof(string), "Administrator set server restart today, in time: %d:%d", restarth, restartm);
        SendClientMessageToAll(-1, string);
        SetTimer("RLTimeRestart", (((restarth * 3600) + (restartm * 60)) * 1000), false);
    }
    else if(!sscanf(params, "i", restarts))
    {
        new string[70];
        format(string, sizeof(string), "Administrator set server restart today, in time: %d seconds", restarts);
        SendClientMessageToAll(-1, string);
        SetTimer("RLTimeRestart", (restarts * 1000), false);
    }
    else return SendClientMessage(playerid, -1, "You have entered the wrong format of the command. Use: /restart HOUR MINUTE or /restart SECONDS");
    return 1;
}



Re: Please, how to make one command with two usages? Using ycmd sscanf2 - Riwerry - 29.12.2013

thx mate yo! gonna to try it

btw how I can add if statemens that detect if hours or minutes have two numbers for example /restart 20 30 and when they type /restart 200 300 it type wrong time for example thxx


Re: Please, how to make one command with two usages? Using ycmd sscanf2 - Threshold - 29.12.2013

Two numbers:
pawn Код:
if(restarth > 9 || restartm > 9) //Either minutes or hours is 10+, more than 1 number.
Three numbers:
pawn Код:
if(restarth > 99 || restartm >> 99) //Either minutes or hours is 100+, more than 2 numbers.
This is just an easy example, I think there would of been functions written for this kind of thing, but this is the most simple way of doing it.

--
Alternatively, just ask me what you want added into the command and I'll gladly add it for you. I will explain the code in a PM if you wish.