storewep is bugged
#1

I have made a command /storewep to store it in your trousers/jacket
And the command is not working i mean when i type /takewep [trouser]
its still showing the params of the command
When you type it
Usage: /takewep [trouser/pocket]
pawn Код:
CMD:takewep(playerid, params[]) // Made by CMD
{
    new option[32], string[128], string2[128];
    if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You need to login first!");
    if(sscanf(params, "i", option))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ptakegun [trousers/pocket]");
       
    }
    else if(!strcmp(option, "trousers", true))
    {
        if(!GunInfo[playerid][gGun][0]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your trousers pocket.");
        GivePlayerWeapon(playerid, GunInfo[playerid][gGun][0], GunInfo[playerid][gGunAmmo][0]);
        GunInfo[playerid][gGun][0] = 0;
        GunInfo[playerid][gGunAmmo][0] = 0;
        pInfo[playerid][pTrousers] = 0;
           GUN(GetPlayerWeapon(playerid)));
    }
    else if(!strcmp(option, "pocket", true))
    {
        if(!GunInfo[playerid][gGun][1]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your jacket pocket.");
        GivePlayerWeapon(playerid, GunInfo[playerid][gGun][1], GunInfo[playerid][gGunAmmo][1]);
        GunInfo[playerid][gGun][1] = 0;
        GunInfo[playerid][gGunAmmo][1] = 0;
        pInfo[playerid][pJacket] = 0;
        GUN(GetPlayerWeapon(playerid)));
    }
    return 1;
}
Reply
#2

Hi. I saw that you used "i" in the sscanf syntax: if(sscanf(params, "i", option))
Since "option" represents a string, you have to use "s[32]" ("i" stands for integrer, 1, 2, 3, 4, -1, -2, etc.)

So your code must be something like this:

Код:
CMD:takewep(playerid, params[])
{
	new option[32], string[128], string2[128];
   	if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You need to login first!");
   	if(sscanf(params, "s[32]", option))
	{
 		SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ptakegun [trousers/pocket]");
 		
 	}
 	else if(!strcmp(option, "trousers", true))
	{
 		if(!GunInfo[playerid][gGun][0]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your trousers pocket.");
 		GivePlayerWeapon(playerid, GunInfo[playerid][gGun][0], GunInfo[playerid][gGunAmmo][0]);
		GunInfo[playerid][gGun][0] = 0;
		GunInfo[playerid][gGunAmmo][0] = 0;
		pInfo[playerid][pTrousers] = 0;
	       GUN(GetPlayerWeapon(playerid)));
	}
	else if(!strcmp(option, "pocket", true))
	{
	    if(!GunInfo[playerid][gGun][1]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your jacket pocket.");
 		GivePlayerWeapon(playerid, GunInfo[playerid][gGun][1], GunInfo[playerid][gGunAmmo][1]);
		GunInfo[playerid][gGun][1] = 0;
		GunInfo[playerid][gGunAmmo][1] = 0;
		pInfo[playerid][pJacket] = 0;
		GUN(GetPlayerWeapon(playerid)));
	}
	return 1;
}
+rep?
Reply
#3

Quote:
Originally Posted by Vennox
Посмотреть сообщение
Hi. I saw that you used "i" in the sscanf syntax: if(sscanf(params, "i", option))
Since "option" represents a string, you have to use "s[32]" ("i" stands for integrer, 1, 2, 3, 4, -1, -2, etc.)

So your code must be something like this:

Код:
CMD:takewep(playerid, params[])
{
	new option[32], string[128], string2[128];
   	if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You need to login first!");
   	if(sscanf(params, "s[32]", option))
	{
 		SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ptakegun [trousers/pocket]");
 		
 	}
 	else if(!strcmp(option, "trousers", true))
	{
 		if(!GunInfo[playerid][gGun][0]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your trousers pocket.");
 		GivePlayerWeapon(playerid, GunInfo[playerid][gGun][0], GunInfo[playerid][gGunAmmo][0]);
		GunInfo[playerid][gGun][0] = 0;
		GunInfo[playerid][gGunAmmo][0] = 0;
		pInfo[playerid][pTrousers] = 0;
	       GUN(GetPlayerWeapon(playerid)));
	}
	else if(!strcmp(option, "pocket", true))
	{
	    if(!GunInfo[playerid][gGun][1]) return SendClientMessage(playerid, -1, "[Error] You don't have a weapon in your jacket pocket.");
 		GivePlayerWeapon(playerid, GunInfo[playerid][gGun][1], GunInfo[playerid][gGunAmmo][1]);
		GunInfo[playerid][gGun][1] = 0;
		GunInfo[playerid][gGunAmmo][1] = 0;
		pInfo[playerid][pJacket] = 0;
		GUN(GetPlayerWeapon(playerid)));
	}
	return 1;
}
+rep?
dude if you already added that 32 value in new option[32];
then dont add it again in sscanf params

like
PHP код:
CMD:takewep(playeridparams[])
{
    new 
option[32], string[128], string2[128];
       if(!
IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1"You need to login first!");
       if(
sscanf(params"s"option))
    {
         
SendClientMessage(playeridCOLOR_WHITE"USAGE: /ptakegun [trousers/pocket]");
         
     }
     else if(!
strcmp(option"trousers"true))
    {
         if(!
GunInfo[playerid][gGun][0]) return SendClientMessage(playerid, -1"[Error] You don't have a weapon in your trousers pocket.");
         
GivePlayerWeapon(playeridGunInfo[playerid][gGun][0], GunInfo[playerid][gGunAmmo][0]);
        
GunInfo[playerid][gGun][0] = 0;
        
GunInfo[playerid][gGunAmmo][0] = 0;
        
pInfo[playerid][pTrousers] = 0;
           
GUN(GetPlayerWeapon(playerid)));
    }
    else if(!
strcmp(option"pocket"true))
    {
        if(!
GunInfo[playerid][gGun][1]) return SendClientMessage(playerid, -1"[Error] You don't have a weapon in your jacket pocket.");
         
GivePlayerWeapon(playeridGunInfo[playerid][gGun][1], GunInfo[playerid][gGunAmmo][1]);
        
GunInfo[playerid][gGun][1] = 0;
        
GunInfo[playerid][gGunAmmo][1] = 0;
        
pInfo[playerid][pJacket] = 0;
        
GUN(GetPlayerWeapon(playerid)));
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by CrystalGamer
Посмотреть сообщение
dude if you already added that 32 value in new option[32];
then dont add it again in sscanf params

like
PHP код:
CMD:takewep(playeridparams[])
{
    new 
option[32], string[128], string2[128];
       if(!
IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1"You need to login first!");
       if(
sscanf(params"s"option))
    {
         
SendClientMessage(playeridCOLOR_WHITE"USAGE: /ptakegun [trousers/pocket]");
         
     }
     else if(!
strcmp(option"trousers"true))
    {
         if(!
GunInfo[playerid][gGun][0]) return SendClientMessage(playerid, -1"[Error] You don't have a weapon in your trousers pocket.");
         
GivePlayerWeapon(playeridGunInfo[playerid][gGun][0], GunInfo[playerid][gGunAmmo][0]);
        
GunInfo[playerid][gGun][0] = 0;
        
GunInfo[playerid][gGunAmmo][0] = 0;
        
pInfo[playerid][pTrousers] = 0;
           
GUN(GetPlayerWeapon(playerid)));
    }
    else if(!
strcmp(option"pocket"true))
    {
        if(!
GunInfo[playerid][gGun][1]) return SendClientMessage(playerid, -1"[Error] You don't have a weapon in your jacket pocket.");
         
GivePlayerWeapon(playeridGunInfo[playerid][gGun][1], GunInfo[playerid][gGunAmmo][1]);
        
GunInfo[playerid][gGun][1] = 0;
        
GunInfo[playerid][gGunAmmo][1] = 0;
        
pInfo[playerid][pJacket] = 0;
        
GUN(GetPlayerWeapon(playerid)));
    }
    return 
1;

https://sampforum.blast.hk/showthread.php?tid=570927

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
The specifier "s" is used, as before, for strings - but they are now more advanced. As before they support collection, so doing:

pawn Код:
sscanf("hello 27", "si", str, val);
Will give:

Код:
hello
27
Doing:

pawn Код:
sscanf("hello there 27", "si", str, val);
Will fail as "there" is not a number. However doing:

pawn Код:
sscanf("hello there", "s", str);
Will give:

Код:
hello there
Because there is nothing after "s" in the specifier, the string gets everything. To stop this simply add a space:

pawn Код:
sscanf("hello there", "s ", str);
Will give:

Код:
hello
You can also escape parts of strings with "\\" - note that it is two backslashes as 1 is used by the compiler:

pawn Код:
sscanf("hello\\ there 27", "si", str, val);
Will give:

Код:
hello there
27
All these examples however will give warnings in the server as the new version has array sizes. The above code should be:

pawn Код:
new
    str[32],
    val;
sscanf("hello\\ there 27", "s[32]i", str, val);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)