Advertisement
Guest User

BF3 Vaulting mechanism

a guest
Oct 4th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.36 KB | None | 0 0
  1. local CSSLegsVar = CreateClientConVar( "CSS_Legs", 1, true, false )
  2.  
  3. function LegsLandingPunch( )
  4.  
  5.     local PL = LocalPlayer()
  6.    
  7.     if not PL.LastZVelocity then
  8.     PL.LastZVelocity = 0
  9.     end
  10.    
  11.     if not PL:OnGround() and PL:GetVelocity().z < 0 then
  12.     PL.LastZVelocity = PL:GetVelocity().z
  13.     end
  14.    
  15.     if not PL:OnGround() and not PL.Jumping then
  16.    
  17.         PL.Jumping = true
  18.        
  19.     elseif PL:OnGround() and PL.Jumping and PL.LastZVelocity <= -100 then
  20.    
  21.         if PL.VaultView and CurTime() <= PL.VaultView then
  22.        
  23.         PL:VaultViewSet( 0, 0, 0, 0, 0, 0, "VaultOver_Reset" )
  24.        
  25.         end
  26.    
  27.         PL.Jumping = false
  28.         PL:VaultViewSet( PL.LastZVelocity*-0.06, 0, 0, PL.LastZVelocity* 0.045, 0, 30, "LandingStart" )
  29.         PL:VaultViewSet( 0, 0, 0, 0, 0.1, 5, "LandingReset" )
  30.        
  31.         PL.LastZVelocity = 0
  32.        
  33.     end
  34.    
  35.     if PL.VaultView and CurTime() <= PL.VaultView then
  36.    
  37.         PL.LastZVelocity = -150
  38.        
  39.     end
  40.  
  41. end
  42. hook.Add("Think","LegsLAndingPunchHook",LegsLandingPunch)
  43.  
  44. function LegsNoCroucher( ply, bind, pressed )
  45.  
  46.     if pressed and ply.Leaning then
  47.    
  48.         if bind == "+forward" then
  49.        
  50.             if ply.Lean1 == -1 then
  51.             ply.Lean1 = 0
  52.             ply.LeanPos_Z = 0
  53.             elseif ply.Lean1 == 0 then
  54.             ply.Lean1 = 1
  55.             ply.LeanPos_Z = 21
  56.             end
  57.            
  58.         end
  59.         if bind == "+moveleft" then
  60.            
  61.             if ply.Lean2 == 1 then
  62.             ply.Lean2 = 0
  63.             ply.LeanPos = 0
  64.             elseif ply.Lean2 == 0 then
  65.             ply.Lean2 = -1
  66.             ply.LeanPos = -30
  67.             end
  68.            
  69.         end
  70.         if bind == "+moveright" then
  71.            
  72.             if ply.Lean2 == -1 then
  73.             ply.Lean2 = 0
  74.             ply.LeanPos = 0
  75.             elseif ply.Lean2 == 0 then
  76.             ply.Lean2 = 1
  77.             ply.LeanPos = 30
  78.             end
  79.            
  80.         end
  81.         if bind == "+back" then
  82.            
  83.             if ply.Lean1 == 1 then
  84.             ply.Lean1 = 0
  85.             ply.LeanPos_Z = 0
  86.             elseif ply.Lean1 == 0 then
  87.             ply.Lean1 = -1
  88.             ply.LeanPos_Z = -21
  89.             end
  90.            
  91.         end
  92.         return true
  93.        
  94.     end
  95.  
  96.     local self = ply
  97.    
  98.     local Sprint = self:KeyDown(131072)
  99.     local Vel = self:GetVelocity():Length()
  100.     local Direction = self:GetVelocity():Normalize()
  101.     local OnGround = self:OnGround()
  102.     local OnlyRunningForward = (self:KeyDown(8) and not self:KeyDown(16) and not self:KeyDown(512) and not self:KeyDown(1024))
  103.    
  104.     if Sprint and Vel >= 170 and OnGround and OnlyRunningForward and bind == "+duck" then
  105.    
  106.         self.VaultView_Yaw = self:EyeAngles().y
  107.         self.Sliding = true
  108.        
  109.     end
  110.  
  111.     if bind == "+duck" and ((ply:GetMoveType() == MOVETYPE_FLY) or (ply:GetMoveType() == MOVETYPE_FLYGRAVITY) or ply.Vaulting and CurTime() <= ply.Vaulting) then
  112.     return true
  113.     end
  114.    
  115. end
  116. hook.Add("PlayerBindPress","LegsNoCroucherHook",LegsNoCroucher)
  117.  
  118. function CreateLegs()
  119.  
  120.     local self = LocalPlayer()
  121.  
  122.     if self.CSSLegs and IsValid(self.CSSLegs) then return end
  123.    
  124.     self.CSSLegs = ClientsideModel( "models/player/t_phoenix_flora.mdl" )
  125.     local Pos = self:GetPos() - Angle(0,self:EyeAngles().y,0):Forward()*12
  126.     self.CSSLegs.Mode = 1
  127.     self.CSSLegs.ZVector = 0
  128.     self.CSSLegs:SetPos( Pos )
  129.     self.CSSLegs:SetAngles( Angle(0,self:EyeAngles().y,0) )
  130.     self.CSSLegs:Spawn()
  131.     self.CSSLegs.AutomaticFrameAdvance = true
  132.     self.CSSLegs:SetNoDraw(true)
  133.     self.CSSLegs:SetSequence( self.CSSLegs:LookupSequence("Idle_Lower") )
  134.     self.CSSLegs:SetCycle(0)
  135.     -- self.CSSLegs:SetModelScale(Vector(0.9,0.9,0.9))
  136.    
  137.     local LEGS = self.CSSLegs
  138.    
  139.     function LEGS:BuildBonePositions(NumBones,NumPhysBones)
  140.  
  141.         local bonetable = { "ValveBiped.Bip01_R_Finger0", "ValveBiped.Bip01_R_Finger01", "ValveBiped.Bip01_R_Finger02", "ValveBiped.Bip01_R_Finger1", "ValveBiped.Bip01_R_Finger11", "ValveBiped.Bip01_R_Finger12", "ValveBiped.Bip01_R_Finger2", "ValveBiped.Bip01_R_Finger21", "ValveBiped.Bip01_R_Finger22", "ValveBiped.Bip01_L_Finger0", "ValveBiped.Bip01_L_Finger01", "ValveBiped.Bip01_L_Finger02", "ValveBiped.Bip01_L_Finger1", "ValveBiped.Bip01_L_Finger11", "ValveBiped.Bip01_L_Finger12", "ValveBiped.Bip01_L_Finger2", "ValveBiped.Bip01_L_Finger21", "ValveBiped.Bip01_L_Finger22", "ValveBiped.Bip01_R_Ulna", "ValveBiped.Bip01_L_Ulna", "ValveBiped.Bip01_L_Wrist", "ValveBiped.Bip01_R_Wrist", "ValveBiped.Bip01_L_Clavicle", "ValveBiped.Bip01_R_Clavicle", "ValveBiped.Bip01_Head1", "ValveBiped.Bip01_Neck1", "ValveBiped.Bip01_L_UpperArm", "ValveBiped.Bip01_L_Forearm", "ValveBiped.Bip01_L_Hand", "ValveBiped.Bip01_R_UpperArm", "ValveBiped.Bip01_R_Forearm", "ValveBiped.Bip01_R_Hand", "ValveBiped.Bip01_Spine4" }
  142.         local bonetable2 = { "ValveBiped.Bip01_Spine2" }
  143.  
  144.         for _, bonez in pairs( bonetable ) do
  145.  
  146.             local bone = self:LookupBone(bonez)
  147.  
  148.             local matrix = self:GetBoneMatrix(bone)
  149.  
  150.             matrix:Scale(Vector(0,0,0))
  151.  
  152.             self:SetBoneMatrix(bone,matrix)
  153.  
  154.         end
  155.        
  156.         for _, bonez2 in pairs( bonetable2 ) do
  157.  
  158.             local bone = self:LookupBone(bonez2)
  159.  
  160.             local matrix = self:GetBoneMatrix(bone)
  161.  
  162.             matrix:Scale(Vector(0.7,0.7,0.7))
  163.  
  164.             self:SetBoneMatrix(bone,matrix)
  165.  
  166.         end
  167.        
  168.     end
  169.    
  170. end
  171.  
  172. function RemoveLegs()
  173.  
  174.     local self = LocalPlayer()
  175.  
  176.     if self.CSSLegs and IsValid(self.CSSLegs) then
  177.    
  178.     self.CSSLegs:Remove()
  179.    
  180.     end
  181.    
  182. end
  183.  
  184. function LeanOn( ply )
  185.  
  186.     ply.Lean1 = 0
  187.     ply.Lean2 = 0
  188.    
  189.     ply.Leaning = true
  190.    
  191. end
  192. concommand.Add("+lean",LeanOn)
  193.  
  194. function LeanOff( ply )
  195.  
  196.     ply.Leaning = false
  197.  
  198.     ply.Lean1 = 0
  199.     ply.Lean2 = 0
  200.    
  201.     ply.LeanPos = 0
  202.     ply.LeanPos_Z = 0
  203.    
  204. end
  205. concommand.Add("-lean",LeanOff)
  206.  
  207. function _R.Player:VaultViewSet( pitch, yaw, roll, height, time, speed, name )
  208.  
  209.     timer.Create( name, time, 1, function()
  210.    
  211.         self.VaultTarget_Speed = speed
  212.    
  213.         self.VaultTarget_P_Blender2 = (0.01*speed)
  214.         self.VaultTarget_Y_Blender2 = (0.01*speed)
  215.         self.VaultTarget_R_Blender2 = (0.01*speed)
  216.         self.VaultPos_Z_Blender2 = (0.01*speed)
  217.    
  218.         self.VaultTarget_P = pitch
  219.         self.VaultTarget_Y = yaw
  220.         self.VaultTarget_R = roll
  221.         self.VaultPos_Z = height
  222.    
  223.     end)
  224.    
  225. end
  226.  
  227. function VaultViewLimit( cm )
  228.  
  229.     local ply = LocalPlayer()
  230.    
  231.     if (ply.VaultViewDone or ply.VaultUpViewDone or ply.Sliding) and ply.VaultView_Yaw then
  232.    
  233.         local YAW = ply.VaultView_Yaw
  234.         local MYYAW = ply:EyeAngles().y
  235.         local THEANG = ply:EyeAngles()
  236.        
  237.         if math.AngleDifference( YAW, MYYAW ) >= 90 then
  238.         cm:SetViewAngles( Angle(THEANG.p,YAW - 90,THEANG.r) )
  239.         elseif math.AngleDifference( YAW, MYYAW ) <= -90 then
  240.         cm:SetViewAngles( Angle(THEANG.p,YAW + 90,THEANG.r) )
  241.         end
  242.    
  243.     end
  244.  
  245. end
  246. hook.Add("CreateMove","VaultViewLimitHook",VaultViewLimit)
  247.  
  248. function VaultViewCalc( ply, pos, angles, fov )
  249.  
  250.     if ply.VaultView and CurTime() < ply.VaultView and not ply.VaultViewDone then
  251.    
  252.         ply:SetHull( Vector(-16,-16,70), Vector(16,16,72) )
  253.         ply:SetHullDuck( Vector(-16,-16,70), Vector(16,16,72) )
  254.    
  255.         ply.VaultView_Yaw = ply:EyeAngles().y
  256.    
  257.         ply.VaultViewDone = true
  258.    
  259.         ply:VaultViewSet( 20, -10, 25, 0, 0, 7, "VaultOver_Start" )
  260.         ply:VaultViewSet( 20, -10, 25, 10, 0.1, 7, "VaultOver_Mid" )
  261.         ply:VaultViewSet( -10, -5, 0, 25, 0.2, 10, "VaultOver_End" )
  262.        
  263.     elseif ((ply.VaultView and CurTime() >= ply.VaultView) or not ply.VaultView) and ply.VaultViewDone then
  264.    
  265.         ply:SetHull( Vector(-16,-16,0), Vector(16,16,72) )
  266.         ply:SetHullDuck( Vector(-16,-16,0), Vector(16,16,36) )
  267.    
  268.         ply.VaultViewDone = false
  269.    
  270.         ply:VaultViewSet( 0, 0, 0, 0, 0, 5, "VaultOver_Reset" )
  271.        
  272.     end
  273.  
  274.     if ply.VaultUpView and CurTime() < ply.VaultUpView and not ply.VaultUpViewDone then
  275.    
  276.         ply:SetHull( Vector(-16,-16,70), Vector(16,16,72) )
  277.         ply:SetHullDuck( Vector(-16,-16,70), Vector(16,16,72) )
  278.    
  279.         ply.VaultView_Yaw = ply:EyeAngles().y
  280.    
  281.         ply.VaultUpViewDone = true
  282.    
  283.         ply:VaultViewSet( 30, -10, 0, -20, 0, 5, "VaultOnto_Start" )
  284.         ply:VaultViewSet( 30, -10, 0, 20, 0.1, 5, "VaultOnto_Mid" )
  285.         ply:VaultViewSet( 0, -5, 0, 10, 0.3, 5, "VaultOnto_End" )
  286.        
  287.     elseif ((ply.VaultUpView and CurTime() >= ply.VaultUpView) or not ply.VaultUpView) and ply.VaultUpViewDone then
  288.    
  289.         ply:SetHull( Vector(-16,-16,0), Vector(16,16,72) )
  290.         ply:SetHullDuck( Vector(-16,-16,0), Vector(16,16,36) )
  291.    
  292.         ply.VaultUpViewDone = false
  293.    
  294.         ply:VaultViewSet( 0, 0, 0, 0, 0, 5, "VaultOnto_Reset" )
  295.        
  296.     end
  297.    
  298.     if not ply.VaultTarget_Speed then ply.VaultTarget_Speed = 5 end
  299.    
  300.     if not ply.VaultTarget_P then ply.VaultTarget_P = 0 end
  301.     if not ply.VaultTarget_Y then ply.VaultTarget_Y = 0 end
  302.     if not ply.VaultTarget_R then ply.VaultTarget_R = 0 end
  303.     if not ply.VaultPos_Z then ply.VaultPos_Z = 0 end
  304.    
  305.     if not ply.LeanPos then ply.LeanPos = 0 end
  306.     if not ply.LeanPos_Z then ply.LeanPos_Z = 0 end
  307.    
  308.     if not ply.VaultTarget_P_Blender then ply.VaultTarget_P_Blender = ply.VaultTarget_P end
  309.     if not ply.VaultTarget_Y_Blender then ply.VaultTarget_Y_Blender = ply.VaultTarget_Y end
  310.     if not ply.VaultTarget_R_Blender then ply.VaultTarget_R_Blender = ply.VaultTarget_R end
  311.     if not ply.VaultPos_Z_Blender then ply.VaultPos_Z_Blender = ply.VaultPos_Z end
  312.    
  313.     if not ply.LeanPos_Blender then ply.LeanPos_Blender = ply.LeanPos end
  314.     if not ply.LeanPos_Blender_Z then ply.LeanPos_Blender_Z = ply.LeanPos_Z end
  315.    
  316.     if not ply.VaultTarget_P_Blender2 then ply.VaultTarget_P_Blender2 = 1 end
  317.     if not ply.VaultTarget_Y_Blender2 then ply.VaultTarget_Y_Blender2 = 1 end
  318.     if not ply.VaultTarget_R_Blender2 then ply.VaultTarget_R_Blender2 = 1 end
  319.     if not ply.VaultPos_Z_Blender2 then ply.VaultPos_Z_Blender2 = 1 end
  320.    
  321.     if not ply.LeanPos_Blender2 then ply.LeanPos_Blender2 = 1 end
  322.     if not ply.LeanPos_Blender2_Z then ply.LeanPos_Blender2_Z = 1 end
  323.    
  324.     local SPEEDBASE1 = ply.VaultTarget_Speed*ply.VaultTarget_P_Blender2
  325.     local SPEEDBASE2 = ply.VaultTarget_Speed*ply.VaultTarget_Y_Blender2
  326.     local SPEEDBASE3 = ply.VaultTarget_Speed*ply.VaultTarget_R_Blender2
  327.     local SPEEDBASE4 = ply.VaultTarget_Speed*ply.VaultPos_Z_Blender2
  328.    
  329.     if ply.VaultTarget_P_Blender < ply.VaultTarget_P then
  330.     ply.VaultTarget_P_Blender2 = math.Clamp( ply.VaultTarget_P_Blender2 + FrameTime()*8, 0.01, 1 )
  331.     local SPEED = math.Clamp( ply.VaultTarget_P - ply.VaultTarget_P_Blender, 0.01, 500 )*(SPEEDBASE1)
  332.     ply.VaultTarget_P_Blender = math.Clamp( ply.VaultTarget_P_Blender + FrameTime()*SPEED, -89, ply.VaultTarget_P )
  333.     elseif ply.VaultTarget_P_Blender > ply.VaultTarget_P then
  334.     ply.VaultTarget_P_Blender2 = math.Clamp( ply.VaultTarget_P_Blender2 + FrameTime()*8, 0.01, 1 )
  335.     local SPEED = math.Clamp( ply.VaultTarget_P_Blender - ply.VaultTarget_P, 0.01, 500 )*(SPEEDBASE1)
  336.     ply.VaultTarget_P_Blender = math.Clamp( ply.VaultTarget_P_Blender - FrameTime()*SPEED, ply.VaultTarget_P, 89 )
  337.     end
  338.    
  339.     if ply.VaultTarget_Y_Blender < ply.VaultTarget_Y then
  340.     ply.VaultTarget_Y_Blender2 = math.Clamp( ply.VaultTarget_Y_Blender2 + FrameTime()*8, 0.01, 1 )
  341.     local SPEED = math.Clamp( ply.VaultTarget_Y - ply.VaultTarget_Y_Blender, 0.01, 500 )*(SPEEDBASE2)
  342.     ply.VaultTarget_Y_Blender = math.Clamp( ply.VaultTarget_Y_Blender + FrameTime()*SPEED, -89, ply.VaultTarget_Y )
  343.     elseif ply.VaultTarget_Y_Blender > ply.VaultTarget_Y then
  344.     ply.VaultTarget_Y_Blender2 = math.Clamp( ply.VaultTarget_Y_Blender2 + FrameTime()*8, 0.01, 1 )
  345.     local SPEED = math.Clamp( ply.VaultTarget_Y_Blender - ply.VaultTarget_Y, 0.01, 500 )*(SPEEDBASE2)
  346.     ply.VaultTarget_Y_Blender = math.Clamp( ply.VaultTarget_Y_Blender - FrameTime()*SPEED, ply.VaultTarget_Y, 89 )
  347.     end
  348.    
  349.     if ply.VaultTarget_R_Blender < ply.VaultTarget_R then
  350.     ply.VaultTarget_R_Blender2 = math.Clamp( ply.VaultTarget_R_Blender2 + FrameTime()*8, 0.01, 1 )
  351.     local SPEED = math.Clamp( ply.VaultTarget_R - ply.VaultTarget_R_Blender, 0.01, 500 )*(SPEEDBASE3)
  352.     ply.VaultTarget_R_Blender = math.Clamp( ply.VaultTarget_R_Blender + FrameTime()*SPEED, -89, ply.VaultTarget_R )
  353.     elseif ply.VaultTarget_R_Blender > ply.VaultTarget_R then
  354.     ply.VaultTarget_R_Blender2 = math.Clamp( ply.VaultTarget_R_Blender2 + FrameTime()*8, 0.01, 1 )
  355.     local SPEED = math.Clamp( ply.VaultTarget_R_Blender - ply.VaultTarget_R, 0.01, 500 )*(SPEEDBASE3)
  356.     ply.VaultTarget_R_Blender = math.Clamp( ply.VaultTarget_R_Blender - FrameTime()*SPEED, ply.VaultTarget_R, 89 )
  357.     end
  358.    
  359.     if ply.VaultPos_Z_Blender < ply.VaultPos_Z then
  360.     ply.VaultPos_Z_Blender2 = math.Clamp( ply.VaultPos_Z_Blender2 + FrameTime()*8, 0.01, 1 )
  361.     local SPEED = math.Clamp( ply.VaultPos_Z - ply.VaultPos_Z_Blender, 0.01, 500 )*(SPEEDBASE4)
  362.     ply.VaultPos_Z_Blender = math.Clamp( ply.VaultPos_Z_Blender + FrameTime()*SPEED, -89, ply.VaultPos_Z )
  363.     elseif ply.VaultPos_Z_Blender > ply.VaultPos_Z then
  364.     ply.VaultPos_Z_Blender2 = math.Clamp( ply.VaultPos_Z_Blender2 + FrameTime()*8, 0.01, 1 )
  365.     local SPEED = math.Clamp( ply.VaultPos_Z_Blender - ply.VaultPos_Z, 0.01, 500 )*(SPEEDBASE4)
  366.     ply.VaultPos_Z_Blender = math.Clamp( ply.VaultPos_Z_Blender - FrameTime()*SPEED, ply.VaultPos_Z, 89 )
  367.     end
  368.    
  369.     if ply.LeanPos_Blender < ply.LeanPos then
  370.     ply.LeanPos_Blender2 = math.Clamp( ply.LeanPos_Blender2 + FrameTime()*8, 0.01, 1 )
  371.     local SPEED = math.Clamp( ply.LeanPos - ply.LeanPos_Blender, 0.01, 500 )*(5*ply.LeanPos_Blender2)
  372.     ply.LeanPos_Blender = math.Clamp( ply.LeanPos_Blender + FrameTime()*SPEED, -100, ply.LeanPos )
  373.     elseif ply.LeanPos_Blender > ply.LeanPos then
  374.     ply.LeanPos_Blender2 = math.Clamp( ply.LeanPos_Blender2 + FrameTime()*8, 0.01, 1 )
  375.     local SPEED = math.Clamp( ply.LeanPos_Blender - ply.LeanPos, 0.01, 500 )*(5*ply.LeanPos_Blender2)
  376.     ply.LeanPos_Blender = math.Clamp( ply.LeanPos_Blender - FrameTime()*SPEED, ply.LeanPos, 100 )
  377.     end
  378.    
  379.     if ply.LeanPos_Blender_Z < ply.LeanPos_Z then
  380.     ply.LeanPos_Blender2_Z = math.Clamp( ply.LeanPos_Blender2_Z + FrameTime()*8, 0.01, 1 )
  381.     local SPEED = math.Clamp( ply.LeanPos_Z - ply.LeanPos_Blender_Z, 0.01, 500 )*(5*ply.LeanPos_Blender2_Z)
  382.     ply.LeanPos_Blender_Z = math.Clamp( ply.LeanPos_Blender_Z + FrameTime()*SPEED, -100, ply.LeanPos_Z )
  383.     elseif ply.LeanPos_Blender_Z > ply.LeanPos_Z then
  384.     ply.LeanPos_Blender2_Z = math.Clamp( ply.LeanPos_Blender2_Z + FrameTime()*8, 0.01, 1 )
  385.     local SPEED = math.Clamp( ply.LeanPos_Blender_Z - ply.LeanPos_Z, 0.01, 500 )*(5*ply.LeanPos_Blender2_Z)
  386.     ply.LeanPos_Blender_Z = math.Clamp( ply.LeanPos_Blender_Z - FrameTime()*SPEED, ply.LeanPos_Z, 100 )
  387.     end
  388.    
  389.     if ply.VaultTarget_P_Blender != 0 then
  390.     angles.p = angles.p + ply.VaultTarget_P_Blender
  391.     end
  392.     if ply.VaultTarget_Y_Blender != 0 then
  393.     angles.y = angles.y + ply.VaultTarget_Y_Blender
  394.     end
  395.     if ply.VaultTarget_R_Blender != 0 then
  396.     angles.r = angles.r + ply.VaultTarget_R_Blender
  397.     end
  398.     if ply.VaultPos_Z_Blender != 0 then
  399.     pos.z = pos.z + ply.VaultPos_Z_Blender
  400.     end
  401.    
  402.     if ply.LeanPos_Blender != 0 then
  403.    
  404.     local MUL = ply.LeanPos_Blender
  405.     pos.x = pos.x + (ply:EyeAngles():Right()*MUL).x
  406.     pos.y = pos.y + (ply:EyeAngles():Right()*MUL).y
  407.     if MUL < 0 then
  408.     pos.z = pos.z - (MUL*-0.25)
  409.     else
  410.     pos.z = pos.z - (MUL*0.25)
  411.     end
  412.     angles.r = angles.r + MUL
  413.    
  414.     local TR = {}
  415.     TR.start = ply:EyePos() + Vector((ply:EyeAngles():Right()*MUL).x,(ply:EyeAngles():Right()*MUL).y,0)
  416.     TR.endpos = TR.start + (ply:EyeAngles():Right()*(MUL*1.5))
  417.     TR.mask = MASK_PLAYERSOLID
  418.     TR.filter = ply
  419.     local Trace = util.TraceLine(TR)
  420.    
  421.     if Trace.Hit and ply.Leaning then
  422.    
  423.     local POS1 = Trace.HitPos
  424.     local POS2 = ply:EyePos()
  425.     POS1.z = 0
  426.     POS2.z = 0
  427.    
  428.     if ply.Lean2 == 1 then
  429.     ply.LeanPos = math.Clamp(POS1:Distance(POS2)*0.5,0,25)
  430.     else
  431.     ply.LeanPos = math.Clamp(POS1:Distance(POS2)*-0.5,-25,0)
  432.     end
  433.     end
  434.    
  435.     end
  436.    
  437.     if ply.LeanPos_Blender_Z != 0 then
  438.    
  439.     local MUL = ply.LeanPos_Blender_Z
  440.     pos.z = pos.z + MUL
  441.    
  442.     local TR = {}
  443.     TR.start = ply:EyePos() + Vector(0,0,MUL)
  444.     TR.endpos = TR.start + Vector(0,0,MUL)
  445.     TR.mask = MASK_PLAYERSOLID
  446.     TR.filter = ply
  447.     local Trace = util.TraceLine(TR)
  448.    
  449.     if Trace.Hit and ply.Leaning then
  450.    
  451.     local POS1 = Trace.HitPos
  452.     local POS2 = ply:EyePos()
  453.    
  454.     if ply.Lean1 == 1 then
  455.     ply.LeanPos_Z = math.Clamp(POS1:Distance(POS2)*0.5,0,15)
  456.     else
  457.     ply.LeanPos_Z = math.Clamp(POS1:Distance(POS2)*-0.5,-15,0)
  458.     end
  459.     end
  460.    
  461.     end
  462.    
  463. end
  464. hook.Add("CalcView","VaultViewCalcHook",VaultViewCalc)
  465.  
  466. function CSSSliding(um)
  467.  
  468.     local PL = um:ReadEntity()
  469.     local BOOL = um:ReadBool()
  470.     PL.VaultView_Yaw = PL:EyeAngles().y
  471.     PL.Sliding = BOOL
  472.    
  473. end
  474. usermessage.Hook("CSS_Sliding",CSSSliding)
  475.  
  476. function ResetLegs()
  477. RemoveLegs()
  478. end
  479. concommand.Add("ResetLegs",ResetLegs)
  480.  
  481. function _R.Player:Walking()
  482. if self:GetMoveType() == MOVETYPE_WALK or self:GetMoveType() == MOVETYPE_LADDER or self:GetMoveType() == MOVETYPE_FLY or self:GetMoveType() == MOVETYPE_FLYGRAVITY then
  483. return true
  484. else
  485. return false
  486. end
  487. end
  488.  
  489. function CSSCreationFuncs()
  490.  
  491.     local self = LocalPlayer()
  492.  
  493.     if not self:Alive() or self:Health() <= 0 or self:InVehicle() or not self:Walking() or not CSSLegsVar:GetBool() then
  494.     RemoveLegs()
  495.     else
  496.     CreateLegs()
  497.     end
  498.    
  499.     if self.CSSLegs and IsValid(self.CSSLegs) and self.CSSLegs.Mode == 1 then
  500.    
  501.         local LEGS = self.CSSLegs
  502.        
  503.         local Param_X = 0
  504.         local Param_Y = 0
  505.        
  506.         if self:KeyDown(8) then
  507.         Param_X = 1
  508.         LastParam_X = 1
  509.         elseif self:KeyDown(16) then
  510.         Param_X = -1
  511.         LastParam_X = -1
  512.         else
  513.         Param_X = 0
  514.         LastParam_X = 0
  515.         end
  516.         if self:KeyDown(512) then
  517.         Param_Y = -1
  518.         LastParam_Y = -1
  519.         elseif self:KeyDown(1024) then
  520.         Param_Y = 1
  521.         LastParam_Y = 1
  522.         else
  523.         Param_Y = 0
  524.         LastParam_Y = 0
  525.         end
  526.        
  527.         if not LEGS.BLEND_X then LEGS.BLEND_X = Param_X end
  528.         if not LEGS.BLEND_Y then LEGS.BLEND_Y = Param_Y end
  529.        
  530.         if LEGS.BLEND_X < Param_X then
  531.         local SPEED = math.Clamp(Param_X - LEGS.BLEND_X,0.02,500)*5
  532.         LEGS.BLEND_X = math.Clamp( LEGS.BLEND_X + FrameTime()*SPEED, -1, Param_X )
  533.         elseif LEGS.BLEND_X > Param_X then
  534.         local SPEED = math.Clamp(LEGS.BLEND_X - Param_X,0.01,500)*6
  535.         LEGS.BLEND_X = math.Clamp( LEGS.BLEND_X - FrameTime()*SPEED, Param_X, 1 )
  536.         end
  537.        
  538.         if LEGS.BLEND_Y < Param_Y then
  539.         local SPEED = math.Clamp(Param_Y - LEGS.BLEND_Y,0.02,500)*5
  540.         LEGS.BLEND_Y = math.Clamp( LEGS.BLEND_Y + FrameTime()*SPEED, -1, Param_Y )
  541.         elseif LEGS.BLEND_Y > Param_Y then
  542.         local SPEED = math.Clamp(LEGS.BLEND_Y - Param_Y,0.01,500)*6
  543.         LEGS.BLEND_Y = math.Clamp( LEGS.BLEND_Y - FrameTime()*SPEED, Param_Y, 1 )
  544.         end
  545.        
  546.         LEGS:SetPoseParameter( "move_x", ( LEGS.BLEND_X ) )
  547.         LEGS:SetPoseParameter( "move_y", ( LEGS.BLEND_Y ) )
  548.        
  549.         if self:OnGround() and self:GetMoveType() == MOVETYPE_WALK and not self.Sliding and LEGS.CancelTypeMoves then
  550.         LEGS.CancelTypeMoves = false
  551.         end
  552.        
  553.         if self:GetMoveType() == MOVETYPE_FLY and not LEGS.CancelTypeMoves then
  554.         LEGS.Mode = 2
  555.         LEGS.CancelTypeMoves = true
  556.         LEGS.Moving = false
  557.         LEGS.Running = false
  558.         LEGS.Crouch = false
  559.         LEGS.Jump = true
  560.         LEGS:SetSequence("t_mantle")
  561.         LEGS:SetPlaybackRate(1.2)
  562.         LEGS:SetCycle(0)
  563.         LEGS.AnimEnd = CurTime() + 1
  564.         self.VaultView = CurTime() + 0.6
  565.         self.Vaulting = CurTime() + 0.8
  566.         return
  567.         elseif self:GetMoveType() == MOVETYPE_WALK and self.Sliding and not LEGS.CancelTypeMoves and self:KeyDown(4) then
  568.         self:VaultViewSet( 10, 0, 0, 0, 0, 8, "Slide_Start" )
  569.         self:VaultViewSet( 0, 0, 0, 0, 0.2, 8, "Slide_Reset" )
  570.         LEGS.Mode = 2
  571.         LEGS.CancelTypeMoves = true
  572.         LEGS.Moving = false
  573.         LEGS.Running = false
  574.         LEGS.Crouch = false
  575.         LEGS.Jump = true
  576.         LEGS:SetSequence("t_slide")
  577.         LEGS:SetPlaybackRate(0.9)
  578.         LEGS:SetCycle(0)
  579.         LEGS.AnimEnd2 = CurTime() + LEGS:SequenceDuration()
  580.         return
  581.         elseif self:GetMoveType() == MOVETYPE_FLYGRAVITY and not LEGS.CancelTypeMoves then
  582.         LEGS.Mode = 2
  583.         LEGS.CancelTypeMoves = true
  584.         LEGS.Moving = false
  585.         LEGS.Running = false
  586.         LEGS.Crouch = false
  587.         LEGS.Jump = false
  588.         LEGS:SetSequence("t_vaultup")
  589.         LEGS:SetPlaybackRate(1.25)
  590.         LEGS:SetCycle(0)
  591.         LEGS.AnimEnd3 = CurTime() + LEGS:SequenceDuration()
  592.         self.VaultUpView = CurTime() + 0.6
  593.         return
  594.         end    
  595.        
  596.         if not LEGS.Jump and not LEGS.Crouch and not self:OnGround() then
  597.         LEGS.Jump = true
  598.         LEGS:SetSequence("Jump")
  599.         LEGS:SetPlaybackRate(0.8)
  600.         LEGS:SetCycle(0)
  601.         end
  602.        
  603.         if LEGS.Jump and self:OnGround() then
  604.         LEGS.Moving = false
  605.         LEGS.Running = false
  606.         LEGS.Jump = false
  607.         if not LEGS.Crouch then
  608.         if self:GetVelocity():Length() > 10 and self:GetVelocity():Length() < 170 then
  609.         LEGS:SetSequence("walk_lower")
  610.         LEGS:SetPlaybackRate(1)
  611.         elseif self:GetVelocity():Length() >= 170 then
  612.         LEGS:SetSequence("Run_lower")
  613.         LEGS:SetPlaybackRate(1)
  614.         else
  615.         LEGS:SetSequence("Idle_lower")
  616.         LEGS:SetPlaybackRate(1)
  617.         end
  618.         LEGS:SetCycle(0)
  619.         end
  620.         end
  621.        
  622.         if LEGS.Jump and LEGS.ZVector and LEGS.ZVector > -7.5 then
  623.         LEGS.ZVector = math.Clamp(LEGS.ZVector - FrameTime()*50,-7.5,0)
  624.         elseif not LEGS.Jump and LEGS.ZVector and LEGS.ZVector < 0 then
  625.         LEGS.ZVector = math.Clamp(LEGS.ZVector + FrameTime()*50,-7.5,0)
  626.         end
  627.        
  628.         if LEGS.Jump then return end
  629.        
  630.         if not LEGS.Crouch and self:KeyDown(4) then
  631.         LEGS.Crouch = true
  632.         -- LEGS:SetModelScale(Vector(0.9,0.9,0.5))
  633.         if self:GetVelocity():Length() > 10 then
  634.         LEGS:SetSequence("Crouch_walk_lower")
  635.         else
  636.         LEGS:SetSequence("Crouch_Idle_Lower")
  637.         end
  638.         LEGS:SetPlaybackRate(1)
  639.         LEGS:SetCycle(0)
  640.         end
  641.        
  642.         if LEGS.Crouch and not self:KeyDown(4) then
  643.         LEGS.Crouch = false
  644.         -- LEGS:SetModelScale(Vector(0.9,0.9,0.9))
  645.         if self:GetVelocity():Length() > 10 and self:GetVelocity():Length() < 170 then
  646.         LEGS:SetSequence("walk_lower")
  647.         LEGS:SetPlaybackRate(1)
  648.         elseif self:GetVelocity():Length() >= 170 then
  649.         LEGS:SetSequence("Run_lower")
  650.         LEGS:SetPlaybackRate(1)
  651.         else
  652.         LEGS:SetSequence("Idle_lower")
  653.         LEGS:SetPlaybackRate(1)
  654.         end
  655.         LEGS:SetCycle(0)
  656.         end
  657.        
  658.         if not LEGS.Moving and self:GetVelocity():Length() > 10 and self:GetVelocity():Length() < 170 then
  659.         LEGS.Moving = true
  660.         if LEGS.Crouch then
  661.         LEGS:SetSequence("Crouch_walk_lower")
  662.         else
  663.         LEGS:SetSequence("walk_lower")
  664.         end
  665.         LEGS:SetPlaybackRate(1)
  666.         LEGS:SetCycle(0)
  667.         elseif LEGS.Running and LEGS.Moving and self:GetVelocity():Length() < 170 and self:GetVelocity():Length() > 10 then
  668.         LEGS.Moving = true
  669.         LEGS.Running = false
  670.         if LEGS.Crouch then
  671.         LEGS:SetSequence("Crouch_walk_lower")
  672.         else
  673.         LEGS:SetSequence("walk_lower")
  674.         end
  675.         LEGS:SetPlaybackRate(1)
  676.         LEGS:SetCycle(0)
  677.         elseif LEGS.Moving and self:GetVelocity():Length() <= 10 then
  678.         LEGS.Moving = false
  679.         LEGS.Running = false
  680.         if LEGS.Crouch then
  681.         LEGS:SetSequence("Crouch_Idle_lower")
  682.         else
  683.         LEGS:SetSequence("Idle_lower")
  684.         end
  685.         LEGS:SetPlaybackRate(1)
  686.         LEGS:SetCycle(0)
  687.         end
  688.        
  689.         if LEGS.Moving and not LEGS.Running and not LEGS.Crouch and self:GetVelocity():Length() >= 170 then
  690.         LEGS.Running = true
  691.         if LEGS.Crouch then
  692.         LEGS:SetSequence("Crouch_walk_lower")
  693.         LEGS:SetPlaybackRate(1)
  694.         else
  695.         LEGS:SetSequence("Run_lower")
  696.         LEGS:SetPlaybackRate(1)
  697.         end
  698.         LEGS:SetCycle(0)
  699.         end
  700.        
  701.         if LEGS.Moving and LEGS.Running and self:GetVelocity():Length() > 10 and self:GetVelocity():Length() < 170 then
  702.         LEGS.Running = false
  703.         if LEGS.Crouch then
  704.         LEGS:SetSequence("Crouch_walk_lower")
  705.         else
  706.         LEGS:SetSequence("Run_lower")
  707.         end
  708.         LEGS:SetPlaybackRate(1.3)
  709.         LEGS:SetCycle(0)
  710.         end
  711.        
  712.         if LEGS.Running and self:KeyDown(131072) then
  713.         LEGS:SetPlaybackRate(1.3)
  714.         elseif LEGS.Running and not self:KeyDown(131072) then
  715.         LEGS:SetPlaybackRate(1)
  716.         end
  717.    
  718.     end
  719.    
  720.     if self.CSSLegs and IsValid(self.CSSLegs) and self.CSSLegs.Mode == 2 then
  721.    
  722.         local LEGS = self.CSSLegs
  723.        
  724.         local Param_X = 0
  725.         local Param_Y = 0
  726.        
  727.         if self:KeyDown(8) then
  728.         Param_X = 1
  729.         LastParam_X = 1
  730.         elseif self:KeyDown(16) then
  731.         Param_X = -1
  732.         LastParam_X = -1
  733.         else
  734.         Param_X = 0
  735.         LastParam_X = 0
  736.         end
  737.         if self:KeyDown(512) then
  738.         Param_Y = -1
  739.         LastParam_Y = -1
  740.         elseif self:KeyDown(1024) then
  741.         Param_Y = 1
  742.         LastParam_Y = 1
  743.         else
  744.         Param_Y = 0
  745.         LastParam_Y = 0
  746.         end
  747.        
  748.         if not LEGS.BLEND_X then LEGS.BLEND_X = Param_X end
  749.         if not LEGS.BLEND_Y then LEGS.BLEND_Y = Param_Y end
  750.        
  751.         if LEGS.BLEND_X < Param_X then
  752.         local SPEED = math.Clamp(Param_X - LEGS.BLEND_X,0.02,500)*5
  753.         LEGS.BLEND_X = math.Clamp( LEGS.BLEND_X + FrameTime()*SPEED, -1, Param_X )
  754.         elseif LEGS.BLEND_X > Param_X then
  755.         local SPEED = math.Clamp(LEGS.BLEND_X - Param_X,0.01,500)*6
  756.         LEGS.BLEND_X = math.Clamp( LEGS.BLEND_X - FrameTime()*SPEED, Param_X, 1 )
  757.         end
  758.        
  759.         if LEGS.BLEND_Y < Param_Y then
  760.         local SPEED = math.Clamp(Param_Y - LEGS.BLEND_Y,0.02,500)*5
  761.         LEGS.BLEND_Y = math.Clamp( LEGS.BLEND_Y + FrameTime()*SPEED, -1, Param_Y )
  762.         elseif LEGS.BLEND_Y > Param_Y then
  763.         local SPEED = math.Clamp(LEGS.BLEND_Y - Param_Y,0.01,500)*6
  764.         LEGS.BLEND_Y = math.Clamp( LEGS.BLEND_Y - FrameTime()*SPEED, Param_Y, 1 )
  765.         end
  766.        
  767.         LEGS:SetPoseParameter( "move_x", ( LEGS.BLEND_X ) )
  768.         LEGS:SetPoseParameter( "move_y", ( LEGS.BLEND_Y ) )
  769.        
  770.         if LEGS.AnimEnd then
  771.         RunConsoleCommand("-duck")
  772.         end
  773.         if LEGS.AnimEnd3 then
  774.         RunConsoleCommand("-duck")
  775.         end
  776.        
  777.         if LEGS.AnimEnd and CurTime() >= LEGS.AnimEnd then
  778.        
  779.             LEGS.Moving = false
  780.             LEGS.Running = false
  781.             LEGS.Crouch = false
  782.             LEGS.Jump = true
  783.             LEGS.Mode = 1
  784.             LEGS:SetSequence("Jump")
  785.             LEGS:SetPlaybackRate(0)
  786.             LEGS:SetCycle(0)
  787.             LEGS.AnimEnd = nil
  788.            
  789.         end
  790.        
  791.         local TR = {}
  792.         TR.start = self:GetPos()
  793.         TR.endpos = self:GetPos()
  794.         TR.mask = MASK_PLAYERSOLID
  795.         TR.filter = self
  796.         TR.mins = Vector(-16.6,-16.6,5)
  797.         TR.maxs = Vector(16.6,16.6,35)
  798.         local Trace = util.TraceHull(TR)
  799.        
  800.         if LEGS.AnimEnd2 and (CurTime() >= LEGS.AnimEnd2 or not self:KeyDown(4) or not self:OnGround() or Trace.Hit) then
  801.        
  802.             LEGS.Moving = false
  803.             LEGS.Running = false
  804.             LEGS.Crouch = true
  805.             LEGS.Jump = false
  806.             LEGS.Mode = 1
  807.             if self:GetVelocity():Length() >= 10 then
  808.             LEGS:SetSequence("Crouch_walk_lower")
  809.             else
  810.             LEGS:SetSequence("Crouch_Idle_lower")
  811.             end
  812.             LEGS:SetPlaybackRate(1)
  813.             LEGS:SetCycle(0)
  814.             LEGS.AnimEnd2 = nil
  815.             self.Sliding = false
  816.            
  817.         end
  818.        
  819.         if LEGS.AnimEnd3 and CurTime() >= LEGS.AnimEnd3 then
  820.        
  821.             LEGS.Moving = false
  822.             LEGS.Running = false
  823.             LEGS.Crouch = false
  824.             LEGS.Jump = true
  825.             LEGS.Mode = 1
  826.             LEGS:SetSequence("Idle_lower")
  827.             LEGS:SetPlaybackRate(1)
  828.             LEGS:SetCycle(0)
  829.             LEGS.AnimEnd3 = nil
  830.            
  831.         end
  832.        
  833.     end
  834.    
  835. end
  836. hook.Add("Think","CSSCreationFuncsHook",CSSCreationFuncs)
  837.  
  838. function _R.Player:Moving()
  839.  
  840.     if self:KeyDown(8) or self:KeyDown(16) or self:KeyDown(512) or self:KeyDown(1024) then
  841.     return true
  842.     else
  843.     return false
  844.     end
  845.    
  846. end
  847.  
  848. function CSSLegsThink()
  849.  
  850.     local self = LocalPlayer()
  851.    
  852.     local Pos = self:EyePos()
  853.     local Ang = self:EyeAngles() + Angle(self:GetPunchAngle().p,self:GetPunchAngle().y,self:GetPunchAngle().r)
  854.     local FOV = 100
  855.  
  856.     cam.Start3D( Pos, Ang, FOV )
  857.    
  858.     local LastAng = self:EyeAngles().y
  859.     if not EyeAng2 then EyeAng2 = LastAng end
  860.     if not EyeAng2_F then EyeAng2_F = EyeAng2 end
  861.  
  862.     if self.CSSLegs and IsValid(self.CSSLegs) then
  863.    
  864.     if (math.AngleDifference( LastAng, EyeAng2 ) > 80) then EyeAng2 = LastAng - 80 end
  865.     if (math.AngleDifference( LastAng, EyeAng2 ) < -80) then EyeAng2 = LastAng + 80 end
  866.     if (self:GetVelocity():Length() >= 10) and self.CSSLegs.Mode == 1 and self:Moving() then
  867.     EyeAng2 = LastAng
  868.     EyeAng2_F = LastAng
  869.     end
  870.    
  871.     -- if EyeAng2_F < EyeAng2 then
  872.     -- EyeAng2_F = math.Clamp(EyeAng2_F + FrameTime()*800,-360,EyeAng2)
  873.     -- elseif EyeAng2_F > EyeAng2 then
  874.     -- EyeAng2_F = math.Clamp(EyeAng2_F - FrameTime()*800,EyeAng2,360)
  875.     -- end
  876.    
  877.     local Pos = self:GetPos() - Angle(0,self:EyeAngles().y,0):Forward()*(5.5 + self:EyeAngles().p*0.2) - self:GetRight()*1
  878.     self.CSSLegs:SetPos( Pos + Vector(0,0,self.CSSLegs.ZVector+0.5 or 0.5) )
  879.     self.CSSLegs:SetAngles( Angle(0,EyeAng2,0) )
  880.     self.CSSLegs:FrameAdvance( FrameTime() )
  881.     if self.CSSLegs.Mode == 1 and (self:KeyDown(4) and self:EyeAngles().p >= 30) or (not self:KeyDown(4) and self:EyeAngles().p >= 35) then
  882.     self.CSSLegs:DrawModel()
  883.     elseif self.CSSLegs.Mode == 2 then
  884.     if (self.Sliding and self:EyeAngles().p < -10) then return end
  885.     self.CSSLegs:DrawModel()
  886.     end
  887.    
  888.     end
  889.    
  890.     cam.End3D()
  891.  
  892. end
  893. hook.Add("RenderScreenspaceEffects","CSSLegsThinkHook",CSSLegsThink)
  894.  
  895. function SlideFoot( ply, pos, foot, sound, volume, rf )
  896.  
  897.     if not SinglePlayer() then
  898.    
  899.     if ply.Sliding then
  900.     return true
  901.     end
  902.    
  903.     end
  904.    
  905. end
  906. hook.Add("PlayerFootstep","SlideFootHook",SlideFoot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement