Laser color.
#3

pawn Код:
CMD:lasercol(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, C_GREY, "USAGE: /lasercol [color]");

    if(!strcmp(params, "red", true)) SetPVarInt(playerid, "color", 19080);
    else if(!strcmp(params, "blue", true)) SetPVarInt(playerid, "color", 18643);
    else if(!strcmp(params, "pink", true)) SetPVarInt(playerid, "color", 19081);
    else if(!strcmp(params, "orange", true)) SetPVarInt(playerid, "color", 19082);
    else if(!strcmp(params, "green", true)) SetPVarInt(playerid, "color", 19083);
    else if(!strcmp(params, "yellow", true)) SetPVarInt(playerid, "color", 19084);
    else SendClientMessage(playerid, C_VIOLET, "Color not available!");
    return 1;
}
1. Changed false to true because otherwise 'YELLOW' would be invalid (true for 'ignorecase' in strcmp).
2. strcmp returns 0 when it matches, so I added a ! before strcmp().
3. No need to use sscanf. sscanf is for SPLITTING strings with MULTIPLE parameters. Waste of memory and CPU.
4. sscanf returns 1 if the input is invalid, so your code would NEVER work because you basically said 'if sscanf is invalid, process input'.
Reply


Messages In This Thread
Laser color. - by Dan. - 26.07.2012, 11:06
Re: Laser color. - by [IKS]Niko_Hs™ - 26.07.2012, 11:20
Re: Laser color. - by MP2 - 26.07.2012, 11:21
Re: Laser color. - by Dan. - 26.07.2012, 11:30
Re: Laser color. - by Kindred - 26.07.2012, 11:32
Re: Laser color. - by MP2 - 26.07.2012, 13:48

Forum Jump:


Users browsing this thread: 2 Guest(s)