Advertisement
Animescapetower

Untitled

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