Advertisement
TaylorsRus

Combat

Jan 3rd, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.69 KB | None | 0 0
  1. -- A short recent combat script, the bottom is a bit messy.
  2. local Players = game:GetService("Players")
  3. local RepStorage = game:GetService("ReplicatedStorage")
  4. local Debris = game:GetService("Debris")
  5.  
  6. local ServerModules = script.Parent.Parent
  7. local RepModules = RepStorage:WaitForChild("Modules")
  8. local Data = RepModules:WaitForChild("Data")
  9. local Controllers = ServerModules:WaitForChild("Controllers")
  10. local DamageController = require(Controllers:WaitForChild("DamageController"))
  11. local RagdollModule = require(RepModules:WaitForChild("RagdollModule"))
  12. local PlayerData = require(Data:WaitForChild("PlayerData"))
  13.  
  14. local Anims = RepStorage:WaitForChild("Animations")
  15.  
  16. local CombatModule = {}
  17. CombatModule.__index = CombatModule
  18.  
  19. function CombatModule:M1(Char, Enemy)
  20.     local Hum, HumRP = Char:WaitForChild("Humanoid"), Char:WaitForChild("HumanoidRootPart")
  21.  
  22.     local ClientFunctions = require(Char:WaitForChild("ClientFunctions"))
  23.  
  24.     local CurrentType = Char:GetAttribute("Type")
  25.     local DataIndex = PlayerData.Stats[CurrentType]
  26.  
  27.     local DAMAGE = DataIndex.MeleeDamage
  28.     local COMBO_SPEED = DataIndex.ComboWalkSpeed
  29.     local WALK_SPEED = DataIndex.WalkSpeed
  30.  
  31.     local COMBO_RESET = 1.35
  32.     local MAX_COMBO = 5
  33.  
  34.     local FINISH_COOLDOWN = 1
  35.     local PUNCH_COOLDOWN = .45
  36.  
  37.     local STUN_VELOCITY = 13
  38.     local FLING_VELOCITY = 70
  39.     local FLING_DESPAWN = 1.25
  40.     local RAGDOLL_TIME = 2
  41.  
  42.     local EFFECTS_DELAY = .25
  43.     local PARTICLES_EMITTION = 15
  44.     local HIT_PARTICLES = 1
  45.  
  46.     local Counter = 0
  47.     local CombatMode = false
  48.     local SpeedSet = false
  49.     local CanAttack = true
  50.  
  51.     Char:SetAttribute("Attacking", true)
  52.     Char:SetAttribute("MechanicDisable", true)
  53.     Char:SetAttribute("Combo", Char:GetAttribute("Combo") + 1)
  54.     ClientFunctions:Run(false)
  55.  
  56.     local Combo = Char:GetAttribute("Combo")
  57.     local PunchAnim = Anims:WaitForChild("Basic"..Combo)
  58.     local PunchSound = HumRP:WaitForChild("Swing")    
  59.  
  60.     local PunchTrack = Hum:WaitForChild("Animator"):LoadAnimation(PunchAnim)        
  61.     PunchTrack:Play()
  62.    
  63.     task.delay(PunchTrack.Length - 0.05, function() PunchTrack:AdjustSpeed(0) task.wait(PUNCH_COOLDOWN) PunchTrack:Stop() end)
  64.    
  65.     PunchSound:Play()
  66.  
  67.     task.delay(EFFECTS_DELAY, function()
  68.         Hum.WalkSpeed = COMBO_SPEED
  69.        
  70.         if Enemy then
  71.             local EnemyHum, EnemyRP = Enemy:WaitForChild("Humanoid"), Enemy:WaitForChild("HumanoidRootPart")
  72.             local HitSound = EnemyRP:WaitForChild("Smack")
  73.        
  74.             local Direction = (EnemyRP.Position - HumRP.Position)
  75.                
  76.             for i = 1, HIT_PARTICLES do
  77.                 EnemyRP:WaitForChild("HitParticle"..i):Emit(PARTICLES_EMITTION)
  78.             end
  79.  
  80.             HitSound:Play()
  81.             DamageController:DamageHumanoid(Enemy, {DAMAGE})
  82.        
  83.             if Combo == MAX_COMBO then
  84.                 RagdollModule:Ragdoll(Enemy, RAGDOLL_TIME)
  85.  
  86.                 EnemyRP.AssemblyLinearVelocity = Direction * FLING_VELOCITY            
  87.             end
  88.         end
  89.     end)
  90.  
  91.     if Combo == MAX_COMBO then
  92.         Hum.WalkSpeed = 0
  93.  
  94.         task.wait(FINISH_COOLDOWN)
  95.  
  96.         Char:SetAttribute("Combo", 0)
  97.         Char:SetAttribute("MechanicDisable", false)
  98.  
  99.         Hum.WalkSpeed = WALK_SPEED
  100.         CombatMode = true
  101.     else
  102.         task.wait(PUNCH_COOLDOWN)
  103.     end
  104.  
  105.     Char:SetAttribute("Attacking", false)
  106.  
  107.     while not CombatMode do
  108.         Counter += .01
  109.         task.wait(.01)
  110.  
  111.  
  112.         if Counter >= COMBO_RESET then
  113.             Char:SetAttribute("Combo", 0)        
  114.             CombatMode = true    
  115.             SpeedSet = false
  116.  
  117.         elseif Counter >= (COMBO_RESET / 1.5) and not SpeedSet then
  118.             warn("Walk Speed")
  119.  
  120.             Hum.WalkSpeed = WALK_SPEED
  121.             SpeedSet = true
  122.             Char:SetAttribute("MechanicDisable", false)
  123.         end
  124.  
  125.         if Char:GetAttribute("Attacking") then        
  126.             Counter = 0
  127.             CombatMode = true
  128.             SpeedSet = false
  129.         end
  130.     end        
  131. end
  132.  
  133.  
  134. function CombatModule:M2(Char, Enemy)
  135.     print("Clicked M2")
  136. end
  137.  
  138. return CombatModule
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement