Advertisement
rolexttp

ChatGpt StringyBoi

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