Attempt to call method 'SetNWAngle' (a nil value)

Let me give in a bit of context what code I’m basing off of the error:


local pPr = FindMetaTable( "Player" )
local origAng
local recoilCool = 5
local whyAmITryingToMakeThisAgainPleaseEndMySuffering = Angle( 0, 0, 0 )

-- Convenience function to set it FAAAAAASTEEEEEEEEEEEEER
function pPr:SetRecoilOffset( p, y, r )

	pPr:SetNWAngle( 'waitWhat', Angle( p, y, r ) )

end

hook.Add( "Initialize", "HL2_CSSRECOIL_INIT", function() 

	pPr:SetRecoilOffset( 0, 0, 0 )

end)

hook.Add( "PlayerSpawn", "HL2_CSSRECOIL_SPAWN", function() 

	pPr:SetRecoilOffset( 0, 0, 0 )

end)

hook.Add( "CalcView", "HL2_CSSRECOIL", function( ply, pos, ang, fov )

	local changeAng = ply:GetNWAngle( "waitWhat" )

	ang.p = ang.p - changeAng.p
	ang.y = ang.y - changeAng.y
	ang.r = ang.r - changeAng.r
	origAng = Angle(ang.p + changeAng.p, ang.y + changeAng.y, ang.r + changeAng.r)
	ply:SetNWAngle( "waitWhat", LerpAngle( FrameTime() * recoilCool, ang, origAng ) )

	--ang = ang

	return pos, ang, fov

end)

Placed in autorun is a file saved with the code above and when trying to execute the SetRecoilOffset() function, this error shows:


[ERROR] lua/autorun/hl2mod_cssrecoil.lua:32: attempt to call method 'SetNWAngle' (a nil value)
  1. SetRecoilOffset - lua/autorun/hl2mod_cssrecoil.lua:32
   2. unknown - lua_run:1


Any help would be appreciated to fix the problem and/or improve the code I have at the moment. I’m trying to make a universal code to recreate a Counter-Strike-esque recoil for some certain SWEPs and have been stumped on where to begin. Thanks.

Use self instead of pPr in SetRecoilOffset.

Did the trick. Now that that’s out of the way, I’ll need to figure out how to get the code to do what it’s supposed to do with the CalcView hook…