[lua] Class.ShotSpeed = function(ply)
for k, v in pairs(ply:GetWeapons()) do
v.Primary.Delay = (v.Primary.Delay * (1 + (ply.ShotSpeed / 100)))
v.Secondary.Delay = (v.Secondary.Delay * (1 + (ply.ShotSpeed / 100)))
v.Primary.RPM = (v.Primary.RPM * (1 + (ply.ShotSpeed / 100)))
end
end[/lua]
This seems to do nothing
What is the best way to change someone's firerate
[editline]17th September 2015[/editline]
i have seen it done in multiple places mainly rpg type addons but cant seem to get it to work
Maybe they edited the weapons themself?
the weapon i am trying to alter has Primary.RPM
i changed that, no errors i also changed the way i am doing it
[lua]
if SERVER then
local function onweaponpickup(weapon)
local ply = weapon:GetOwner()
inv_firerate(ply, weapon)
end
hook.Add('WeaponEquip', 'onweaponpickup', onweaponpickup )
function inv_firerate(ply, weapon)
if IsValid(weapon.Primary) then
if IsValid(weapon.Primary.Delay) then
weapon.Primary.Delay = (weapon.Primary.Delay * (1 + (ply.ShotSpeed / 100)))
end
if IsValid(weapon.Secondary.Delay) then
weapon.Secondary.Delay = (weapon.Secondary.Delay * (1 + (ply.ShotSpeed / 100)))
end
if IsValid(weapon.Primary.RPM) then
weapon.Primary.RPM = (weapon.Primary.RPM * (1 + (ply.ShotSpeed / 100)))
end
end
end
end
[/lua]
This is what i get when i print the table for said weapon (testing with a random weapon)
[code]
AdminSpawnable = true
Author =
AutoSwitchFrom = true
AutoSwitchTo = true
Base = clout_gun_base
BounceWeaponIcon = false
CanBeSilenced = false
Category = Clout's CSGO Weapons
ClassName = clt_akvlcn
Contact =
DrawAmmo = true
DrawCrosshair = true
DrawWeaponInfoBox = false
FiresUnderwater = false
Folder = weapons/clt_akvlcn
Gun = clt_akvlcn
HoldType = ar2
Instructions =
IronSightsAng = 2.342000 -0.145000 0.000000
IronSightsPos = 4.869000 -14.039000 1.769000
Primary:
Ammo = ar2
Automatic = true
ClipSize = 30
Damage = 23
DefaultClip = 90
IronAccuracy = 0.02
KickDown = 0.3
KickHorizontal = 0.4
KickUp = 0.6
RPM = 575
SilencedSound =
Sound = clt_vcln-1
Spread = 0.03
PrintName = AK-47 Vulcan
Purpose =
RunSightsAng = 0.000000 -26.590000 1.608000
RunSightsPos = -5.131000 4.952000 -2.370000
Secondary:
IronFOV = 70
SelectiveFire = false
ShowWorldModel = false
SightsAng = 2.342000 -0.145000 0.000000
SightsPos = 4.869000 -14.039000 1.769000
Slot = 2
SlotPos = 3
Spawnable = true
ViewModel = models/weapons/v_vulakclt.mdl
ViewModelFOV = 70
ViewModelFlip = true
WElements:
clt_vlcn_wrld:
angle = -12.407 2.015 180.000
bodygroup:
bone = ValveBiped.Bip01_R_Hand
color:
a = 255
b = 255
g = 255
r = 255
material =
model = models/weapons/w_vulakclt.mdl
pos = 3.444000 1.483000 0.400000
rel =
size = 1.000000 1.000000 1.000000
skin = 0
surpresslightning = false
type = Model
Weight = 43
WorldModel = models/weapons/w_rif_ak47.mdl
data:
ironsights = 1
[/code]
I mean edit the weapon ITSELF - the SOURCE of the weapon inside /lua/weapons from the addon.
It might be that the weapon in question, in-fact, does not use these variable to control it's rate of fire.
I've seen quite a few examples of badly coded weapons where it wasn't used, and it instead was hardcoded.
This is how I did it:
[code] s:AddHook( "Think", function( this )
local k, v, wep, pl, prim, sec, save, mul
for k, v in ipairs( player.GetAll( ) ) do
if not v:Alive( ) then continue end
wep = v:GetActiveWeapon( )
if not wep:IsValid( ) then continue end
mul = math.max( .1, 1 - ( RPG:GetSkill( v, this:GetID( ) ) * .05 ) )
mul = RPG:TimeScaleMultiplier( v, mul, 0 )
save = wep:GetSaveTable( )
prim = save.m_flNextPrimaryAttack
sec = save.m_flNextSecondaryAttack
wep.RPG_LastPrimaryDelay = wep.RPG_LastPrimaryDelay or 0
wep.RPG_LastSecondaryDelay = wep.RPG_LastSecondaryDelay or 0
if not ( prim and sec ) then continue end
if prim > wep.RPG_LastPrimaryDelay then
prim = math.max( prim > .065 and .065 or .01, prim * mul )
wep:SetSaveValue( "m_flNextPrimaryAttack", prim )
end
if sec > wep.RPG_LastSecondaryDelay then
sec = math.max( sec > .065 and .065 or .01, sec * mul )
wep:SetSaveValue( "m_flNextSecondaryAttack", sec )
end
wep.RPG_LastPrimaryDelay = prim
wep.RPG_LastSecondaryDelay = sec
end
end )[/code]
It's incredibly dirty, but it will work on nearly every weapon barring those that manage the time themselves instead of using the engine methods. You should have an idea of what you need to do from that.
[QUOTE=Kogitsune;48714556]This is how I did it:
[code] s:AddHook( "Think", function( this )
local k, v, wep, pl, prim, sec, save, mul
for k, v in ipairs( player.GetAll( ) ) do
if not v:Alive( ) then continue end
wep = v:GetActiveWeapon( )
if not wep:IsValid( ) then continue end
mul = math.max( .1, 1 - ( RPG:GetSkill( v, this:GetID( ) ) * .05 ) )
mul = RPG:TimeScaleMultiplier( v, mul, 0 )
save = wep:GetSaveTable( )
prim = save.m_flNextPrimaryAttack
sec = save.m_flNextSecondaryAttack
wep.RPG_LastPrimaryDelay = wep.RPG_LastPrimaryDelay or 0
wep.RPG_LastSecondaryDelay = wep.RPG_LastSecondaryDelay or 0
if not ( prim and sec ) then continue end
if prim > wep.RPG_LastPrimaryDelay then
prim = math.max( prim > .065 and .065 or .01, prim * mul )
wep:SetSaveValue( "m_flNextPrimaryAttack", prim )
end
if sec > wep.RPG_LastSecondaryDelay then
sec = math.max( sec > .065 and .065 or .01, sec * mul )
wep:SetSaveValue( "m_flNextSecondaryAttack", sec )
end
wep.RPG_LastPrimaryDelay = prim
wep.RPG_LastSecondaryDelay = sec
end
end )[/code]
It's incredibly dirty, but it will work on nearly every weapon barring those that manage the time themselves instead of using the engine methods. You should have an idea of what you need to do from that.[/QUOTE]
mul = math.max( .1, 1 - ( RPG:GetSkill( v, this:GetID( ) ) * .05 ) )
seems so backwards to me! lol but i got it working thanks alot!
ended up multiplying it by .001 (so 100 shotspeed = 2X normal shotspeed)
Sorry, you need to Log In to post a reply to this thread.