All pastes #958059 Raw Edit

Unnamed

public text v1 · immutable
#958059 ·published 2008-03-26 13:24 UTC
rendered paste body
local attachment = false

function CI_GetViewModelPosition (self, pos, ang) 
 
	local IRONSIGHT_TIME = 0.25
	
	--print ("Start Ang: "..tostring(ang).."\n")
	
	if self.Weapon:GetNetworkedBool ("Ironsights") then
		ang = LocalPlayer():GetViewModel():GetAngles()
		--[[local vm = self.Owner:GetViewModel()
		print ("vm: "..tostring(vm))
		
		local brl = vm:GetAttachment (1)
		PrintTable (brl)]]
		local aAng = attachment.Ang
		
		if not self.aDefPitch then
			self.aDefPitch = aAng.r - ang.p
			self.aDefYaw = aAng.y - ang.y
		else
			local diff = (aAng.r - wpnang.p) - self.aDefPitch
			ang.p = ang.p - diff
			--how about yaw now?
			--print (aAng.y.." - "..wpnang.y)
		
		end
	else
		self.aDefPitch = nil
	end
	
	--ang.y = ang.y + 10
	
	--print ("End Ang: "..tostring(ang).."\n")
	
	--garry's ironsight code
	
	if ( !self.IronSightsPos ) then return pos, ang end 
   
 	local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) 
 	 
 	if ( bIron != self.bLastIron ) then 
 	 
 		self.bLastIron = bIron  
 		self.fIronTime = CurTime() 
 		 
 		if ( bIron ) then  
 			self.SwayScale 	= 0.3 
 			self.BobScale 	= 0.1 
 		else  
 			self.SwayScale 	= 1.0 
 			self.BobScale 	= 1.0 
 		end 
 	 
 	end 
 	 
 	local fIronTime = self.fIronTime or 0 
   
 	if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then  
 		return pos, ang  
 	end 
 	 
 	local Mul = 1.0 
 	 
 	if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then 
 	 
 		Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) 
 		 
 		if (!bIron) then Mul = 1 - Mul end 
 	 
 	end 
   
 	local Offset	= self.IronSightsPos 
 	 
 	if ( self.IronSightsAng ) then 
 	 
 		ang = ang * 1 
 		ang:RotateAroundAxis( ang:Right(), 		self.IronSightsAng.x * Mul ) 
 		ang:RotateAroundAxis( ang:Up(), 		self.IronSightsAng.y * Mul ) 
 		ang:RotateAroundAxis( ang:Forward(), 	self.IronSightsAng.z * Mul ) 
 	 
 	 
 	end 
 	 
 	local Right 	= ang:Right() 
 	local Up 		= ang:Up() 
 	local Forward 	= ang:Forward() 
 	 
 	 
   
 	pos = pos + Offset.x * Right * Mul 
 	pos = pos + Offset.y * Forward * Mul 
 	pos = pos + Offset.z * Up * Mul 
   
 	return pos, ang 
 	 
end 

local function CI_GetAttachmentThink ()
	attachment = LocalPlayer():GetViewModel():GetAttachment (1)
	wpnang = LocalPlayer():GetViewModel():GetAngles()
	--PrintTable (attachment)
	draw.SimpleText (tostring(attachment.Pos).."/"..tostring(attachment.Ang), "ScoreboardText", ScrW() / 2 - 70, ScrH() - 120, Color(0,0,0,255),1,1)
	draw.SimpleText (LocalPlayer():GetViewModel():GetAngles().y.."/"..LocalPlayer():EyeAngles().y, "ScoreboardText", ScrW() / 2 - 70, ScrH() - 90, Color(0,0,0,255),1,1)
	if LocalPlayer():GetActiveWeapon() and LocalPlayer():GetActiveWeapon() != NULL and LocalPlayer():GetActiveWeapon():GetTable().aDefYaw then
		draw.SimpleText (LocalPlayer():GetActiveWeapon():GetTable().aDefYaw, "ScoreboardText", ScrW() / 2 - 70, ScrH() - 60, Color(0,0,0,255),1,1)
	end
	draw.SimpleText (wpnang.y..", "..attachment.Ang.y, "ScoreboardText", ScrW() / 2 - 70, ScrH() - 30, Color(0,0,0,255),1,1)
end

hook.Add ("HUDPaint", "CI_GAT", CI_GetAttachmentThink)

local function CI_Initialize ()
	for _,wpn in pairs (weapons.GetList()) do
		if wpn.IronSightsPos then
			print ("has ironsights: "..wpn.Classname)
			wpn.GetViewModelPosition = CI_GetViewModelPosition
		end
	end
end

hook.Add ("Initialize", "CI_Init", CI_Initialize)