Advertisement
Guest User

Untitled

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