function onRunning(N)if N>.01 then local X=15.0 playAnimation("\119\097\108\107",.1,Humanoid)setAnimationSpeed(N/X)pose="\082\117\110\110\105\110\103"else playAnimation("\105\100\108\101",.1,Humanoid)pose="\083\116\097\110\100\105\110\103"end end function onDied()pose="\068\101\097\100"end function onJumping()playAnimation("\106\117\109\112",.1,Humanoid)jumpAnimTime=jumpAnimDuration pose="\074\117\109\112\105\110\103"end function onClimbing(N)local X=5.0 playAnimation("\099\108\105\109\098",.1,Humanoid)setAnimationSpeed(N/X)pose="\067\108\105\109\098\105\110\103"end function onGettingUp()pose="\071\101\116\116\105\110\103\085\112"end function onFreeFall()if jumpAnimTime<=0 then playAnimation("\102\097\108\108",fallTransitionTime,Humanoid)end pose="\070\114\101\101\070\097\108\108"end function onFallingDown()pose="\070\097\108\108\105\110\103\068\111\119\110"end function onSeated()pose="\083\101\097\116\101\100"end function onPlatformStanding()pose="\080\108\097\116\102\111\114\109\083\116\097\110\100\105\110\103"end function onSwimming(N)if N>1.0 then local X=10.0 playAnimation("\115\119\105\109",.4,Humanoid)setAnimationSpeed(N/X)pose="\083\119\105\109\109\105\110\103"else playAnimation("\115\119\105\109\105\100\108\101",.4,Humanoid)pose="\083\116\097\110\100\105\110\103"end end function getTool()for N,X in ipairs(Figure:GetChildren())do if X.className=="\084\111\111\108"then return X end end return nil end function getToolAnim(N)for N,X in ipairs(N:GetChildren())do if X.Name=="\116\111\111\108\097\110\105\109"and X.className=="\083\116\114\105\110\103\086\097\108\117\101"then return X end end return nil end function animateTool()if toolAnim=="\078\111\110\101"then playToolAnimation("\116\111\111\108\110\111\110\101",toolTransitionTime,Humanoid)return end if toolAnim=="\083\108\097\115\104"then playToolAnimation("\116\111\111\108\115\108\097\115\104",0,Humanoid)return end if toolAnim=="\076\117\110\103\101"then playToolAnimation("\116\111\111\108\108\117\110\103\101",0,Humanoid)return end end function moveSit()RightShoulder.MaxVelocity=.15 LeftShoulder.MaxVelocity=.15 RightShoulder:SetDesiredAngle(1.57)LeftShoulder:SetDesiredAngle(-1.57)RightHip:SetDesiredAngle(1.57)LeftHip:SetDesiredAngle(-1.57)end local N=0 function move(X)local Y=1 local Q=1 local w=X-N N=X local R=0 local b=false if jumpAnimTime>0 then jumpAnimTime=jumpAnimTime-w end if pose=="\070\114\101\101\070\097\108\108"and jumpAnimTime<=0 then playAnimation("\102\097\108\108",fallTransitionTime,Humanoid)elseif pose=="\083\101\097\116\101\100"then playAnimation("\115\105\116",.5,Humanoid)return elseif pose=="\082\117\110\110\105\110\103"then playAnimation("\119\097\108\107",.1,Humanoid)elseif pose=="\068\101\097\100"or pose=="\071\101\116\116\105\110\103\085\112"or pose=="\070\097\108\108\105\110\103\068\111\119\110"or pose=="\083\101\097\116\101\100"or pose=="\080\108\097\116\102\111\114\109\083\116\097\110\100\105\110\103"then stopAllAnimations()Y=.1 Q=1 b=true end local A=getTool()if A then animStringValueObject=getToolAnim(A)if animStringValueObject then toolAnim=animStringValueObject.Value animStringValueObject.Parent=nil toolAnimTime=X+.3 end if X>toolAnimTime then toolAnimTime=0 toolAnim="\078\111\110\101"end animateTool()else stopToolAnimations()toolAnim="\078\111\110\101"toolAnimInstance=nil toolAnimTime=0 end end



function onRunning(speed)
	if speed > 0.01 then
		local scale = 15.0
		playAnimation("walk", 0.1, Humanoid)
		setAnimationSpeed(speed / scale)
		pose = "Running"
	else
		playAnimation("idle", 0.1, Humanoid)
		pose = "Standing"
	end
end

function onDied()
	pose = "Dead"
end

function onJumping()
	playAnimation("jump", 0.1, Humanoid)
	jumpAnimTime = jumpAnimDuration
	pose = "Jumping"
end

function onClimbing(speed)
	local scale = 5.0
	playAnimation("climb", 0.1, Humanoid)
	setAnimationSpeed(speed / scale)
	pose = "Climbing"
end

function onGettingUp()
	pose = "GettingUp"
end

function onFreeFall()
	if (jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	end
	pose = "FreeFall"
end

function onFallingDown()
	pose = "FallingDown"
end

function onSeated()
	pose = "Seated"
end

function onPlatformStanding()
	pose = "PlatformStanding"
end

function onSwimming(speed)
	if speed > 1.00 then
		local scale = 10.0
		playAnimation("swim", 0.4, Humanoid)
		setAnimationSpeed(speed / scale)
		pose = "Swimming"
	else
		playAnimation("swimidle", 0.4, Humanoid)
		pose = "Standing"
	end
end

function getTool()	
	for _, kid in ipairs(Figure:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end

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

function animateTool()
	
	if (toolAnim == "None") then
		playToolAnimation("toolnone", toolTransitionTime, Humanoid)
		return
	end

	if (toolAnim == "Slash") then
		playToolAnimation("toolslash", 0, Humanoid)
		return
	end

	if (toolAnim == "Lunge") then
		playToolAnimation("toollunge", 0, Humanoid)
		return
	end
end

function moveSit()
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder:SetDesiredAngle(3.14 /2)
	LeftShoulder:SetDesiredAngle(-3.14 /2)
	RightHip:SetDesiredAngle(3.14 /2)
	LeftHip:SetDesiredAngle(-3.14 /2)
end

local lastTick = 0

function move(time)
	local amplitude = 1
	local frequency = 1
  	local deltaTime = time - lastTick
  	lastTick = time

	local climbFudge = 0
	local setAngles = false

  	if (jumpAnimTime > 0) then
  		jumpAnimTime = jumpAnimTime - deltaTime
  	end

	if (pose == "FreeFall" and jumpAnimTime <= 0) then
		playAnimation("fall", fallTransitionTime, Humanoid)
	elseif (pose == "Seated") then
		playAnimation("sit", 0.5, Humanoid)
		return
	elseif (pose == "Running") then
		playAnimation("walk", 0.1, Humanoid)
	elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
		stopAllAnimations()
		amplitude = 0.1
		frequency = 1
		setAngles = true
	end

	-- Tool Animation handling
	local tool = getTool()
	if tool then
	
		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
		stopToolAnimations()
		toolAnim = "None"
		toolAnimInstance = nil
		toolAnimTime = 0
	end
end
