Optional string (sscanf)
#1

So I wanted to create a /mute command wherein the admin who uses the command may or may not input a reason as to why he'd mute the player. Here's where I got so far

PHP код:
CMD:mute(playeridparams[])
{
    new 
idreason[64], time;
    if (
sscanf(params"dS[24]d"idreasontime))
    {
        
SendClientMessage(playerid, -1"USAGE: /mute [id] [reason (optional)] [minutes]");
        return 
1;
    }
    
Mute(idreasontime);
    return 
1;

Thing is that when I use it, say for example, like this

Код:
/mute 1 20
/mute - the command

1 - the ID

20 - the minutes

it sends me the

Код:
SendClientMessage(playerid, -1, "USAGE: /mute [id] [reason (optional)] [minutes]");
I wanted the reason to be optional. How u do that?


Oh and it sends me a
Код:
sscanf warning: No default value found.
Reply
#2

Код:
CMD:mute(playerid, params[])
{
    new id, reason[64], time;
    if (sscanf(params, "dS(No Reason Given)[24]d", id, reason, time))
    {
        SendClientMessage(playerid, -1, "USAGE: /mute [id] [reason (optional)] [minutes]");
        return 1;
    }
    Mute(id, reason, time);
    return 1;
}
Reply
#3

PHP код:
CMD:mute(playeridparams[]) 

    new 
idtimereason[64]; 
    if(!
sscanf(params"uds[64]"idtimereason)) 
    { 
        if(!
IsPlayerConnected(id)) return SendClientMessage(playerid, -1"disconnected");
        
        
Mute(idreasontime);
        return 
1
    }
    
    if(
sscanf(params"ud"params[0], params[1])) return SendClientMessage(playerid, -1"USAGE: /mute [id] [minutes] [reason (optional)]");
    
Mute(params[0], ""params[1]); //I recommend using the code that is in "Mute" here.
    
return 1

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)