Strval or sscanf?
#1

I am creating a inventory system where you can use /inv use 1, /inv usetool 3 etc. But I got as far as /inv use/usetool. I can't find a way to make it so you can input an integer to use a inventory slot. The code is:

pawn Код:
CMD:inv(playerid, params[])
{
    new option[20];
    if(isnull(params))
    {
        return cmd_inventory(playerid, params);
    }
    if(!strcmp(option, "use", true))
    {
        new invid;
       
        if(sscanf(params, "i", invid))
        {
            if (invid == 1)
            {
                SendClientMessage(playerid, USAGE, "1 Working.");
            }
            if (invid == 2)
            {
                SendClientMessage(playerid, USAGE, "2 Working.");
            }
        }
        return 1;
    }
    if(!strcmp(option, "usetool", true))
    {
        return 1;
    }
return 1;
}
This code probably looks daft as I am not an experienced pawno coder, but I have tried a number of things, including Strval.

So I was wondering if any of you guys could give me a hand here, should I use Strval or sscanf? And how would I go about doing so.
Reply
#2

Just beneath the insull block, put an sscanf statement like this:
pawn Код:
sscanf(params, "S(NULL)[20]I(0)", option, invid);
Then you may check if option is not NULL.
Reply
#3

That compiled fine but it doesnt work IG, any more suggestions? I'm close to pulling my hair out with this bug.
Reply
#4

Last reply was yesterday, anyone got a solution at all? Really need this.
Reply
#5

try this:
pawn Код:
CMD:inv(playerid, params[])
{
    new option[20];
    if(isnull(params))
    {
        return cmd_inventory(playerid, params);
    }
    if(!strcmp(option, "use", true))
    {
        new invid;
       
        if(!sscanf(params, "i", invid))
        {
            if (invid == 1)
            {
                SendClientMessage(playerid, USAGE, "1 Working.");
            }
            if (invid == 2)
            {
                SendClientMessage(playerid, USAGE, "2 Working.");
            }
        }
        return 1;
    }
    if(!strcmp(option, "usetool", true))
    {
        return 1;
    }
return 1;
}
Reply
#6

Nothing, I use it and nothing appears on my screen. Thanks for trying though.
Reply
#7

try this, I am not sure though...

pawn Код:
CMD:inv(playerid, params[])
{
    new option[20];
    if(isnull(params))
    {
        return cmd_inventory(playerid, params);
    }
    if(strcmp(option, "use", true) == 0) // <-- This edited
    {
        new invid;
       
        if(sscanf(params, "i", invid))
        {
            if (invid == 1)
            {
                SendClientMessage(playerid, USAGE, "1 Working.");
            }
            if (invid == 2)
            {
                SendClientMessage(playerid, USAGE, "2 Working.");
            }
        }
        return 1;
    }
    if(!strcmp(option, "usetool", true))
    {
        return 1;
    }
return 1;
}
Reply
#8

Nothing again, it compiles fine though. Thanks for the comment.
Reply
#9

Quote:
Originally Posted by L.Hudson
Посмотреть сообщение
try this, I am not sure though...

[pawn]
if(strcmp(option, "use", true) == 0) // <-- This edited
! is the same with == 0.

Код:
if( !IsPlayerInAnyVehicle( playerid ) )
=
Код:
if( IsPlayerInAnyVehicle( playerid ) == 0 )
Try this:
Код:
CMD:inv( playerid, params[ ] )
{
	if( isnull( params ) )
		return cmd_inventory( playerid, params );

	if( !strcmp( params, "use", true ) )
	{
		new lsTMP[ 4 ], invid;

		if( !sscanf( params, "s[4]i", lsTMP, invid ) )
		{
			switch( invid )
			{
				case 1: SendClientMessage( playerid, USAGE, "1 Working." );
				case 2: SendClientMessage( playerid, USAGE, "2 Working." );
			}
		}
		return 1;
	}
	if( !strcmp( params, "usetool", true ) )
	{
		return 1;
	}
	return 1;
}
Reply
#10

Tried it but when I use /inv use 1/2 nothing appears. It says nothing. Thanks for the comment though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)