SWEP Wall functions?

I’m trying to make a piece of code that tells the viewmodel to go into a special holstered-esque position when the player is facing and is up against a wall. Mirrors Edge does this.

A more direct example of what I’m trying to do is implemented in The Red Crayon’s updated base that he will use with his MoH swep pack in the future.

I already have a code that sort of works, it disables firing and goes into a custom position when it’s the player is near a wall.


local trace = self.Owner:GetEyeTrace()
	if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 30 then
	self:SetIronsights( true )
    	self.IronSightsPos = self.wallSightsPos                    
    	self.IronSightsAng = self.wallSightsAng   
	self.Weapon:SetNextPrimaryFire(CurTime() + 1000000000000000000000000000000) 
	wallmode = true

end
	local trace = self.Owner:GetEyeTrace()
	if trace.HitPos:Distance(self.Owner:GetShootPos()) >= 31 then
	self:SetIronsights( false )
    	self.IronSightsPos = self.aIronSightsPos                    
    	self.IronSightsAng = self.aIronSightsAng
	self.Weapon:SetNextPrimaryFire(CurTime())
	wallmode = false
end

	local trace = self.Owner:GetEyeTrace()
	if trace.HitPos:Distance(self.Owner:GetShootPos()) > 33 then
    	self.IronSightsPos = self.IronSightsPos                    
    	self.IronSightsAng = self.IronSightsAng  
	self.Weapon:SetNextPrimaryFire(CurTime())
	wallmode = false

end

I’ve tried using variables and separate functions but I can’t seem to find a way for the weapon to go back to its original (non-holstered) ironsights position. The weapon will still zoom and become more accurate, but will not aim down the sights.

Any ideas?

Problem is with this bit on line 21

    self.IronSightsPos = self.IronSightsPos                    
    self.IronSightsAng = self.IronSightsAng

You aren’t setting anything there at all, what you need to do is have two variables and do this in cl_init.lua

[lua]
//set ironsights and all that above
self.a = self.IronSightsAng
self.p = self.IronSightsPos
[/lua]

And replace this code

    self.IronSightsPos = self.IronSightsPos                    
	self.IronSightsAng = self.IronSightsAng  

With this

   self.IronSightsPos = self.p               
self.IronSightsAng = self.a

Could you elaborate a little bit more? For one thing, never done a cl_init before, and I think I have multiple ironsights variables already defined in my shared.lua file. I.E. wallSightsPos = wall position, aIronSightsPos = standard position.

If defining these can not be a part of the shared file, could you help me compose a cl_init that would work with what you said? I’m pretty sure the swep knows all the positions, but it is constantly being told to cancel actually moving to the regular ironsights position when the player is away from a wall. Could make a video if you need an example.