How can i make a cmd with optional options?
#6

That's because the sscanf statement is using an optional parameter, and sscanf will never return true if you're only using an optional parameter in this instance.

There are multiple ways to do this but they're all essentially the same.
Examples:
PHP код:
CMD:kill(playeridparams[])
{    
    new 
lookupid INVALID_PLAYER_ID;
    if(
sscanf(params"u"lookupid)) {
        
SendClientMessage(playerid, -1"USAGE: You can use \"/kill [playerid]\"");
        
SetPlayerHealth(playerid0.0);
        return 
1;
    }
    if(!
IsPlayerConnected(lookupid)) {
        
SendClientMessage(playerid, -1"ERROR: The specified player is not connected.");
        return 
1;
    }
    
SetPlayerHealth(lookupid0.0);
    return 
1;

PHP код:
CMD:kill(playeridparams[])
{
    new 
lookupid = -1;
    
sscanf(params"U(-1)"lookupid);
    if(
lookupid == -1)
    {
        
SendClientMessage(playerid, -1"USAGE: You can use \"/kill [playerid]\"");
        
SetPlayerHealth(playerid0.0);
    }
    else if(!
IsPlayerConnected(lookupid))
        
SendClientMessage(playerid, -1"ERROR: The specified player is not connected.");
    else
        
SetPlayerHealth(lookupid0.0);
    return 
1;

Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)