Sub-Urban

Crab Walk Sound

Apr 15th, 2021 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.61 KB | None | 0 0
  1. local Figure = owner.Character
  2. Figure.Animate:Destroy()
  3. local walkspeedanim = 3
  4. Figure.HumanoidRootPart.Running.SoundId = "rbxassetid://3426632334"
  5. Figure.HumanoidRootPart.Running.Volume = 10
  6. local Torso = Figure:WaitForChild("Torso")
  7. local RightShoulder = Torso:WaitForChild("Right Shoulder")
  8. local LeftShoulder = Torso:WaitForChild("Left Shoulder")
  9. local RightHip = Torso:WaitForChild("Right Hip")
  10. local LeftHip = Torso:WaitForChild("Left Hip")
  11. local Neck = Torso:WaitForChild("Neck")
  12. local Humanoid = Figure:WaitForChild("Humanoid")
  13. local pose = "Standing"
  14.  
  15. local currentAnim = ""
  16. local currentAnimInstance = nil
  17. local currentAnimTrack = nil
  18. local currentAnimKeyframeHandler = nil
  19. local currentAnimSpeed = 1.0
  20. local animTable = {}
  21. local animNames = {
  22.     idle =  {  
  23.         { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
  24.         { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
  25.     },
  26.     walk =  {  
  27.         { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
  28.     },
  29.     run =   {
  30.         { id = "run.xml", weight = 10 }
  31.     },
  32.     jump =  {
  33.         { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  34.     },
  35.     fall =  {
  36.         { id = "http://www.roblox.com/asset/?id=180436148", weight = 10 }
  37.     },
  38.     climb = {
  39.         { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
  40.     },
  41.     sit =   {
  42.         { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
  43.     }, 
  44.     toolnone = {
  45.         { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
  46.     },
  47.     toolslash = {
  48.         { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  49.         --              { id = "slash.xml", weight = 10 }
  50.     },
  51.     toollunge = {
  52.         { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  53.     },
  54.     wave = {
  55.         { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  56.     },
  57.     point = {
  58.         { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  59.     },
  60.     dance1 = {
  61.         { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
  62.         { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
  63.         { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
  64.     },
  65.     dance2 = {
  66.         { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
  67.         { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
  68.         { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
  69.     },
  70.     dance3 = {
  71.         { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
  72.         { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
  73.         { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
  74.     },
  75.     laugh = {
  76.         { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  77.     },
  78.     cheer = {
  79.         { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  80.     },
  81. }
  82. local dances = {"dance1", "dance2", "dance3"}
  83.  
  84. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  85. local emoteNames = { wave = false, point = false, dance1 = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  86.  
  87. function configureAnimationSet(name, fileList)
  88.     if (animTable[name] ~= nil) then
  89.         for _, connection in pairs(animTable[name].connections) do
  90.             connection:disconnect()
  91.         end
  92.     end
  93.     animTable[name] = {}
  94.     animTable[name].count = 0
  95.     animTable[name].totalWeight = 0
  96.     animTable[name].connections = {}
  97.  
  98.     -- check for config values
  99.     local config = script:FindFirstChild(name)
  100.     if (config ~= nil) then
  101.         --      print("Loading anims " .. name)
  102.         table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  103.         table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  104.         local idx = 1
  105.         for _, childPart in pairs(config:GetChildren()) do
  106.             if (childPart:IsA("Animation")) then
  107.                 table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  108.                 animTable[name][idx] = {}
  109.                 animTable[name][idx].anim = childPart
  110.                 local weightObject = childPart:FindFirstChild("Weight")
  111.                 if (weightObject == nil) then
  112.                     animTable[name][idx].weight = 1
  113.                 else
  114.                     animTable[name][idx].weight = weightObject.Value
  115.                 end
  116.                 animTable[name].count = animTable[name].count + 1
  117.                 animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  118.                 --          print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  119.                 idx = idx + 1
  120.             end
  121.         end
  122.     end
  123.  
  124.     -- fallback to defaults
  125.     if (animTable[name].count <= 0) then
  126.         for idx, anim in pairs(fileList) do
  127.             animTable[name][idx] = {}
  128.             animTable[name][idx].anim = Instance.new("Animation")
  129.             animTable[name][idx].anim.Name = name
  130.             animTable[name][idx].anim.AnimationId = anim.id
  131.             animTable[name][idx].weight = anim.weight
  132.             animTable[name].count = animTable[name].count + 1
  133.             animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  134.             --          print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  135.         end
  136.     end
  137. end
  138.  
  139. -- Setup animation objects
  140. function scriptChildModified(child)
  141.     local fileList = animNames[child.Name]
  142.     if (fileList ~= nil) then
  143.         configureAnimationSet(child.Name, fileList)
  144.     end
  145. end
  146.  
  147. script.ChildAdded:connect(scriptChildModified)
  148. script.ChildRemoved:connect(scriptChildModified)
  149.  
  150.  
  151. for name, fileList in pairs(animNames) do
  152.     configureAnimationSet(name, fileList)
  153. end
  154.  
  155. -- ANIMATION
  156.  
  157. -- declarations
  158. local toolAnim = "None"
  159. local toolAnimTime = 0
  160.  
  161. local jumpAnimTime = 0
  162. local jumpAnimDuration = 0.3
  163.  
  164. local toolTransitionTime = 0.1
  165. local fallTransitionTime = 0.3
  166. local jumpMaxLimbVelocity = 0.75
  167.  
  168. -- functions
  169.  
  170. function stopAllAnimations()
  171.     local oldAnim = currentAnim
  172.  
  173.     -- return to idle if finishing an emote
  174.     if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  175.         oldAnim = "idle"
  176.     end
  177.  
  178.     currentAnim = ""
  179.     currentAnimInstance = nil
  180.     if (currentAnimKeyframeHandler ~= nil) then
  181.         currentAnimKeyframeHandler:disconnect()
  182.     end
  183.  
  184.     if (currentAnimTrack ~= nil) then
  185.         currentAnimTrack:Stop()
  186.         currentAnimTrack:Destroy()
  187.         currentAnimTrack = nil
  188.     end
  189.     return oldAnim
  190. end
  191.  
  192. function setAnimationSpeed(speed)
  193.     if speed ~= currentAnimSpeed then
  194.         currentAnimSpeed = speed
  195.         currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  196.     end
  197. end
  198.  
  199. function keyFrameReachedFunc(frameName)
  200.     if (frameName == "End") then
  201.  
  202.         local repeatAnim = currentAnim
  203.         -- return to idle if finishing an emote
  204.         if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  205.             repeatAnim = "idle"
  206.         end
  207.  
  208.         local animSpeed = currentAnimSpeed
  209.         playAnimation(repeatAnim, 0.0, Humanoid)
  210.         setAnimationSpeed(animSpeed)
  211.     end
  212. end
  213.  
  214. -- Preload animations
  215. function playAnimation(animName, transitionTime, humanoid)
  216.  
  217.     local roll = math.random(1, animTable[animName].totalWeight)
  218.     local origRoll = roll
  219.     local idx = 1
  220.     while (roll > animTable[animName][idx].weight) do
  221.         roll = roll - animTable[animName][idx].weight
  222.         idx = idx + 1
  223.     end
  224.     --      print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  225.     local anim = animTable[animName][idx].anim
  226.  
  227.     -- switch animation    
  228.     if (anim ~= currentAnimInstance) then
  229.  
  230.         if (currentAnimTrack ~= nil) then
  231.             currentAnimTrack:Stop(transitionTime)
  232.             currentAnimTrack:Destroy()
  233.         end
  234.  
  235.         currentAnimSpeed = 1.0
  236.  
  237.         -- load it to the humanoid; get AnimationTrack
  238.         currentAnimTrack = humanoid:LoadAnimation(anim)
  239.         currentAnimTrack.Priority = Enum.AnimationPriority.Core
  240.  
  241.         -- play the animation
  242.         currentAnimTrack:Play(transitionTime)
  243.         currentAnim = animName
  244.         currentAnimInstance = anim
  245.  
  246.         -- set up keyframe name triggers
  247.         if (currentAnimKeyframeHandler ~= nil) then
  248.             currentAnimKeyframeHandler:disconnect()
  249.         end
  250.         currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  251.  
  252.     end
  253.  
  254. end
  255.  
  256. -------------------------------------------------------------------------------------------
  257. -------------------------------------------------------------------------------------------
  258.  
  259. local toolAnimName = ""
  260. local toolAnimTrack = nil
  261. local toolAnimInstance = nil
  262. local currentToolAnimKeyframeHandler = nil
  263.  
  264. function toolKeyFrameReachedFunc(frameName)
  265.     if (frameName == "End") then
  266.         --      print("Keyframe : ".. frameName)   
  267.         playToolAnimation(toolAnimName, 0.0, Humanoid)
  268.     end
  269. end
  270.  
  271.  
  272. function playToolAnimation(animName, transitionTime, humanoid, priority)     
  273.  
  274.     local roll = math.random(1, animTable[animName].totalWeight)
  275.     local origRoll = roll
  276.     local idx = 1
  277.     while (roll > animTable[animName][idx].weight) do
  278.         roll = roll - animTable[animName][idx].weight
  279.         idx = idx + 1
  280.     end
  281.     --      print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  282.     local anim = animTable[animName][idx].anim
  283.  
  284.     if (toolAnimInstance ~= anim) then
  285.  
  286.         if (toolAnimTrack ~= nil) then
  287.             toolAnimTrack:Stop()
  288.             toolAnimTrack:Destroy()
  289.             transitionTime = 0
  290.         end
  291.  
  292.         -- load it to the humanoid; get AnimationTrack
  293.         toolAnimTrack = humanoid:LoadAnimation(anim)
  294.         if priority then
  295.             toolAnimTrack.Priority = priority
  296.         end
  297.  
  298.         -- play the animation
  299.         toolAnimTrack:Play(transitionTime)
  300.         toolAnimName = animName
  301.         toolAnimInstance = anim
  302.  
  303.         currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  304.     end
  305. end
  306.  
  307. function stopToolAnimations()
  308.     local oldAnim = toolAnimName
  309.  
  310.     if (currentToolAnimKeyframeHandler ~= nil) then
  311.         currentToolAnimKeyframeHandler:disconnect()
  312.     end
  313.  
  314.     toolAnimName = ""
  315.     toolAnimInstance = nil
  316.     if (toolAnimTrack ~= nil) then
  317.         toolAnimTrack:Stop()
  318.         toolAnimTrack:Destroy()
  319.         toolAnimTrack = nil
  320.     end
  321.  
  322.  
  323.     return oldAnim
  324. end
  325.  
  326. -------------------------------------------------------------------------------------------
  327. -------------------------------------------------------------------------------------------
  328.  
  329.  
  330. function onRunning(speed)
  331.     if speed > 0.01 then
  332.         playAnimation("walk", 0.1, Humanoid)
  333.         if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
  334.             setAnimationSpeed(speed / walkspeedanim)
  335.         end
  336.         pose = "Running"
  337.     else
  338.         if emoteNames[currentAnim] == nil then
  339.             playAnimation("idle", 0.1, Humanoid)
  340.             pose = "Standing"
  341.         end
  342.     end
  343. end
  344.  
  345. function onDied()
  346.     pose = "Dead"
  347. end
  348.  
  349. function onJumping()
  350.     playAnimation("jump", 0.1, Humanoid)
  351.     jumpAnimTime = jumpAnimDuration
  352.     pose = "Jumping"
  353. end
  354.  
  355. function onClimbing(speed)
  356.     playAnimation("climb", 0.1, Humanoid)
  357.     setAnimationSpeed(speed / 12.0)
  358.     pose = "Climbing"
  359. end
  360.  
  361. function onGettingUp()
  362.     pose = "GettingUp"
  363. end
  364.  
  365. function onFreeFall()
  366.     if (jumpAnimTime <= 0) then
  367.         playAnimation("fall", fallTransitionTime, Humanoid)
  368.     end
  369.     pose = "FreeFall"
  370. end
  371.  
  372. function onFallingDown()
  373.     pose = "FallingDown"
  374. end
  375.  
  376. function onSeated()
  377.     pose = "Seated"
  378. end
  379.  
  380. function onPlatformStanding()
  381.     pose = "PlatformStanding"
  382. end
  383.  
  384. function onSwimming(speed)
  385.     if speed > 0 then
  386.         pose = "Running"
  387.     else
  388.         pose = "Standing"
  389.     end
  390. end
  391.  
  392. function getTool() 
  393.     for _, kid in ipairs(Figure:GetChildren()) do
  394.         if kid.className == "Tool" then return kid end
  395.     end
  396.     return nil
  397. end
  398.  
  399. function getToolAnim(tool)
  400.     for _, c in ipairs(tool:GetChildren()) do
  401.         if c.Name == "toolanim" and c.className == "StringValue" then
  402.             return c
  403.         end
  404.     end
  405.     return nil
  406. end
  407.  
  408. function animateTool()
  409.  
  410.     if (toolAnim == "None") then
  411.         playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
  412.         return
  413.     end
  414.  
  415.     if (toolAnim == "Slash") then
  416.         playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
  417.         return
  418.     end
  419.  
  420.     if (toolAnim == "Lunge") then
  421.         playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
  422.         return
  423.     end
  424. end
  425.  
  426. function moveSit()
  427.     RightShoulder.MaxVelocity = 0.15
  428.     LeftShoulder.MaxVelocity = 0.15
  429.     RightShoulder:SetDesiredAngle(3.14 /2)
  430.     LeftShoulder:SetDesiredAngle(-3.14 /2)
  431.     RightHip:SetDesiredAngle(3.14 /2)
  432.     LeftHip:SetDesiredAngle(-3.14 /2)
  433. end
  434.  
  435. local lastTick = 0
  436.  
  437. function move(time)
  438.     local amplitude = 1
  439.     local frequency = 1
  440.     local deltaTime = time - lastTick
  441.     lastTick = time
  442.  
  443.     local climbFudge = 0
  444.     local setAngles = false
  445.  
  446.     if (jumpAnimTime > 0) then
  447.         jumpAnimTime = jumpAnimTime - deltaTime
  448.     end
  449.  
  450.     if (pose == "FreeFall" and jumpAnimTime <= 0) then
  451.         playAnimation("fall", fallTransitionTime, Humanoid)
  452.     elseif (pose == "Seated") then
  453.         playAnimation("sit", 0.5, Humanoid)
  454.         return
  455.     elseif (pose == "Running") then
  456.         playAnimation("walk", 0.1, Humanoid)
  457.     elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  458.         --      print("Wha " .. pose)
  459.         stopAllAnimations()
  460.         amplitude = 0.1
  461.         frequency = 1
  462.         setAngles = true
  463.     end
  464.  
  465.     if (setAngles) then
  466.         local desiredAngle = amplitude * math.sin(time * frequency)
  467.  
  468.         RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  469.         LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  470.         RightHip:SetDesiredAngle(-desiredAngle)
  471.         LeftHip:SetDesiredAngle(-desiredAngle)
  472.     end
  473.  
  474.     -- Tool Animation handling
  475.     local tool = getTool()
  476.     if tool and tool:FindFirstChild("Handle") then
  477.  
  478.         local animStringValueObject = getToolAnim(tool)
  479.  
  480.         if animStringValueObject then
  481.             toolAnim = animStringValueObject.Value
  482.             -- message recieved, delete StringValue
  483.             animStringValueObject.Parent = nil
  484.             toolAnimTime = time + .3
  485.         end
  486.  
  487.         if time > toolAnimTime then
  488.             toolAnimTime = 0
  489.             toolAnim = "None"
  490.         end
  491.  
  492.         animateTool()      
  493.     else
  494.         stopToolAnimations()
  495.         toolAnim = "None"
  496.         toolAnimInstance = nil
  497.         toolAnimTime = 0
  498.     end
  499. end
  500.  
  501. -- connect events
  502. Humanoid.Died:connect(onDied)
  503. Humanoid.Running:connect(onRunning)
  504. Humanoid.Jumping:connect(onJumping)
  505. Humanoid.Climbing:connect(onClimbing)
  506. Humanoid.GettingUp:connect(onGettingUp)
  507. Humanoid.FreeFalling:connect(onFreeFall)
  508. Humanoid.FallingDown:connect(onFallingDown)
  509. Humanoid.Seated:connect(onSeated)
  510. Humanoid.PlatformStanding:connect(onPlatformStanding)
  511. Humanoid.Swimming:connect(onSwimming)
  512.  
  513. -- setup emote chat hook
  514. game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
  515.     local emote = ""
  516.     if msg == "/e dance" then
  517.         emote = dances[math.random(1, #dances)]
  518.     elseif (string.sub(msg, 1, 3) == "/e ") then
  519.         emote = string.sub(msg, 4)
  520.     elseif (string.sub(msg, 1, 7) == "/emote ") then
  521.         emote = string.sub(msg, 8)
  522.     end
  523.  
  524.     if (pose == "Standing" and emoteNames[emote] ~= nil) then
  525.         playAnimation(emote, 0.1, Humanoid)
  526.     end
  527.  
  528. end)
  529.  
  530.  
  531. -- main program
  532.  
  533. -- initialize to idle
  534. playAnimation("idle", 0.1, Humanoid)
  535. pose = "Standing"
  536.  
  537. while Figure.Parent ~= nil do
  538.     local _, time = wait(0.1)
  539.     move(time)
  540. end
Add Comment
Please, Sign In to add comment