Advertisement
1x1x1x1IAMbck

animations

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