problems with sscanf
#1

Hello everyone,
I am trying to make a trunk / boot system it's based that you can store certain items in the vehicle's rear boot/trunk (how americans or english people would say it).
However I have problems with this:
pawn Code:
CMD:vehtrunk( playerid, params[] )
{
    new option[64];
    if( sscanf( params, "s[64]", option ) )
    {
        SendClientMessage( playerid, COLOR_GREEN, "SYNTAX: /vehtrunk [info/open/close/putgun/takegun/putcocaine/takecocaine/putheroin]");
        SendClientMessage( playerid, COLOR_GREEN, "[takeheroin/putecstasy/takeecstasy/putcrack/takecrack/putweed/takeweed/putcrystalmeth]");
        SendClientMessage( playerid, COLOR_GREEN, "[takecrystalmeth/putsteroids/takesteroids/putgascan/takegascan/putmaterials/takematerials]");

        return 1;
    }

    if ( !isnull( option ) )
    {

        new closest = GetClosestVehicleInRange( playerid, 3.0 );

        new szString[128];


        else if ( !strcmp( option, "putgun", true ) )
        {
            new slot;
            if( sscanf( params, "d", slot ) )
                return SendClientMessage( playerid, COLOR_BEIGE, "SYNTAX: /vehtrunk putgun [1-4 slot]");

            printf(" Slot: %d", slot );
        }
    }

    return 1;
}
My problem is that when I do /vehtrunk putgun and only that, I get the message "SYNTAX: /vehtrunk putgun [1-4 slot]", however, if I do for example /vehtrunk putgun 3, nothing happens, and the message is not printed to the console.

p.s: I removed irrevelant bits of code.

Why?
Reply
#2

I'd personally have /trunk put gun (gun)
Reply
#3

I think it's the same thing.. even with that way you tell me I would have problems.. I need some orientation to use sscanf properly in this situation.
Reply
#4

bump
Reply
#5

pawn Code:
CMD:vehtrunk( playerid, params[] )
{
    new option[64];
    if(!sscanf( params, "s[64]", option ))
    {
        SendClientMessage( playerid, COLOR_GREEN, "SYNTAX: /vehtrunk [info/open/close/putgun/takegun/putcocaine/takecocaine/putheroin]");
        SendClientMessage( playerid, COLOR_GREEN, "[takeheroin/putecstasy/takeecstasy/putcrack/takecrack/putweed/takeweed/putcrystalmeth]");
        SendClientMessage( playerid, COLOR_GREEN, "[takecrystalmeth/putsteroids/takesteroids/putgascan/takegascan/putmaterials/takematerials]");

        return 1;
    }

    if ( !isnull( option ) )
    {

        new closest = GetClosestVehicleInRange( playerid, 3.0 );

        new szString[128];


        else if ( !strcmp( option, "putgun", true ) )
        {
            new slot;
            if( sscanf( params, "d", slot ) )
                return SendClientMessage( playerid, COLOR_BEIGE, "SYNTAX: /vehtrunk putgun [1-4 slot]");

            printf(" Slot: %d", slot );
        }
    }

    return 1;
}
Reply
#6

pawn Code:
CMD:vehtrunk( playerid, params[ ] )
{
    if( !isnull( params ) )
    {
        SendClientMessage( playerid, COLOR_GREEN, "SYNTAX: /vehtrunk [info/open/close/putgun/takegun/putcocaine/takecocaine/putheroin]" );
        SendClientMessage( playerid, COLOR_GREEN, "[takeheroin/putecstasy/takeecstasy/putcrack/takecrack/putweed/takeweed/putcrystalmeth]" );
        SendClientMessage( playerid, COLOR_GREEN, "[takecrystalmeth/putsteroids/takesteroids/putgascan/takegascan/putmaterials/takematerials]" );
        return 1;
    }
    if( strcmp( params, "info", true ) == 0)
    {
        // Code about Info
    }
    else if( strcmp( params, "open", true ) == 0)
    {
        // Code about Open
    }
    else if( strcmp( params, "close", true ) == 0)
    {
        // Code about Close
    }
    else if( strcmp( params, "putgun", true ) == 0)
    {
        // Code about Putgun
    }
    // Continue up to the last...
    else if( strcmp( params, "takematerials", true ) == 0)
    {
        // Code about Takematerials
    }
    else
    {
        SendClientMessage( playerid, COLOR_GREEN, "SYNTAX: /vehtrunk [info/open/close/putgun/takegun/putcocaine/takecocaine/putheroin]" );
        SendClientMessage( playerid, COLOR_GREEN, "[takeheroin/putecstasy/takeecstasy/putcrack/takecrack/putweed/takeweed/putcrystalmeth]" );
        SendClientMessage( playerid, COLOR_GREEN, "[takecrystalmeth/putsteroids/takesteroids/putgascan/takegascan/putmaterials/takematerials]" );
        return 1;
    }
    return 1;
}
Reply
#7

----
Reply
#8

These commands are not really helping, as in, for example, when I need to do "putmaterials" and insert an ammount of items to place in the trunk, I will need to use sscanf again to extract that the same way.

I now know why is it caused; now how do I fix it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)