--------------------- -- Your Name is Benny --------------------- BENNY.AddConvar( "cam_f", -75 ) BENNY.AddConvar( "cam_r", 12 ) BENNY.AddConvar( "cam_u", 12 ) BENNY.AddConvar( "cam_fov", 75 ) BENNY.AddConvar( "cam_fp", 0 ) BENNY.AddConvar( "cam_fp_fov", 75 ) local lastfp local m = 3 local m2 = Vector( m, m, m ) local m1 = m2:GetNegated() TPSOverride = TPSOverride or Angle( 0, 0, 0 ) function CamSpot( ang, pos ) if !ang then ang = TPSOverride end if !pos then pos = LocalPlayer():EyePos() end local f, r, u = TPSOverride:Forward(), TPSOverride:Right(), TPSOverride:Up() local tr = { start = pos, endpos = pos + (f*c_cam_f:GetFloat()) + (r*c_cam_r:GetFloat()) + (u*c_cam_u:GetFloat()), filter = LocalPlayer(), -- ply, mins = m1, maxs = m2, } if c_cam_fp:GetBool() then tr.endpos = LocalPlayer():EyePos() end tr = util.TraceHull(tr) return tr.HitPos end function Convert( fovDegrees, ratio ) local halfAngleRadians = fovDegrees * ( 0.5 * math.pi / 180 ) local t = math.tan( halfAngleRadians ) t = t * ratio local retDegrees = ( 180 / math.pi ) * math.atan( t ) return retDegrees * 2 end function QConvert( fovDegrees ) return Convert( fovDegrees, (3/4)/(ScrH()/ScrW()) ) end function GM:PreDrawViewModels() local fp = c_cam_fp:GetBool() if fp then cam.Start3D( nil, nil, QConvert( c_cam_fp_fov:GetFloat() ) ) cam.IgnoreZ( true ) local p = LocalPlayer() p.IWantDraw = true p:DrawModel() local w = p:HandlerCheck() if w:GetActiveR():IsValid() then w:GetActiveR():DrawModel() end p.IWantDraw = false cam.IgnoreZ( false ) cam.End3D() end end function GM:PrePlayerDraw( ply, flags ) local fp = c_cam_fp:GetBool() if fp and ply == LocalPlayer() and !ply.IWantDraw then return true end end function GM:CalcView( ply, pos, ang, fov ) local view = { origin = CamSpot(TPSOverride), -- pos includes the smoothstair offset which looks stupid here angles = TPSOverride, fov = c_cam_fov:GetFloat(), drawviewer = true } local fp = c_cam_fp:GetBool() if fp then ply:SetupBones() local bm = ply:GetBoneMatrix(ply:LookupBone("DEF-spine.003")) view.origin = bm:GetTranslation() view.origin:Add( vector_up*8 ) if ply:GetLayerSequence( BGESTURE_JUMP ) == ply:LookupSequence("dive_end_handgun") then local progress = ply:GetLayerCycle( BGESTURE_JUMP ) progress = math.TimeFraction( 0.15, 0.7, progress ) progress = math.Clamp( progress, 0, 1 ) progress = math.ease.OutCirc( progress ) local Dir = ply:GetVelocity() Dir.z = 0 Dir:Normalize() Dir:Rotate( Angle( 0, view.angles.y, 0 ) ) Dir:Negate() local Addition = Angle( (progress*360), 0, 0 ) local new = Angle( view.angles ) new:Add( Addition ) view.angles = new end local special = math.Remap( ang.p, 0, 79, 0, 1 ) special = math.Clamp(special, 0, 1 ) special = math.ease.InCubic( special ) local special2 = math.Remap( ang.p, -79, 0, 0, 1 ) special2 = math.Clamp(special2, 0, 1 ) special2 = special2 * (1-special) view.origin:Sub(ang:Forward()*2) view.origin:Add(ang:Up()*4*special2) view.origin:Add(ang:Up()*4*special) end if lastfp == nil then lastfp = !fp end if lastfp and !fp then local bid = ply:LookupBone("DEF-spine.006") ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) local bid = ply:LookupBone("DEF-spine.005") ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) --local bid = ply:LookupBone("Weapon") --ply:ManipulateBonePosition( bid, vector_origin ) lastfp = fp elseif !lastfp and fp then local bid = ply:LookupBone("DEF-spine.006") ply:ManipulateBoneScale( bid, vector_origin ) local bid = ply:LookupBone("DEF-spine.005") ply:ManipulateBoneScale( bid, vector_origin ) --local bid = ply:LookupBone("Weapon") --ply:ManipulateBonePosition( bid, Vector(-3, 1, 0) ) lastfp = fp end return view end -- During a full update, bone manipulations will be reset to the server's value. Fix that gameevent.Listen( "OnRequestFullUpdate" ) hook.Add( "OnRequestFullUpdate", "Benny_OnRequestFullUpdate_CameraFP", function( data ) if CLIENT then local ply = LocalPlayer() if !ply:IsValid() then return end local fp = c_cam_fp:GetBool() if lastfp == nil then lastfp = !fp end timer.Simple( 0, function() if !fp then local bid = ply:LookupBone("DEF-spine.006") if !bid then return end ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) local bid = ply:LookupBone("DEF-spine.005") if !bid then return end ply:ManipulateBoneScale( bid, Vector(1, 1, 1) ) lastfp = fp elseif fp then local bid = ply:LookupBone("DEF-spine.006") if !bid then return end ply:ManipulateBoneScale( bid, vector_origin ) local bid = ply:LookupBone("DEF-spine.005") if !bid then return end ply:ManipulateBoneScale( bid, vector_origin ) lastfp = fp end end) end end ) hook.Add( "InputMouseApply", "Benny_InputMouseApply", function( cmd, x, y, ang ) local p = LocalPlayer() local w = p:HandlerCheck() if w then--and (y!=0 or x!=0) then if x != 0 then TPSOverride.y = TPSOverride.y + (-x*0.022) end if y != 0 then TPSOverride.p = math.Clamp( TPSOverride.p + (y*0.022), -80, 80 ) end return true end end) hook.Add("CreateMove", "Benny_CreateMove_Camera", function( cmd ) local p = LocalPlayer() if p:GetMoveType() == MOVETYPE_NOCLIP then cmd:SetViewAngles( TPSOverride ) else local tr_forward = util.TraceLine( { start = CamSpot(TPSOverride), endpos = CamSpot(TPSOverride)+(TPSOverride:Forward()*(2^16)), filter = p, mask = MASK_SHOT, } ) local planner = (tr_forward.HitPos-p:EyePos()):Angle() planner:Normalize() cmd:SetViewAngles( planner ) local moveintent = Vector( cmd:GetForwardMove(), cmd:GetSideMove(), 0 ) local fixang = Angle() fixang.y = cmd:GetViewAngles().y - TPSOverride.y moveintent:Rotate( fixang ) cmd:SetForwardMove( moveintent.x ) cmd:SetSideMove( moveintent.y ) end end)