Advertisement
OofeyDoofy

MoCap

Feb 28th, 2018
10,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.89 KB | None | 0 0
  1. print("Installing..")
  2. wait(0.25)
  3. script.Name = "Animate"
  4.  
  5. local plr = game.Players.LocalPlayer
  6. local C = plr.Character
  7. wait(0.5)
  8. script.Parent = C
  9. local animate = C:FindFirstChild("Animate")
  10.  
  11. wait(0.25)
  12.  
  13. model=Instance.new("Model",script)cheer=Instance.new("StringValue")
  14. cheeranim=Instance.new("Animation")climb=Instance.new("StringValue")
  15. climbanim=Instance.new("Animation")dance=Instance.new("StringValue")
  16. animation1=Instance.new("Animation")weight=Instance.new("NumberValue")
  17. animation2=Instance.new("Animation")weight_2=Instance.new("NumberValue")
  18. animation3=Instance.new("Animation")weight_3=Instance.new("NumberValue")
  19. dance2=Instance.new("StringValue")animation1_2=Instance.new("Animation")
  20. weight_4=Instance.new("NumberValue")animation2_2=Instance.new("Animation")
  21. weight_5=Instance.new("NumberValue")animation3_2=Instance.new("Animation")
  22. weight_6=Instance.new("NumberValue")dance3=Instance.new("StringValue")
  23. animation1_3=Instance.new("Animation")weight_7=Instance.new("NumberValue")
  24. animation2_3=Instance.new("Animation")weight_8=Instance.new("NumberValue")
  25. animation3_3=Instance.new("Animation")weight_9=Instance.new("NumberValue")
  26. fall=Instance.new("StringValue")fallanim=Instance.new("Animation")
  27. idle=Instance.new("StringValue")animation1_4=Instance.new("Animation")
  28. weight_10=Instance.new("NumberValue")animation2_4=Instance.new("Animation")
  29. weight_11=Instance.new("NumberValue")jump=Instance.new("StringValue")
  30. jumpanim=Instance.new("Animation")laugh=Instance.new("StringValue")
  31. laughanim=Instance.new("Animation")point=Instance.new("StringValue")
  32. pointanim=Instance.new("Animation")pose=Instance.new("StringValue")
  33. mocappose=Instance.new("Animation")weight_12=Instance.new("NumberValue")
  34. run=Instance.new("StringValue")runanim=Instance.new("Animation")
  35. sit=Instance.new("StringValue")sitanim=Instance.new("Animation")
  36. swim=Instance.new("StringValue")swim_2=Instance.new("Animation")
  37. swimidle=Instance.new("StringValue")swimidle_2=Instance.new("Animation")
  38. toollunge=Instance.new("StringValue")toollungeanim=Instance.new("Animation")
  39. toolnone=Instance.new("StringValue")toolnoneanim=Instance.new("Animation")
  40. toolslash=Instance.new("StringValue")toolslashanim=Instance.new("Animation")
  41. walk=Instance.new("StringValue")walkanim=Instance.new("Animation")
  42. wave=Instance.new("StringValue")waveanim=Instance.new("Animation")cheer.Name="cheer"
  43. cheer.Parent=model;cheeranim.Name="CheerAnim"
  44. cheeranim.AnimationId="http://www.roblox.com/asset/?id=507770677"cheeranim.Parent=cheer;climb.Name="climb"climb.Parent=model
  45. climbanim.Name="ClimbAnim"climbanim.AnimationId="rbxassetid://913362637"
  46. climbanim.Parent=climb;dance.Name="dance"dance.Parent=model;animation1.Name="Animation1"
  47. animation1.AnimationId="http://www.roblox.com/asset/?id=507771019"animation1.Parent=dance;weight.Value=10;weight.Name="Weight"
  48. weight.Parent=animation1;animation2.Name="Animation2"
  49. animation2.AnimationId="http://www.roblox.com/asset/?id=507771955"animation2.Parent=dance;weight_2.Value=10;weight_2.Name="Weight"
  50. weight_2.Parent=animation2;animation3.Name="Animation3"
  51. animation3.AnimationId="http://www.roblox.com/asset/?id=507772104"animation3.Parent=dance;weight_3.Value=10;weight_3.Name="Weight"
  52. weight_3.Parent=animation3;dance2.Name="dance2"dance2.Parent=model
  53. animation1_2.Name="Animation1"animation1_2.AnimationId="http://www.roblox.com/asset/?id=507776043"
  54. animation1_2.Parent=dance2;weight_4.Value=10;weight_4.Name="Weight"
  55. weight_4.Parent=animation1_2;animation2_2.Name="Animation2"
  56. animation2_2.AnimationId="http://www.roblox.com/asset/?id=507776720"animation2_2.Parent=dance2;weight_5.Value=10
  57. weight_5.Name="Weight"weight_5.Parent=animation2_2;animation3_2.Name="Animation3"
  58. animation3_2.AnimationId="http://www.roblox.com/asset/?id=507776879"animation3_2.Parent=dance2;weight_6.Value=10
  59. weight_6.Name="Weight"weight_6.Parent=animation3_2;dance3.Name="dance3"
  60. dance3.Parent=model;animation1_3.Name="Animation1"
  61. animation1_3.AnimationId="http://www.roblox.com/asset/?id=507777268"animation1_3.Parent=dance3;weight_7.Value=10
  62. weight_7.Name="Weight"weight_7.Parent=animation1_3;animation2_3.Name="Animation2"
  63. animation2_3.AnimationId="http://www.roblox.com/asset/?id=507777451"animation2_3.Parent=dance3;weight_8.Value=10
  64. weight_8.Name="Weight"weight_8.Parent=animation2_3;animation3_3.Name="Animation3"
  65. animation3_3.AnimationId="http://www.roblox.com/asset/?id=507777623"animation3_3.Parent=dance3;weight_9.Value=10
  66. weight_9.Name="Weight"weight_9.Parent=animation3_3;fall.Name="fall"fall.Parent=model
  67. fallanim.Name="FallAnim"fallanim.AnimationId="rbxassetid://913365531"fallanim.Parent=fall
  68. idle.Name="idle"idle.Parent=model;animation1_4.Name="Animation1"
  69. animation1_4.AnimationId="rbxassetid://913367814"animation1_4.Parent=idle;weight_10.Value=9
  70. weight_10.Name="Weight"weight_10.Parent=animation1_4;animation2_4.Name="Animation2"
  71. animation2_4.AnimationId="rbxassetid://913373430"animation2_4.Parent=idle;weight_11.Value=1
  72. weight_11.Name="Weight"weight_11.Parent=animation2_4;jump.Name="jump"jump.Parent=model
  73. jumpanim.Name="JumpAnim"jumpanim.AnimationId="rbxassetid://913370268"jumpanim.Parent=jump
  74. laugh.Name="laugh"laugh.Parent=model;laughanim.Name="LaughAnim"
  75. laughanim.AnimationId="http://www.roblox.com/asset/?id=507770818"laughanim.Parent=laugh;point.Name="point"point.Parent=model
  76. pointanim.Name="PointAnim"pointanim.AnimationId="http://www.roblox.com/asset/?id=507770453"
  77. pointanim.Parent=point;pose.Name="pose"pose.Parent=model;mocappose.Name="MocapPose"
  78. mocappose.AnimationId="rbxassetid://0"mocappose.Parent=pose;weight_12.Name="Weight"
  79. weight_12.Parent=mocappose;run.Name="run"run.Parent=model;runanim.Name="RunAnim"
  80. runanim.AnimationId="rbxassetid://913376220"runanim.Parent=run;sit.Name="sit"sit.Parent=model
  81. sitanim.Name="SitAnim"sitanim.AnimationId="http://www.roblox.com/asset/?id=507768133"
  82. sitanim.Parent=sit;swim.Name="swim"swim.Parent=model;swim_2.Name="Swim"
  83. swim_2.AnimationId="rbxassetid://913384386"swim_2.Parent=swim;swimidle.Name="swimidle"swimidle.Parent=model
  84. swimidle_2.Name="SwimIdle"swimidle_2.AnimationId="rbxassetid://913389285"
  85. swimidle_2.Parent=swimidle;toollunge.Name="toollunge"toollunge.Parent=model
  86. toollungeanim.Name="ToolLungeAnim"toollungeanim.AnimationId="http://www.roblox.com/asset/?id=522638767"
  87. toollungeanim.Parent=toollunge;toolnone.Name="toolnone"toolnone.Parent=model
  88. toolnoneanim.Name="ToolNoneAnim"toolnoneanim.AnimationId="http://www.roblox.com/asset/?id=507768375"
  89. toolnoneanim.Parent=toolnone;toolslash.Name="toolslash"toolslash.Parent=model
  90. toolslashanim.Name="ToolSlashAnim"toolslashanim.AnimationId="http://www.roblox.com/asset/?id=522635514"
  91. toolslashanim.Parent=toolslash;walk.Name="walk"walk.Parent=model;walkanim.Name="WalkAnim"
  92. walkanim.AnimationId="rbxassetid://913402848"walkanim.Parent=walk;wave.Name="wave"wave.Parent=model
  93. waveanim.Name="WaveAnim"waveanim.AnimationId="http://www.roblox.com/asset/?id=507770239"
  94. waveanim.Parent=wave
  95.  
  96. function Ungroup(this)--n
  97. for _,e in pairs(this:children()) do--n
  98. e.Parent = this.Parent;--n
  99. end--n
  100. end--n
  101. --n
  102.  
  103. wait(0.25)
  104. if animate then
  105.     animate:destroy()
  106. end
  107.  
  108. Ungroup(script.Model)--y
  109. wait(0.1)script.Model:destroy()
  110.  
  111. print([[Completed MoCap animations,
  112. Animations by ROBLOX, Script Injecter by SlayKillerX66]])
  113.  
  114. local Character = C
  115. local Humanoid = Character:WaitForChild("Humanoid")
  116. local pose = "Standing"
  117.  
  118. local currentAnim = ""
  119. local currentAnimInstance = nil
  120. local currentAnimTrack = nil
  121. local currentAnimKeyframeHandler = nil
  122. local currentAnimSpeed = 1.0
  123.  
  124. local runAnimTrack = nil
  125. local runAnimKeyframeHandler = nil
  126.  
  127. local animTable = {}
  128. local animNames = {
  129.     idle =  {  
  130.                 { id = "http://www.roblox.com/asset/?id=507766666", weight = 1 },
  131.                 { id = "http://www.roblox.com/asset/?id=507766951", weight = 1 },
  132.                 { id = "http://www.roblox.com/asset/?id=507766388", weight = 9 }
  133.             },
  134.     walk =  {  
  135.                 { id = "http://www.roblox.com/asset/?id=507777826", weight = 10 }
  136.             },
  137.     run =   {
  138.                 { id = "http://www.roblox.com/asset/?id=507767714", weight = 10 }
  139.             },
  140.     swim =  {
  141.                 { id = "http://www.roblox.com/asset/?id=507784897", weight = 10 }
  142.             },
  143.     swimidle =  {
  144.                 { id = "http://www.roblox.com/asset/?id=507785072", weight = 10 }
  145.             },
  146.     jump =  {
  147.                 { id = "http://www.roblox.com/asset/?id=507765000", weight = 10 }
  148.             },
  149.     fall =  {
  150.                 { id = "http://www.roblox.com/asset/?id=507767968", weight = 10 }
  151.             },
  152.     climb = {
  153.                 { id = "http://www.roblox.com/asset/?id=507765644", weight = 10 }
  154.             },
  155.     sit =   {
  156.                 { id = "http://www.roblox.com/asset/?id=507768133", weight = 10 }
  157.             }, 
  158.     toolnone = {
  159.                 { id = "http://www.roblox.com/asset/?id=507768375", weight = 10 }
  160.             },
  161.     toolslash = {
  162.                 { id = "http://www.roblox.com/asset/?id=522635514", weight = 10 }
  163.             },
  164.     toollunge = {
  165.                 { id = "http://www.roblox.com/asset/?id=522638767", weight = 10 }
  166.             },
  167.     wave = {
  168.                 { id = "http://www.roblox.com/asset/?id=507770239", weight = 10 }
  169.             },
  170.     point = {
  171.                 { id = "http://www.roblox.com/asset/?id=507770453", weight = 10 }
  172.             },
  173.     dance = {
  174.                 { id = "http://www.roblox.com/asset/?id=507771019", weight = 10 },
  175.                 { id = "http://www.roblox.com/asset/?id=507771955", weight = 10 },
  176.                 { id = "http://www.roblox.com/asset/?id=507772104", weight = 10 }
  177.             },
  178.     dance2 = {
  179.                 { id = "http://www.roblox.com/asset/?id=507776043", weight = 10 },
  180.                 { id = "http://www.roblox.com/asset/?id=507776720", weight = 10 },
  181.                 { id = "http://www.roblox.com/asset/?id=507776879", weight = 10 }
  182.             },
  183.     dance3 = {
  184.                 { id = "http://www.roblox.com/asset/?id=507777268", weight = 10 },
  185.                 { id = "http://www.roblox.com/asset/?id=507777451", weight = 10 },
  186.                 { id = "http://www.roblox.com/asset/?id=507777623", weight = 10 }
  187.             },
  188.     laugh = {
  189.                 { id = "http://www.roblox.com/asset/?id=507770818", weight = 10 }
  190.             },
  191.     cheer = {
  192.                 { id = "http://www.roblox.com/asset/?id=507770677", weight = 10 }
  193.             },
  194. }
  195.  
  196. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  197. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  198.  
  199. local PreloadAnimsUserFlag = false
  200. local successPreloadAnim, msgPreloadAnim = pcall(function()
  201.     PreloadAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserPreloadAnimations")
  202. end)
  203. if not successPreloadAnim then
  204.     PreloadAnimsUserFlag = false
  205. end
  206.  
  207. math.randomseed(tick())
  208.  
  209. function configureAnimationSet(name, fileList)
  210.     if (animTable[name] ~= nil) then
  211.         for _, connection in pairs(animTable[name].connections) do
  212.             connection:disconnect()
  213.         end
  214.     end
  215.     animTable[name] = {}
  216.     animTable[name].count = 0
  217.     animTable[name].totalWeight = 0
  218.     animTable[name].connections = {}
  219.  
  220.     local allowCustomAnimations = true
  221.     local AllowDisableCustomAnimsUserFlag = false
  222.  
  223.     local success, msg = pcall(function()
  224.         AllowDisableCustomAnimsUserFlag = UserSettings():IsUserFeatureEnabled("UserAllowDisableCustomAnims2")
  225.     end)
  226.  
  227.     if (AllowDisableCustomAnimsUserFlag) then
  228.         local success, msg = pcall(function() allowCustomAnimations = game:GetService("StarterPlayer").AllowCustomAnimations end)
  229.         if not success then
  230.             allowCustomAnimations = true
  231.         end
  232.     end
  233.  
  234.     -- check for config values
  235.     local config = script:FindFirstChild(name)
  236.     if (allowCustomAnimations and config ~= nil) then
  237.         table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  238.         table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  239.         local idx = 1
  240.         for _, childPart in pairs(config:GetChildren()) do
  241.             if (childPart:IsA("Animation")) then
  242.                 table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  243.                 animTable[name][idx] = {}
  244.                 animTable[name][idx].anim = childPart
  245.                 local weightObject = childPart:FindFirstChild("Weight")
  246.                 if (weightObject == nil) then
  247.                     animTable[name][idx].weight = 1
  248.                 else
  249.                     animTable[name][idx].weight = weightObject.Value
  250.                 end
  251.                 animTable[name].count = animTable[name].count + 1
  252.                 animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  253.                 idx = idx + 1
  254.             end
  255.         end
  256.     end
  257.  
  258.     -- fallback to defaults
  259.     if (animTable[name].count <= 0) then
  260.         for idx, anim in pairs(fileList) do
  261.             animTable[name][idx] = {}
  262.             animTable[name][idx].anim = Instance.new("Animation")
  263.             animTable[name][idx].anim.Name = name
  264.             animTable[name][idx].anim.AnimationId = anim.id
  265.             animTable[name][idx].weight = anim.weight
  266.             animTable[name].count = animTable[name].count + 1
  267.             animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  268. --          print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  269.         end
  270.     end
  271.    
  272.     -- preload anims
  273.     if PreloadAnimsUserFlag then
  274.         for i, animType in pairs(animTable) do
  275.             for idx = 1, animType.count, 1 do
  276.                 Humanoid:LoadAnimation(animType[idx].anim)
  277.             end
  278.         end
  279.     end
  280. end
  281.  
  282. -- Setup animation objects
  283. function scriptChildModified(child)
  284.     local fileList = animNames[child.Name]
  285.     if (fileList ~= nil) then
  286.         configureAnimationSet(child.Name, fileList)
  287.     end
  288. end
  289.  
  290. script.ChildAdded:connect(scriptChildModified)
  291. script.ChildRemoved:connect(scriptChildModified)
  292.  
  293.  
  294. for name, fileList in pairs(animNames) do
  295.     configureAnimationSet(name, fileList)
  296. end
  297.  
  298. -- ANIMATION
  299.  
  300. -- declarations
  301. local toolAnim = "None"
  302. local toolAnimTime = 0
  303.  
  304. local jumpAnimTime = 0
  305. local jumpAnimDuration = 0.31
  306.  
  307. local toolTransitionTime = 0.1
  308. local fallTransitionTime = 0.2
  309.  
  310. -- functions
  311.  
  312. function stopAllAnimations()
  313.     local oldAnim = currentAnim
  314.  
  315.     -- return to idle if finishing an emote
  316.     if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  317.         oldAnim = "idle"
  318.     end
  319.  
  320.     currentAnim = ""
  321.     currentAnimInstance = nil
  322.     if (currentAnimKeyframeHandler ~= nil) then
  323.         currentAnimKeyframeHandler:disconnect()
  324.     end
  325.  
  326.     if (currentAnimTrack ~= nil) then
  327.         currentAnimTrack:Stop()
  328.         currentAnimTrack:Destroy()
  329.         currentAnimTrack = nil
  330.     end
  331.  
  332.     -- clean up walk if there is one
  333.     if (runAnimKeyframeHandler ~= nil) then
  334.         runAnimKeyframeHandler:disconnect()
  335.     end
  336.    
  337.     if (runAnimTrack ~= nil) then
  338.         runAnimTrack:Stop()
  339.         runAnimTrack:Destroy()
  340.         runAnimTrack = nil
  341.     end
  342.    
  343.     return oldAnim
  344. end
  345.  
  346. function getHeightScale()
  347.     if Humanoid then
  348.         local bodyHeightScale = Humanoid:FindFirstChild("BodyHeightScale")
  349.         if bodyHeightScale and bodyHeightScale:IsA("NumberValue") then
  350.             return bodyHeightScale.Value
  351.         end
  352.     end
  353.    
  354.     return 1
  355. end
  356.  
  357. local smallButNotZero = 0.0001
  358. function setRunSpeed(speed)
  359.     if speed < 0.33 then
  360.         currentAnimTrack:AdjustWeight(1.0)     
  361.         runAnimTrack:AdjustWeight(smallButNotZero)
  362.     elseif speed < 0.66 then
  363.         local weight = ((speed - 0.33) / 0.33)
  364.         currentAnimTrack:AdjustWeight(1.0 - weight + smallButNotZero)
  365.         runAnimTrack:AdjustWeight(weight + smallButNotZero)
  366.     else
  367.         currentAnimTrack:AdjustWeight(smallButNotZero)
  368.         runAnimTrack:AdjustWeight(1.0)
  369.     end
  370.    
  371.     local speedScaled = speed * 1.25
  372.  
  373.     local heightScale = getHeightScale()   
  374.    
  375.     runAnimTrack:AdjustSpeed(speedScaled / heightScale)
  376.     currentAnimTrack:AdjustSpeed(speedScaled / heightScale)
  377. end
  378.  
  379.  
  380. function setAnimationSpeed(speed)
  381.     if speed ~= currentAnimSpeed then
  382.         currentAnimSpeed = speed
  383.         if currentAnim == "walk" then
  384.             setRunSpeed(speed)
  385.         else
  386.             currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  387.         end
  388.     end
  389. end
  390.  
  391. function keyFrameReachedFunc(frameName)
  392.     if (frameName == "End") then
  393.         if currentAnim == "walk" then
  394.             runAnimTrack.TimePosition = 0.0
  395.             currentAnimTrack.TimePosition = 0.0
  396.         else
  397.             local repeatAnim = currentAnim
  398.             -- return to idle if finishing an emote
  399.             if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  400.                 repeatAnim = "idle"
  401.             end
  402.            
  403.             local animSpeed = currentAnimSpeed
  404.             playAnimation(repeatAnim, 0.15, Humanoid)
  405.             setAnimationSpeed(animSpeed)
  406.         end
  407.     end
  408. end
  409.  
  410. function rollAnimation(animName)
  411.     local roll = math.random(1, animTable[animName].totalWeight)
  412.     local origRoll = roll
  413.     local idx = 1
  414.     while (roll > animTable[animName][idx].weight) do
  415.         roll = roll - animTable[animName][idx].weight
  416.         idx = idx + 1
  417.     end
  418.     return idx
  419. end
  420.  
  421. function playAnimation(animName, transitionTime, humanoid)  
  422.     local idx = rollAnimation(animName)
  423.     local anim = animTable[animName][idx].anim
  424.  
  425.     -- switch animation    
  426.     if (anim ~= currentAnimInstance) then
  427.        
  428.         if (currentAnimTrack ~= nil) then
  429.             currentAnimTrack:Stop(transitionTime)
  430.             currentAnimTrack:Destroy()
  431.         end
  432.  
  433.         if (runAnimTrack ~= nil) then
  434.             runAnimTrack:Stop(transitionTime)
  435.             runAnimTrack:Destroy()
  436.         end
  437.  
  438.         currentAnimSpeed = 1.0
  439.    
  440.         -- load it to the humanoid; get AnimationTrack
  441.         currentAnimTrack = humanoid:LoadAnimation(anim)
  442.         currentAnimTrack.Priority = Enum.AnimationPriority.Core
  443.          
  444.         -- play the animation
  445.         currentAnimTrack:Play(transitionTime)
  446.         currentAnim = animName
  447.         currentAnimInstance = anim
  448.  
  449.         -- set up keyframe name triggers
  450.         if (currentAnimKeyframeHandler ~= nil) then
  451.             currentAnimKeyframeHandler:disconnect()
  452.         end
  453.         currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  454.        
  455.         -- check to see if we need to blend a walk/run animation
  456.         if animName == "walk" then
  457.             local runAnimName = "run"
  458.             local runIdx = rollAnimation(runAnimName)
  459.  
  460.             runAnimTrack = humanoid:LoadAnimation(animTable[runAnimName][runIdx].anim)
  461.             runAnimTrack.Priority = Enum.AnimationPriority.Core
  462.             runAnimTrack:Play(transitionTime)      
  463.            
  464.             if (runAnimKeyframeHandler ~= nil) then
  465.                 runAnimKeyframeHandler:disconnect()
  466.             end
  467.             runAnimKeyframeHandler = runAnimTrack.KeyframeReached:connect(keyFrameReachedFunc) 
  468.         end
  469.     end
  470.  
  471. end
  472.  
  473. -------------------------------------------------------------------------------------------
  474. -------------------------------------------------------------------------------------------
  475.  
  476. local toolAnimName = ""
  477. local toolAnimTrack = nil
  478. local toolAnimInstance = nil
  479. local currentToolAnimKeyframeHandler = nil
  480.  
  481. function toolKeyFrameReachedFunc(frameName)
  482.     if (frameName == "End") then
  483.         playToolAnimation(toolAnimName, 0.0, Humanoid)
  484.     end
  485. end
  486.  
  487.  
  488. function playToolAnimation(animName, transitionTime, humanoid, priority)           
  489.         local idx = rollAnimation(animName)
  490.         local anim = animTable[animName][idx].anim
  491.  
  492.         if (toolAnimInstance ~= anim) then
  493.            
  494.             if (toolAnimTrack ~= nil) then
  495.                 toolAnimTrack:Stop()
  496.                 toolAnimTrack:Destroy()
  497.                 transitionTime = 0
  498.             end
  499.                    
  500.             -- load it to the humanoid; get AnimationTrack
  501.             toolAnimTrack = humanoid:LoadAnimation(anim)
  502.             if priority then
  503.                 toolAnimTrack.Priority = priority
  504.             end
  505.              
  506.             -- play the animation
  507.             toolAnimTrack:Play(transitionTime)
  508.             toolAnimName = animName
  509.             toolAnimInstance = anim
  510.  
  511.             currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  512.         end
  513. end
  514.  
  515. function stopToolAnimations()
  516.     local oldAnim = toolAnimName
  517.  
  518.     if (currentToolAnimKeyframeHandler ~= nil) then
  519.         currentToolAnimKeyframeHandler:disconnect()
  520.     end
  521.  
  522.     toolAnimName = ""
  523.     toolAnimInstance = nil
  524.     if (toolAnimTrack ~= nil) then
  525.         toolAnimTrack:Stop()
  526.         toolAnimTrack:Destroy()
  527.         toolAnimTrack = nil
  528.     end
  529.  
  530.     return oldAnim
  531. end
  532.  
  533. -------------------------------------------------------------------------------------------
  534. -------------------------------------------------------------------------------------------
  535. -- STATE CHANGE HANDLERS
  536.  
  537. function onRunning(speed)
  538.     if speed > 0.5 then
  539.         local scale = 16.0
  540.         playAnimation("walk", 0.2, Humanoid)
  541.         setAnimationSpeed(speed / scale)
  542.         pose = "Running"
  543.     else
  544.         if emoteNames[currentAnim] == nil then
  545.             playAnimation("idle", 0.2, Humanoid)
  546.             pose = "Standing"
  547.         end
  548.     end
  549. end
  550.  
  551. function onDied()
  552.     pose = "Dead"
  553. end
  554.  
  555. function onJumping()
  556.     playAnimation("jump", 0.1, Humanoid)
  557.     jumpAnimTime = jumpAnimDuration
  558.     pose = "Jumping"
  559. end
  560.  
  561. function onClimbing(speed)
  562.     local scale = 5.0
  563.     playAnimation("climb", 0.1, Humanoid)
  564.     setAnimationSpeed(speed / scale)
  565.     pose = "Climbing"
  566. end
  567.  
  568. function onGettingUp()
  569.     pose = "GettingUp"
  570. end
  571.  
  572. function onFreeFall()
  573.     if (jumpAnimTime <= 0) then
  574.         playAnimation("fall", fallTransitionTime, Humanoid)
  575.     end
  576.     pose = "FreeFall"
  577. end
  578.  
  579. function onFallingDown()
  580.     pose = "FallingDown"
  581. end
  582.  
  583. function onSeated()
  584.     pose = "Seated"
  585. end
  586.  
  587. function onPlatformStanding()
  588.     pose = "PlatformStanding"
  589. end
  590.  
  591. -------------------------------------------------------------------------------------------
  592. -------------------------------------------------------------------------------------------
  593.  
  594. function onSwimming(speed)
  595.     if speed > 1.00 then
  596.         local scale = 10.0
  597.         playAnimation("swim", 0.4, Humanoid)
  598.         setAnimationSpeed(speed / scale)
  599.         pose = "Swimming"
  600.     else
  601.         playAnimation("swimidle", 0.4, Humanoid)
  602.         pose = "Standing"
  603.     end
  604. end
  605.  
  606. function animateTool()
  607.     if (toolAnim == "None") then
  608.         playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
  609.         return
  610.     end
  611.  
  612.     if (toolAnim == "Slash") then
  613.         playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
  614.         return
  615.     end
  616.  
  617.     if (toolAnim == "Lunge") then
  618.         playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
  619.         return
  620.     end
  621. end
  622.  
  623. function getToolAnim(tool)
  624.     for _, c in ipairs(tool:GetChildren()) do
  625.         if c.Name == "toolanim" and c.className == "StringValue" then
  626.             return c
  627.         end
  628.     end
  629.     return nil
  630. end
  631.  
  632. local lastTick = 0
  633.  
  634. function stepAnimate(currentTime)
  635.     local amplitude = 1
  636.     local frequency = 1
  637.     local deltaTime = currentTime - lastTick
  638.     lastTick = currentTime
  639.  
  640.     local climbFudge = 0
  641.     local setAngles = false
  642.  
  643.     if (jumpAnimTime > 0) then
  644.         jumpAnimTime = jumpAnimTime - deltaTime
  645.     end
  646.  
  647.     if (pose == "FreeFall" and jumpAnimTime <= 0) then
  648.         playAnimation("fall", fallTransitionTime, Humanoid)
  649.     elseif (pose == "Seated") then
  650.         playAnimation("sit", 0.5, Humanoid)
  651.         return
  652.     elseif (pose == "Running") then
  653.         playAnimation("walk", 0.2, Humanoid)
  654.     elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  655.         stopAllAnimations()
  656.         amplitude = 0.1
  657.         frequency = 1
  658.         setAngles = true
  659.     end
  660.  
  661.     -- Tool Animation handling
  662.     local tool = Character:FindFirstChildOfClass("Tool")
  663.     local requireHandleCheck = not UserSettings():IsUserFeatureEnabled("UserToolR15Fix")
  664.     if tool and ((requireHandleCheck and tool.RequiresHandle) or tool:FindFirstChild("Handle")) then
  665.         local animStringValueObject = getToolAnim(tool)
  666.  
  667.         if animStringValueObject then
  668.             toolAnim = animStringValueObject.Value
  669.             -- message recieved, delete StringValue
  670.             animStringValueObject.Parent = nil
  671.             toolAnimTime = currentTime + .3
  672.         end
  673.  
  674.         if currentTime > toolAnimTime then
  675.             toolAnimTime = 0
  676.             toolAnim = "None"
  677.         end
  678.  
  679.         animateTool()      
  680.     else
  681.         stopToolAnimations()
  682.         toolAnim = "None"
  683.         toolAnimInstance = nil
  684.         toolAnimTime = 0
  685.     end
  686. end
  687.  
  688. -- connect events
  689. Humanoid.Died:connect(onDied)
  690. Humanoid.Running:connect(onRunning)
  691. Humanoid.Jumping:connect(onJumping)
  692. Humanoid.Climbing:connect(onClimbing)
  693. Humanoid.GettingUp:connect(onGettingUp)
  694. Humanoid.FreeFalling:connect(onFreeFall)
  695. Humanoid.FallingDown:connect(onFallingDown)
  696. Humanoid.Seated:connect(onSeated)
  697. Humanoid.PlatformStanding:connect(onPlatformStanding)
  698. Humanoid.Swimming:connect(onSwimming)
  699.  
  700. -- setup emote chat hook
  701. game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
  702.     local emote = ""
  703.     if (string.sub(msg, 1, 3) == "/e ") then
  704.         emote = string.sub(msg, 4)
  705.     elseif (string.sub(msg, 1, 7) == "/emote ") then
  706.         emote = string.sub(msg, 8)
  707.     end
  708.    
  709.     if (pose == "Standing" and emoteNames[emote] ~= nil) then
  710.         playAnimation(emote, 0.1, Humanoid)
  711.     end
  712. end)
  713.  
  714.  
  715.  
  716. -- initialize to idle
  717. playAnimation("idle", 0.1, Humanoid)
  718. pose = "Standing"
  719.  
  720. -- loop to handle timed state transitions and tool animations
  721. while Character.Parent ~= nil do
  722.     local _, currentGameTime = wait(0.1)
  723.     stepAnimate(currentGameTime)
  724. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement