PDA

View Full Version : Weapon help


silverms
14/04/2017, 05:33 PM
is there a way to check if like this number 12342 is a weapon id?

AndreiWow
14/04/2017, 05:40 PM
If you want to make a givegun weapon or something like that you can check if the weapon id is between 1 and 46 otherwise the id is not good.

silverms
14/04/2017, 05:51 PM
how to check if it was between 1 and 46?

ISmokezU
14/04/2017, 06:01 PM
new weaponid
if(weaponid < 1 || weaponid > 46)

AndreiWow
14/04/2017, 06:06 PM
Well for example if you want to make a give weapon cmd you can do something like this

Let's say that your command is /givewep <playerid> <weaponid>

We will use weaponid to see what the player inserted, of course we'll use sscanf for that which you can find here: http://wiki.sa-mp.com/wiki/Fast_Commands


if (sscanf(params, "ud", id, weaponid)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/givewep <playerid/partname> <weaponid>\"");


define id and weaponid to avoid any errors

And you can check if the id that the player inserted is valid by doing this

if(weaponid >=1 && weaponid <= 46)
{
code here
}
else
{
code here if he inserted an invalid it
}

LEOTorres
14/04/2017, 06:11 PM
Just checking inbetween the values would not work here, because there are values inbetween the ranges you have listed which aren't actually weapons.

new example = 57;

if (example >= 0 && example <= 46 && example != 19 && example != 20 && example != 21)
{
//variable holds valid weaponid
}

else
{
//variable does not hold valid weaponid
}