PDA

View Full Version : Checking if a player holds specific weapons



nico
01-05-2016, 03:56 PM
I want to check if a player hold specific weapons, explosives to be more percise.

I can't figure out how to do it.

There is pPlayer.pev.weapons:


int weapons
Entity weapons bit vector. Largely used by monsters to track which weapons they have, and by players for internal purposes.



And there are WeaponIds. (WeaponIds.htm).

But I don't know how to use it though, need some help. If anyone could make an example hot to check for genades or satchels that would be nice.

w00tguy123
01-05-2016, 04:08 PM
CBasePlayer has a method for that:



if (plr.HasNamedPlayerItem("weapon_crowbar") !is null)
{
// player has le crowbar
}

You used to be able to check the weapons bitfield with hammer ents (http://forums.svencoop.com/showthread.php/42115-Weapon-values) (no AS required), but according to Solo this no longer works. I haven't actually tested that though.

nico
02-05-2016, 01:34 AM
CBasePlayer has a method for that:



if (plr.HasNamedPlayerItem("weapon_crowbar") !is null)
{
// player has le crowbar
}

You used to be able to check the weapons bitfield with hammer ents (http://forums.svencoop.com/showthread.php/42115-Weapon-values) (no AS required), but according to Solo this no longer works. I haven't actually tested that though.

Cool thx, way easier than I thought :P

Now I also plan on using WeaponTertiaryAttackHook(CBasePlayer@, CBasePlayerWeapon@), which should consume x ammo of CBasePlayerWeapon. So I guess I check for m_iClip size, but to take ammo from the weapon, can I just modify that value?

w00tguy123
02-05-2016, 02:15 AM
Yep, you can modify m_iClip directly.

Are you trying to hook into an existing weapon's tertiary attack? I think you can only override TertiaryAttack() in your own custom weapon.

nico
02-05-2016, 02:19 AM
Yep, you can modify m_iClip directly.

Are you trying to hook into an existing weapon's tertiary attack? I think you can only override TertiaryAttack() in your own custom weapon.

Aww, I plan on using existing weapons. Have not tried it yet. I hope it will work :/

Nero
03-05-2016, 09:35 PM
I'm pretty sure you can't mess with existing weapons in any way :/
Haven't tried it though.

m_iClip is only for weapons that have a clip (reloadable)
For WEAPON_NOCLIP you have to use:

self.m_pPlayer.m_rgAmmo( self.m_iPrimaryAmmoType, self.m_pPlayer.m_rgAmmo( self.m_iPrimaryAmmoType ) - int );

Where int is the amount of ammo to remove.

nico
04-05-2016, 01:41 AM
TertiaryAttack is map script only btw :(