Advertisement
TheTomatooo

Combat Server

Sep 18th, 2023
6,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | Source Code | 0 0
  1. local rp = game:GetService("ReplicatedStorage")
  2. local remotes = rp:WaitForChild("Remotes")
  3. local animations = rp:WaitForChild("Animations")
  4.  
  5. local punchRemote = remotes:WaitForChild("Punch")
  6.  
  7. local debris = game:GetService("Debris")
  8. local ss = game:GetService("ServerStorage")
  9. local modules = ss:WaitForChild("Modules")
  10.  
  11. local TomatoHitbox = require(modules:WaitForChild("TomatoHitbox"))
  12. local hitService = require(modules:WaitForChild("HitService"))
  13.  
  14. local lastPunch = {}
  15.  
  16. local MAX_COMBO = 4
  17.  
  18. local function changeCombo(char)
  19.     local combo = char:GetAttribute("Combo")
  20.    
  21.     local player = game:GetService("Players"):GetPlayerFromCharacter(char)
  22.    
  23.     if lastPunch[player] then
  24.         local passedTime = os.clock() - lastPunch[player]
  25.         print(passedTime)
  26.         if passedTime <= 1.25 then
  27.             if combo >= MAX_COMBO then
  28.                 char:SetAttribute("Combo",1)
  29.             else
  30.                 char:SetAttribute("Combo",combo + 1)
  31.             end
  32.         else
  33.             char:SetAttribute("Combo",1)
  34.         end
  35.     else
  36.         if combo >= MAX_COMBO then
  37.             char:SetAttribute("Combo",1)
  38.         else
  39.             char:SetAttribute("Combo",combo + 1)
  40.         end
  41.     end
  42.    
  43.     lastPunch[player] = os.clock()
  44. end
  45.  
  46. local function getPunchAnim(char,jump)
  47.     local combo = char:GetAttribute("Combo")
  48.     local punchAnims = animations:WaitForChild("Combat"):GetChildren()
  49.     local extraAnims = animations:WaitForChild("Extra")
  50.    
  51.     local inAir = char.Humanoid.FloorMaterial == Enum.Material.Air
  52.    
  53.     local currAnim
  54.    
  55.     if combo == MAX_COMBO then
  56.         if not inAir then
  57.             if not jump then
  58.                 currAnim = punchAnims[combo]
  59.             else
  60.                 currAnim = extraAnims:WaitForChild("UpperCut")
  61.             end
  62.  
  63.         else
  64.             currAnim = extraAnims:WaitForChild("DownSlam")
  65.         end
  66.     else
  67.         currAnim = punchAnims[combo]
  68.     end
  69.    
  70.  
  71.    
  72.     return currAnim
  73. end
  74.  
  75. local function stopAnims(object)
  76.     for i,v in pairs(object:GetPlayingAnimationTracks()) do
  77.         v:Stop()
  78.     end
  79. end
  80.  
  81. punchRemote.OnServerEvent:Connect(function(player,jump)
  82.     local char = player.Character
  83.     local hum = char:WaitForChild("Humanoid")
  84.     local humRp = char:WaitForChild("HumanoidRootPart")
  85.    
  86.     local attacking = char:GetAttribute("Attacking")
  87.     local punching = char:GetAttribute("Punch")
  88.     local stunned = char:GetAttribute("Stunned")
  89.    
  90.     if attacking or punching or stunned then return end
  91.    
  92.     char:SetAttribute("Attacking",true)
  93.     char:SetAttribute("Punch",true)
  94.    
  95.     changeCombo(char)
  96.     stopAnims(hum)
  97.    
  98.     hum.WalkSpeed = 10
  99.     hum.JumpPower = 0
  100.    
  101.     local ragdoll = false
  102.     local downSlam = false
  103.     local upperCut = false
  104.    
  105.     local newHitbox = TomatoHitbox.new()
  106.     newHitbox.Size = Vector3.new(6,6,6)
  107.     newHitbox.CFrame = humRp
  108.     newHitbox.Offset = CFrame.new(0,0,-2.5)
  109.    
  110.     newHitbox.onTouch = function(enemyHum)
  111.         if enemyHum ~= hum then
  112.             if enemyHum.Parent:GetAttribute("Ragdolled") or enemyHum.Health <= 0 then return end
  113.            
  114.             local enemyHumRp = enemyHum.Parent.HumanoidRootPart
  115.            
  116.             local center = (enemyHumRp.Position - humRp.Position).Unit
  117.             local strength = 10
  118.            
  119.             if char:GetAttribute("Combo") == MAX_COMBO then
  120.                 ragdoll = true
  121.                 strength = 35
  122.             end
  123.            
  124.             local knockback = center * strength
  125.            
  126.             if downSlam then
  127.                 enemyHumRp.CFrame = enemyHumRp.CFrame * CFrame.new(0,-2,0) * CFrame.Angles(math.rad(90),0,0)
  128.                
  129.                 knockback = nil
  130.             elseif upperCut then
  131.                 local uppercutVelocity = Instance.new("BodyVelocity")
  132.                 uppercutVelocity.P = 50000
  133.                 uppercutVelocity.MaxForce = Vector3.new(0,math.huge,0)
  134.                 uppercutVelocity.Velocity = Vector3.new(0,50,0)
  135.                 uppercutVelocity.Parent = enemyHumRp
  136.                
  137.                 debris:AddItem(uppercutVelocity,0.2)
  138.                
  139.                 knockback = nil
  140.             end
  141.            
  142.             hitService.Hit(enemyHum,2,1.25,knockback,ragdoll,2)
  143.            
  144.             if char:GetAttribute("Combo") ~= MAX_COMBO then
  145.                 local bv = Instance.new("BodyVelocity")
  146.                 bv.MaxForce = Vector3.new(math.huge,0,math.huge)
  147.                 bv.P = 50000
  148.                 bv.Velocity = knockback
  149.                 bv.Parent = humRp
  150.                
  151.                 debris:AddItem(bv,0.2)
  152.             end
  153.  
  154.            
  155.         end
  156.     end
  157.    
  158.     local combatAnim = getPunchAnim(char,jump)
  159.    
  160.     local playPunchAnim = hum:LoadAnimation(combatAnim)
  161.    
  162.     playPunchAnim.KeyframeReached:Connect(function(kf)
  163.         if kf == "Hit" then
  164.             char:SetAttribute("Attacking",false)
  165.            
  166.             if combatAnim.Name == "DownSlam" then
  167.                 downSlam = true
  168.             elseif combatAnim.Name == "UpperCut" then
  169.                 upperCut = true
  170.             end
  171.            
  172.             task.spawn(function()
  173.                 if not char:GetAttribute("Stunned") then
  174.                     newHitbox:Start()
  175.                     task.wait(0.1)
  176.                     newHitbox:Stop()
  177.                     newHitbox:Destroy()
  178.                 else
  179.                     newHitbox:Stop()
  180.                     newHitbox:Destroy()
  181.                 end
  182.  
  183.             end)
  184.  
  185.            
  186.             if char:GetAttribute("Combo") == MAX_COMBO then
  187.                 task.wait(1)
  188.             end
  189.            
  190.             char:SetAttribute("Punch",false)
  191.            
  192.         end
  193.     end)
  194.    
  195.     playPunchAnim.Stopped:Connect(function()
  196.         hum.WalkSpeed = 16
  197.         hum.JumpPower = 50
  198.     end)
  199.    
  200.     playPunchAnim:Play()
  201.    
  202. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement