Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game.Players
- local LocalPlayer = Players.LocalPlayer
- local Character = LocalPlayer.Character
- local Humanoid = Character.Humanoid
- local Animator = Humanoid.Animator :: Animator
- local Backpack = LocalPlayer.Backpack
- local Sword = Backpack:FindFirstChild("Sword") :: Tool
- local combatAnimationTracks = {} :: {[string]: AnimationTrack}
- local combatConnections = {} :: {[RBXScriptConnection]: true}
- -- initialize animations and put them in a local list we can refer
- for _, anim: Animation in workspace.Anims:GetChildren() do
- local at = Animator:LoadAnimation(anim)
- at.Priority = Enum.AnimationPriority.Action2
- combatAnimationTracks[anim.Name] = at
- end
- -- Set State serves as our "change state" function
- -- it'll transition from state A to B by cleaning
- -- connections and stopping animations specific states
- -- might have played/oppened
- local function SetState(StateFunction: () -> ()): ()
- for name, animTrack in combatAnimationTracks do
- animTrack:Stop(0)
- end
- for connection in combatConnections do
- connection:Disconnect()
- end
- StateFunction()
- end
- -- state functions
- function SwordEquipped()
- combatAnimationTracks.Equip:Play()
- local comboCount = 0
- combatConnections[Sword.Activated:Connect(function()
- comboCount += 1
- local slashAnim = "Slash"..tostring(comboCount)
- print(slashAnim)
- combatAnimationTracks[slashAnim]:Play()
- comboCount %= 2
- end)] = true
- combatConnections[Sword.Unequipped:Connect(function()
- combatAnimationTracks.Equip:Play(0.100000001, 1, -1)
- combatAnimationTracks.Equip.Ended:Wait()
- SetState(Idle)
- end)] = true
- end
- function Idle()
- combatAnimationTracks.Idle:Play()
- combatAnimationTracks.Idle.Looped = true
- if Sword then
- combatConnections[Sword.Equipped:Connect(function()
- SetState(SwordEquipped)
- end)] = true
- end
- end
- -- Kickstart state management
- Idle(LocalPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement