Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Melee Weapon Handler
- local Storage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local CP = game:GetService("ContentProvider")
- local Remotes = Storage:WaitForChild("Remotes")
- local Modules = Storage:WaitForChild("Modules")
- local HitAnims = script:WaitForChild("HitAnims")
- local RaycastHitbox = require(Modules.Utils.RaycastHitboxV3)
- local AllowedActions = {
- ['Equip'] = true,
- ['Init'] = true,
- ['Attack'] = true,
- ['Block'] = true,
- ['Damage'] = true,
- };
- local EquipCooldowns = {};
- local EquippedWeapons = {};
- local AttackCooldowns = {};
- local BlockCooldowns = {};
- for _,v in pairs(HitAnims:GetChildren()) do
- CP:PreloadAsync({v})
- end
- local function setCooldown(plr, duration)
- EquipCooldowns[plr.UserId] = true
- coroutine.resume(coroutine.create(function()
- wait(duration)
- EquipCooldowns[plr.UserId] = nil
- end))
- end
- local function getRandomHitAnim()
- local anims = HitAnims:GetChildren()
- local random = math.random(1, #anims)
- return HitAnims[anims[random].Name]
- end
- Players.PlayerAdded:Connect(function(plr)
- plr.CharacterAdded:Wait()
- plr.Character.Humanoid.Died:Connect(function()
- EquippedWeapons[plr.UserId] = nil
- end)
- end)
- Players.PlayerRemoving:Connect(function(plr)
- if EquippedWeapons[plr.UserId] then
- EquippedWeapons[plr.UserId] = nil
- end
- end)
- Remotes.MeleeMain.OnServerInvoke = function(plr, data)
- local Action = data.Action
- if Action then
- if not AllowedActions[Action] then
- plr:Kick('No exploiting.')
- return;
- end
- if Action == 'Equip' then
- if EquipCooldowns[plr.UserId] then
- return;
- end
- local weaponData = data.Data
- local weaponName = weaponData.Name
- if plr.Character:FindFirstChild(weaponName.. 'Weld').Transparency == 0 then
- -- equip
- plr.Character[weaponName.. 'Weld'].Transparency = 1
- setCooldown(plr, 1)
- local sword = script[weaponName]:Clone()
- sword.Parent = plr.Character
- EquippedWeapons[plr.UserId] = {
- Weapon = sword,
- -- Hitbox = RaycastHitbox:Initialize(sword),
- Blocking = false,
- Attacking = false,
- PrevBlock = tick()
- }
- local weld = Instance.new("Motor6D", sword)
- weld.Name = 'Weld'
- weld.Part0 = sword
- weld.Part1 = plr.Character['Right Arm']
- weld.C0 = CFrame.new(-2.5, 1 ,0) * CFrame.Angles(0, math.rad(-90), 0)
- return 'Equip', EquippedWeapons[plr.UserId].Weapon
- elseif plr.Character[weaponName.. 'Weld'].Transparency == 1 then
- -- un equip
- plr.Character[weaponName.. 'Weld'].Transparency = 0
- EquippedWeapons[plr.UserId].Weapon:Destroy()
- if EquippedWeapons[plr.UserId].Blocking == true then
- -- stop anim
- EquippedWeapons[plr.UserId].BlockAnim:Stop(0.08)
- end
- plr.Character.Humanoid.WalkSpeed = 16
- EquippedWeapons[plr.UserId] = nil
- setCooldown(plr, 1)
- return 'Unequip'
- end
- end
- if Action == 'Init' then
- -- init weld
- local weaponData = data.Data
- local sheathePos = weaponData:FindFirstChild('Sheathe_Pos').Value or 'None'
- local WeaponClone = script:WaitForChild(weaponData.Name)
- WeaponClone = WeaponClone:Clone()
- WeaponClone.Parent = plr.Character
- WeaponClone.Name = WeaponClone.Name.. 'Weld'
- if typeof(sheathePos) == 'number' then
- -- has sheathe pos
- -- 1 = back | 2 = front
- if sheathePos == 1 then
- local weld = Instance.new("Motor6D", WeaponClone)
- weld.Name = 'Weld'
- weld.Part0 = WeaponClone
- weld.Part1 = plr.Character.Torso
- weld.C0 = CFrame.new(0,0, -0.5) * CFrame.Angles(0, 0, math.rad(45))
- elseif sheathePos == 2 then
- local weld = Instance.new("Motor6D", WeaponClone)
- weld.Name = 'Weld'
- weld.Part0 = WeaponClone
- weld.Part1 = plr.Character.Torso
- weld.C0 = CFrame.new(0,0,0)
- end
- end
- end
- if Action == 'Damage' then
- if EquippedWeapons[plr.UserId] then
- if plr.Character:FindFirstChild('Stunned') then
- -- warn'you are stunned'
- return;
- end
- --[[
- if EquippedWeapons[plr.UserId].Attacking == false then
- print'not attaking'
- return;
- end
- ]]--
- if EquippedWeapons[plr.UserId].Blocking == true then
- return;
- end
- local thingHit = data.Hit
- if not thingHit then return end
- if thingHit:FindFirstChild('Humanoid') then
- if thingHit.Humanoid.Health <= 0 then return end
- local targetName = thingHit.Name
- -- has hum
- if game.Players:FindFirstChild(targetName) then
- -- print'found player test'
- if EquippedWeapons[game.Players[targetName].UserId] then
- if EquippedWeapons[game.Players[targetName].UserId].Blocking == true then
- -- check if behind target
- -- print'other player is blocking'
- local dot = thingHit.Head.CFrame.LookVector:Dot(plr.Character.Head.CFrame.LookVector)
- if (dot > 0.5) then
- -- is behind
- local DamageToTake = data.Damage
- thingHit.Humanoid:TakeDamage(DamageToTake)
- return;
- end
- -- target is blocking
- local hitEffect = script:WaitForChild("Hit_Effect")
- local clone = hitEffect:Clone()
- clone.Parent = thingHit.HumanoidRootPart
- clone.Weld.Part1 = thingHit.Torso
- clone.Particle:Emit(20)
- game.Debris:AddItem(clone, 0.5)
- local chipDamage = data.ChipDmg
- thingHit.Humanoid:TakeDamage(chipDamage)
- return;
- elseif EquippedWeapons[game.Players[targetName].UserId].Blocking == false then
- coroutine.resume(coroutine.create(function()
- local stunned = Instance.new("BoolValue", thingHit)
- stunned.Name = 'Stunned'
- stunned.Value = true
- local bv = Instance.new("BodyVelocity", thingHit.PrimaryPart)
- bv.Name = 'StunnedBV'
- bv.MaxForce = Vector3.new(9999,9999,9999)
- bv.Velocity = Vector3.new(0,0,0)
- plr.Character.Humanoid.JumpPower = 0
- local chosenAnim = getRandomHitAnim()
- local hitAnim = thingHit.Humanoid:LoadAnimation(HitAnims[chosenAnim.Name])
- hitAnim:Play()
- game.Debris:AddItem(stunned, hitAnim.Length)
- game.Debris:AddItem(bv, hitAnim.Length)
- coroutine.resume(coroutine.create(function()
- wait(hitAnim.Length)
- plr.Character.Humanoid.JumpPower = 50
- end))
- end))
- local DamageToTake = data.Damage
- thingHit.Humanoid:TakeDamage(DamageToTake)
- return;
- end
- else
- coroutine.resume(coroutine.create(function()
- local stunned = Instance.new("BoolValue", thingHit)
- stunned.Name = 'Stunned'
- stunned.Value = true
- local bv = Instance.new("BodyVelocity", thingHit.PrimaryPart)
- bv.Name = 'StunnedBV'
- bv.MaxForce = Vector3.new(9999,9999,9999)
- bv.Velocity = Vector3.new(0,0,0)
- plr.Character.Humanoid.JumpPower = 0
- local chosenAnim = getRandomHitAnim()
- local hitAnim = thingHit.Humanoid:LoadAnimation(HitAnims[chosenAnim.Name])
- hitAnim:Play()
- game.Debris:AddItem(stunned, hitAnim.Length)
- game.Debris:AddItem(bv, hitAnim.Length)
- coroutine.resume(coroutine.create(function()
- wait(hitAnim.Length)
- plr.Character.Humanoid.JumpPower = 50
- end))
- end))
- local DamageToTake = data.Damage
- thingHit.Humanoid:TakeDamage(DamageToTake)
- return;
- end
- else
- local DamageToTake = data.Damage
- thingHit.Humanoid:TakeDamage(DamageToTake)
- local chosenAnim = getRandomHitAnim()
- local hitAnim = thingHit.Humanoid:LoadAnimation(HitAnims[chosenAnim.Name])
- hitAnim:Play()
- coroutine.resume(coroutine.create(function()
- local stunned = Instance.new("BoolValue", thingHit)
- stunned.Name = 'Stunned'
- stunned.Value = true
- game.Debris:AddItem(stunned, hitAnim.Length)
- end))
- end
- else
- --print'what?'
- end
- else
- return;
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment