Professional Documents
Culture Documents
Parent
local LoadAnimation = require(game:GetService("ReplicatedStorage").Helpers["Load
Animation"])
local userEmoteToRunThresholdChange do
local success, value = pcall(function()
return
UserSettings():IsUserFeatureEnabled("UserEmoteToRunThresholdChange")
end)
userEmoteToRunThresholdChange = success and value
end
local userPlayEmoteByIdAnimTrackReturn do
local success, value = pcall(function()
return
UserSettings():IsUserFeatureEnabled("UserPlayEmoteByIdAnimTrackReturn2")
end)
userPlayEmoteByIdAnimTrackReturn = success and value
end
local FFlagUserFixLoadAnimationError do
local success, result = pcall(function()
return UserSettings():IsUserFeatureEnabled("UserFixLoadAnimationError")
end)
FFlagUserFixLoadAnimationError = success and result
end
local AnimationSpeedDampeningObject =
script:FindFirstChild("ScaleDampeningPercent")
local HumanoidHipHeight = 2
local PreloadedAnims = {}
local animTable = {}
local animNames = {
idle = {
{ id = "rbxassetid://15306265141", weight = 1 },
},
walk = {
{ id = "http://www.roblox.com/asset/?id=10921261968", weight = 10 }
},
run = {
{ id = "http://www.roblox.com/asset/?id=10921261968", weight = 10 }
},
swim = {
{ id = "http://www.roblox.com/asset/?id=2510199791", weight = 10 }
},
swimidle = {
{ id = "http://www.roblox.com/asset/?id=913389285", weight = 10 }
},
jump = {
{ id = "http://www.roblox.com/asset/?id=2510197830", weight = 10 }
},
fall = {
{ id = "http://www.roblox.com/asset/?id=2510195892", weight = 10 }
},
climb = {
{ id = "http://www.roblox.com/asset/?id=507765644", weight = 10 }
},
sit = {
{ id = "http://www.roblox.com/asset/?id=2506281703", weight = 10 }
},
toolnone = {
{ id = "http://www.roblox.com/asset/?id=507768375", weight = 10 }
},
toolslash = {
{ id = "http://www.roblox.com/asset/?id=522635514", weight = 10 }
},
toollunge = {
{ id = "http://www.roblox.com/asset/?id=522638767", weight = 10 }
},
wave = {
{ id = "http://www.roblox.com/asset/?id=507770239", weight = 10 }
},
point = {
{ id = "http://www.roblox.com/asset/?id=507770453", weight = 10 }
},
dance = {
{ id = "http://www.roblox.com/asset/?id=507771019", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507771955", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507772104", weight = 10 }
},
dance2 = {
{ id = "http://www.roblox.com/asset/?id=507776043", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507776720", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507776879", weight = 10 }
},
dance3 = {
{ id = "http://www.roblox.com/asset/?id=507777268", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507777451", weight = 10 },
{ id = "http://www.roblox.com/asset/?id=507777623", weight = 10 }
},
laugh = {
{ id = "http://www.roblox.com/asset/?id=507770818", weight = 10 }
},
cheer = {
{ id = "http://www.roblox.com/asset/?id=507770677", weight = 10 }
},
}
math.randomseed(tick())
return 0
end
local idx = 0
for _, childPart in pairs(config:GetChildren()) do
if childPart:IsA("Animation") then
local newWeight = 1
local weightObject = childPart:FindFirstChild("Weight")
if weightObject ~= nil then
newWeight = weightObject.Value
end
animTable[name].count = animTable[name].count + 1
idx = animTable[name].count
animTable[name][idx] = {}
animTable[name][idx].anim = childPart
animTable[name][idx].weight = newWeight
animTable[name].totalWeight = animTable[name].totalWeight +
animTable[name][idx].weight
table.insert(animTable[name].connections,
childPart.Changed:Connect(function(property) configureAnimationSet(name, fileList)
end))
table.insert(animTable[name].connections,
childPart.ChildAdded:Connect(function(property) configureAnimationSet(name,
fileList) end))
table.insert(animTable[name].connections,
childPart.ChildRemoved:Connect(function(property) configureAnimationSet(name,
fileList) end))
end
end
end
-- fallback to defaults
if animTable[name].count <= 0 then
for idx, anim in pairs(fileList) do
animTable[name][idx] = {}
animTable[name][idx].anim = Instance.new("Animation")
animTable[name][idx].anim.Name = name
animTable[name][idx].anim.AnimationId = anim.id
animTable[name][idx].weight = anim.weight
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight +
anim.weight
end
end
-- preload anims
for i, animType in pairs(animTable) do
for idx = 1, animType.count, 1 do
if PreloadedAnims[animType[idx].anim.AnimationId] == nil then
LoadAnimation(animType[idx].anim)
PreloadedAnims[animType[idx].anim.AnimationId] = true
end
end
end
end
-----------------------------------------------------------------------------------
-------------------------
-- fallback to defaults
if animTable[name].count <= 0 then
for idx, anim in pairs(fileList) do
animTable[name][idx] = {}
animTable[name][idx].anim = Instance.new("Animation")
animTable[name][idx].anim.Name = name
animTable[name][idx].anim.AnimationId = anim.id
animTable[name][idx].weight = anim.weight
animTable[name].count = animTable[name].count + 1
animTable[name].totalWeight = animTable[name].totalWeight +
anim.weight
-- print(name .. " [" .. idx .. "] " .. anim.id .. " (" ..
anim.weight .. ")")
end
end
-- preload anims
for i, animType in pairs(animTable) do
for idx = 1, animType.count, 1 do
LoadAnimation(animType[idx].anim)
end
end
end
script.ChildAdded:Connect(scriptChildModified)
script.ChildRemoved:Connect(scriptChildModified)
-- ANIMATION
-- declarations
local toolAnim = "None"
local toolAnimTime = 0
local jumpAnimTime = 0
local jumpAnimDuration = 0.31
-- functions
function stopAllAnimations()
local oldAnim = currentAnim
currentAnim = ""
currentAnimInstance = nil
if currentAnimKeyframeHandler ~= nil then
currentAnimKeyframeHandler:Disconnect()
end
return oldAnim
end
function getHeightScale()
if Humanoid then
if not Humanoid.AutomaticScalingEnabled then
return 1
end
function setAnimationSpeed(speed)
if currentAnim == "walk" then
setRunSpeed(speed)
else
if speed ~= currentAnimSpeed then
currentAnimSpeed = speed
currentAnimTrack:AdjustSpeed(currentAnimSpeed)
end
end
end
function keyFrameReachedFunc(frameName)
if frameName == "End" then
if currentAnim == "walk" then
if userNoUpdateOnLoop == true then
if runAnimTrack.Looped ~= true then
runAnimTrack.TimePosition = 0.0
end
if currentAnimTrack.Looped ~= true then
currentAnimTrack.TimePosition = 0.0
end
else
runAnimTrack.TimePosition = 0.0
currentAnimTrack.TimePosition = 0.0
end
else
local repeatAnim = currentAnim
-- return to idle if finishing an emote
if emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] ==
false then
repeatAnim = "idle"
end
repeatAnim = "idle"
currentlyPlayingEmote = false
end
function rollAnimation(animName)
local roll = math.random(1, animTable[animName].totalWeight)
local idx = 1
while roll > animTable[animName][idx].weight do
roll = roll - animTable[animName][idx].weight
idx = idx + 1
end
return idx
end
currentAnimSpeed = 1.0
runAnimTrack = LoadAnimation(animTable[runAnimName][runIdx].anim)
runAnimTrack.Priority = Enum.AnimationPriority.Core
runAnimTrack:Play(transitionTime)
-----------------------------------------------------------------------------------
--------
-----------------------------------------------------------------------------------
--------
function toolKeyFrameReachedFunc(frameName)
if frameName == "End" then
playToolAnimation(toolAnimName, 0.0, Humanoid)
end
end
currentToolAnimKeyframeHandler =
toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
end
end
function stopToolAnimations()
local oldAnim = toolAnimName
toolAnimName = ""
toolAnimInstance = nil
if toolAnimTrack ~= nil then
toolAnimTrack:Stop()
toolAnimTrack:Destroy()
toolAnimTrack = nil
end
return oldAnim
end
-----------------------------------------------------------------------------------
--------
-----------------------------------------------------------------------------------
--------
-- STATE CHANGE HANDLERS
function onRunning(speed)
local movedDuringEmote =
userEmoteToRunThresholdChange and currentlyPlayingEmote and
Humanoid.MoveDirection == Vector3.new(0, 0, 0)
local speedThreshold = movedDuringEmote and Humanoid.WalkSpeed or 0.75
if speed > speedThreshold then
local scale = 16.0
playAnimation("walk", 0.2, Humanoid)
setAnimationSpeed(speed / scale)
pose = "Running"
else
if emoteNames[currentAnim] == nil and not currentlyPlayingEmote then
playAnimation("idle", 0.2, Humanoid)
pose = "Standing"
end
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 animateTool()
if toolAnim == "None" then
playToolAnimation("toolnone", toolTransitionTime, Humanoid,
Enum.AnimationPriority.Idle)
return
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
local lastTick = 0
function stepAnimate(currentTime)
local amplitude = 1
local frequency = 1
local deltaTime = currentTime - lastTick
lastTick = currentTime
local climbFudge = 0
local setAngles = false
if animStringValueObject then
toolAnim = animStringValueObject.Value
-- message recieved, delete StringValue
animStringValueObject.Parent = nil
toolAnimTime = currentTime + .3
end
animateTool()
else
stopToolAnimations()
toolAnim = "None"
toolAnimInstance = nil
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)
Humanoid.PlatformStanding:Connect(onPlatformStanding)
Humanoid.Swimming:Connect(onSwimming)
PlayEmote.OnInvoke = function(emote)
-- Only play emotes when idling
if pose ~= "Standing" then
return
end
if userPlayEmoteByIdAnimTrackReturn then
return true, currentAnimTrack
else
return true
end
elseif typeof(emote) == "Instance" and emote:IsA("Animation") then
-- Non-default emotes
playEmote(emote, EMOTE_TRANSITION_TIME, Humanoid)
if userPlayEmoteByIdAnimTrackReturn then
return true, currentAnimTrack
else
return true
end
end
if false then
-- initialize to idle
playAnimation("idle", 0.1, Humanoid)
pose = "Standing"
end