Possible to add a string in SetTimer?
#5

This is using sscanf2.5. This tool is especially useful for commands such as this.
pawn Код:
if(!strcmp(cmdtext,"/reload",true))
{
    if(!IsPlayerAdmin(playerid)) // If they are not Admin then it sends the message
    {
        return SendClientMessage(playerid,-1,"You are not authorised to use this command.");
    }
    new gmxdelay; // A new variable that the player will type after typing "/reload"
    // This is the line that checks if they didn't type the command correctly.
    if(sscanf(params,"d",gmxdelay))
    {
        // So if they didn't type it correctly then tell them how to use it.
        return SendClientMessage(playerid,-1,"Syntax: /reload <minutes>");
    }
    if(gmxdelay == 0) // If they typed 0
    {
        return SendClientMessage(playerid,-1,"It must be at least one minute.");
    }
    else
    {
        // The "gmxdelay*1000*60" is what converts it to minutes.
        // gmxdelay is multiplied by 1000, which is one second
        // that product is then multiplied by 60 to equal a minute
        SetTimer("gmxtimer",gmxdelay*1000*60,false);
        new
            string[128]; // A new optional string to format
        format(string,sizeof(string),"The server will restart in %d minute.",gmxdelay);
        SendClientMessageToAll(-1,string);
    }
    return 1;
}
forward gmxtimer();
public gmxtimer() // So once the timer is up, then it....
{
    // sends the gmx command to RCON
    SendRconCommand("gmx");
}
Here is the same example with ZCMD.
pawn Код:
CMD:reload(playerid,params[])
{
    if(!IsPlayerAdmin(playerid)) // If they are not Admin then it sends the message
    {
        return SendClientMessage(playerid,-1,"You are not authorised to use this command.");
    }
    new gmxdelay; // A new variable that the player will type after typing "/reload"
    // This is the line that checks if they didn't type the command correctly.
    if(sscanf(params,"d",gmxdelay))
    {
        // So if they didn't type it correctly then tell them how to use it.
        return SendClientMessage(playerid,-1,"Syntax: /reload <minutes>");
    }
    if(gmxdelay == 0) // If they typed 0
    {
        return SendClientMessage(playerid,-1,"It must be at least one minute.");
    }
    else
    {
        // The "gmxdelay*1000*60" is what converts it to minutes.
        // gmxdelay is multiplied by 1000, which is one second
        // that product is then multiplied by 60 to equal a minute
        SetTimer("gmxtimer",gmxdelay*1000*60,false);
        new
            string[128]; // A new optional string to format
        format(string,sizeof(string),"The server will restart in %d minute.",gmxdelay);
        SendClientMessageToAll(-1,string);
    }
    return 1;
}
forward gmxtimer();
public gmxtimer() // So once the timer is up, then it....
{
    // sends the gmx command to RCON
    SendRconCommand("gmx");
}
Hope I was of any help.
Reply


Messages In This Thread
Possible to add a string in SetTimer? - by nickdodd25 - 29.03.2012, 03:28
Re: Possible to add a string in SetTimer? - by AustinJ - 29.03.2012, 03:40
Re: Possible to add a string in SetTimer? - by nickdodd25 - 04.04.2012, 03:17
Re: Possible to add a string in SetTimer? - by ViniBorn - 04.04.2012, 03:32
Re: Possible to add a string in SetTimer? - by ReneG - 04.04.2012, 03:35
Re: Possible to add a string in SetTimer? - by nickdodd25 - 04.04.2012, 03:58
Re: Possible to add a string in SetTimer? - by ReneG - 04.04.2012, 04:26
Re: Possible to add a string in SetTimer? - by nickdodd25 - 07.04.2012, 23:09
Re: Possible to add a string in SetTimer? - by Jonny5 - 07.04.2012, 23:46
Re: Possible to add a string in SetTimer? - by ReneG - 07.04.2012, 23:49
Re: Possible to add a string in SetTimer? - by [DOG]irinel1996 - 08.04.2012, 00:14
Re: Possible to add a string in SetTimer? - by Y_Less - 08.04.2012, 00:23

Forum Jump:


Users browsing this thread: 1 Guest(s)