Advertisement
Guest User

Untitled

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