SyntaxIsHere

Untitled

Nov 17th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | None | 0 0
  1. --Animation Script, By Syntax
  2.  
  3.  
  4. local Figure = script.Parent
  5. local Torso = Figure:WaitForChild("Torso")
  6. local RightShoulder = Torso:WaitForChild("Right Shoulder")
  7. local LeftShoulder = Torso:WaitForChild("Left Shoulder")
  8. local RightHip = Torso:WaitForChild("Right Hip")
  9. local LeftHip = Torso:WaitForChild("Left Hip")
  10. local Neck = Torso:WaitForChild("Neck")
  11. local Humanoid = Figure:WaitForChild("Humanoid")
  12. local pose = "Standing"
  13. local currentAnim = ""
  14. local currentAnimInstance, currentAnimTrack, currentAnimKeyframeHandler
  15. local currentAnimSpeed = 1
  16. local animTable = {}
  17. local animNames = {
  18. idle = {
  19. {
  20. id = "http://www.roblox.com/asset/?id=180435571",
  21. weight = 9
  22. },
  23. {
  24. id = "http://www.roblox.com/asset/?id=180435792",
  25. weight = 1
  26. }
  27. },
  28. walk = {
  29. {
  30. id = "http://www.roblox.com/asset/?id=180426354",
  31. weight = 10
  32. }
  33. },
  34. run = {
  35. {id = "run.xml", weight = 10}
  36. },
  37. jump = {
  38. {
  39. id = "http://www.roblox.com/asset/?id=125750702",
  40. weight = 10
  41. }
  42. },
  43. fall = {
  44. {
  45. id = "http://www.roblox.com/asset/?id=180436148",
  46. weight = 10
  47. }
  48. },
  49. climb = {
  50. {
  51. id = "http://www.roblox.com/asset/?id=180436334",
  52. weight = 10
  53. }
  54. },
  55. sit = {
  56. {
  57. id = "http://www.roblox.com/asset/?id=178130996",
  58. weight = 10
  59. }
  60. },
  61. toolnone = {
  62. {
  63. id = "http://www.roblox.com/asset/?id=182393478",
  64. weight = 10
  65. }
  66. },
  67. toolslash = {
  68. {
  69. id = "http://www.roblox.com/asset/?id=129967390",
  70. weight = 10
  71. }
  72. },
  73. toollunge = {
  74. {
  75. id = "http://www.roblox.com/asset/?id=129967478",
  76. weight = 10
  77. }
  78. },
  79. wave = {
  80. {
  81. id = "http://www.roblox.com/asset/?id=128777973",
  82. weight = 10
  83. }
  84. },
  85. point = {
  86. {
  87. id = "http://www.roblox.com/asset/?id=128853357",
  88. weight = 10
  89. }
  90. },
  91. dance1 = {
  92. {
  93. id = "http://www.roblox.com/asset/?id=182435998",
  94. weight = 10
  95. },
  96. {
  97. id = "http://www.roblox.com/asset/?id=182491037",
  98. weight = 10
  99. },
  100. {
  101. id = "http://www.roblox.com/asset/?id=182491065",
  102. weight = 10
  103. }
  104. },
  105. dance2 = {
  106. {
  107. id = "http://www.roblox.com/asset/?id=182436842",
  108. weight = 10
  109. },
  110. {
  111. id = "http://www.roblox.com/asset/?id=182491248",
  112. weight = 10
  113. },
  114. {
  115. id = "http://www.roblox.com/asset/?id=182491277",
  116. weight = 10
  117. }
  118. },
  119. dance3 = {
  120. {
  121. id = "http://www.roblox.com/asset/?id=182436935",
  122. weight = 10
  123. },
  124. {
  125. id = "http://www.roblox.com/asset/?id=182491368",
  126. weight = 10
  127. },
  128. {
  129. id = "http://www.roblox.com/asset/?id=182491423",
  130. weight = 10
  131. }
  132. },
  133. laugh = {
  134. {
  135. id = "http://www.roblox.com/asset/?id=129423131",
  136. weight = 10
  137. }
  138. },
  139. cheer = {
  140. {
  141. id = "http://www.roblox.com/asset/?id=129423030",
  142. weight = 10
  143. }
  144. }
  145. }
  146. local dances = {
  147. "dance1",
  148. "dance2",
  149. "dance3"
  150. }
  151. local emoteNames = {
  152. wave = false,
  153. point = false,
  154. dance1 = true,
  155. dance2 = true,
  156. dance3 = true,
  157. laugh = false,
  158. cheer = false
  159. }
  160. function configureAnimationSet(name, fileList)
  161. if animTable[name] ~= nil then
  162. for _, connection in pairs(animTable[name].connections) do
  163. connection:disconnect()
  164. end
  165. end
  166. animTable[name] = {}
  167. animTable[name].count = 0
  168. animTable[name].totalWeight = 0
  169. animTable[name].connections = {}
  170. local config = script:FindFirstChild(name)
  171. if config ~= nil then
  172. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child)
  173. configureAnimationSet(name, fileList)
  174. end))
  175. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child)
  176. configureAnimationSet(name, fileList)
  177. end))
  178. local idx = 1
  179. for _, childPart in pairs(config:GetChildren()) do
  180. if childPart:IsA("Animation") then
  181. table.insert(animTable[name].connections, childPart.Changed:connect(function(property)
  182. configureAnimationSet(name, fileList)
  183. end))
  184. animTable[name][idx] = {}
  185. animTable[name][idx].anim = childPart
  186. local weightObject = childPart:FindFirstChild("Weight")
  187. if weightObject == nil then
  188. animTable[name][idx].weight = 1
  189. else
  190. animTable[name][idx].weight = weightObject.Value
  191. end
  192. animTable[name].count = animTable[name].count + 1
  193. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  194. idx = idx + 1
  195. end
  196. end
  197. end
  198. if animTable[name].count <= 0 then
  199. for idx, anim in pairs(fileList) do
  200. animTable[name][idx] = {}
  201. animTable[name][idx].anim = Instance.new("Animation")
  202. animTable[name][idx].anim.Name = name
  203. animTable[name][idx].anim.AnimationId = anim.id
  204. animTable[name][idx].weight = anim.weight
  205. animTable[name].count = animTable[name].count + 1
  206. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  207. end
  208. end
  209. end
  210. function scriptChildModified(child)
  211. local fileList = animNames[child.Name]
  212. if fileList ~= nil then
  213. configureAnimationSet(child.Name, fileList)
  214. end
  215. end
  216. script.ChildAdded:connect(scriptChildModified)
  217. script.ChildRemoved:connect(scriptChildModified)
  218. for name, fileList in pairs(animNames) do
  219. configureAnimationSet(name, fileList)
  220. end
  221. local toolAnim = "None"
  222. local toolAnimTime = 0
  223. local jumpAnimTime = 0
  224. local jumpAnimDuration = 0.3
  225. local toolTransitionTime = 0.1
  226. local fallTransitionTime = 0.3
  227. local jumpMaxLimbVelocity = 0.75
  228. function stopAllAnimations()
  229. local oldAnim = currentAnim
  230. if emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false then
  231. oldAnim = "idle"
  232. end
  233. currentAnim = ""
  234. currentAnimInstance = nil
  235. if currentAnimKeyframeHandler ~= nil then
  236. currentAnimKeyframeHandler:disconnect()
  237. end
  238. if currentAnimTrack ~= nil then
  239. currentAnimTrack:Stop()
  240. currentAnimTrack:Destroy()
  241. currentAnimTrack = nil
  242. end
  243. return oldAnim
  244. end
  245. function setAnimationSpeed(speed)
  246. if speed ~= currentAnimSpeed then
  247. currentAnimSpeed = speed
  248. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  249. end
  250. end
  251. function keyFrameReachedFunc(frameName)
  252. if frameName == "End" then
  253. local repeatAnim = currentAnim
  254. if emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false then
  255. repeatAnim = "idle"
  256. end
  257. local animSpeed = currentAnimSpeed
  258. playAnimation(repeatAnim, 0, Humanoid)
  259. setAnimationSpeed(animSpeed)
  260. end
  261. end
  262. function playAnimation(animName, transitionTime, humanoid)
  263. local roll = math.random(1, animTable[animName].totalWeight)
  264. local origRoll = roll
  265. local idx = 1
  266. while roll > animTable[animName][idx].weight do
  267. roll = roll - animTable[animName][idx].weight
  268. idx = idx + 1
  269. end
  270. local anim = animTable[animName][idx].anim
  271. if anim ~= currentAnimInstance then
  272. if currentAnimTrack ~= nil then
  273. currentAnimTrack:Stop(transitionTime)
  274. currentAnimTrack:Destroy()
  275. end
  276. currentAnimSpeed = 1
  277. currentAnimTrack = humanoid:LoadAnimation(anim)
  278. currentAnimTrack.Priority = Enum.AnimationPriority.Core
  279. currentAnimTrack:Play(transitionTime)
  280. currentAnim = animName
  281. currentAnimInstance = anim
  282. if currentAnimKeyframeHandler ~= nil then
  283. currentAnimKeyframeHandler:disconnect()
  284. end
  285. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  286. end
  287. end
  288. local toolAnimName = ""
  289. local toolAnimTrack, toolAnimInstance, currentToolAnimKeyframeHandler
  290. function toolKeyFrameReachedFunc(frameName)
  291. if frameName == "End" then
  292. playToolAnimation(toolAnimName, 0, Humanoid)
  293. end
  294. end
  295. function playToolAnimation(animName, transitionTime, humanoid, priority)
  296. local roll = math.random(1, animTable[animName].totalWeight)
  297. local origRoll = roll
  298. local idx = 1
  299. while roll > animTable[animName][idx].weight do
  300. roll = roll - animTable[animName][idx].weight
  301. idx = idx + 1
  302. end
  303. local anim = animTable[animName][idx].anim
  304. if toolAnimInstance ~= anim then
  305. if toolAnimTrack ~= nil then
  306. toolAnimTrack:Stop()
  307. toolAnimTrack:Destroy()
  308. transitionTime = 0
  309. end
  310. toolAnimTrack = humanoid:LoadAnimation(anim)
  311. if priority then
  312. toolAnimTrack.Priority = priority
  313. end
  314. toolAnimTrack:Play(transitionTime)
  315. toolAnimName = animName
  316. toolAnimInstance = anim
  317. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  318. end
  319. end
  320. function stopToolAnimations()
  321. local oldAnim = toolAnimName
  322. if currentToolAnimKeyframeHandler ~= nil then
  323. currentToolAnimKeyframeHandler:disconnect()
  324. end
  325. toolAnimName = ""
  326. toolAnimInstance = nil
  327. if toolAnimTrack ~= nil then
  328. toolAnimTrack:Stop()
  329. toolAnimTrack:Destroy()
  330. toolAnimTrack = nil
  331. end
  332. return oldAnim
  333. end
  334. function onRunning(speed)
  335. if speed > 0.01 then
  336. playAnimation("walk", 0.1, Humanoid)
  337. if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
  338. setAnimationSpeed(speed / 14.5)
  339. end
  340. pose = "Running"
  341. elseif emoteNames[currentAnim] == nil then
  342. playAnimation("idle", 0.1, Humanoid)
  343. pose = "Standing"
  344. end
  345. end
  346. function onDied()
  347. pose = "Dead"
  348. end
  349. function onJumping()
  350. playAnimation("jump", 0.1, Humanoid)
  351. jumpAnimTime = jumpAnimDuration
  352. pose = "Jumping"
  353. end
  354. function onClimbing(speed)
  355. playAnimation("climb", 0.1, Humanoid)
  356. setAnimationSpeed(speed / 12)
  357. pose = "Climbing"
  358. end
  359. function onGettingUp()
  360. pose = "GettingUp"
  361. end
  362. function onFreeFall()
  363. if jumpAnimTime <= 0 then
  364. playAnimation("fall", fallTransitionTime, Humanoid)
  365. end
  366. pose = "FreeFall"
  367. end
  368. function onFallingDown()
  369. pose = "FallingDown"
  370. end
  371. function onSeated()
  372. pose = "Seated"
  373. end
  374. function onPlatformStanding()
  375. pose = "PlatformStanding"
  376. end
  377. function onSwimming(speed)
  378. if speed > 0 then
  379. pose = "Running"
  380. else
  381. pose = "Standing"
  382. end
  383. end
  384. function getTool()
  385. for _, kid in ipairs(Figure:GetChildren()) do
  386. if kid.className == "Tool" then
  387. return kid
  388. end
  389. end
  390. return nil
  391. end
  392. function getToolAnim(tool)
  393. for _, c in ipairs(tool:GetChildren()) do
  394. if c.Name == "toolanim" and c.className == "StringValue" then
  395. return c
  396. end
  397. end
  398. return nil
  399. end
  400. function animateTool()
  401. if toolAnim == "None" then
  402. playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
  403. return
  404. end
  405. if toolAnim == "Slash" then
  406. playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
  407. return
  408. end
  409. if toolAnim == "Lunge" then
  410. playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
  411. return
  412. end
  413. end
  414. function moveSit()
  415. RightShoulder.MaxVelocity = 0.15
  416. LeftShoulder.MaxVelocity = 0.15
  417. RightShoulder:SetDesiredAngle(1.57)
  418. LeftShoulder:SetDesiredAngle(-1.57)
  419. RightHip:SetDesiredAngle(1.57)
  420. LeftHip:SetDesiredAngle(-1.57)
  421. end
  422. local lastTick = 0
  423. function move(time)
  424. local amplitude = 1
  425. local frequency = 1
  426. local deltaTime = time - lastTick
  427. lastTick = time
  428. local climbFudge = 0
  429. local setAngles = false
  430. if jumpAnimTime > 0 then
  431. jumpAnimTime = jumpAnimTime - deltaTime
  432. end
  433. if pose == "FreeFall" and jumpAnimTime <= 0 then
  434. playAnimation("fall", fallTransitionTime, Humanoid)
  435. elseif pose == "Seated" then
  436. playAnimation("sit", 0.5, Humanoid)
  437. return
  438. elseif pose == "Running" then
  439. playAnimation("walk", 0.1, Humanoid)
  440. elseif pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding" then
  441. stopAllAnimations()
  442. amplitude = 0.1
  443. frequency = 1
  444. setAngles = true
  445. end
  446. if setAngles then
  447. local desiredAngle = amplitude * math.sin(time * frequency)
  448. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  449. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  450. RightHip:SetDesiredAngle(-desiredAngle)
  451. LeftHip:SetDesiredAngle(-desiredAngle)
  452. end
  453. local tool = getTool()
  454. if tool and tool:FindFirstChild("Handle") then
  455. local animStringValueObject = getToolAnim(tool)
  456. if animStringValueObject then
  457. toolAnim = animStringValueObject.Value
  458. animStringValueObject.Parent = nil
  459. toolAnimTime = time + 0.3
  460. end
  461. if time > toolAnimTime then
  462. toolAnimTime = 0
  463. toolAnim = "None"
  464. end
  465. animateTool()
  466. else
  467. stopToolAnimations()
  468. toolAnim = "None"
  469. toolAnimInstance = nil
  470. toolAnimTime = 0
  471. end
  472. end
  473. Humanoid.Died:connect(onDied)
  474. Humanoid.Running:connect(onRunning)
  475. Humanoid.Jumping:connect(onJumping)
  476. Humanoid.Climbing:connect(onClimbing)
  477. Humanoid.GettingUp:connect(onGettingUp)
  478. Humanoid.FreeFalling:connect(onFreeFall)
  479. Humanoid.FallingDown:connect(onFallingDown)
  480. Humanoid.Seated:connect(onSeated)
  481. Humanoid.PlatformStanding:connect(onPlatformStanding)
  482. Humanoid.Swimming:connect(onSwimming)
  483. game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
  484. local emote = ""
  485. if msg == "/e dance" then
  486. emote = dances[math.random(1, #dances)]
  487. elseif string.sub(msg, 1, 3) == "/e " then
  488. emote = string.sub(msg, 4)
  489. elseif string.sub(msg, 1, 7) == "/emote " then
  490. emote = string.sub(msg, 8)
  491. end
  492. if pose == "Standing" and emoteNames[emote] ~= nil then
  493. playAnimation(emote, 0.1, Humanoid)
  494. end
  495. end)
  496. playAnimation("idle", 0.1, Humanoid)
  497. pose = "Standing"
  498. while Figure.Parent ~= nil do
  499. local _, time = wait(0.1)
  500. move(time)
  501. end
Add Comment
Please, Sign In to add comment