local E=script.Parent local z=E:WaitForChild("\084\111\114\115\111")local a=z:WaitForChild("\082\105\103\104\116 \083\104\111\117\108\100\101\114")local L=z:WaitForChild("\076\101\102\116 \083\104\111\117\108\100\101\114")local Y=z:WaitForChild("\082\105\103\104\116 \072\105\112")local m=z:WaitForChild("\076\101\102\116 \072\105\112")local s=E:WaitForChild("\072\117\109\097\110\111\105\100")local U="\083\116\097\110\100\105\110\103"local K="\078\111\110\101"local q=0 local function k(E)if E>0 then U="\082\117\110\110\105\110\103"else U="\083\116\097\110\100\105\110\103"end end local function l()U="\068\101\097\100"end local function A()U="\074\117\109\112\105\110\103"end local function I()U="\067\108\105\109\098\105\110\103"end local function M()U="\071\101\116\116\105\110\103\085\112"end local function b()U="\070\114\101\101\070\097\108\108"end local function G()U="\070\097\108\108\105\110\103\068\111\119\110"end local function R()U="\083\101\097\116\101\100"end local function y()a.MaxVelocity=.5 L.MaxVelocity=.5 a.DesiredAngle=3.14 L.DesiredAngle=-3.14 Y.DesiredAngle=0 m.DesiredAngle=0 end local function d()a.MaxVelocity=.5 L.MaxVelocity=.5 a.DesiredAngle=3.14 L.DesiredAngle=-3.14 Y.DesiredAngle=0 m.DesiredAngle=0 end local function O()a.MaxVelocity=.15 L.MaxVelocity=.15 a.DesiredAngle=1.57 L.DesiredAngle=-1.57 Y.DesiredAngle=1.57 m.DesiredAngle=-1.57 end local function J()for E,z in ipairs(E:GetChildren())do if z.className=="\084\111\111\108"then return z end end return nil end local function h(E)for E,z in ipairs(E:GetChildren())do if z.Name=="\116\111\111\108\097\110\105\109"and z.className=="\083\116\114\105\110\103\086\097\108\117\101"then return z end end return nil end local function r()if K=="\078\111\110\101"then a.DesiredAngle=1.57 return end if K=="\083\108\097\115\104"then a.MaxVelocity=.5 a.DesiredAngle=0 return end if K=="\076\117\110\103\101"then a.MaxVelocity=.5 L.MaxVelocity=.5 Y.MaxVelocity=.5 m.MaxVelocity=.5 a.DesiredAngle=1.57 L.DesiredAngle=1.0 Y.DesiredAngle=1.57 m.DesiredAngle=1.0 return end end local function Q(E)local z local s if U=="\074\117\109\112\105\110\103"then y()return end if U=="\070\114\101\101\070\097\108\108"then d()return end if U=="\083\101\097\116\101\100"then O()return end local k=0 if U=="\082\117\110\110\105\110\103"then a.MaxVelocity=.15 L.MaxVelocity=.15 z=1 s=9 elseif U=="\067\108\105\109\098\105\110\103"then a.MaxVelocity=.5 L.MaxVelocity=.5 z=1 s=9 k=3.14 else z=.1 s=1 end local l=z*math.sin(E*s)a.DesiredAngle=l+k L.DesiredAngle=l-k Y.DesiredAngle=-l m.DesiredAngle=-l local A=J()if A then local z=h(A)if z then K=z.Value z.Parent=nil q=E+.3 end if E>q then q=0 K="\078\111\110\101"end r()else K="\078\111\110\101"q=0 end end s.Died:connect(l)s.Running:connect(k)s.Jumping:connect(A)s.Climbing:connect(I)s.GettingUp:connect(M)s.FreeFalling:connect(b)s.FallingDown:connect(G)s.Seated:connect(R)while E.Parent~=nil do local E,z=wait(.1)Q(z)end
-- ANIMATION
-- declarations
local Figure = script.Parent
local Torso = Figure:WaitForChild("Torso")
local RightShoulder = Torso:WaitForChild("Right Shoulder")
local LeftShoulder = Torso:WaitForChild("Left Shoulder")
local RightHip = Torso:WaitForChild("Right Hip")
local LeftHip = Torso:WaitForChild("Left Hip")
local Humanoid = Figure:WaitForChild("Humanoid")
local pose = "Standing"
local toolAnim = "None"
local toolAnimTime = 0
-- functions
local function onRunning(speed)
	if speed > 0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end
local function onDied()
	pose = "Dead"
end
local function onJumping()
	pose = "Jumping"
end
local function onClimbing()
	pose = "Climbing"
end
local function onGettingUp()
	pose = "GettingUp"
end
local function onFreeFall()
	pose = "FreeFall"
end
local function onFallingDown()
	pose = "FallingDown"
end
local function onSeated()
	pose = "Seated"
end
local function moveJump()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 3.14
	LeftShoulder.DesiredAngle = -3.14
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end
-- same as jump for now
local function moveFreeFall()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 3.14
	LeftShoulder.DesiredAngle = -3.14
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end
local function moveSit()
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder.DesiredAngle = 3.14 / 2
	LeftShoulder.DesiredAngle = -3.14 / 2
	RightHip.DesiredAngle = 3.14 / 2
	LeftHip.DesiredAngle = -3.14 / 2
end
local function getTool()
	for _, kid in ipairs(Figure:GetChildren()) do
		if kid.className == "Tool" then
			return kid
		end
	end
	return nil
end
local function getToolAnim(tool)
	for _, c in ipairs(tool:GetChildren()) do
		if c.Name == "toolanim" and c.className == "StringValue" then
			return c
		end
	end
	return nil
end
local function animateTool()
	if toolAnim == "None" then
		RightShoulder.DesiredAngle = 1.57
		return
	end
	if toolAnim == "Slash" then
		RightShoulder.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = 0
		return
	end
	if toolAnim == "Lunge" then
		RightShoulder.MaxVelocity = 0.5
		LeftShoulder.MaxVelocity = 0.5
		RightHip.MaxVelocity = 0.5
		LeftHip.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = 1.57
		LeftShoulder.DesiredAngle = 1.0
		RightHip.DesiredAngle = 1.57
		LeftHip.DesiredAngle = 1.0
		return
	end
end
local function move(time)
	local amplitude
	local frequency
	if pose == "Jumping" then
		moveJump()
		return
	end
	if pose == "FreeFall" then
		moveFreeFall()
		return
	end
	if pose == "Seated" then
		moveSit()
		return
	end
	local climbFudge = 0
	if pose == "Running" then
		RightShoulder.MaxVelocity = 0.15
		LeftShoulder.MaxVelocity = 0.15
		amplitude = 1
		frequency = 9
	elseif pose == "Climbing" then
		RightShoulder.MaxVelocity = 0.5
		LeftShoulder.MaxVelocity = 0.5
		amplitude = 1
		frequency = 9
		climbFudge = 3.14
	else
		amplitude = 0.1
		frequency = 1
	end
	local desiredAngle = amplitude * math.sin(time * frequency)
	RightShoulder.DesiredAngle = desiredAngle + climbFudge
	LeftShoulder.DesiredAngle = desiredAngle - climbFudge
	RightHip.DesiredAngle = -desiredAngle
	LeftHip.DesiredAngle = -desiredAngle
	local tool = getTool()
	if tool then
		local animStringValueObject = getToolAnim(tool)
		if animStringValueObject then
			toolAnim = animStringValueObject.Value
			-- message recieved, delete StringValue
			animStringValueObject.Parent = nil
			toolAnimTime = time + .3
		end
		if time > toolAnimTime then
			toolAnimTime = 0
			toolAnim = "None"
		end
		animateTool()
	else
		toolAnim = "None"
		toolAnimTime = 0
	end
end
-- connect events
Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
-- main program
while Figure.Parent ~= nil do
	local _, time = wait(0.1)
	move(time)
end
