SA-MP Forums Archive
SSCANF optional parameter? - 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: SSCANF optional parameter? (/showthread.php?tid=411998)



SSCANF optional parameter? - denNorske - 31.01.2013

Hi all

I am making a Mute command, and some other commands, but i was wondering how i could get only optional "reason" parameter? (the "s" in the (sscanf(params"us[128]")))

pawn Код:
CMD:mute(playerid, params[])
{
    new
        targetid,
        reason[128],
        string[200],
        string2[200];
       
       
    if (!IsPlayerAdmin(playerid) && AccInfo[playerid][aLevel] < 3)
        return SendClientMessage(playerid, orange, " - Only "cgreen"Level 3+"corange" can perform this command - ");
    if(sscanf(params,"us[128]", targetid, reason))
        return SendClientMessage(playerid, orange," - Usage: "cblue"\"/MUTE [playerid] [Reason]\" "corange" - Will prevent a player from chatting -");
    if(targetid == INVALID_PLAYER_ID)
        return SendClientMessage(playerid, orange, " - - - - - Player was not found online / Wrong name/id - - - - - -");
    if(targetid==playerid)
        return SendClientMessage(playerid, red," - Sorry, you can't mute yourself! - ");
    if(AccInfo[targetid][aLevel] > 1)
        return SendClientMessage(playerid, red, " - It is not possible to mute Administrators -");
    if(GetPVarInt(targetid, "muted") == 1)
        return SendClientMessage(playerid, blue, " - Selected Player is already muted -");
       
    SetPVarInt(targetid, "muted", 1);
    format(string, sizeof(string), " - Administrator "cwhite"%s "corange"Muted You! "cgrey"||"cblue" (Reason: "cwhite"%s"cblue")", PlayerName(playerid), reason);
    SendClientMessage(targetid, orange, string);
    format(string2,sizeof(string2),"You have muted "cwhite"%s "cblue"Successfully! He will be unmuted automatically", PlayerName(targetid));
    SendClientMessage(playerid, blue , string2);
    SetTimerEx("UnMute", 1000*UNMUTETIME, false, "i", targetid);
    return 1;
}
I've heard that you can use (-1) behind it, but i am in addition using a [128] behind, so what could i do ?

Thanks for reading!


Re: SSCANF optional parameter? - denNorske - 31.01.2013

Quote:
Originally Posted by ******
Посмотреть сообщение
Is the first post of the sscanf topic, with extensive documentation on all the specifiers, somehow not clear? If so I would be happy to fix up the parts you find confusing if you point them out:

https://sampforum.blast.hk/showthread.php?tid=120356
You could have had another example containing an optional string there too^^ Sorry, wasn't the meaning to ask dumb questions, which i did now xD

Could you do that? I think beginners like me (heeh) will understand better then ^^

Thanks!