How do I make optional parameters in sscanf? - 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: How do I make optional parameters in sscanf? (
/showthread.php?tid=643458)
How do I make optional parameters in sscanf? -
EtayJ - 20.10.2017
I am trying to create a command like this:
/give currentgun
/give gun <gunid>
but everything I've tried till now just didn't work, how can I simply make optional parameters?
Re: How do I make optional parameters in sscanf? -
Logic_ - 20.10.2017
PHP код:
if(sscanf(params, "s[buffer size]S(default value)[buffer size]", type, optional))
Example:
PHP код:
flags:kick(CMD_ADMIN);
CMD:kick(playerid, params[])
{
if(pInfo[playerid][AdminLvl] < 1) return 0;
new targetid, str[144], reason[72];
if(sscanf(params, "uS(No reason given)[72]", targetid, reason)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /kick [ID] [REASON]"), 0;
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: "COL_GREY"Player is not connected."), 0;
if(pInfo[targetid][AdminLvl] > pInfo[playerid][AdminLvl]) return SendClientMessage(playerid, COLOR_RED, "ERROR: "COL_GREY"Player's admin level is higher or same as yours."), 0;
format(str, sizeof str, "%s %s has kicked %s for reason: %s.", gStaff[pInfo[playerid][AdminLvl]], pName[playerid], pName[targetid], reason);
SendClientMessageToAll(COLOR_PINK, str);
KickEx(targetid);
return 1;
}
Re: How do I make optional parameters in sscanf? -
EtayJ - 20.10.2017
I am either blind or the wiki page really does miss that information.
Thanks for the help!