Thread: Checking if a player holds specific weapons

Results 1 to 7 of 7
  1. #1
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    445

    Checking if a player holds specific weapons

    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.

  2. #2
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,596

    Re: Checking if a player holds specific weapons

    CBasePlayer has a method for that:

    Code:
    if (plr.HasNamedPlayerItem("weapon_crowbar") !is null)
    {
        // player has le crowbar
    }
    You used to be able to check the weapons bitfield with hammer ents (no AS required), but according to Solo this no longer works. I haven't actually tested that though.
    Love,
    w00tguy

  3. #3
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    445

    Re: Checking if a player holds specific weapons

    Quote Originally Posted by w00tguy123 View Post
    CBasePlayer has a method for that:

    Code:
    if (plr.HasNamedPlayerItem("weapon_crowbar") !is null)
    {
        // player has le crowbar
    }
    You used to be able to check the weapons bitfield with hammer ents (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?

  4. #4
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,596

    Re: Checking if a player holds specific weapons

    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.
    Love,
    w00tguy

  5. #5
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    445

    Re: Checking if a player holds specific weapons

    Quote Originally Posted by w00tguy123 View Post
    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 :/

  6. #6
    Japanese Wannabe NYO~~~! ゞ(´゜ω゜)つ~☆ Nero's Avatar
    Join Date
    Jul 2002
    Location
    Eskilstuna, Sweden.
    Posts
    579

    Re: Checking if a player holds specific weapons

    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.
    Nero of TSP and Wotnet
    Ingame names: Nero, Horny-Girl-13
    IRC nick: Nero (probably)

  7. #7
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    445

    Re: Checking if a player holds specific weapons

    TertiaryAttack is map script only btw

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •