Check if player has the weapon
#1

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
Reply
#2

Код:
if(GetPlayerWeapon(playerid) != yourweaponid)
{
    ...here do your stuff
}
Reply
#3

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;
}
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)