Advertisement
TaylorsRus

Combat

Jan 3rd, 2022
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.00 KB | None | 0 0
  1. local RepStorage = game:GetService("ReplicatedStorage")
  2. local RunService = game:GetService("RunService")
  3. local TweenService = game:GetService("TweenService")
  4. local InputService = game:GetService("UserInputService")
  5. local Players = game:GetService("Players")
  6. local Lighting = game:GetService("Lighting")
  7. local Debris = game:GetService("Debris")
  8.  
  9. local RepModules = RepStorage:WaitForChild("Modules")
  10. local Data = RepModules:WaitForChild("Data")
  11.  
  12. local HitboxModule = require(RepModules:WaitForChild("HitboxModule"))
  13. local CameraShake = require(RepModules:WaitForChild("CameraShaker"))
  14. local PlayerData = require(Data:WaitForChild("PlayerData"))
  15.  
  16. local Plr = Players:GetPlayerFromCharacter(script.Parent)
  17. local PlrGui = Plr:WaitForChild("PlayerGui")
  18. local Char = Plr.Character
  19. local Hum = Char:WaitForChild("Humanoid")
  20. local HumRP = Char:WaitForChild("HumanoidRootPart")
  21. local Animator = Hum:WaitForChild("Animator")
  22. local Cam = workspace.CurrentCamera
  23.  
  24. local ClientFunctions = {}
  25.  
  26. local Anims = RepStorage:WaitForChild("Animations")
  27. local Events = RepStorage:WaitForChild("Events")
  28.  
  29. local DataIndex = PlayerData.Stats
  30. local DashValue = false
  31. local LockOnValue = false
  32. local InventoryValue = false
  33.  
  34. local RunTrack = Animator:LoadAnimation(Anims:WaitForChild("Running"))
  35. local BlockTrack = Animator:LoadAnimation(Anims:WaitForChild("Blocking"))
  36.  
  37. function ClientFunctions:Run(Status)
  38.     local SPEED_UP = 78
  39.     local SLOW_DOWN = 70
  40.     local TWEEN_SPEED = .6
  41.  
  42.     local WALK_SPEED = DataIndex[Char:GetAttribute("Type")].WalkSpeed
  43.     local RUN_SPEED = DataIndex[Char:GetAttribute("Type")].RunSpeed
  44.     local ANIM_SPEED = DataIndex[Char:GetAttribute("Type")].RunAnimationSpeed
  45.  
  46.     if Status then 
  47.         if Char:GetAttribute("Running") or Char:GetAttribute("Attacking") or Char:GetAttribute("Blocking") or Char:GetAttribute("MechanicDisable") then
  48.             return
  49.         end
  50.  
  51.         RunTrack:Play()
  52.         RunTrack:AdjustSpeed(ANIM_SPEED)
  53.        
  54.         Hum.WalkSpeed = RUN_SPEED  
  55.         Char:SetAttribute("Running", true)
  56.     else       
  57.         RunTrack:Stop()
  58.        
  59.         Hum.WalkSpeed = WALK_SPEED
  60.         Char:SetAttribute("Running", false)
  61.     end
  62. end
  63.  
  64. function ClientFunctions:Block(Status)
  65.     local BLOCK_SPEED = 4
  66.  
  67.     if Status then 
  68.         if Char:GetAttribute("Attacking") or Char:GetAttribute("Dashing") or Char:GetAttribute("Blocking") or Char:GetAttribute("MechanicDisable") then
  69.             return         
  70.         end
  71.        
  72.         self:Run(false)
  73.  
  74.         BlockTrack:Play()
  75.         Char:SetAttribute("Blocking", true)
  76.         Hum.WalkSpeed = BLOCK_SPEED            
  77.     else
  78.         BlockTrack:Stop()
  79.         Char:SetAttribute("Blocking", false)
  80.         Hum.WalkSpeed = DataIndex[Char:GetAttribute("Type")].WalkSpeed
  81.     end
  82. end
  83.  
  84. function ClientFunctions:Dash()
  85.     if Char:GetAttribute("Attacking") or Char:GetAttribute("Blocking") or Char:GetAttribute("Dashing") or Char:GetAttribute("MechanicDisable") --[[or ShiftLock ~= Enum.MouseBehavior.LockCenter]] then
  86.         return
  87.     end
  88.  
  89.     local VELOCITY_FORCE = 30
  90.     local VELOCITY_DESPAWN = .4
  91.     local VELOCITY_DELAY = .1
  92.     local DASH_COOLDOWN = 2.25
  93.     local ANIMATION_SPEED = 2
  94.    
  95.     local Direction
  96.     local Connection
  97.  
  98.     local Keys = {Forward = Enum.KeyCode.W, Backward = Enum.KeyCode.S, Left = Enum.KeyCode.A, Right = Enum.KeyCode.D}  
  99.  
  100.     for MovementDirection, MovementKey in pairs(Keys) do
  101.         if InputService:IsKeyDown(MovementKey) then
  102.             Direction = MovementDirection
  103.            
  104.         elseif Hum.MoveDirection.Magnitude == 0 then
  105.             return
  106.         end
  107.     end
  108.  
  109.     local DashAnim = Anims:WaitForChild("Dash"..Direction)
  110.     local DashSound = HumRP:WaitForChild("Dash")
  111.  
  112.     local DashTrack = Animator:LoadAnimation(DashAnim)
  113.     DashTrack.Priority = Enum.AnimationPriority.Action
  114.  
  115.     local DashForce = Instance.new("BodyVelocity")
  116.     DashForce.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  117.  
  118.     Hum.JumpPower = 0
  119.  
  120.     DashSound:Play()
  121.     DashTrack:Play()   
  122.     DashTrack:AdjustSpeed(ANIMATION_SPEED)
  123.     Char:SetAttribute("Dashing", true) 
  124.  
  125.     task.wait(VELOCITY_DELAY)
  126.  
  127.     DashForce.Parent = HumRP
  128.     Debris:AddItem(DashForce, VELOCITY_DESPAWN)
  129.  
  130.     Connection = RunService.RenderStepped:Connect(function()
  131.         DashForce.Velocity = Hum.MoveDirection * VELOCITY_FORCE
  132.     end)
  133.  
  134.     task.delay(DASH_COOLDOWN, function()   
  135.         Char:SetAttribute("Dashing", false)
  136.         Hum.JumpPower = DataIndex[Char:GetAttribute("Type")].JumpPower
  137.         Connection:Disconnect()
  138.     end)
  139. end
  140.  
  141. function ClientFunctions:CombatStatement(Click, Range, ShiftLock)
  142.     if Char:GetAttribute("Attacking") or Char:GetAttribute("Blocking") or Char:GetAttribute("Sliding")  then
  143.         return
  144.     end
  145.    
  146.     local RayInstance, RayBool = HitboxModule:Raycast(Char, Range, true)
  147.     local Enemy
  148.  
  149.     if RayBool then
  150.         Enemy = HitboxModule:Magnitude(Char, Range)
  151.     end    
  152.  
  153.     Events:WaitForChild("Combat"):FireServer(Enemy, Click)
  154. end
  155.  
  156. function ClientFunctions:Inventory()
  157.     -- Due a rewrite.  
  158.     local InventoryGui = PlrGui:WaitForChild("InventoryGui")
  159.     local ImageLabel = InventoryGui:WaitForChild("ImageLabel")
  160.     local VPF = ImageLabel:WaitForChild("ViewportFrame")
  161.     local Blur = Lighting:WaitForChild("Blur")
  162.  
  163.     local Clone
  164.     local HoldInDisplay
  165.     local MouseInDisplay
  166.  
  167.     local function CallbackOn(State)
  168.         if State == Enum.TweenStatus.Canceled then
  169.             TweenService:Create(Blur, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 0}):Play()
  170.         else
  171.             InventoryGui.Enabled = true
  172.             Blur.Enabled = true
  173.         end
  174.     end
  175.  
  176.     local function CallbackOff(State)
  177.         if State == Enum.TweenStatus.Canceled then
  178.             TweenService:Create(Blur, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 13}):Play()   
  179.         else
  180.             InventoryGui.Enabled = false
  181.             Blur.Enabled = false
  182.         end
  183.     end
  184.  
  185.     if not InventoryValue then
  186.         InventoryValue = true
  187.         InventoryGui.Enabled = true
  188.         Blur.Enabled = true
  189.  
  190.         ImageLabel:TweenPosition(UDim2.new(0.278, 0, 0.048, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1.65, true, CallbackOn)
  191.         TweenService:Create(Blur, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 13}):Play()
  192.  
  193.         if not VPF then
  194.             local VPFCam = Instance.new("Camera")
  195.             VPFCam.Parent = VPF
  196.             VPFCam.CFrame = CFrame.new(0, 0, 0)
  197.             VPF.CurrentCamera = VPFCam
  198.  
  199.             Char.Archivable = true
  200.  
  201.             Clone = Char:Clone()
  202.             Clone.Parent = VPF.WorldModel
  203.             Clone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, - 7.5), Vector3.new(0, 0, 0)))
  204.             Clone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
  205.  
  206.             for _,Child in ipairs(Clone:GetDescendants()) do
  207.                 if Child:IsA("Script") or Child:IsA("LocalScript") or Child:IsA("Folder") then         
  208.                     Child:Destroy()
  209.                 end
  210.             end
  211.         end
  212.  
  213.         VPF.MouseEnter:Connect(function() MouseInDisplay = true end)
  214.         VPF.MouseLeave:Connect(function() MouseInDisplay = false end)
  215.  
  216.     else
  217.         InventoryValue = false
  218.         InventoryGui.ImageLabel:TweenPosition(UDim2.new(-.5, 0, 0.048, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1.65, true, CallbackOff)
  219.         TweenService:Create(Blur, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = 0}):Play()
  220.     end
  221. end
  222.  
  223. function ClientFunctions:LockOn()
  224.     local ENEMY_RANGE = 35
  225.     local TWEEN_TIME = .35
  226.  
  227.     local MAGNITUDE_OFFSET = 11
  228.     local CHARACTERS_OFFSET = Vector3.new(3, 3, 0)
  229.     local MODIFIED_OFFSET = Vector3.new(1, 0, 1)
  230.     local FINAL_CFRAME = Vector3.new(0, 1, 0)
  231.  
  232.     local Enemy = HitboxModule:Magnitude(Char, 35)
  233.     local OriginalCFrame = Cam.CFrame
  234.  
  235.     if not LockOnValue then
  236.         if not Enemy then
  237.             print("No enemy in range")
  238.             return
  239.         end
  240.  
  241.         LockOnValue = true
  242.         Cam.CameraType = Enum.CameraType.Scriptable
  243.  
  244.         task.spawn(function()  
  245.             while LockOnValue do
  246.                 local CharPos = HumRP.Position
  247.                 local EnemyPos = Enemy:WaitForChild("HumanoidRootPart").Position
  248.  
  249.                 local Difference = EnemyPos + ((CharPos + CHARACTERS_OFFSET) - EnemyPos).Unit * ((CharPos - EnemyPos).Magnitude + MAGNITUDE_OFFSET)
  250.                 local NewVar = CFrame.new(Difference, EnemyPos)
  251.                 local ModEnemyPos = (CharPos - EnemyPos).Unit * MODIFIED_OFFSET
  252.                 local NewCF = CFrame.lookAt(CharPos, CharPos + ModEnemyPos, HumRP.CFrame.UpVector) * CFrame.fromAxisAngle(FINAL_CFRAME, math.pi)
  253.  
  254.                 Char:SetPrimaryPartCFrame(NewCF)
  255.                 TweenService:Create(Cam, TweenInfo.new(TWEEN_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CFrame = NewVar}):Play()
  256.                 RunService.RenderStepped:Wait()
  257.             end
  258.         end)
  259.     else   
  260.         LockOnValue = false
  261.         Cam.CameraType = Enum.CameraType.Custom
  262.     end
  263. end
  264.  
  265. function ClientFunctions:Ragdoll(Type)
  266.     if Type then
  267.         Hum:ChangeState(Enum.HumanoidStateType.Ragdoll)
  268.  
  269.         Hum.BreakJointsOnDeath = false
  270.         Hum.RequiresNeck = false   
  271.     else
  272.         Hum:ChangeState(Enum.HumanoidStateType.GettingUp)
  273.  
  274.         Hum.BreakJointsOnDeath = true
  275.         Hum.RequiresNeck = true
  276.     end
  277. end
  278.  
  279. function ClientFunctions:CameraShake(Preset)   
  280.     local function ShakeCamera(ShakeCf)
  281.         Cam.CFrame = Cam.CFrame * ShakeCf
  282.     end
  283.  
  284.     local RenderPriority = Enum.RenderPriority.Camera.Value + 1
  285.     local CamShake = CameraShake.new(RenderPriority, ShakeCamera)
  286.  
  287.     CamShake:Start()   
  288.     CamShake:Shake(CameraShake.Presets[Preset])
  289. end
  290.  
  291. function ClientFunctions:ChildAdded(Child)
  292.     if Child.Name == "CamShake" then
  293.         ClientFunctions:CameraShake(Child.Value)
  294.     end
  295. end
  296.  
  297. return ClientFunctions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement