Raised This Month: $ Target: $400
 0% 

Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-12-2011 , 17:47   Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #1

Alright so I've been looking up how to modify the players weapon fire rate dynamically. And I've found some code, but have been struggling to get it working properly. I've modified it for my uses, but it is still not working. So I figured I'd make a post that would not just help me, but others trying to do something similar.

I would truly appreciate any and all help received.

Here is my current code (I have cut out non-relevant code for ease of reading).

Code:
new g_offsActiveWeapon;
new g_offsNextPrimaryAttack;

public OnPluginStart()
{
    g_offsActiveWeapon = FindSendPropOffs("CBasePlayer","m_hActiveWeapon");
    g_offsNextPrimaryAttack = FindSendPropOffs("CBaseCombatWeapon","m_flNextPrimaryAttack");
}

public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
}

public OnPostThinkPost(client)
{    
    if(IsClientConnected(client) && IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client))
    {
        new Float:gameTime = GetGameTime();

        SetEntDataFloat(client, g_offsNextPrimaryAttack, gameTime,true);
    }
}
What I am planning to do is eventually have a modifier so that different players fire at different rates. However, weapons do not seem to fire at a different rate. Instead the animations for all weapons and times from reload to fire for weapons like the xm1014 seem to be skewed.

Does anyone else have experience in matters such as these?


And before anyone mentions "weapon mod" I have taken a look at the code, and have tried to figure out the basis for how m_flNextPrimaryAttack works, so that I may create the code I need properly. However, there isn't a lot of documentation about using prop offsets like these.

Like I said above, any help is more than welcome.
Sil3nt Pr0digy is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-12-2011 , 17:57   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #2

I believe there were issues with setting it too low.
I don't remember the exact values, though.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-12-2011 , 17:59   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #3

Quote:
Originally Posted by Monkeys View Post
I believe there were issues with setting it too low.
I don't remember the exact values, though.
I have tried setting it to several different values, but none seem to work properly.

I tried the way of "Weapon Mod" and tried values ranging from .01 to 45 and saw no difference other than animation skew.

Surely there is a way to do this.
Sil3nt Pr0digy is offline
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-12-2011 , 22:37   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #4

Anyone? I would really appreciate some feedback from people who understand the finer tunings of sourcemod and or the source engine.
Sil3nt Pr0digy is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-12-2011 , 22:51   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #5

I'm guessing you're attempting this on css?

And patience is a virtue.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-13-2011 , 03:30   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #6

Quote:
Originally Posted by Monkeys View Post
I'm guessing you're attempting this on css?

And patience is a virtue.
Yes I am.

I'm also obviously using SDKHook lol.
Sil3nt Pr0digy is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-13-2011 , 05:10   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #7

I believe CSS didn't allow delays to be below 0.6, not too sure on that one.
How exactly are you testing the different values? Because the snippet you posted only tested one: no delay.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 03-13-2011 , 10:19   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #8

You're doing it wrong. Look at this

PHP Code:
        if (FloatCompare(GetEntPropFloat(meleeProp_SendENTPROP_ANIM_CYCLE), Float:0.0) == 0)
        {
            
//DebugPrintToAll("OnPreThink melee mod ran for %N, modifier %f", client, meleeSpeedMod[client]);
        
            
new Float:flNextPrimaryAttack GetEntPropFloat(meleeProp_SendENTPROP_NEXT_P_ATTACK);
            new 
Float:flNextSecondaryAttack GetEntPropFloat(meleeProp_SendENTPROP_NEXT_S_ATTACK);
            
            
SetEntPropFloat(meleeProp_SendENTPROP_PLAYBACK_RATEmeleeSpeedMod[client]);
            
SetEntPropFloat(meleeProp_SendENTPROP_NEXT_P_ATTACKflNextPrimaryAttack - ((meleeSpeedMod[client] - 1.0) / 2));
            
SetEntPropFloat(meleeProp_SendENTPROP_NEXT_S_ATTACKflNextSecondaryAttack - ((meleeSpeedMod[client] - 1.0) / 2));
        } 
AtomicStryker is offline
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-13-2011 , 14:25   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #9

Quote:
Originally Posted by Monkeys View Post
I believe CSS didn't allow delays to be below 0.6, not too sure on that one.
How exactly are you testing the different values? Because the snippet you posted only tested one: no delay.
I was doing something like this:

Code:
public OnPostThinkPost(client)
{    
    if(IsClientConnected(client) && IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client))
    {
        new Float:time;
        new Float:gameTime = GetGameTime();
        
        new Float:g_flMultiplier = 20.0;
        
        time = (GetEntDataFloat(client, g_offsNextPrimaryAttack) - gameTime) * g_flMultiplier;
        SetEntDataFloat(client, g_offsNextPrimaryAttack, time + gameTime, true);
    }
}
Which is pretty much what they do in Weapon Mod, but I still don't quite understand what I am doing wrong.
Sil3nt Pr0digy is offline
Sil3nt Pr0digy
Member
Join Date: Mar 2011
Old 03-13-2011 , 14:30   Re: Help Modifying Weapon Fire Rate Using m_flNextPrimaryAttack
Reply With Quote #10

Quote:
Originally Posted by AtomicStryker View Post
You're doing it wrong. Look at this

PHP Code:
        if (FloatCompare(GetEntPropFloat(meleeProp_SendENTPROP_ANIM_CYCLE), Float:0.0) == 0)
        {
            
//DebugPrintToAll("OnPreThink melee mod ran for %N, modifier %f", client, meleeSpeedMod[client]);
        
            
new Float:flNextPrimaryAttack GetEntPropFloat(meleeProp_SendENTPROP_NEXT_P_ATTACK);
            new 
Float:flNextSecondaryAttack GetEntPropFloat(meleeProp_SendENTPROP_NEXT_S_ATTACK);
            
            
SetEntPropFloat(meleeProp_SendENTPROP_PLAYBACK_RATEmeleeSpeedMod[client]);
            
SetEntPropFloat(meleeProp_SendENTPROP_NEXT_P_ATTACKflNextPrimaryAttack - ((meleeSpeedMod[client] - 1.0) / 2));
            
SetEntPropFloat(meleeProp_SendENTPROP_NEXT_S_ATTACKflNextSecondaryAttack - ((meleeSpeedMod[client] - 1.0) / 2));
        } 
Care to break down and explain any of the code? There is not much documentation on modifying prop values.
Sil3nt Pr0digy 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 12:55.


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