Why does my swep not have any recoil?

I was trying to make a simple pistol and I got it working in game with attachments, but when I fire it does not recoil at all.

I derived it from this base: http://www.facepunch.com/showthread.php?t=1032378

I was using this for recoil but it literally didn’t affect anything.
[lua]SWEP.Primary.Recoil[/lua]

part of code:
[lua]

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModelFOV = 90
SWEP.ViewModelFlip = false

SWEP.ViewModel = “models/weapons/v_pist_u45.mdl”
SWEP.WorldModel = “models/weapons/w_pist_usp.mdl”
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true

SWEP.Weight = 1
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

SWEP.ForceApply = 10
SWEP.TracerFreq = 1

SWEP.Primary.Sound = Sound(“CSTM_USP45”)
SWEP.Primary.Damage = 15
SWEP.Primary.Recoil = 1.5
SWEP.Primary.RecoilXRand = .3
SWEP.Primary.RecoilYRand = 0.1
SWEP.Primary.Force = 1
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = 6
SWEP.Primary.Delay = 0.5
SWEP.Primary.DefaultClip = 70
SWEP.Primary.Automatic = true

SWEP.Primary.ClipSize = 20
SWEP.Primary.DefaultClip = 40
SWEP.Primary.Ammo = “ar2”

SWEP.Primary.Tracer = 20
SWEP.SetDeploySpeed = 1

function SWEP:ShootBullet( damage, num_bullets, aimcone )

local bullet = {}
bullet.Num 		= num_bullets
bullet.Src 		= self.Owner:GetShootPos()	// Source
bullet.Dir 		= self.Owner:GetAimVector()	// Dir of bullet
bullet.Spread 	= Vector( aimcone, aimcone, 90 )		// Aim Cone
bullet.Tracer	= 1	// Show a tracer on every x bullets 
    bullet.TracerName = "AirboatGunHeavyTracer" // what Tracer Effect should be used
bullet.Force	= 1	// Amount of force to give to phys objects
bullet.Damage	= damage
bullet.AmmoType = "Pistol"

self.Owner:FireBullets( bullet )

self:ShootEffects()

end

function SWEP:CanPrimaryAttack()

if ( self:Clip1() <= 0 ) then

	self:EmitSound( "Weapon_Pistol.Empty" )
	self:SetNextPrimaryFire( CurTime() + 0.2 )
	self:Reload()
	return false

end

return true

end

function SWEP:PrimaryAttack()

if ( !self:CanPrimaryAttack() ) then return end

self:ShootBullet( self.Primary.Damage, 1, self.Primary.Cone )

self.Weapon:EmitSound( self.Primary.Sound )

self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 

self:TakePrimaryAmmo( 1 )


self.Weapon:SetNextPrimaryFire( CurTime() + .1 )

local trace = self.Owner:GetEyeTrace().HitPos
local ent = self.Owner:GetEyeTrace().Entity

self.Owner:ViewPunch( Angle( -1, 0, 0 ) )

if self.Weapon:Clip1() <= 0 then
	self:Reload()
	return
end

/*
//water effect
local vPoint = trace
local effectdata = EffectData()
effectdata:SetStart( vPoint ) // not sure if we need a start and origin (endpoint) for this effect, but whatever
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1 )
util.Effect( "WaterSurfaceExplosion", effectdata )	
*/



	
end

[/lua]

This Piece right here is what your wanting to look at.



self.Owner:ViewPunch( Angle( -1, 0, 0 ) )


Normally this should just work, it could be the angle punch is only -1. Try decreasing the value a bit more to something like -5 or -10 see if the recoil viewpunch is even working. Even at -1 you’d think it would work. I’m still looking at the code to see what’s wrong. Do you get any errors when you shoot or when you first initialize a game related to this weapon?

Edit:
I tested the code myself and did get a small recoil exactly 1 up every time I shot, so I’m not even sure why its not working for you.

I am not getting any errors, and also when you shoot at a wall is the bullet hole slowly going up?

All I ever see is visual recoil and that is it.

Yeah, ViewPunch is just visual effects.

If you’re seeing your aimpos change it’s not because the viewpunch unless you have the bullets fire at eyeangles + viewpunch angles.

SWEP.Primary.Recoil is simply just a variable, filling it out doesn’t do anything-- you have to write something that uses it.

The “base” you put above isn’t really a base. Not in the sense that it handles stuff like shooting for you. It just lets you place models on your viewmodel.

Here’s a snippet from Garry’s old GM12 era Counter-Strike weapons.



	if ( (game.SinglePlayer() && SERVER) || ( !game.SinglePlayer() && CLIENT && IsFirstTimePredicted() ) ) then
	
		local eyeang = self.Owner:EyeAngles()
		eyeang.pitch = eyeang.pitch - recoil
		self.Owner:SetEyeAngles( eyeang )
	
	end


You’d want to shove this under ShootBullets or PrimaryAttack.

Last time I checked this isn’t a very good way to do recoil but you get the idea.

I actually looked into that same way but I ended up not doing it. I might just go look at other swep bases or something.

That or just I guess use someone elses base and add on that part of the code to it.

I really am trying to get attachments on the guns and there are not to many things that do that. I can’t use customizable weaponry because it spews out errors and then deletes the scopes and FA:2 sweps are not finished.

If I have to use another base does anyone have one they recommend?

CSTM uses the thing you linked above for attachments actually.

I’d say make your own base.