Advertisement
g14ndev

Combat v2

Mar 7th, 2024
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.86 KB | Gaming | 0 0
  1. -- local script ---
  2. local plr = game.Players.LocalPlayer
  3. local UIS = game:GetService("UserInputService")
  4.  
  5. local count = 1
  6. local db = false -- wether a hit can be perfomed or not
  7. local animations = script.Animations
  8. local waitTime = 0.1 -- cooldown between hits
  9. local maxComboTime = 1.5
  10. local lastClickTime = 0
  11. local speedMul = 2.0
  12.  
  13. UIS.InputBegan:Connect(function(input , gpe)
  14.     if gpe then return end
  15.     local characterMove -- initializing animation folder and variables for said animations
  16.     local hit1
  17.     local hit2
  18.     local hit3
  19.     local hit4
  20.  
  21.  
  22.     if input.UserInputType == Enum.UserInputType.MouseButton1 and plr.Character:GetAttribute("Stun") == false and plr.Character:GetAttribute("IFrame") == false then
  23.         local currentTime = tick()
  24.         local timeSinceLastClick = currentTime - lastClickTime
  25.         lastClickTime = currentTime
  26.         if plr.state["type"].Value == 1 then -- checks if the users "type" is 1 ("refrencing a specific character")
  27.             characterMove = animations.AlastorAnimations
  28.             hit1 = characterMove["1"]  -- asign each hit to a specific animation in the characterMove folder
  29.             hit2 = characterMove["2"]
  30.             hit3 = characterMove["1"]
  31.             hit4 = characterMove["2"]
  32.            
  33.         end
  34.         if db == true then return end -- if db is true then we cannot click
  35.         if timeSinceLastClick > maxComboTime then
  36.             count = 1
  37.         end
  38.        
  39.         if count == 1 and not db then
  40.             local targetCount = 2
  41.            
  42.            
  43.             local humanoid = plr.Character:WaitForChild("Humanoid")
  44.             local animator = humanoid:WaitForChild("Animator")
  45.             local animationTrack = animator:LoadAnimation(hit1)
  46.            
  47.            
  48.             animationTrack:Play()
  49.             animationTrack:AdjustSpeed(speedMul)
  50.             animationTrack.KeyframeReached:Connect(function(keyframeName)
  51.                
  52.                 if keyframeName == "Damage" then
  53.                     game.ReplicatedStorage.CombatRemote:FireServer(count -1)
  54.                 else
  55.                     return
  56.                 end
  57.                
  58.             end)
  59.             count = targetCount
  60.             db = true
  61.             task.wait(waitTime) -- setting db to true then waiting to set it to false
  62.             db = false
  63.  
  64.        
  65.         elseif count == 2 and not db then
  66.             local targetCount = 3
  67.            
  68.             local humanoid = plr.Character:WaitForChild("Humanoid")
  69.             local animator = humanoid:WaitForChild("Animator")
  70.             local animationTrack = animator:LoadAnimation(hit2)
  71.            
  72.             animationTrack:Play()
  73.             animationTrack:AdjustSpeed(speedMul)
  74.             animationTrack.KeyframeReached:Connect(function(keyframeName)
  75.  
  76.                 if keyframeName == "Damage" then
  77.                     game.ReplicatedStorage.CombatRemote:FireServer(count -1)
  78.  
  79.                 end
  80.  
  81.             end)
  82.             count = targetCount
  83.             db = true
  84.             task.wait(waitTime)
  85.             db = false
  86.            
  87.  
  88.        
  89.         elseif count == 3 and not db then
  90.             local targetCount = 4
  91.            
  92.            
  93.             local humanoid = plr.Character:WaitForChild("Humanoid")
  94.             local animator = humanoid:WaitForChild("Animator")
  95.             local animationTrack = animator:LoadAnimation(hit3)
  96.            
  97.             animationTrack:Play()
  98.             animationTrack:AdjustSpeed(speedMul)
  99.             animationTrack.KeyframeReached:Connect(function(keyframeName)
  100.  
  101.                 if keyframeName == "Damage" then
  102.                     game.ReplicatedStorage.CombatRemote:FireServer(count -1)
  103.  
  104.                 end
  105.  
  106.             end)
  107.             count = targetCount
  108.             db = true
  109.             task.wait(waitTime)
  110.             db = false
  111.  
  112.        
  113.        
  114.         elseif count > 3 and not db then
  115.            
  116.            
  117.             local humanoid = plr.Character:WaitForChild("Humanoid")
  118.             local animator = humanoid:WaitForChild("Animator")
  119.             local animationTrack = animator:LoadAnimation(hit4)
  120.            
  121.             animationTrack:Play()
  122.             animationTrack:AdjustSpeed(speedMul)
  123.             animationTrack.KeyframeReached:Connect(function(keyframeName)
  124.  
  125.                 if keyframeName == "Damage" then
  126.                     game.ReplicatedStorage.CombatRemote:FireServer(4)
  127.  
  128.                 end
  129.  
  130.             end)
  131.             count = 1
  132.             db = true
  133.            
  134.             task.wait(maxComboTime)
  135.            
  136.             db = false
  137.            
  138.         end
  139.     end
  140. end)
  141.  
  142. -- server script ---
  143.  
  144. local debris = game:GetService("Debris")
  145. local damage = 1
  146. local stunTime = 0.8
  147. local Modules = game:GetService("ServerStorage").Modules
  148. local RagdollModule = require(Modules.RagDollModule)
  149. local ragTime = 2
  150. local reTime = 5
  151. local userInputService = game:GetService("UserInputService")
  152. game.ReplicatedStorage.CombatRemote.OnServerEvent:Connect(function(player, count)
  153.     local TBL = {player.Name,count}
  154.    
  155.     local miss = game.ServerStorage.Sounds["Punch Swing "]:Clone()
  156.    
  157.     miss.Parent = player.Character
  158.     miss:Play()
  159.     debris:AddItem(miss,3)
  160.    
  161.    
  162.     local character = player.Character
  163.    
  164.     character:SetAttribute("Attacking", true)
  165.     if character then
  166.         local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  167.        
  168.         -- Create the damage box
  169.         local damageBox = Instance.new("Part")
  170.        
  171.         damageBox.CanTouch = true
  172.         damageBox.Size = Vector3.new(5, 6, 5) -- Adjust the size as needed
  173.         damageBox.Anchored = false
  174.         damageBox.CanCollide = false
  175.         damageBox.Transparency = 0.5
  176.         damageBox.BrickColor = BrickColor.new("Bright red")
  177.        
  178.         damageBox.Name = "DamageBox"
  179.         damageBox.Parent = game.Workspace
  180.         damageBox.CFrame = humanoidRootPart.CFrame * CFrame.new(0,0,-2.5) -- Adjust the distance in front of the player      
  181.        
  182.        
  183.         damageBox.Touched:Connect(function(target)
  184.             if target == nil then return end
  185.            
  186.             if target.Name == "Block" then
  187.                 character.Humanoid.AutoRotate = false
  188.                 character:SetAttribute("Stun", true)
  189.                
  190.                 task.wait(2)
  191.                 character.Humanoid.AutoRotate = true
  192.                 character:SetAttribute("Stun",false)
  193.                
  194.                
  195.                 return
  196.             end
  197.             if target.Parent == nil then return end
  198.            
  199.             local hum = target.Parent:FindFirstChild("Humanoid")
  200.            
  201.             if hum and count <= 3 and target.Parent:GetAttribute("IFrame") == false and target.Parent:GetAttribute("Ragdoll") == false then
  202.    
  203.                 if target.Parent ~= player.Character then
  204.                     local punch = game.ServerStorage.Sounds:WaitForChild("HitPunch")
  205.                     local Pclone = punch:Clone()
  206.  
  207.                     Pclone.Parent = player.Character
  208.                     Pclone:Play()
  209.                     debris:AddItem(Pclone,3)
  210.                     if hum.Health - damage <= 0  and hum.Health > 0 then
  211.                         hum:TakeDamage(damage)
  212.                         player.leaderstats.kills.Value +=1
  213.                         RagdollModule.RagdollCharacter(target.Parent)
  214.                         RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
  215.                         task.wait(reTime)
  216.                         RagdollModule.Unragdoll(target.Parent)
  217.                         return
  218.                     end
  219.                     hum:TakeDamage(damage)
  220.                    
  221.                     target.Parent:SetAttribute("Stun", true)
  222.                     task.wait(stunTime)
  223.                     target.Parent:SetAttribute("Stun", false)
  224.                    
  225.                 end
  226.             elseif hum and count > 3 and target.Parent:GetAttribute("IFrame") == false and target.Parent:GetAttribute("Ragdoll") == false then
  227.                
  228.                 if target.Parent ~= player.Character then
  229.                     local punch = game.ServerStorage.Sounds:WaitForChild("HitPunch")
  230.                     local Pclone = punch:Clone()
  231.  
  232.                     Pclone.Parent = player.Character
  233.                     Pclone:Play()
  234.                     debris:AddItem(Pclone,3)
  235.                     if hum.Health - damage <= 0  and hum.Health > 0 then
  236.                         hum:TakeDamage(damage)
  237.                         player.leaderstats.kills.Value +=1
  238.                         RagdollModule.RagdollCharacter(target.Parent)
  239.                         RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
  240.                         task.wait(reTime)
  241.                         RagdollModule.Unragdoll(target.Parent)
  242.                         return
  243.                     end
  244.                     hum:TakeDamage(damage)
  245.                    
  246.                    
  247.                     target.Parent:SetAttribute("Stun", true)
  248.                     RagdollModule.RagdollCharacter(target.Parent)
  249.                     RagdollModule.knockBack(target.Parent, character:WaitForChild("HumanoidRootPart"))
  250.                     task.wait(1)
  251.                     target.Parent:SetAttribute("Stun", false)
  252.                     task.wait(ragTime -1)
  253.                     RagdollModule.Unragdoll(target.Parent)
  254.                    
  255.  
  256.                 end
  257.             else
  258.                 return
  259.            
  260.             end
  261.            
  262.            
  263.            
  264.         end)
  265.         debris:AddItem(damageBox,0.1)
  266.        
  267.     else
  268.         return
  269.     end
  270.     task.wait(0.5)
  271.     character:SetAttribute("Attacking", false)
  272.    
  273.    
  274.    
  275.    
  276. end)
  277.  
  278.  
  279. -- ragdoll module ---
  280.  
  281. -- RagdollModule.lua
  282.  
  283. local RagdollModule = {}
  284.  
  285.  
  286. function RagdollModule.knockBack(target, attackerHRP)
  287.     local targetHRP = target:WaitForChild("HumanoidRootPart")
  288.     if targetHRP == nil then return end
  289.     -- Calculate the direction from the attacker's HRP to the target's HRP
  290.     local direction = (targetHRP.Position - attackerHRP.Position).Unit * Vector3.new(40,0,40) + Vector3.new(0,40)
  291.     local att = Instance.new("Attachment",targetHRP)
  292.     -- Apply a force to the target's HRP in the calculated direction
  293.     local knockbackForce = Instance.new("LinearVelocity", att)
  294.     knockbackForce.VectorVelocity = direction  -- Adjust the force as needed
  295.     knockbackForce.MaxForce = 20000
  296.     knockbackForce.Attachment0 = att
  297.  
  298.     -- Apply an upward force to put the target in the air
  299.     game.Debris:AddItem(att,0.1)
  300. end
  301.  
  302. function RagdollModule.RagdollCharacter(target)
  303.     if target:GetAttribute("Ragdoll") == true then return end
  304.     target:SetAttribute("Ragdoll", true)
  305.     target:WaitForChild("Humanoid"):ChangeState(Enum.HumanoidStateType.Physics)
  306.    
  307.    
  308.     -- Check if the target has a Humanoid
  309.     local humanoid = target:FindFirstChildOfClass("Humanoid")
  310.     if not humanoid then
  311.         return
  312.     end
  313.  
  314.     for i, joint in pairs(target:GetDescendants())do
  315.         if joint:IsA('Motor6D') then
  316.             local socket = Instance.new("BallSocketConstraint", joint.Parent)
  317.             local att0 = Instance.new('Attachment', joint.Part0)
  318.             local att1 = Instance.new('Attachment', joint.Part1)
  319.            
  320.             att0.CFrame = joint.C0
  321.             att1.CFrame = joint.C1
  322.            
  323.             socket.Attachment0 = att0
  324.             socket.Attachment1 = att1
  325.            
  326.             socket.TwistLimitsEnabled = true
  327.             socket.LimitsEnabled = true
  328.            
  329.            
  330.             joint.Enabled = false
  331.         end
  332.     end
  333.    
  334.     target.Humanoid.AutoRotate = false
  335.    
  336.    
  337.  
  338. end
  339.  
  340. function RagdollModule.Unragdoll(target)
  341.     if target == nil then return end
  342.     target:SetAttribute("Stun", false)
  343.    
  344.    
  345.     target:WaitForChild("Humanoid"):ChangeState(Enum.HumanoidStateType.GettingUp)
  346.  
  347.     for i, joint in pairs(target:GetDescendants())do
  348.         if joint:IsA("Motor6D") then
  349.  
  350.  
  351.             joint.Enabled = true
  352.         elseif joint:IsA("BallSocketConstraint") then
  353.             joint.Enabled = false
  354.            
  355.            
  356.         end
  357.     end
  358.  
  359.    
  360.     target:SetAttribute("Ragdoll", false)
  361.     target.Humanoid.AutoRotate = true
  362. end
  363.  
  364. return RagdollModule
  365.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement