Advertisement
TaylorsRus

Damage

Mar 9th, 2023
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. local Damage = {}
  2.  
  3. local Physics = require(script.Parent:FindFirstChild("Physics"))
  4. local DataStore = require(script.Parent:FindFirstChild("DataStore"))
  5.  
  6. local TweenService = game:GetService("TweenService")
  7. local Lighting = game:GetService("Lighting")
  8.  
  9. local DELAY_TIME = .2
  10. local MINIMUM_HP = 10
  11. local MINIMUM_STAMINA = 10
  12.  
  13. function Damage:EffectHumanoid(Attacker, Victim, Purpose, Hitbox)
  14.     local Skills = game:GetService("ServerScriptService").Server
  15.     .Modules.SkillHandler.Skills
  16.    
  17.     for _,Skill in Skills:GetDescendants() do
  18.         if Skill ~= Purpose or not Skill:IsA("ModuleScript") then continue end
  19.        
  20.         local Module = require(Skill)
  21.         Module:HitEffects(Attacker, Victim, Hitbox)
  22.        
  23.         self:TakeHit(Attacker, Victim, Module.Hit)
  24.     end
  25.    
  26.     warn("No skill called",Purpose,"found.")
  27. end
  28.  
  29. function Damage:TakeHit(Attacker, Victim, Args)
  30.     local Shared = require(script.Parent:FindFirstChild("Shared"))
  31.    
  32.     if Attacker:FindFirstAncestor("Players") then Attacker = Attacker.Character end
  33.     local VictimHumanoid, VictimHumRP = Victim:WaitForChild("Humanoid"), Victim:WaitForChild("HumanoidRootPart")
  34.  
  35.     print("Damage =",Args.Damage,"Stamina =",Args.Stamina,"Blockable =",tostring(Args.Blockable))
  36.  
  37.     local KnockOut = VictimHumanoid.Health - Args.Damage <= MINIMUM_HP
  38.         or DataStore:GetData(Victim, "Stamina") - Args.Damage <= MINIMUM_STAMINA
  39.    
  40.     local VictimBlocking, VictimPerfectBlock = DataStore:GetData(Victim, "Blocking") and Args.Blockable,
  41.         DataStore:GetData(Victim, "PerfectBlocking") and Args.Blockable
  42.    
  43.     if VictimPerfectBlock then self:PerfectBlock(Victim) return end
  44.     if KnockOut then self:KnockOut(Attacker, Victim) return end
  45.     if VictimBlocking  then self:Block(Victim, Args.Stamina) return end        
  46.    
  47.     task.wait(DELAY_TIME)
  48.     VictimHumRP:WaitForChild("Smack"):Play()
  49.     VictimHumanoid.Health -= Args.Damage
  50. end
  51.  
  52. function Damage:Block(Character, DealtStamina)
  53.     local HumRP = Character:WaitForChild("HumanoidRootPart")   
  54.     local Stamina = DataStore:GetData(Character, "Stamina")
  55.    
  56.     task.wait(DELAY_TIME)
  57.     HumRP:WaitForChild("Block"):Play()
  58.     DataStore:SetData(Character, "Stamina", Stamina - DealtStamina)
  59. end
  60.  
  61.  
  62. function Damage:PerfectBlock(Character)
  63.     local HumRP = Character:WaitForChild("HumanoidRootPart")
  64.    
  65.     task.wait(DELAY_TIME)
  66.     HumRP:WaitForChild("PerfectBlock"):Play()
  67. end
  68.  
  69. function Damage:KnockOut(Character, Direction)
  70.     local Humanoid, HumRP = Character:FindFirstChild("Humanoid"), Character:FindFirstChild("HumanoidRootPart")
  71.     local Blur = Lighting:FindFirstChild("Blur")
  72.    
  73.     Humanoid.Health = 1
  74.     Blur.Enabled = true
  75.    
  76.     local Fling = Instance.new("BodyVelocity")
  77.     Fling.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  78.     Fling.Velocity = Direction * 100
  79.     Fling.Parent = HumRP
  80.     game:GetService("Debris"):AddItem(Fling, .7)
  81.    
  82.     Physics:Ragdoll(Character, true)
  83.    
  84.     if not Shared:IsDummy(Character) then Shared["ClientServer"]:FireClient(game:GetService("Players"):GetPlayerFromCharacter(Character), "EffectsHandler", "KnockOut") end
  85. end
  86.  
  87.  
  88. return Damage
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement