Raised This Month: $51 Target: $400
 12% 

Solved Ham_Weapon_SecondaryAttack on elites, for example


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 06-30-2017 , 09:58   Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #1

Is it possible to make Ham_Weapon_SecondaryAttack working for weapons that haven't zoom or silencer?

I just put this code and it doesn't display the print
PHP Code:
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_elite""fw_Weapon_SecondaryAttack")

public 
fw_Weapon_SecondaryAttack(ent)
{
    
client_print(0print_chat"Hey")

The other way is hook FM_CmdStart and check for IN_ATTACK2... but I prefer the previous code.

Some way to make it possible? Just a offset or something?

Last edited by baneado; 07-05-2017 at 12:39.
baneado is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 06-30-2017 , 10:17   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #2

https://github.com/s1lentq/ReGameDLL.../wpn_elite.cpp

Elites don't have a secondary attack registered. (as in, the method SecondaryAttack)

Your options are either use a custom version of ReGameDLL to add this method, or hook the button attack2 while the player is holding the elites.
__________________

Last edited by gabuch2; 06-30-2017 at 10:18.
gabuch2 is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 06-30-2017 , 11:28   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #3

1. Ham_Weapon_SecondaryAttack is called just for weapons who already have an secondary attack as GabbyIggy told you ( Zoom, USP-Silencer, Glock/Famasa/Galil Shoot burst style, etc. )

2. The good way of dealing with index is doing:
PHP Code:
new OwnerId peventpev_owner); 
3. You can also make a special command like "+myoption" and users can bind click-right(replacing +attack2) with your command like:
Code:
bind mouse2 "+myoption"
__________________
Project: Among Us

Last edited by Craxor; 06-30-2017 at 11:29.
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-30-2017 , 11:44   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #4

Quote:
Originally Posted by Gabe Iggy View Post
https://github.com/s1lentq/ReGameDLL.../wpn_elite.cpp

Elites don't have a secondary attack registered. (as in, the method SecondaryAttack)
That's not the issue. It's a virtual function and it's inherited from CBasePlayerWeapon, so all weapons do have the SecondaryAttack() method. The thing is that it's never called for weapons that aren't meant to have a secondary attack. Take a look here.

Quote:
hook the button attack2 while the player is holding the elites.
That seems like a valid option.


What would probably be the best thing to do is to hook bool CBasePlayerWeapon::HasSecondaryAttack() and to return true from it. You can hook it with Orpheu, Okapi or ReAPI.
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2017 , 15:54   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
What would probably be the best thing to do is to hook bool CBasePlayerWeapon::HasSecondaryAttack() and to return true from it. You can hook it with Orpheu, Okapi or ReAPI.
He could try to hook ItemPostFrame with hamsandwich and add IN_ATTACK2 to pev_button. Tho this could mess up things, I'm not sure if it's a good ideea.
But yeah, hooking HasSecondaryAttack and altering the return value is by far the best and safest way in case the function is not copied by the compiler where it's used. It's called only from ItemPostFrame, and from what I saw while working with similar functions, some times the compiler just copy/paste the function, so hooking it does nothing, because the original function is never called. If this is the case, then hooking ItemPostFrame and handling that function at a plugin level(redoing the code) would be the solution.
__________________

Last edited by HamletEagle; 06-30-2017 at 15:59.
HamletEagle is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 06-30-2017 , 15:58   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #6

Best way is hooking HasSecondaryAttack as Klippy said, but you also can do it the way how game actually does it too

Code:
public plugin_init()
{
      ....
      RegisterHam(Ham_Item_PostFrame, "weapon_elite", "OnItemPostFrame");
      ....
}

.......

public OnItemPostFrame(weapon)
{
     .... checks here

     static player;
     player = get_ent_data_entity(weapon, "CBasePlayerItem", "m_pPlayer");

     static buttons;
     buttons = pev(player, pev_button, buttons);

     if ((buttons & IN_ATTACK2) && (get_ent_data_float(weapon, "CBasePlayerWeapon", "m_flNextSecondaryAttack") <= 0.0))
     {
          //Your attack goes here
          // Or you can do this ExecuteHamB(Ham_Weapon_SecondaryAttack, weapon);
          set_pev(player, pev_button, buttons &= ~IN_ATTACK2);
     }
}
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2017 , 16:00   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #7

What I said basically.
__________________

Last edited by HamletEagle; 06-30-2017 at 16:00.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 06-30-2017 , 16:02   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #8

@nihi, did you test if is working?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 06-30-2017 , 16:10   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #9

Quote:
Originally Posted by HamletEagle
What I said basically.
I started to write this before your reply.

Quote:
Originally Posted by Craxor
@nihi, did you test if is working?
It's working fine for me.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-30-2017 , 16:18   Re: Ham_Weapon_SecondaryAttack on elites, for example
Reply With Quote #10

Quote:
Originally Posted by Craxor View Post
@nihi, did you test if is working?
It should work, that's how game does it. It just ignores the HasSecondaryAttack check, the rest of the logic is the same.
__________________

Last edited by HamletEagle; 06-30-2017 at 16:19.
HamletEagle is offline
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 02:04.


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