AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Ham_Weapon_SecondaryAttack on elites, for example (https://forums.alliedmods.net/showthread.php?t=299033)

baneado 06-30-2017 09:58

Ham_Weapon_SecondaryAttack on elites, for example
 
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?

gabuch2 06-30-2017 10:17

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
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.

Craxor 06-30-2017 11:28

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
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"

klippy 06-30-2017 11:44

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
Quote:

Originally Posted by Gabe Iggy (Post 2532653)
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.

HamletEagle 06-30-2017 15:54

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
Quote:

Originally Posted by KliPPy (Post 2532674)
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.

NiHiLaNTh 06-30-2017 15:58

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
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);
    }
}


HamletEagle 06-30-2017 16:00

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
What I said basically.

Craxor 06-30-2017 16:02

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
@nihi, did you test if is working?

NiHiLaNTh 06-30-2017 16:10

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
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.

HamletEagle 06-30-2017 16:18

Re: Ham_Weapon_SecondaryAttack on elites, for example
 
Quote:

Originally Posted by Craxor (Post 2532735)
@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.


All times are GMT -4. The time now is 23:00.

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