Advertisement
1x1x1x1IAMbck

Animations only

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