Advertisement
PolynomialCookie

Untitled

Jun 11th, 2021
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.41 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local ServerScriptService = game:GetService("ServerScriptService")
  4.  
  5. local combat_handler, ragdoll_module = require(ReplicatedStorage:WaitForChild("combat_handler")), require(ServerScriptService:WaitForChild("RagdollModule"))
  6. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  7.  
  8. local RemoteEvents = {
  9.     ["PunchEvent"] = Remotes:FindFirstChild("PunchEvent"),
  10.     ["BlockEvent"] = Remotes:FindFirstChild("BlockEvent")
  11. }
  12.  
  13. -- Fireable functions
  14. local function create_newvalues(player)
  15.     -- Making new combat bool values
  16.     local combat_values = Instance.new("Folder", player)
  17.     combat_values.Name = "CombatValues"
  18.    
  19.     -- [[Punch values]] --
  20.     local normalpunch_value, heavypunch_value = Instance.new("BoolValue", combat_values), Instance.new("BoolValue", combat_values)
  21.     normalpunch_value.Name, heavypunch_value.Name = "NormalPunch", "HeavyPunch"
  22.  
  23.     local punch_cooldown = Instance.new("BoolValue", combat_values)
  24.     punch_cooldown.Name = "punch_cooldown"
  25.    
  26.     -- [[Block values]] --
  27.     local block, block_debounce = Instance.new("BoolValue", combat_values), Instance.new("BoolValue", combat_values)
  28.     block.Name = "Block" --[[]] block_debounce.Name = "block_cooldown"
  29. end
  30.  
  31. -- .TouchedEvent
  32. local function arm_touched(hit, player, character)
  33.     local CombatValues_folder, punch_type = player:FindFirstChild("CombatValues")
  34.     local model_humanoid = hit.Parent:FindFirstChild("Humanoid")
  35.    
  36.     local enemy_player
  37.     if model_humanoid then
  38.         enemy_player = Players:GetPlayerFromCharacter(hit.Parent)
  39.     end
  40.    
  41.     -- Checking if the enemy is blocking
  42.     if enemy_player then
  43.         local cbv_folder = enemy_player:FindFirstChild("CombatValues")
  44.        
  45.         if cbv_folder then
  46.             local block_value = cbv_folder["Block"]
  47.            
  48.             if block_value.Value then return end
  49.         end
  50.     end
  51.     -- Punch functions/events
  52.     local punch_debounce = CombatValues_folder:FindFirstChild("punch_cooldown")
  53.     if not punch_debounce.Value then return end
  54.    
  55.     -- Checking to see if the enemy has a humanoid and preventing hitbox exploits
  56.     if not model_humanoid or model_humanoid == character:FindFirstChild("Humanoid") then return end
  57.    
  58.     local char_hrp, model_hrp = character:FindFirstChild("HumanoidRootPart"), hit.Parent:FindFirstChild("HumanoidRootPart")
  59.     if ((char_hrp.Position - model_hrp.Position).Magnitude > 5.5) then return end
  60.    
  61.     -- Calculating the punch type
  62.     for key, value in ipairs(CombatValues_folder:GetChildren()) do
  63.         local str = value.Name
  64.         if str:match("Punch") and value.Value then
  65.             local punch_type, punchtype_value = str, CombatValues_folder[str]
  66.             punchtype_value.Value = false
  67.            
  68.             -- Firing the module function to get back information
  69.             local punch_damage = combat_handler.return_punchInfo(punch_type)["Damage"]
  70.             model_humanoid:TakeDamage(punch_damage)
  71.            
  72.             local punch_maxforce, punch_velocity, debounce = combat_handler.return_punchInfo(punch_type)["maxForce"], combat_handler.return_punchInfo(punch_type)["velocity"], 1
  73.             local ragdoll_debounce = 2.5
  74.            
  75.             local function create_bodyvelocity()
  76.                 local push_force = Instance.new("BodyVelocity", model_hrp)
  77.                
  78.                 push_force.MaxForce = punch_maxforce
  79.                 push_force.Velocity = char_hrp.CFrame.lookVector * punch_velocity
  80.                 if punch_type == "HeavyPunch" then
  81.                     ragdoll_module.Ragdoll(hit.Parent, enemy_player)
  82.                 end
  83.                
  84.                 wait(debounce)
  85.                 push_force:Destroy()
  86.             end
  87.            
  88.             if punch_type == "HeavyPunch" then
  89.                 create_bodyvelocity()
  90.                 wait(ragdoll_debounce)
  91.                 ragdoll_module.DisableRagdoll(hit.Parent, enemy_player)
  92.                
  93.             elseif punch_type == "NormalPunch" then
  94.                 create_bodyvelocity()
  95.             end
  96.            
  97.             break
  98.         end
  99.        
  100.     end
  101. end
  102.  
  103. -- Detect arm event
  104. local function detectArm(character, player, cbv_folder)
  105.     for _, bodypart in pairs(character:GetChildren()) do
  106.         if bodypart.Name:match("Arm") then
  107.  
  108.             for key, v in pairs(cbv_folder:GetChildren()) do
  109.                 if v.Name:match("Punch") and v.Value then
  110.                     local str
  111.  
  112.                     if v.Name == "HeavyPunch" then str = "Right Arm" elseif v.Name == "NormalPunch" then str = "Left Arm" end
  113.                    
  114.                     character[str].Touched:Connect(function(hit)
  115.                         arm_touched(hit, player, character)
  116.                     end)
  117.  
  118.                 end
  119.             end
  120.  
  121.         end
  122.     end
  123. end
  124. Players.PlayerAdded:Connect(function(player)
  125.     -- Firing the function when the player joins the game
  126.     create_newvalues(player)
  127.     player.CharacterAdded:Connect(function(character)
  128.         local cbv_folder = player:WaitForChild("CombatValues")
  129.        
  130.         -- Checking if the arms touched another player
  131.         for _, bp in pairs(character:GetChildren()) do
  132.             if bp.Name:match("Arm") then
  133.                
  134.                 bp.Touched:Connect(function()
  135.                     detectArm(character, player, cbv_folder)
  136.                 end)
  137.                
  138.             end
  139.         end
  140.        
  141.     end)
  142. end)
  143.  
  144. -- .OnServerEvent event (punch)
  145. RemoteEvents["PunchEvent"].OnServerEvent:Connect(function(player, punch_type, anim_finished)
  146.     -- Getting information from module functions
  147.     local CombatValues_folder = player:WaitForChild("CombatValues")
  148.     local punchtype_value, punch_cooldown = CombatValues_folder[punch_type], CombatValues_folder:FindFirstChild("punch_cooldown")
  149.    
  150.     local punch_debouncetime = combat_handler.return_punchInfo(punch_type)["debounce_time"]
  151.     local b_cooldown = CombatValues_folder["block_cooldown"]
  152.    
  153.     -- Server-side debounce so exploiters cry
  154.     if not punch_cooldown.Value and not b_cooldown.Value then
  155.         punch_cooldown.Value = true --[[]] punchtype_value.Value = true
  156.        
  157.         wait(punch_debouncetime)
  158.         punchtype_value.Value = false
  159.         punch_cooldown.Value = false --[[]] RemoteEvents["PunchEvent"]:FireClient(player, false)
  160.         --[[]] else player:Kick()
  161.     end
  162. end)
  163.  
  164. -- .OnServerEvent event (block)
  165. RemoteEvents["BlockEvent"].OnServerEvent:Connect(function(player, end_block)
  166.     -- Getting the values and information ready
  167.     local CombatValues_folder = player:WaitForChild("CombatValues")
  168.     local block_value, block_debounce = CombatValues_folder["Block"] ,CombatValues_folder:FindFirstChild("block_cooldown")
  169.    
  170.     local debounce_time, p_cooldown = 2, CombatValues_folder["punch_cooldown"]
  171.    
  172.     -- Checking if we're supposed to end the block
  173.     if end_block then
  174.         block_value.Value = false
  175.         wait(debounce_time)
  176.         RemoteEvents["BlockEvent"]:FireClient(player)
  177.         block_debounce.Value = false
  178.         return
  179.     end
  180.    
  181.     -- Starting the block
  182.     if not block_value.Value and not p_cooldown.Value and not block_debounce.Value then
  183.         block_debounce.Value = true --[[]] block_value.Value = true
  184.     end
  185. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement