sscanf optional param. ?
#1

Well I have made /unmute command, syntax is:
/unmute [playerid] [reason]

But how to make reason' param optional, so if player type /unmute 7
It will send message to playerid 7 'Admin xx have unmuted you !'
And if player type /unmute 7 do not repeat it.
Gonna send message 'Admin xx have unmuted you, reason: do not repait it.'


My unmute command:

pawn Код:
YCMD:unmute(playerid, params[], help)
{
    #pragma unused help
    if(PlayerInfo[playerid][pAdmin] < 1 && PlayerInfo[playerid][pHelper] < 1)
        return SCM(playerid,-1,"Admins and Helpers only!");
    new player, reason[128];
    if(sscanf(params, "us[128]", player, reason))
        return SCM(playerid, -1, "Syntax: /unmute [playerid/PartOfName] [reason]");
    else if(player== INVALID_PLAYER_ID)
        return SCM(playerid, -1, "* Wrong ID!");
    else if(!Logged[player])
        return SCM(playerid, -1, " Player not logged in yet !");
    else if(!PlayerInfo[player][pMuted])
        return SCM(playerid, -1, " *Player not muted !");

    PlayerInfo[player][pMuted] = 0;
    new string[128];
    format(string, sizeof(string), " Admin %s have unmuted you.  Reason: %s", RPname(playerid), reason);
    SCM(player, DARKGREEN, string);
    format(string, sizeof(string), " *Player %s is not muted anymore ! ", RPname(player));
    SCM(playerid, YELLOW, string);

    return 1;
}
Reply
#2

Just change 1 line, this code should work

pawn Код:
if(sscanf(params, "uS(No Reason)[128]", player, reason))
Reply
#3

Gonna try, thanks !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)