Josemmoya

Untitled

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