Advertisement
Animescapetower

EH

Dec 4th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.45 KB | None | 0 0
  1. local s = Instance.new("Sound")
  2. s.Name = "BGMusic"
  3. s.SoundId = "http://www.roblox.com/asset/?id=228576456"
  4. s.Pitch = 1
  5. s.Volume = 1
  6. s.Looped = true
  7. s.archivable = false
  8. s.Parent = game.Workspace
  9. wait(0.1)
  10. s:play()
  11. function waitForChild(parent, childName)
  12. local child = parent:findFirstChild(childName)
  13. if child then return child end
  14. while true do
  15. child = parent.ChildAdded:wait()
  16. if child.Name==childName then return child end
  17. end
  18. end
  19.  
  20. local Figure = script.Parent
  21. local Torso = waitForChild(Figure, "Torso")
  22. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  23. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  24. local RightHip = waitForChild(Torso, "Right Hip")
  25. local LeftHip = waitForChild(Torso, "Left Hip")
  26. local Neck = waitForChild(Torso, "Neck")
  27. local Humanoid = waitForChild(Figure, "Humanoid")
  28. local pose = "Standing"
  29.  
  30. local currentAnim = ""
  31. local currentAnimTrack = nil
  32. local currentAnimKeyframeHandler = nil
  33. local currentAnimSpeed = 1.0
  34. local oldAnimTrack = nil
  35. local animTable = {}
  36. local animNames = {
  37. idle = {
  38. { id = "rbxassetid://1218803113", weight = 9 },
  39. { id = "rbxassetid://1218803113", weight = 1 }
  40. },
  41. walk = {
  42. { id = "rbxassetid://1218805656", weight = 10 }
  43. },
  44. run = {
  45. { id = "run.xml", weight = 10 }
  46. },
  47. jump = {
  48. { id = "rbxassetid://1218804094", weight = 10 }
  49. },
  50. fall = {
  51. { id = "rbxassetid://125750759", weight = 10 }
  52. },
  53. climb = {
  54. { id = "rbxassetid://125750800", weight = 10 }
  55. },
  56. toolnone = {
  57. { id = "rbxassetid://125750867", weight = 10 }
  58. },
  59. toolslash = {
  60. { id = "rbxassetid://129967390", weight = 10 }
  61. -- { id = "slash.xml", weight = 10 }
  62. },
  63. toollunge = {
  64. { id = "rbxassetid://129967478", weight = 10 }
  65. },
  66. wave = {
  67. { id = "rbxassetid://128777973", weight = 10 }
  68. },
  69. point = {
  70. { id = "rbxassetid://128853357", weight = 10 }
  71. },
  72. dance = {
  73. { id = "rbxassetid://130018893", weight = 10 },
  74. { id = "rbxassetid://132546839", weight = 10 },
  75. { id = "rbxassetid://132546884", weight = 10 }
  76. },
  77. laugh = {
  78. { id = "rbxassetid://129423131", weight = 10 }
  79. },
  80. cheer = {
  81. { id = "rbxassetid://=129423030", weight = 10 }
  82. },
  83. }
  84.  
  85. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  86. local emoteNames = { wave = false, point = false, dance = true, laugh = false, cheer = false}
  87.  
  88. math.randomseed(tick())
  89.  
  90. -- Setup animation objects
  91. for name, fileList in pairs(animNames) do
  92. animTable[name] = {}
  93. animTable[name].count = 0
  94. animTable[name].totalWeight = 0
  95.  
  96. -- check for config values
  97. local config = script:FindFirstChild(name)
  98. if (config ~= nil) then
  99. -- print("Loading anims " .. name)
  100. local idx = 1
  101. for _, childPart in pairs(config:GetChildren()) do
  102. animTable[name][idx] = {}
  103. animTable[name][idx].anim = childPart
  104. local weightObject = childPart:FindFirstChild("Weight")
  105. if (weightObject == nil) then
  106. animTable[name][idx].weight = 1
  107. else
  108. animTable[name][idx].weight = weightObject.Value
  109. end
  110. animTable[name].count = animTable[name].count + 1
  111. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  112. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  113. idx = idx + 1
  114. end
  115. end
  116.  
  117. -- fallback to defaults
  118. if (animTable[name].count <= 0) then
  119. for idx, anim in pairs(fileList) do
  120. animTable[name][idx] = {}
  121. animTable[name][idx].anim = Instance.new("Animation")
  122. animTable[name][idx].anim.Name = name
  123. animTable[name][idx].anim.AnimationId = anim.id
  124. animTable[name][idx].weight = anim.weight
  125. animTable[name].count = animTable[name].count + 1
  126. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  127. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  128. end
  129. end
  130. end
  131.  
  132. -- ANIMATION
  133.  
  134. -- declarations
  135. local toolAnim = "None"
  136. local toolAnimTime = 0
  137.  
  138. local jumpAnimTime = 0
  139. local jumpAnimDuration = 0.175
  140.  
  141. local toolTransitionTime = 0.1
  142. local fallTransitionTime = 0.2
  143. local jumpMaxLimbVelocity = 0.75
  144.  
  145. -- functions
  146.  
  147. function stopAllAnimations()
  148. local oldAnim = currentAnim
  149.  
  150. -- return to idle if finishing an emote
  151. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  152. oldAnim = "idle"
  153. end
  154.  
  155. currentAnim = ""
  156. if (currentAnimKeyframeHandler ~= nil) then
  157. currentAnimKeyframeHandler:disconnect()
  158. end
  159.  
  160. if (oldAnimTrack ~= nil) then
  161. oldAnimTrack:Stop()
  162. oldAnimTrack:Destroy()
  163. oldAnimTrack = nil
  164. end
  165. if (currentAnimTrack ~= nil) then
  166. currentAnimTrack:Stop()
  167. currentAnimTrack:Destroy()
  168. currentAnimTrack = nil
  169. end
  170. return oldAnim
  171. end
  172.  
  173. function setAnimationSpeed(speed)
  174. if speed ~= currentAnimSpeed then
  175. currentAnimSpeed = speed
  176. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  177. end
  178. end
  179.  
  180. function keyFrameReachedFunc(frameName)
  181. if (frameName == "End") then
  182. -- print("Keyframe : ".. frameName)
  183. local repeatAnim = stopAllAnimations()
  184. local animSpeed = currentAnimSpeed
  185. playAnimation(repeatAnim, 0.0, Humanoid)
  186. setAnimationSpeed(animSpeed)
  187. end
  188. end
  189.  
  190. -- Preload animations
  191. function playAnimation(animName, transitionTime, humanoid)
  192. if (animName ~= currentAnim) then
  193.  
  194. if (oldAnimTrack ~= nil) then
  195. oldAnimTrack:Stop()
  196. oldAnimTrack:Destroy()
  197. end
  198.  
  199. currentAnimSpeed = 1.0
  200. local roll = math.random(1, animTable[animName].totalWeight)
  201. local origRoll = roll
  202. local idx = 1
  203. while (roll > animTable[animName][idx].weight) do
  204. roll = roll - animTable[animName][idx].weight
  205. idx = idx + 1
  206. end
  207. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  208. local anim = animTable[animName][idx].anim
  209.  
  210. -- load it to the humanoid; get AnimationTrack
  211. oldAnimTrack = currentAnimTrack
  212. currentAnimTrack = humanoid:LoadAnimation(anim)
  213.  
  214. -- play the animation
  215. currentAnimTrack:Play(transitionTime)
  216. currentAnim = animName
  217.  
  218. -- set up keyframe name triggers
  219. if (currentAnimKeyframeHandler ~= nil) then
  220. currentAnimKeyframeHandler:disconnect()
  221. end
  222. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  223. end
  224. end
  225.  
  226. -------------------------------------------------------------------------------------------
  227. -------------------------------------------------------------------------------------------
  228.  
  229. local toolAnimName = ""
  230. local toolOldAnimTrack = nil
  231. local toolAnimTrack = nil
  232. local currentToolAnimKeyframeHandler = nil
  233.  
  234. function toolKeyFrameReachedFunc(frameName)
  235. if (frameName == "End") then
  236. -- print("Keyframe : ".. frameName)
  237. local repeatAnim = stopToolAnimations()
  238. playToolAnimation(repeatAnim, 0.0, Humanoid)
  239. end
  240. end
  241.  
  242.  
  243. function playToolAnimation(animName, transitionTime, humanoid)
  244. if (animName ~= toolAnimName) then
  245.  
  246. if (toolAnimTrack ~= nil) then
  247. toolAnimTrack:Stop()
  248. toolAnimTrack:Destroy()
  249. transitionTime = 0
  250. end
  251.  
  252. local roll = math.random(1, animTable[animName].totalWeight)
  253. local origRoll = roll
  254. local idx = 1
  255. while (roll > animTable[animName][idx].weight) do
  256. roll = roll - animTable[animName][idx].weight
  257. idx = idx + 1
  258. end
  259. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  260. local anim = animTable[animName][idx].anim
  261.  
  262. -- load it to the humanoid; get AnimationTrack
  263. toolOldAnimTrack = toolAnimTrack
  264. toolAnimTrack = humanoid:LoadAnimation(anim)
  265.  
  266. -- play the animation
  267. toolAnimTrack:Play(transitionTime)
  268. toolAnimName = animName
  269.  
  270. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  271. end
  272. end
  273.  
  274. function stopToolAnimations()
  275. local oldAnim = toolAnimName
  276.  
  277. if (currentToolAnimKeyframeHandler ~= nil) then
  278. currentToolAnimKeyframeHandler:disconnect()
  279. end
  280.  
  281. toolAnimName = ""
  282. if (toolAnimTrack ~= nil) then
  283. toolAnimTrack:Stop()
  284. toolAnimTrack:Destroy()
  285. toolAnimTrack = nil
  286. end
  287.  
  288.  
  289. return oldAnim
  290. end
  291.  
  292. -------------------------------------------------------------------------------------------
  293. -------------------------------------------------------------------------------------------
  294.  
  295.  
  296. function onRunning(speed)
  297. if speed>0 then
  298. playAnimation("walk", 0.1, Humanoid)
  299. pose = "Running"
  300. else
  301. playAnimation("idle", 0.1, Humanoid)
  302. pose = "Standing"
  303. end
  304. end
  305.  
  306. function onDied()
  307. pose = "Dead"
  308. end
  309.  
  310. function onJumping()
  311. playAnimation("jump", 0.1, Humanoid)
  312. jumpAnimTime = jumpAnimDuration
  313. pose = "Jumping"
  314. end
  315.  
  316. function onClimbing(speed)
  317. playAnimation("climb", 0.1, Humanoid)
  318. setAnimationSpeed(speed / 12.0)
  319. pose = "Climbing"
  320. end
  321.  
  322. function onGettingUp()
  323. pose = "GettingUp"
  324. end
  325.  
  326. function onFreeFall()
  327. if (jumpAnimTime <= 0) then
  328. playAnimation("fall", fallTransitionTime, Humanoid)
  329. end
  330. pose = "FreeFall"
  331. end
  332.  
  333. function onFallingDown()
  334. pose = "FallingDown"
  335. end
  336.  
  337. function onSeated()
  338. pose = "Seated"
  339. end
  340.  
  341. function onPlatformStanding()
  342. pose = "PlatformStanding"
  343. end
  344.  
  345. function onSwimming(speed)
  346. if speed>0 then
  347. pose = "Running"
  348. else
  349. pose = "Standing"
  350. end
  351. end
  352.  
  353. function getTool()
  354. for _, kid in ipairs(Figure:GetChildren()) do
  355. if kid.className == "Tool" then return kid end
  356. end
  357. return nil
  358. end
  359.  
  360. function getToolAnim(tool)
  361. for _, c in ipairs(tool:GetChildren()) do
  362. if c.Name == "toolanim" and c.className == "StringValue" then
  363. return c
  364. end
  365. end
  366. return nil
  367. end
  368.  
  369. function animateTool()
  370.  
  371. if (toolAnim == "None") then
  372. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  373. return
  374. end
  375.  
  376. if (toolAnim == "Slash") then
  377. playToolAnimation("toolslash", 0, Humanoid)
  378. return
  379. end
  380.  
  381. if (toolAnim == "Lunge") then
  382. playToolAnimation("toollunge", 0, Humanoid)
  383. return
  384. end
  385. end
  386.  
  387. function moveSit()
  388. RightShoulder.MaxVelocity = 0.15
  389. LeftShoulder.MaxVelocity = 0.15
  390. RightShoulder:SetDesiredAngle(3.14 /2)
  391. LeftShoulder:SetDesiredAngle(-3.14 /2)
  392. RightHip:SetDesiredAngle(3.14 /2)
  393. LeftHip:SetDesiredAngle(-3.14 /2)
  394. end
  395.  
  396. local lastTick = 0
  397.  
  398. function move(time)
  399. local amplitude = 1
  400. local frequency = 1
  401. local deltaTime = time - lastTick
  402. lastTick = time
  403.  
  404. local climbFudge = 0
  405. local setAngles = false
  406.  
  407. if (jumpAnimTime > 0) then
  408. jumpAnimTime = jumpAnimTime - deltaTime
  409. end
  410.  
  411. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  412. playAnimation("fall", fallTransitionTime, Humanoid)
  413. elseif (pose == "Seated") then
  414. stopAllAnimations()
  415. moveSit()
  416. return
  417. elseif (pose == "Running") then
  418. playAnimation("walk", 0.1, Humanoid)
  419. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  420. -- print("Wha " .. pose)
  421. amplitude = 0.1
  422. frequency = 1
  423. setAngles = true
  424. end
  425.  
  426. if (setAngles) then
  427. desiredAngle = amplitude * math.sin(time * frequency)
  428.  
  429. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  430. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  431. RightHip:SetDesiredAngle(-desiredAngle)
  432. LeftHip:SetDesiredAngle(-desiredAngle)
  433. end
  434.  
  435. -- Tool Animation handling
  436. local tool = getTool()
  437. if tool then
  438.  
  439. animStringValueObject = getToolAnim(tool)
  440.  
  441. if animStringValueObject then
  442. toolAnim = animStringValueObject.Value
  443. -- message recieved, delete StringValue
  444. animStringValueObject.Parent = nil
  445. toolAnimTime = time + .3
  446. end
  447.  
  448. if time > toolAnimTime then
  449. toolAnimTime = 0
  450. toolAnim = "None"
  451. end
  452.  
  453. animateTool()
  454. else
  455. stopToolAnimations()
  456. toolAnim = "None"
  457. toolAnimTime = 0
  458. end
  459. end
  460.  
  461. -- connect events
  462. Humanoid.Died:connect(onDied)
  463. Humanoid.Running:connect(onRunning)
  464. Humanoid.Jumping:connect(onJumping)
  465. Humanoid.Climbing:connect(onClimbing)
  466. Humanoid.GettingUp:connect(onGettingUp)
  467. Humanoid.FreeFalling:connect(onFreeFall)
  468. Humanoid.FallingDown:connect(onFallingDown)
  469. Humanoid.Seated:connect(onSeated)
  470. Humanoid.PlatformStanding:connect(onPlatformStanding)
  471. Humanoid.Swimming:connect(onSwimming)
  472.  
  473. -- setup emote chat hook
  474. Game.Players.LocalPlayer.Chatted:connect(function(msg)
  475. local emote = ""
  476. if (string.sub(msg, 1, 3) == "/e ") then
  477. emote = string.sub(msg, 4)
  478. elseif (string.sub(msg, 1, 7) == "/emote ") then
  479. emote = string.sub(msg, 8)
  480. end
  481.  
  482. if (pose == "Standing" and emoteNames[emote] ~= nil) then
  483. playAnimation(emote, 0.1, Humanoid)
  484. end
  485. -- print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
  486. end)
  487.  
  488.  
  489. -- main program
  490.  
  491. local runService = game:service("RunService");
  492.  
  493. -- initialize to idle
  494. playAnimation("idle", 0.1, Humanoid)
  495. pose = "Standing"
  496.  
  497. while Figure.Parent~=nil do
  498. local _, time = wait(0.1)
  499. move(time)
  500. end
  501.  
  502.  
  503.  
  504.  
  505. game.Players.PlayerAdded:connect(function(player)
  506.  
  507. local leaderstats = Instance.new("IntValue")
  508. leaderstats.Name = "leaderstats"
  509. leaderstats.Value = 0
  510.  
  511. local rank = Instance.new("StringValue")
  512. rank.Name = "Rank"
  513. rank.Value = player:GetRoleInGroup(2863574) -- put group id in parentheses
  514.  
  515. leaderstats.Parent = player
  516. rank.Parent = leaderstats
  517.  
  518. end)
  519.  
  520.  
  521. local debounce = false
  522.  
  523.  
  524. function onHit(hit)
  525. local human = hit.Parent:findFirstChild("Humanoid")
  526. if (human ~= nil) and debounce == false then
  527.  
  528. debounce = true
  529.  
  530. local message = Instance.new("Message")
  531. message.Text = "Hey you guy's"
  532. message.Parent = game.Players:playerFromCharacter(hit.Parent)
  533. wait(4)
  534. message.Text = "Nope you don't deserve animation"
  535. wait(4)
  536. message.Text = "WELP GOOD NIGHT"
  537. message:remove()
  538.  
  539. debounce = false
  540. end
  541. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement