if(!strcmp(params, "kick", true))
{
if( sscanf(params, "su", params, id))
return SendUsageError( playerid, "/toggle [Kick] [ID]" );
if(!strcmp(params, "kick", true))
{
if( sscanf(params, "su", id))
return SendUsageError( playerid, "/toggle [ID]" );
Originally Posted by The Great Emmet_
EVERY format specifier (that is, everything except '', {} and p) now has an optional equivalent - this is just their letter capitalised, so for example the old "z" optional string specifier is now "S" (there is still "z" and, for completeness, "Z", but both give warnings). In addition to optional specifiers, there are also now default values:
|
new subcmd[10], subcmdval[128]; if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval)) { //Return something if user doesn't put it anything for "s[10]"! } if (strcmp(subcmd, "kick", true)) { new targetid; if (sscanf(subcmdval, "u", targetid)) { //Return something if user did "/cmd kick" but didn't put any value afterwards! } // Continue what happens if id was given }
Make a sscanf before the strcmp to check for even more parameters, but make it optional so it doesn't have to be included.
(https://sampforum.blast.hk/showthread.php?tid=570927) So simply: Code:
new subcmd[10], subcmdval[128]; if (sscanf(params, "s[10]S()[128]", subcmd, subcmdval)) { //Return something if user doesn't put it anything for "s[10]"! } if (strcmp(subcmd, "kick", true)) { new targetid; if (sscanf(subcmdval, "u", targetid)) { //Return something if user did "/cmd kick" but didn't put any value afterwards! } // Continue what happens if id was given } |
new option[10];
sscanf(params, "s[10]s[128]", option, params);
if(!strcmp(option, "kick", true))
{
sscanf(params, "u", id);
}
I had a similar problem which I posted on the forums aswell, listen up what you gotta do.
You need an option string where you store the option, and then store the rest of the given text back to the params variable, IE: PHP Code:
|
CMD:event(playerid, params[])
{
if( pInfo[playerid][pAdmin] < 5 )
return 0;
new id;
if (isnull(params))
return SendUsageError( playerid, "/event [create/rename/teles/kick/freeze/disarm/weapons/end]" );
if(!strcmp(params, "kick", true))
{
new kid;
if (sscanf(params, "su", "kick", kid))
return SendUsageError( playerid, "/event [kick] [ID]" );
if(inEvent[kid] == 1)
{
format(str, sizeof(str), "[EVENT] {FFFFFF}%s has been kicked from the event", Name[kid], kid);
SendClientMessageToAll(COLOR_EVENT, str);
SetPlayerHealth(kid, 0);
inEvent[kid] = 0;
eInfo[eventFrozen] = 0;
TogglePlayerControllable(kid, 1);
}
else
{
Error(playerid, "This player is not participating in your event");
}
}
return 1;
}
PHP Code:
|