Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------- Reworked by Malvaviscos
- pointsToDirection = false -- Change this to true if you want the sword to swing in the direction the mouse is on the screen.
- r = game:service("RunService")
- Animate = script.Parent.Animate
- local damage = 5
- local slash_damage = 8
- local lunge_damage = 12
- sword = script.Parent.Handle
- Tool = script.Parent
- swordDirection = "Center"
- local SlashSound = sword:findFirstChild("SlashSound")
- local LungeSound = sword:findFirstChild("LungeSound")
- local UnsheathSound = sword:findFirstChild("UnsheathSound")
- tutorialized = false
- if SlashSound == nil then
- SlashSound = Instance.new("Sound")
- SlashSound.Name = "SlashSound"
- SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
- SlashSound.Parent = sword
- SlashSound.Volume = .7
- end
- if LungeSound == nil then
- LungeSound = Instance.new("Sound")
- LungeSound.Name = "LungeSound"
- LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
- LungeSound.Parent = sword
- LungeSound.Volume = .6
- end
- if UnsheathSound == nil then
- UnsheathSound = Instance.new("Sound")
- UnsheathSound.Name = "UnsheathSound"
- UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
- UnsheathSound.Parent = sword
- UnsheathSound.Volume = 1
- end
- function onMove(mouse) -- Optional mouse directional attacks.
- local totalX = mouse.ViewSizeX
- if mouse.X >= totalX - totalX/3 then
- swordDirection = "Right"
- elseif mouse.X <= totalX/3 then
- swordDirection = "Left"
- else
- swordDirection = "Center"
- end
- end
- function onKeyDown(key)
- key = key:lower()
- if key == "r" then
- stab()
- end
- if key == "e" then
- attackright()
- end
- if key == "q" then
- attackleft()
- end
- if key == "m" then
- printMessage("Press 'q' to swing to the left and press 'e' to swing to the right.", 3)
- wait(3)
- printMessage("Press 'r' to perform a stabbing attack.", 2)
- end
- end
- function getHumanoid(model)
- function excluded(name)
- exclude = {}
- for i, ex in pairs(exclude) do
- if string.lower(ex) == string.lower(name) then
- return true
- end
- end
- return false
- end
- for i, child in pairs(model:getChildren()) do
- if child.className == "Humanoid" and not excluded(child.Name) then
- return child
- end
- end
- end
- function blow(hit)
- local humanoid = getHumanoid(hit.Parent)
- local vCharacter = Tool.Parent
- local vPlayer = game.Players:playerFromCharacter(vCharacter)
- local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
- if humanoid~=nil and humanoid ~= hum and hum ~= nil then
- -- final check, make sure sword is in-hand
- local right_arm = vCharacter:FindFirstChild("Right Arm")
- if (right_arm ~= nil) then
- local joint = right_arm:FindFirstChild("RightGrip")
- if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
- tagHumanoid(humanoid, vPlayer)
- humanoid:TakeDamage(damage)
- wait(1)
- untagHumanoid(humanoid)
- end
- end
- end
- end
- function tagHumanoid(humanoid, player)
- local creator_tag = Instance.new("ObjectValue")
- creator_tag.Value = player
- creator_tag.Name = "creator"
- creator_tag.Parent = humanoid
- end
- function untagHumanoid(humanoid)
- if humanoid ~= nil then
- local tag = humanoid:findFirstChild("creator")
- if tag ~= nil then
- tag.Parent = nil
- end
- end
- end
- function attack()
- damage = slash_damage
- SlashSound:play()
- if swordDirection == "Center" then
- Animate.Value = "Slash1"
- elseif swordDirection == "Right" then
- Animate.Value = "SlashRight"
- elseif swordDirection == "Left" then
- Animate.Value = "SlashLeft"
- end
- --[[local anim = Instance.new("StringValue")
- anim.Name = "toolanim"
- anim.Value = "Slash"
- anim.Parent = Tool]]
- end
- function lunge()
- damage = lunge_damage
- LungeSound:play()
- --[[local anim = Instance.new("StringValue")
- anim.Name = "toolanim"
- anim.Value = "Lunge"
- anim.Parent = Tool]]
- Animate.Value = "Lunge"
- wait(0.6)
- --[[
- wait(.2)
- swordOut()
- wait(.6)
- swordUp()
- ]]
- damage = slash_damage
- end
- stabenabled = true
- function stab()
- if not stabenabled then return end
- stabenabled = false
- damage = lunge_damage
- LungeSound:play()
- --[[local anim = Instance.new("StringValue")
- anim.Name = "toolanim"
- anim.Value = "Lunge"
- anim.Parent = Tool]]
- Animate.Value = "Stab"
- wait(0.6)
- --[[
- wait(.2)
- swordOut()
- wait(.6)
- swordUp()
- ]]
- damage = slash_damage
- stabenabled = true
- end
- function attackright()
- damage = slash_damage
- SlashSound:play()
- Animate.Value = "SlashRight"
- end
- function attackleft()
- damage = slash_damage
- SlashSound:play()
- Animate.Value = "SlashLeft"
- end
- function swordUp()
- Tool.GripForward = Vector3.new(-1,0,0)
- Tool.GripRight = Vector3.new(0,1,0)
- Tool.GripUp = Vector3.new(0,0,1)
- --Tool.Parent["Right Arm"].RightGrip.C1 = CFrame.new(Tool.GripPos.x, Tool.GripPos.y, Tool.GripPos.z, -1,0,0, 0,1,0, 0,0,1)
- end
- function swordOut()
- Tool.GripForward = Vector3.new(0,0,1)
- Tool.GripRight = Vector3.new(0,1,0)
- Tool.GripUp = Vector3.new(1,0,0)
- --Tool.Parent["Right Arm"].RightGrip.C1 = CFrame.new(Tool.GripPos.x, Tool.GripPos.y, Tool.GripPos.z, 0,0,1, 0,1,0, 1,0,0)
- end
- function swordAcross()
- -- parry
- end
- function printMessage(text, time)
- local msg = Instance.new("Hint")
- msg.Text = text
- local player = game.Players:findFirstChild(Tool.Parent.Name)
- if player ~= nil then
- msg.Parent = player
- end
- game:getService("Debris"):addItem(msg, time)
- end
- Tool.Enabled = true
- local last_attack = 0
- function onActivated()
- if not Tool.Enabled then
- return
- end
- Tool.Enabled = false
- local character = Tool.Parent;
- local humanoid = character.Humanoid
- if humanoid == nil then
- print("Humanoid not found")
- return
- end
- t = r.Stepped:wait()
- if (t - last_attack < .2) then
- lunge()
- else
- attack()
- end
- last_attack = t
- --wait(.5)
- Tool.Enabled = true
- end
- function onEquipped(mouse)
- UnsheathSound:play()
- if pointsToDirection then
- mouse.Move:connect(function() onMove(mouse) end)
- end
- mouse.KeyDown:connect(onKeyDown)
- if not tutorialized then
- tutorialized = true
- printMessage("", 0)
- wait(2.5)
- printMessage("Press 'q' to swing to the left and press 'e' to swing to the right.", 3)
- wait(3)
- printMessage("Press 'r' to perform a stabbing attack.", 2)
- wait(2)
- printMessage("Click to control the sword otherwise. Press 'm' to see this message again.", 3.5)
- wait(3.5)
- end
- end
- script.Parent.Activated:connect(onActivated)
- script.Parent.Equipped:connect(onEquipped)
- connection = sword.Touched:connect(blow)
Advertisement
Add Comment
Please, Sign In to add comment