• How would I change the firerate of all CW2.0 weapons with one function?
    6 replies, posted
Hello all again, So here's a question I've seen asked a few times but none with decent answers. I've set up a perk add on, and one of the perks actually changes the fire-rate of all weapons by a certain percentage for that player. So, I thought that quite possibly, I could just see what weapons the player switches to, and do some maths with the delay variable, but a whole load of problems came up. Firstly, I did it on the server so i'm fairly certain it would change for everyone, which is something I've only just realized as i'm writing this. I also can't find a way to reset the fire-rate back again, because the problem i'm having is that when I switch weapon from and back to the weapon, it does the maths equation again and divides the number yet again, therefore making it double as fast as before. And everything I've tried hasn't worked. Even simply getting the original value and assigning it to a variable somehow doesn't work. So, this is extremely frustrating. Another problem is that not all SWEPs use the same variable for the delay value, and therefore I frequently get error messages. So, I was thinking there must be a much simpler way of doing this, and was hoping someone could help me out here and give me some pointers towards a decent idea for this. What I want it to do in a brief summary... If I buy the perk, it will multiple the fire rate by let's say 10% for all weapons just for my client. Thanks for reading, and please try not to be too hostile... I know it can definitely get that way here.
If I understood you right, then my solution would be something like this: For the first one, you should set the default delay multiplier, for example: We have the weapon, let's call it... weapon_ak47... Its firerate/delay in my case: SWEP.Primary.Delay = 0.1 * PlayersPerkMultiplier where "0.1" is a normal Ak-47 ShootDelay and "PlayersPerkMultiplier" is player's personal number. (You can set it with SetPData on Server-side and I would recommend you set it to 1 by default). With every bought/got perk, you will decrease "PlayersPerkMultiplier" to -0,1 (10%)(lower multiplier >> higher firerate) (also, i would recommend you to set max. amount of perks or something) For every swep file you should find this multiplier, i mean something like this: local DefaultPerkMultiplier = 1 --If there will be any problem or something, you should use the default one function SWEP:Initialize() ply = self:GetOwner() PlayersPerkMultiplier = ply:GetPData( "FirerateMultiplier", DefaultPerkMultiplier ) --I have bad experience with setting and getting data, so, maybe i made a big mistake,so i hope anyone will correct me (and of course you should check for Valid) end SWEP.Primary.Delay = 0.1 * PlayersPerkMultiplier Player's "FirerateMultiplier" should be set with the first connect. Also,for the balance, you can modify "PlayersPerkMultiplier" for every weapon, for example: Ak-47's delay is: SWEP.Primary.Delay = 0.085 * PlayersPerkMultiplier + 0.015 Deagle's delay (normal delay = 0.25): SWEP.Primary.Delay = 0.20 * PlayersPerkMultiplier + 0 .05 Sorry for bad spelling and I hope you got what i tried to say.
Thank you for the response!! So much helpful information, but I was hoping there would be a simple solution that wouldn't require me to change any weapon files and would work with all weapons, no matter what the delay variable is called.
If I'm not mistaken, CW2.0 has the base file for weapons, instead of doing this with every file, you can try to put this multiplier in that base file, that's actually the simplest way.
Is there no way to do this in a separate add - on file? I'm creating the perk add on that i'd like to be compatible with any server whatsoever.
Ugh... Probably with SetNextPrimaryFire after every shot, but that's not the best idea, I guess, but.. I can't even realize how to do it. Something with SetNextPrimaryFire: if not IsValid(ply) then return end if not IsValid(ply:GetActiveWeapon()) then return end local weapon = ply:GetActiveWeapon() --loop this somehow-- local def_delay = weapon:GetNextPrimaryFire()-CurTime() weapon:SetNextPrimaryFire(def_delay*PerkMultiplier)
There must be a way to do this simpler, surely. I'm trying to find some other add-ons with this functionality to see if i can learn from the code but I have no clue if there is one.
Sorry, you need to Log In to post a reply to this thread.