SebTDZ

Untitled

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