Adding Movement Penalty to weapons?

Hey guys, so I’m looking for some code help on making weapons inaccurate while moving. I started off with this code and had some success but have been getting strange results, here is the code:
[LUA]
if self.Owner:KeyDown(IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT) then
self.Primary.Cone = self.Primary.Cone * 2
else
self.Primary.Cone = self.Primary.Cone
end
[/LUA]

I inserted this code in a base lua file that links to all of the other weapons. I put this code under:
[LUA]
function SWEP:ShootBulletInformation()
[/LUA]
as that function deemed fit for this code. Now the code works, but my problem is reverting back to the default cone of fire after standing still. I tried to make it so that it reverted in the last line of the code. What I get, is I get the cone I want when I move but when I standstill the cone remains as it was when I was moving and I get this error in console:

Sometimes the Out-of-range value is different.

I’m very new at coding and I only just recently got into Lua so I’m sure I did something wrong, which is why I’m here asking for some help.

On a side note, does anyone also know how to add stamina for sprinting and jumping?

Any help is appreciated and I thank you for it.

P.S. I am using “ALL WW2 Sweps V2” and coding in weapon_dod_sim_base/shared.lua

I dont use the base… but im guessing self.Primary.Cone = self.Primary.Cone * 2 is in the think hook, which multiplies the number each frame… Its like deviding by zero with a slight timer to it. So try adding the number you want not multiplying.

Another thing… if you want lua syntax do this: [LUA*]Cody[/LUA*], without(*).

I have different cones for different weapons, so multiplying by a set number would be better for me. I’d want things like, accurate weapons would be more accurate while moving than inaccurate weapons while standing in some cases.

Adding does a very similar thing. How would you do it without using the base? I want this to apply to all weapons.

[editline]07:59PM[/editline]

well, I got it to work but it doesn’t do exactly what I want.

[LUA]
function SWEP:ShootBulletInformation()

local CurrentDamage
local CurrentRecoil
local CurrentCone

if self.Weapon:GetDTBool(3) then
	CurrentDamage = self.Primary.Damage * self.data.Damage * DamageMul:GetFloat()
	CurrentRecoil = self.Primary.Recoil * self.data.Recoil * RecoilMul:GetFloat()
	CurrentCone = self.Primary.Cone * self.data.Cone
else
	CurrentDamage = self.Primary.Damage * DamageMul:GetFloat()
	CurrentRecoil = self.Primary.Recoil * RecoilMul:GetFloat()
	CurrentCone = self.Primary.Cone
end
// Player is moving
elseif self.Owner:KeyDown(IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT) then
	// Player is aiming
	if (self.Weapon:GetDTBool(1)) then
		self:ShootBullet(CurrentDamage, CurrentRecoil, self.Primary.NumShots, CurrentCone + 5)
		self.Owner:ViewPunch(Angle(math.Rand(-0.75, -1.0) * (CurrentRecoil), math.Rand(-1, 1) * (CurrentRecoil), 0))
	// Player is not aiming
	else
		self:ShootBullet(CurrentDamage, CurrentRecoil, self.Primary.NumShots, CurrentCone + 5)
		self.Owner:ViewPunch(Angle(math.Rand(-0.75, -1.0) * (CurrentRecoil), math.Rand(-1, 1) * (CurrentRecoil), 0))
	end
end

end
[/LUA]

so you should see CurrentCone + 5, and it makes bullets inaccurate when holding down wasd, but the problem is, you can release wasd and shoot then press wasd again and have perfect accuracy.

I want to make it so that my accuracy is reliant on my movement speed %. So if I’m at 100% movement speed then my accuracy would be twice as bad. If I slow down to a halt to 0% then my accuracy is what it should be. If I am crouched and moving so I’m at like 50% move speed, then my accuracy would be half as bad.

still need some help on the subject, any help is appreciated.