How do I make optional parameters in sscanf?
#1

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?
Reply
#2

PHP код:
if(sscanf(params"s[buffer size]S(default value)[buffer size]"typeoptional)) 
Example:

PHP код:
flags:kick(CMD_ADMIN);
CMD:kick(playeridparams[])
{
    if(
pInfo[playerid][AdminLvl] < 1) return 0;
    new 
targetidstr[144], reason[72];
    if(
sscanf(params"uS(No reason given)[72]"targetidreason)) return SendClientMessage(playeridCOLOR_RED"USAGE: /kick [ID] [REASON]"), 0;
    if(
targetid == INVALID_PLAYER_ID) return SendClientMessage(playeridCOLOR_RED"ERROR: "COL_GREY"Player is not connected."), 0;
    if(
pInfo[targetid][AdminLvl] > pInfo[playerid][AdminLvl]) return SendClientMessage(playeridCOLOR_RED"ERROR: "COL_GREY"Player's admin level is higher or same as yours."), 0;
    
format(strsizeof str"%s %s has kicked %s for reason: %s."gStaff[pInfo[playerid][AdminLvl]], pName[playerid], pName[targetid], reason);
    
SendClientMessageToAll(COLOR_PINKstr);
    
KickEx(targetid);
    return 
1;

Reply
#3

I am either blind or the wiki page really does miss that information.
Thanks for the help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)