some admin commands help
#1

Well I have came up with a question rather than a problem .. does sscanf support things like in /freeze command admins have 2 or 3 provisions if he doesnt put the reason it show [Reason]:- Not Specified and if he doesnt specify time he is permanently frozen well can sscanf support things like this?
Reply
#2

Yes, sscanf easily supports multiple parameters. Once you have created these parameters, it is up to you to decide how you wish to utilize them.
Reply
#3

Quote:
Originally Posted by RVRP
Посмотреть сообщение
Yes, sscanf easily supports multiple parameters. Once you have created these parameters, it is up to you to decide how you wish to utilize them.
Hmm can u give me an example please? amm with a small /freeze command please..
Reply
#4

Sure. I have built a barebones command for you. You will need to edit the script specific information (I just used the most generic information I could think of) and you will need to edit what you want to happen when time == 0 or some other number, but this is what it would look like using multiple parameters.

pawn Код:
COMMAND:freeze(playerid, params[])
{  
    new player, time, reason[128];
    if(pInfo[playerid][Admin] < 1)
    {
        SendClientMessage(playerid, RED, "Error: You are not an admin");
    }
    else if(sscanf(params, "iis", player, time, reason ))
    {
        SendClientMessage(playerid, BLUE, "Syntax: /freeze [playerid] [time] [reason]");
    }
    else
    {
        if(time == 0)
        {
             // Freeze the player permanently.
        }
        else
        {
            // Freeze the player for 'time' using a timer.
        }
    }
    return 1;
}
Also, quick warning: this code is not tested. While I'm eyeballing it and it looks good, it may contain an error. I would not recommend actually using this code as, like I said, it is just the 'example' you were asking for.
Reply
#5

Well ok But If The Reason is not specified then? how can i show it btw thanks for the time idea
Reply
#6

I'm not sure if I understand what you are asking, but I'll go ahead and explain to the best of my ability.

If you want the 'reason' to be optional (in other words, if they don't want to put a reason they don't have to), you use 'z' instead of 's' to place an optional string.

Then, you would need to designate an area to decide what would happen if the player did and didn't enter a reason. Check out the new barebones command below:

pawn Код:
COMMAND:freeze(playerid, params[])
{  
    new player, time, reason[128];
    if(pInfo[playerid][Admin] < 1)
    {
        SendClientMessage(playerid, RED, "Error: You are not an admin");
    }
    else if(sscanf(params, "iiz", player, time, reason))
    {
        SendClientMessage(playerid, BLUE, "Syntax: /freeze [playerid] [time] [reason]");
    }
    else
    {
        if(strlen(reason) == 0)
        {
            // What happens if no reason is entered.
        }
        if(strlen(reason) > 0)
        {
            // What happens if a reason is entered.
        }  
        if(time == 0)
        {
             // Freeze the player permanently.
        }
        if(time >= 0)
        {
            // Freeze the player for 'time' using a timer.
        }
    }
    return 1;
}
Reply
#7

You can use:

pawn Код:
if(sscanf(params, "udS(Not Specified)", playersid, time, reason)) return SendClientMessage(...);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)