Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local ServerScriptService = game:GetService("ServerScriptService")
- local combat_handler, ragdoll_module = require(ReplicatedStorage:WaitForChild("combat_handler")), require(ServerScriptService:WaitForChild("RagdollModule"))
- local Remotes = ReplicatedStorage:WaitForChild("Remotes")
- local RemoteEvents = {
- ["PunchEvent"] = Remotes:FindFirstChild("PunchEvent"),
- ["BlockEvent"] = Remotes:FindFirstChild("BlockEvent")
- }
- -- Fireable functions
- local function create_newvalues(player)
- -- Making new combat bool values
- local combat_values = Instance.new("Folder", player)
- combat_values.Name = "CombatValues"
- -- [[Punch values]] --
- local normalpunch_value, heavypunch_value = Instance.new("BoolValue", combat_values), Instance.new("BoolValue", combat_values)
- normalpunch_value.Name, heavypunch_value.Name = "NormalPunch", "HeavyPunch"
- local punch_cooldown = Instance.new("BoolValue", combat_values)
- punch_cooldown.Name = "punch_cooldown"
- -- [[Block values]] --
- local block, block_debounce = Instance.new("BoolValue", combat_values), Instance.new("BoolValue", combat_values)
- block.Name = "Block" --[[]] block_debounce.Name = "block_cooldown"
- end
- -- .TouchedEvent
- local function arm_touched(hit, player, character)
- local CombatValues_folder, punch_type = player:FindFirstChild("CombatValues")
- local model_humanoid = hit.Parent:FindFirstChild("Humanoid")
- local enemy_player
- if model_humanoid then
- enemy_player = Players:GetPlayerFromCharacter(hit.Parent)
- end
- -- Checking if the enemy is blocking
- if enemy_player then
- local cbv_folder = enemy_player:FindFirstChild("CombatValues")
- if cbv_folder then
- local block_value = cbv_folder["Block"]
- if block_value.Value then return end
- end
- end
- -- Punch functions/events
- local punch_debounce = CombatValues_folder:FindFirstChild("punch_cooldown")
- if not punch_debounce.Value then return end
- -- Checking to see if the enemy has a humanoid and preventing hitbox exploits
- if not model_humanoid or model_humanoid == character:FindFirstChild("Humanoid") then return end
- local char_hrp, model_hrp = character:FindFirstChild("HumanoidRootPart"), hit.Parent:FindFirstChild("HumanoidRootPart")
- if ((char_hrp.Position - model_hrp.Position).Magnitude > 5.5) then return end
- -- Calculating the punch type
- for key, value in ipairs(CombatValues_folder:GetChildren()) do
- local str = value.Name
- if str:match("Punch") and value.Value then
- local punch_type, punchtype_value = str, CombatValues_folder[str]
- punchtype_value.Value = false
- -- Firing the module function to get back information
- local punch_damage = combat_handler.return_punchInfo(punch_type)["Damage"]
- model_humanoid:TakeDamage(punch_damage)
- local punch_maxforce, punch_velocity, debounce = combat_handler.return_punchInfo(punch_type)["maxForce"], combat_handler.return_punchInfo(punch_type)["velocity"], 1
- local ragdoll_debounce = 2.5
- local function create_bodyvelocity()
- local push_force = Instance.new("BodyVelocity", model_hrp)
- push_force.MaxForce = punch_maxforce
- push_force.Velocity = char_hrp.CFrame.lookVector * punch_velocity
- if punch_type == "HeavyPunch" then
- ragdoll_module.Ragdoll(hit.Parent, enemy_player)
- end
- wait(debounce)
- push_force:Destroy()
- end
- if punch_type == "HeavyPunch" then
- create_bodyvelocity()
- wait(ragdoll_debounce)
- ragdoll_module.DisableRagdoll(hit.Parent, enemy_player)
- elseif punch_type == "NormalPunch" then
- create_bodyvelocity()
- end
- break
- end
- end
- end
- -- Detect arm event
- local function detectArm(character, player, cbv_folder)
- for _, bodypart in pairs(character:GetChildren()) do
- if bodypart.Name:match("Arm") then
- for key, v in pairs(cbv_folder:GetChildren()) do
- if v.Name:match("Punch") and v.Value then
- local str
- if v.Name == "HeavyPunch" then str = "Right Arm" elseif v.Name == "NormalPunch" then str = "Left Arm" end
- character[str].Touched:Connect(function(hit)
- arm_touched(hit, player, character)
- end)
- end
- end
- end
- end
- end
- Players.PlayerAdded:Connect(function(player)
- -- Firing the function when the player joins the game
- create_newvalues(player)
- player.CharacterAdded:Connect(function(character)
- local cbv_folder = player:WaitForChild("CombatValues")
- -- Checking if the arms touched another player
- for _, bp in pairs(character:GetChildren()) do
- if bp.Name:match("Arm") then
- bp.Touched:Connect(function()
- detectArm(character, player, cbv_folder)
- end)
- end
- end
- end)
- end)
- -- .OnServerEvent event (punch)
- RemoteEvents["PunchEvent"].OnServerEvent:Connect(function(player, punch_type, anim_finished)
- -- Getting information from module functions
- local CombatValues_folder = player:WaitForChild("CombatValues")
- local punchtype_value, punch_cooldown = CombatValues_folder[punch_type], CombatValues_folder:FindFirstChild("punch_cooldown")
- local punch_debouncetime = combat_handler.return_punchInfo(punch_type)["debounce_time"]
- local b_cooldown = CombatValues_folder["block_cooldown"]
- -- Server-side debounce so exploiters cry
- if not punch_cooldown.Value and not b_cooldown.Value then
- punch_cooldown.Value = true --[[]] punchtype_value.Value = true
- wait(punch_debouncetime)
- punchtype_value.Value = false
- punch_cooldown.Value = false --[[]] RemoteEvents["PunchEvent"]:FireClient(player, false)
- --[[]] else player:Kick()
- end
- end)
- -- .OnServerEvent event (block)
- RemoteEvents["BlockEvent"].OnServerEvent:Connect(function(player, end_block)
- -- Getting the values and information ready
- local CombatValues_folder = player:WaitForChild("CombatValues")
- local block_value, block_debounce = CombatValues_folder["Block"] ,CombatValues_folder:FindFirstChild("block_cooldown")
- local debounce_time, p_cooldown = 2, CombatValues_folder["punch_cooldown"]
- -- Checking if we're supposed to end the block
- if end_block then
- block_value.Value = false
- wait(debounce_time)
- RemoteEvents["BlockEvent"]:FireClient(player)
- block_debounce.Value = false
- return
- end
- -- Starting the block
- if not block_value.Value and not p_cooldown.Value and not block_debounce.Value then
- block_debounce.Value = true --[[]] block_value.Value = true
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement