Raised This Month: $32 Target: $400
 8% 

How do i hook player shooting event?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Siveroo
Junior Member
Join Date: Apr 2020
Old 03-19-2021 , 10:39   How do i hook player shooting event?
Reply With Quote #1

As the title said, i want to run some piece of code if a player is shooting, (not just left clicking, +attack, or whatever). I want it to trigger if the players actually shoots a bullet. I've search something related to this, and someone said that its possible to use playbackevent, but i dont know what that is, let alone using it. I tried to search how to use it tho, but still have zero clue..
Siveroo is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-19-2021 , 10:50   Re: How do i hook player shooting event?
Reply With Quote #2

Hamsandwich functions:
PHP Code:
Ham_Weapon_PrimaryAttack(iEnt) - For primary attack hook 
PHP Code:
Ham_Weapon_SecondaryAttack(iEnt) - For secondary attack hook 
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 03-19-2021 , 10:58   Re: How do i hook player shooting event?
Reply With Quote #3

I think the closest thing you can do is hooking FireBulletsPlayer() with Orpheu, but that is more complex since you need signatures. Otherwise you'll need to rely on Ham_Weapon_PrimaryAttack and Ham_Weapon_SecondaryAttack but that won't give you the exact moment when they shoot, but rather the moment the attack function is processed. (Example of PrimaryAttack() in weapon_9mmar).
__________________
gabuch2 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-19-2021 , 12:09   Re: How do i hook player shooting event?
Reply With Quote #4

here's the proper way its rather than using primary attack.

https://forums.alliedmods.net/showthread.php?t=54887

you can also catch all fired weapons by hooking FM_TraceLine or Ham_TraceAttack if you're interested to hook a fire for a specific weapon.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-19-2021 at 12:18.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-19-2021 , 13:50   Re: How do i hook player shooting event?
Reply With Quote #5

PrimaryAttack is not a good idea, if you are out of ammo and hold m1 it will still trigger. As Natsheh said, PlayBackEvent is a better option.
__________________
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-19-2021 , 17:02   Re: How do i hook player shooting event?
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
if you are out of ammo and hold m1 it will still trigger
You can easily prevent that:

Code:
const XO_WEAPON = 4 const m_iClientClip = 52 if(cs_get_weapon_ammo(iEnt) == get_pdata_int(iEnt, m_iClientClip, XO_WEAPON)) {     return }
__________________

Last edited by OciXCrom; 03-19-2021 at 17:03.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-20-2021 , 04:11   Re: How do i hook player shooting event?
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
You can easily prevent that:

Code:
const XO_WEAPON = 4 const m_iClientClip = 52 if(cs_get_weapon_ammo(iEnt) == get_pdata_int(iEnt, m_iClientClip, XO_WEAPON)) {     return }
Which is useless when you already have PlaybackEvent. It is called from PrimaryAttack(indirectly, PrimaryAttack -> WeaponFire -> PlaybackEvent) after checking ammo.
Just because you can do something it does not mean you should.
__________________

Last edited by HamletEagle; 03-20-2021 at 04:15.
HamletEagle is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-20-2021 , 06:40   Re: How do i hook player shooting event?
Reply With Quote #8

Basically its like going to a destination C, starting from point A going through Point B, knowing you can go to point C directly without needing to pass through point B.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Siveroo
Junior Member
Join Date: Apr 2020
Old 03-20-2021 , 08:59   Re: How do i hook player shooting event?
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
here's the proper way its rather than using primary attack.

https://forums.alliedmods.net/showthread.php?t=54887

you can also catch all fired weapons by hooking FM_TraceLine or Ham_TraceAttack if you're interested to hook a fire for a specific weapon.
i think im gonna stick with this for now, also im wondering, can i hook knife left click and right click attack too? (still gonna apply the same rule where you need to actually attack, not just detecting if +attack/+attack2 is pressed)
Siveroo is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-20-2021 , 09:03   Re: How do i hook player shooting event?
Reply With Quote #10

Quote:
Originally Posted by HamletEagle View Post
Which is useless when you already have PlaybackEvent. It is called from PrimaryAttack(indirectly, PrimaryAttack -> WeaponFire -> PlaybackEvent) after checking ammo.
Just because you can do something it does not mean you should.
True, but PlaybackEvent requires manually typing in the .sc files and handling precache, while with Ham you can directly use get_weaponname(). If one simple check can prevent all of this, I'd go for that even though the other method is more direct.
__________________

Last edited by OciXCrom; 03-20-2021 at 09:05.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode