Check if player has the weapon - 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: Check if player has the weapon (
/showthread.php?tid=611823)
Check if player has the weapon -
GoldenLion - 11.07.2016
Hi, how would it be possible to check if player has a specific weapon?
Let's say I want to create a /givegun command (example), and when I give player a gun, it checks if player already has the given weapon, if player doesn't have the weapon it will give him the weapon, else it will say "player already has that weapon" or something. It's just an example, I need that for something else. :P
Re: Check if player has the weapon -
K0P - 11.07.2016
Код:
if(GetPlayerWeapon(playerid) != yourweaponid)
{
...here do your stuff
}
Re: Check if player has the weapon -
VVWVV - 11.07.2016
Use this function:
Код:
stock
IsPlayerUsingWeapon(playerid, _weaponid)
{ // Author: VVWVV
const MAX_WEAPONS_SLOTS = 13;
static ammo, weaponid;
for (new i; i != MAX_WEAPONS_SLOTS; i++)
{
if (GetPlayerWeaponData(playerid,
i, weaponid, ammo) == 0)
return 0;
if (weaponid == _weaponid)
return 1;
}
return 0;
}
Re: Check if player has the weapon -
GoldenLion - 11.07.2016
Quote:
Originally Posted by K0P
Код:
if(GetPlayerWeapon(playerid) != yourweaponid)
{
...here do your stuff
}
|
It only checks what weapon player is holding.
Quote:
Originally Posted by VVWVV
Use this function:
Код:
stock
IsPlayerUsingWeapon(playerid, _weaponid)
{ // Author: VVWVV
const MAX_WEAPONS_SLOTS = 13;
static ammo, weaponid;
for (new i; i != MAX_WEAPONS_SLOTS; i++)
{
if (GetPlayerWeaponData(playerid,
i, weaponid, ammo) == 0)
return 0;
if (weaponid == _weaponid)
return 1;
}
return 0;
}
|
Thanks, it works, but I just realized that I already have that in my script lol, u earned a rep tho