Persistent SSCANF Issue, Please help me resolve this once and for all.
#4

as already pointed out, the optional sscanf S()[] specifier is a neat way to do this:
pawn Код:
if(sscanf(params, "s[32]S()[32]",usage,item))
{
    SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
    SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
}
printf("USAGE:%s ITEM:%s", usage,item);
VehicleSQLID[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "id", "vehicles");
if(vehicleid == TrunkOpened[playerid])
{
    if(!strcmp(usage, "store", true))
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else if(!strcmp(item, "get", true)
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else if(!strcmp(item, "view", true)
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store [item]");
        SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weapon, Weed, Cocaine, Money, Armour");
    }
by creating a custom specifier which recognizes a string, and returns a numerical value (1 for weapon, 1 for weed etc), this spaghetti like snippet would look better
not tested btw...
Reply


Messages In This Thread
Persistent SSCANF Issue, Please help me resolve this once and for all. - by Dokins - 13.03.2012, 18:27
Re: Persistent SSCANF Issue, Please help me resolve this once and for all. - by AndreT - 13.03.2012, 18:38
Re: Persistent SSCANF Issue, Please help me resolve this once and for all. - by [ABK]Antonio - 13.03.2012, 18:40
Re: Persistent SSCANF Issue, Please help me resolve this once and for all. - by Babul - 13.03.2012, 18:53

Forum Jump:


Users browsing this thread: 4 Guest(s)