Raised This Month: $ Target: $400
 0% 

Changing the rate of fire in TF2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tf2Ownage
Junior Member
Join Date: Mar 2009
Old 03-24-2009 , 12:16   Changing the rate of fire in TF2
Reply With Quote #1

Hello everyone!
Recently i've been looking for a way to change the rate of fire in Tf2 WITHOUT modifying the .ctx files (which seems to be the only thing people suggest on this forum). I set about searching for many methods of doing it, and finally i found some useful posts and then modified the code and got it to work. So here is the code:

EDIT: MikeJS has posted an inproved version below.

I should say that I need to give credit to many peoples posts which have all contained much useful information that i've used. This can defiantly be improved, eg. changing the values per weapon. If you chose to compile this code then it can be enabled by "sm_InsaneMode 1". If anyone makes improvements be sure to post them here.

Feel free to you the code, but credit is appreciated
Thanks to everyone!
Ownage

Last edited by Tf2Ownage; 08-27-2009 at 17:50.
Tf2Ownage is offline
Darkimmortal
Senior Member
Join Date: Aug 2008
Old 03-24-2009 , 22:33   Re: Changing the rate of fire in TF2
Reply With Quote #2

If that actually works (and it probably does) then it is going to be incredibly useful in my plugins.

+Karma
__________________
Darkimmortal is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 03-25-2009 , 12:09   Re: Changing the rate of fire in TF2
Reply With Quote #3

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
new offsNextPrimaryAttack = -1;
new 
offsNextSecondaryAttack = -1;
new 
offsActiveWeapon = -1;
new 
weaponRateQueue[MAXPLAYERS+1];
new 
weaponRateQueueLen;
new 
Handle:g_hROF INVALID_HANDLE;
new 
Float:rofmult;
public 
OnPluginStart() {
    
offsNextPrimaryAttack FindSendPropInfo("CBaseCombatWeapon""m_flNextPrimaryAttack");
    
offsNextSecondaryAttack FindSendPropInfo("CBaseCombatWeapon""m_flNextSecondaryAttack");
    
offsActiveWeapon FindSendPropInfo("CTFPlayer""m_hActiveWeapon");
    
g_hROF CreateConVar("sm_rof""1.0""ROF multiplier."FCVAR_PLUGIN|FCVAR_NOTIFY);
    
HookConVarChange(g_hROFCvar_rof);
}
public 
OnConfigsExecuted() {
    
rofmult 1.0/GetConVarFloat(g_hROF);
}
public 
OnGameFrame() {
    if(
weaponRateQueueLen) {
        
decl entFloat:time;
        new 
Float:enginetime GetGameTime();
        for(new 
i=0;i<weaponRateQueueLen;i++) {
            
ent weaponRateQueue[i];
            if(
IsValidEntity(ent)) {
                
time = (GetEntDataFloat(entoffsNextPrimaryAttack)-enginetime)*rofmult;
                
SetEntDataFloat(entoffsNextPrimaryAttacktime+enginetimetrue);
                
time = (GetEntDataFloat(entoffsNextSecondaryAttack)-enginetime)*rofmult;
                
SetEntDataFloat(entoffsNextSecondaryAttacktime+enginetimetrue);
            }
        }
        
weaponRateQueueLen 0;
    }
}
public 
Cvar_rof(Handle:convar, const String:oldValue[], const String:newValue[]) {
    
rofmult 1.0/GetConVarFloat(g_hROF);
}
public 
Action:TF2_CalcIsAttackCritical(clientweaponString:weaponname[], &bool:result) {
    new 
ent GetEntDataEnt2(clientoffsActiveWeapon);
    if(
ent!=-1) {
        
weaponRateQueue[weaponRateQueueLen++] = ent;
    }
    return 
Plugin_Continue;

edit: TF2_CalcIsAttackCritical isn't called when crits are off (obviously) and at the end of a round
__________________

Last edited by MikeJS; 03-25-2009 at 13:29.
MikeJS is offline
Tf2Ownage
Junior Member
Join Date: Mar 2009
Old 03-25-2009 , 12:49   Re: Changing the rate of fire in TF2
Reply With Quote #4

Thanks MikeJS for that improved version +K
I was looking for a way to hook 'weapon fire', and i now see that CalcIsAttackCritical is the way to go. If anyone else has improvements then be sure to post them

Tf2Ownage is offline
MomemtumMori
SourceMod Donor
Join Date: Oct 2009
Old 07-07-2010 , 18:49   Re: Changing the rate of fire in TF2
Reply With Quote #5

sry for extrem late reply but

what are the equivalent entities for CSS orangebox?
thx
MomemtumMori is offline
strontiumdog
Veteran Member
Join Date: Jan 2007
Location: BC, Canada
Old 07-07-2010 , 19:03   Re: Changing the rate of fire in TF2
Reply With Quote #6

PHP Code:
offsActiveWeapon FindSendPropInfo("CCSPlayer""m_hActiveWeapon"); 
You'll need to hook event_fire instead of TF2_CalcIsAttackCritical
__________________
Plugins | TheVille
Zombie Mod for DoD:S - l4dod.theville.org
strontiumdog is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 07-07-2010 , 19:07   Re: Changing the rate of fire in TF2
Reply With Quote #7

have a look at my weapon mod to see how i did it, http://forums.alliedmods.net/showthread.php?t=123015.
you can use weapon_fire instead of postthink, i only used postthink as weapon_fire only works for primary attack and i wanted to modify the knife stab aswell.
blodia is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 07-08-2010 , 06:40   Re: Changing the rate of fire in TF2
Reply With Quote #8

Quote:
Originally Posted by strontiumdog View Post
PHP Code:
offsActiveWeapon FindSendPropInfo("CCSPlayer""m_hActiveWeapon"); 
@MomemtumMori: Just use CBasePlayer, it'll make it work on most mods. Posting mod-specific code is silly if it can easily work on others as well
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
chrisAk
Junior Member
Join Date: Aug 2010
Old 08-16-2010 , 10:47   Re: Changing the rate of fire in TF2
Reply With Quote #9

This is a werry noobish question of me, what do i have to type to enable this?

Last edited by chrisAk; 08-16-2010 at 10:59.
chrisAk is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 08-16-2010 , 10:59   Re: Changing the rate of fire in TF2
Reply With Quote #10

http://www.sourcemod.net/compiler.php
Afronanny 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 20:46.


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