SA-MP Forums Archive
Strval or sscanf? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Strval or sscanf? (/showthread.php?tid=360373)



Inventory use help. - dholmes7512 - 17.07.2012

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.


Re: Strval or sscanf? - Vince - 17.07.2012

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.


Re: Strval or sscanf? - dholmes7512 - 17.07.2012

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


Re: Strval or sscanf? - dholmes7512 - 18.07.2012

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


Re: Strval or sscanf? - Andi_Evandy - 18.07.2012

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;
}



Re: Strval or sscanf? - dholmes7512 - 18.07.2012

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


Re: Strval or sscanf? - L.Hudson - 18.07.2012

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;
}



Re: Strval or sscanf? - dholmes7512 - 18.07.2012

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


Re: Strval or sscanf? - IstuntmanI - 18.07.2012

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;
}



Re: Strval or sscanf? - dholmes7512 - 18.07.2012

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