Advertisement
K1ngBlitzy

r6 reanimate

Dec 18th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.37 KB | None | 0 0
  1.  
  2. HumanDied = false
  3. local CountSCIFIMOVIELOL = 1
  4. function SCIFIMOVIELOL(Part0,Part1,Position,Angle)
  5. local AlignPos = Instance.new('AlignPosition', Part1); AlignPos.Name = "AliP_"..CountSCIFIMOVIELOL
  6. AlignPos.ApplyAtCenterOfMass = true;
  7. AlignPos.MaxForce = 5772000--67752;
  8. AlignPos.MaxVelocity = math.huge/9e110;
  9. AlignPos.ReactionForceEnabled = false;
  10. AlignPos.Responsiveness = 200;
  11. AlignPos.RigidityEnabled = false;
  12. local AlignOri = Instance.new('AlignOrientation', Part1); AlignOri.Name = "AliO_"..CountSCIFIMOVIELOL
  13. AlignOri.MaxAngularVelocity = math.huge/9e110;
  14. AlignOri.MaxTorque = 5772000
  15. AlignOri.PrimaryAxisOnly = false;
  16. AlignOri.ReactionTorqueEnabled = false;
  17. AlignOri.Responsiveness = 200;
  18. AlignOri.RigidityEnabled = false;
  19. local AttachmentA=Instance.new('Attachment',Part1); AttachmentA.Name = "AthP_"..CountSCIFIMOVIELOL
  20. local AttachmentB=Instance.new('Attachment',Part0); AttachmentB.Name = "AthP_"..CountSCIFIMOVIELOL
  21. local AttachmentC=Instance.new('Attachment',Part1); AttachmentC.Name = "AthO_"..CountSCIFIMOVIELOL
  22. local AttachmentD=Instance.new('Attachment',Part0); AttachmentD.Name = "AthO_"..CountSCIFIMOVIELOL
  23. AttachmentC.Orientation = Angle or Vector3.new(0,0,0)
  24. AttachmentA.Position = Position or Vector3.new(0,0,0)
  25. AlignPos.Attachment1 = AttachmentA;
  26. AlignPos.Attachment0 = AttachmentB;
  27. AlignOri.Attachment1 = AttachmentC;
  28. AlignOri.Attachment0 = AttachmentD;
  29. CountSCIFIMOVIELOL = CountSCIFIMOVIELOL + 1
  30. return {AlignPos,AttachmentA,AttachmentB,AlignOri,AttachmentC,AttachmentD}
  31. end
  32.  
  33. if _G.netted ~= true then
  34. _G.netted = true
  35. coroutine.wrap(function()
  36. settings().Physics.PhysicsEnvironmentalThrottle = Enum.EnviromentalPhysicsThrottle.Disabled
  37. settings().Physics.ThrottleAdjustTime = math.huge*math.huge
  38. settings().Physics.AllowSleep = false
  39. game:GetService("RunService").RenderStepped:Connect(function()
  40. game:FindFirstChildOfClass("Players").LocalPlayer.MaximumSimulationRadius=math.pow(math.huge,math.huge)
  41. sethiddenproperty(game:FindFirstChildOfClass("Players").LocalPlayer,"SimulationRadius",math.huge*math.huge)
  42. end)
  43. end)()
  44. end
  45.  
  46. game:FindFirstChildOfClass("Players").LocalPlayer["Character"].Archivable = true
  47. local hatnameclone = {}
  48. for _,v in next, game:FindFirstChildOfClass("Players").LocalPlayer["Character"]:GetChildren() do
  49. if v:IsA("Accessory") then
  50. if hatnameclone[v.Name] then
  51. if hatnameclone[v.Name] == "s" then
  52. hatnameclone[v.Name] = {}
  53. end
  54. table.insert(hatnameclone[v.Name],v)
  55. else
  56. hatnameclone[v.Name] = "s"
  57. end
  58. end
  59. end
  60. for _,v in pairs(hatnameclone) do
  61. if type(v) == "table" then
  62. local num = 1
  63. for _,w in pairs(v) do
  64. w.Name = w.Name..num
  65. num = num + 1
  66. end
  67. end
  68. end
  69. hatnameclone = nil
  70. local CloneChar = game:FindFirstChildOfClass("Players").LocalPlayer["Character"]:Clone()
  71. CloneChar.Parent = game:FindFirstChildOfClass("Workspace"):FindFirstChildOfClass("Terrain")
  72. CloneChar.HumanoidRootPart.CFrame = game:FindFirstChildOfClass("Players").LocalPlayer["Character"].HumanoidRootPart.CFrame
  73. CloneChar.Humanoid.BreakJointsOnDeath = false
  74. CloneChar.Name = "non"
  75. CloneChar.Humanoid.DisplayDistanceType = "None"
  76.  
  77. local DeadChar = game:FindFirstChildOfClass("Players").LocalPlayer.Character
  78.  
  79. for _,v in next, DeadChar:GetChildren() do
  80. if v:IsA("Accessory") then
  81. local topacc = false
  82. if v.Handle:FindFirstChildOfClass("Weld") then v.Handle:FindFirstChildOfClass("Weld"):Destroy() end
  83. if v.Handle:FindFirstChildOfClass("Attachment") then
  84. local ath__ = v.Handle:FindFirstChildOfClass("Attachment")
  85. if ath__.Name == "HatAttachment" or ath__.Name == "HairAttachment" or ath__.Name == "FaceFrontAttachment" or ath__.Name == "FaceCenterAttachment" then
  86. topacc = ath__.Name
  87. end
  88. end
  89. local bv = Instance.new("BodyVelocity",v.Handle)
  90. bv.Velocity = Vector3.new(0,0,0)
  91. coroutine.wrap(function()
  92. if topacc then
  93. local allthings = SCIFIMOVIELOL(v.Handle,DeadChar.Torso,Vector3.new(0,1.5,0)+ (DeadChar.Head[topacc].Position + (v.Handle[topacc].Position*-1)),Vector3.new(0,0,0))
  94. local normaltop = allthings[1].Attachment1
  95. local alipos = allthings[1]
  96. local alirot = allthings[4]
  97. local p0 = v.Handle
  98. local p1 = DeadChar.Head
  99. while true do
  100. game:GetService("RunService").RenderStepped:wait()
  101. if HumanDied then break end
  102. coroutine.wrap(function()
  103. if alipos.Attachment1 == normaltop then
  104. p0.CFrame = (((DeadChar.Torso.CFrame * CFrame.new(0,1.5,0)) * p1[topacc].CFrame) * p0[topacc].CFrame:inverse())
  105. else
  106. v.Handle.CFrame = alipos.Attachment1.Parent.CFrame * CFrame.new(alipos.Attachment1.Position) * CFrame.Angles(math.rad(alirot.Attachment1.Rotation.X),math.rad(alirot.Attachment1.Rotation.Y),math.rad(alirot.Attachment1.Rotation.Z))
  107. end
  108. end)()
  109. end
  110. else
  111. SCIFIMOVIELOL(v.Handle,CloneChar[v.Name].Handle,Vector3.new(0,0,0),Vector3.new(0,0,0))
  112. --[[while true do
  113. game:GetService("RunService").RenderStepped:wait()
  114. if HumanDied then break end
  115. local alipos = CloneChar[v.Name].Handle:FindFirstChildOfClass("AlignPosition")
  116. local alirot = CloneChar[v.Name].Handle:FindFirstChildOfClass("AlignOrientation")
  117. v.Handle.CFrame = alipos.Attachment1.Parent.CFrame * CFrame.new(alipos.Attachment1.Position) * CFrame.Angles(math.rad(alirot.Attachment1.Rotation.X),math.rad(alirot.Attachment1.Rotation.Y),math.rad(alirot.Attachment1.Rotation.Z))
  118. end]]
  119. end
  120. end)()
  121. end
  122. end
  123.  
  124. game:FindFirstChildOfClass("Players").LocalPlayer.Character = CloneChar
  125. game:FindFirstChildOfClass("Players").LocalPlayer.Character = DeadChar
  126. local a = DeadChar.Torso
  127. local b = DeadChar.HumanoidRootPart
  128. local c = DeadChar.Humanoid
  129. a.Parent = game:FindFirstChildOfClass("Workspace")
  130. c.Parent = game:FindFirstChildOfClass("Workspace")
  131. local told = a:Clone()
  132. local told1 = c:Clone()
  133. b["RootJoint"].Part0 = told
  134. b["RootJoint"].Part1 = DeadChar.Head
  135. a.Name = "torso"
  136. a.Neck:Destroy()
  137. c.Name = "hum"
  138. told.Parent = DeadChar
  139. told1.Parent = DeadChar
  140. DeadChar.PrimaryPart = told
  141. told1.Health = 0
  142. a.Parent = DeadChar
  143. c.Parent = DeadChar
  144. b:Destroy()
  145. told:Destroy()
  146. told1:Destroy()
  147. a.Name = "Torso"
  148.  
  149. if CloneChar.Head:FindFirstChildOfClass("Decal") then CloneChar.Head:FindFirstChildOfClass("Decal").Transparency = 1 end
  150. if DeadChar:FindFirstChild("Animate") then DeadChar:FindFirstChild("Animate"):Destroy() end
  151.  
  152. local Collider
  153. function UnCollide()
  154. if HumanDied then Collider:Disconnect(); return end
  155. --[[for _,Parts in next, CloneChar:GetDescendants() do
  156. if Parts:IsA("BasePart") then
  157. Parts.CanCollide = false
  158. end
  159. end]]
  160. for _,Parts in next, DeadChar:GetDescendants() do
  161. if Parts:IsA("BasePart") then
  162. Parts.CanCollide = false
  163. end
  164. end
  165. end
  166. Collider = game:GetService("RunService").Stepped:Connect(UnCollide)
  167.  
  168. local resetBindable = Instance.new("BindableEvent")
  169. resetBindable.Event:connect(function()
  170. game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
  171. resetBindable:Destroy()
  172. HumanDied = true
  173. pcall(function()
  174. game:FindFirstChildOfClass("Players").LocalPlayer.Character = DeadChar
  175. DeadChar.hum.Name = "Humanoid"
  176. DeadChar.Humanoid.Health = 0
  177. DeadChar.Head:Destroy()
  178. game:FindFirstChildOfClass("Players").LocalPlayer.Character = CloneChar
  179. CloneChar.Humanoid.Health = 0
  180. CloneChar.Head:Destroy()
  181. for _,v in pairs(game:FindFirstChildOfClass("Workspace"):FindFirstChildOfClass("Terrain"):GetChildren()) do
  182. if v.Name == "non" then
  183. v:Destroy()
  184. end
  185. end
  186. end)
  187. end)
  188. game:GetService("StarterGui"):SetCore("ResetButtonCallback", resetBindable)
  189.  
  190. coroutine.wrap(function()
  191. while true do
  192. game:GetService("RunService").RenderStepped:wait()
  193. if not CloneChar or not CloneChar:FindFirstChild("Head") or not CloneChar:FindFirstChild("Humanoid") or CloneChar:FindFirstChild("Humanoid").Health <= 0 and not DeadChar or not DeadChar:FindFirstChild("Head") or not DeadChar:FindFirstChild("hum") or DeadChar:FindFirstChild("hum").Health <= 0 then
  194. HumanDied = true
  195. pcall(function()
  196. game:FindFirstChildOfClass("Players").LocalPlayer.Character = DeadChar
  197. DeadChar.hum.Name = "Humanoid"
  198. DeadChar.Humanoid.Health = 0
  199. DeadChar.Head:Destroy()
  200. game:FindFirstChildOfClass("Players").LocalPlayer.Character = CloneChar
  201. CloneChar.Humanoid.Health = 0
  202. CloneChar.Head:Destroy()
  203. for _,v in pairs(game:FindFirstChildOfClass("Workspace"):FindFirstChildOfClass("Terrain"):GetChildren()) do
  204. if v.Name == "non" then
  205. v:Destroy()
  206. end
  207. end
  208. end)
  209. if resetBindable then
  210. game:GetService("StarterGui"):SetCore("ResetButtonCallback", true)
  211. resetBindable:Destroy()
  212. end
  213. break
  214. end
  215. end
  216. end)()
  217.  
  218.  
  219. SCIFIMOVIELOL(DeadChar["Head"],CloneChar["Head"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  220. SCIFIMOVIELOL(DeadChar["Torso"],CloneChar["Torso"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  221. SCIFIMOVIELOL(DeadChar["Left Arm"],CloneChar["Left Arm"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  222. SCIFIMOVIELOL(DeadChar["Right Arm"],CloneChar["Right Arm"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  223. SCIFIMOVIELOL(DeadChar["Left Leg"],CloneChar["Left Leg"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  224. SCIFIMOVIELOL(DeadChar["Right Leg"],CloneChar["Right Leg"],Vector3.new(0,0,0),Vector3.new(0,0,0))
  225.  
  226. for _,v in pairs(DeadChar:GetChildren()) do
  227. if v:IsA("BasePart") and v.Name ~= "Head" then
  228. --[[local bv = Instance.new("BodyVelocity",v)
  229. bv.Velocity = Vector3.new(0,0,0)
  230. coroutine.wrap(function()
  231. while true do
  232. game:GetService("RunService").RenderStepped:wait()
  233. if HumanDied then break end
  234. v.CFrame = CloneChar[v.Name].CFrame
  235. end
  236. end)()]]
  237. elseif v:IsA("BasePart") and v.Name == "Head" then
  238. local bv = Instance.new("BodyVelocity",v)
  239. bv.Velocity = Vector3.new(0,0,0)
  240. coroutine.wrap(function()
  241. while true do
  242. game:GetService("RunService").RenderStepped:wait()
  243. if HumanDied then break end
  244. v.CFrame = DeadChar.Torso.CFrame * CFrame.new(0,1.5,0)
  245. end
  246. end)()
  247. end
  248. end
  249.  
  250. for _,BodyParts in next, CloneChar:GetDescendants() do
  251. if BodyParts:IsA("BasePart") or BodyParts:IsA("Part") then
  252. BodyParts.Transparency = 1 end end
  253. game:GetService("RunService").RenderStepped:wait()
  254. game:FindFirstChildOfClass("Players").LocalPlayer.Character = CloneChar
  255. game:FindFirstChildOfClass("Workspace"):FindFirstChildOfClass("Camera").CameraSubject = CloneChar.Humanoid
  256.  
  257. function RUNANIMATESCRIPT(FOLDER)
  258.  
  259. local Figure = FOLDER.Parent
  260. local Torso = Figure:WaitForChild("Torso")
  261. local RightShoulder = Torso:WaitForChild("Right Shoulder")
  262. local LeftShoulder = Torso:WaitForChild("Left Shoulder")
  263. local RightHip = Torso:WaitForChild("Right Hip")
  264. local LeftHip = Torso:WaitForChild("Left Hip")
  265. local Neck = Torso:WaitForChild("Neck")
  266. local Humanoid = Figure:WaitForChild("Humanoid")
  267. local pose = "Standing"
  268.  
  269. local currentAnim = ""
  270. local currentAnimInstance = nil
  271. local currentAnimTrack = nil
  272. local currentAnimKeyframeHandler = nil
  273. local currentAnimSpeed = 1.0
  274. local animTable = {}
  275. local animNames = {
  276. idle = {
  277. { id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
  278. { id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
  279. },
  280. walk = {
  281. { id = "http://www.roblox.com/asset/?id=180426354", weight = 10 }
  282. },
  283. run = {
  284. { id = "run.xml", weight = 10 }
  285. },
  286. jump = {
  287. { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  288. },
  289. fall = {
  290. { id = "http://www.roblox.com/asset/?id=180436148", weight = 10 }
  291. },
  292. climb = {
  293. { id = "http://www.roblox.com/asset/?id=180436334", weight = 10 }
  294. },
  295. sit = {
  296. { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
  297. },
  298. toolnone = {
  299. { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
  300. },
  301. toolslash = {
  302. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  303. -- { id = "slash.xml", weight = 10 }
  304. },
  305. toollunge = {
  306. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  307. },
  308. wave = {
  309. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  310. },
  311. point = {
  312. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  313. },
  314. dance1 = {
  315. { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
  316. { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
  317. { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
  318. },
  319. dance2 = {
  320. { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
  321. { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
  322. { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
  323. },
  324. dance3 = {
  325. { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
  326. { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
  327. { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
  328. },
  329. laugh = {
  330. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  331. },
  332. cheer = {
  333. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  334. },
  335. }
  336. local dances = {"dance1", "dance2", "dance3"}
  337.  
  338. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  339. local emoteNames = { wave = false, point = false, dance1 = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  340.  
  341. function configureAnimationSet(name, fileList)
  342. if (animTable[name] ~= nil) then
  343. for _, connection in pairs(animTable[name].connections) do
  344. connection:disconnect()
  345. end
  346. end
  347. animTable[name] = {}
  348. animTable[name].count = 0
  349. animTable[name].totalWeight = 0
  350. animTable[name].connections = {}
  351.  
  352. -- check for config values
  353. local config = FOLDER:FindFirstChild(name)
  354. if (config ~= nil) then
  355. -- print("Loading anims " .. name)
  356. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  357. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  358. local idx = 1
  359. for _, childPart in pairs(config:GetChildren()) do
  360. if (childPart:IsA("Animation")) then
  361. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  362. animTable[name][idx] = {}
  363. animTable[name][idx].anim = childPart
  364. local weightObject = childPart:FindFirstChild("Weight")
  365. if (weightObject == nil) then
  366. animTable[name][idx].weight = 1
  367. else
  368. animTable[name][idx].weight = weightObject.Value
  369. end
  370. animTable[name].count = animTable[name].count + 1
  371. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  372. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  373. idx = idx + 1
  374. end
  375. end
  376. end
  377.  
  378. -- fallback to defaults
  379. if (animTable[name].count <= 0) then
  380. for idx, anim in pairs(fileList) do
  381. animTable[name][idx] = {}
  382. animTable[name][idx].anim = Instance.new("Animation")
  383. animTable[name][idx].anim.Name = name
  384. animTable[name][idx].anim.AnimationId = anim.id
  385. animTable[name][idx].weight = anim.weight
  386. animTable[name].count = animTable[name].count + 1
  387. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  388. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  389. end
  390. end
  391. end
  392.  
  393. -- Setup animation objects
  394. function scriptChildModified(child)
  395. local fileList = animNames[child.Name]
  396. if (fileList ~= nil) then
  397. configureAnimationSet(child.Name, fileList)
  398. end
  399. end
  400.  
  401. FOLDER.ChildAdded:connect(scriptChildModified)
  402. FOLDER.ChildRemoved:connect(scriptChildModified)
  403.  
  404.  
  405. for name, fileList in pairs(animNames) do
  406. configureAnimationSet(name, fileList)
  407. end
  408.  
  409. -- ANIMATION
  410.  
  411. -- declarations
  412. local toolAnim = "None"
  413. local toolAnimTime = 0
  414.  
  415. local jumpAnimTime = 0
  416. local jumpAnimDuration = 0.3
  417.  
  418. local toolTransitionTime = 0.1
  419. local fallTransitionTime = 0.3
  420. local jumpMaxLimbVelocity = 0.75
  421.  
  422. -- functions
  423.  
  424. function stopAllAnimations()
  425. local oldAnim = currentAnim
  426.  
  427. -- return to idle if finishing an emote
  428. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  429. oldAnim = "idle"
  430. end
  431.  
  432. currentAnim = ""
  433. currentAnimInstance = nil
  434. if (currentAnimKeyframeHandler ~= nil) then
  435. currentAnimKeyframeHandler:disconnect()
  436. end
  437.  
  438. if (currentAnimTrack ~= nil) then
  439. currentAnimTrack:Stop()
  440. currentAnimTrack:Destroy()
  441. currentAnimTrack = nil
  442. end
  443. return oldAnim
  444. end
  445.  
  446. function setAnimationSpeed(speed)
  447. if speed ~= currentAnimSpeed then
  448. currentAnimSpeed = speed
  449. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  450. end
  451. end
  452.  
  453. function keyFrameReachedFunc(frameName)
  454. if (frameName == "End") then
  455.  
  456. local repeatAnim = currentAnim
  457. -- return to idle if finishing an emote
  458. if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  459. repeatAnim = "idle"
  460. end
  461.  
  462. local animSpeed = currentAnimSpeed
  463. playAnimation(repeatAnim, 0.0, Humanoid)
  464. setAnimationSpeed(animSpeed)
  465. end
  466. end
  467.  
  468. -- Preload animations
  469. function playAnimation(animName, transitionTime, humanoid)
  470.  
  471. local roll = math.random(1, animTable[animName].totalWeight)
  472. local origRoll = roll
  473. local idx = 1
  474. while (roll > animTable[animName][idx].weight) do
  475. roll = roll - animTable[animName][idx].weight
  476. idx = idx + 1
  477. end
  478. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  479. local anim = animTable[animName][idx].anim
  480.  
  481. -- switch animation
  482. if (anim ~= currentAnimInstance) then
  483.  
  484. if (currentAnimTrack ~= nil) then
  485. currentAnimTrack:Stop(transitionTime)
  486. currentAnimTrack:Destroy()
  487. end
  488.  
  489. currentAnimSpeed = 1.0
  490.  
  491. -- load it to the humanoid; get AnimationTrack
  492. currentAnimTrack = humanoid:LoadAnimation(anim)
  493. currentAnimTrack.Priority = Enum.AnimationPriority.Core
  494.  
  495. -- play the animation
  496. currentAnimTrack:Play(transitionTime)
  497. currentAnim = animName
  498. currentAnimInstance = anim
  499.  
  500. -- set up keyframe name triggers
  501. if (currentAnimKeyframeHandler ~= nil) then
  502. currentAnimKeyframeHandler:disconnect()
  503. end
  504. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  505.  
  506. end
  507.  
  508. end
  509.  
  510. -------------------------------------------------------------------------------------------
  511. -------------------------------------------------------------------------------------------
  512.  
  513. local toolAnimName = ""
  514. local toolAnimTrack = nil
  515. local toolAnimInstance = nil
  516. local currentToolAnimKeyframeHandler = nil
  517.  
  518. function toolKeyFrameReachedFunc(frameName)
  519. if (frameName == "End") then
  520. -- print("Keyframe : ".. frameName)
  521. playToolAnimation(toolAnimName, 0.0, Humanoid)
  522. end
  523. end
  524.  
  525.  
  526. function playToolAnimation(animName, transitionTime, humanoid, priority)
  527.  
  528. local roll = math.random(1, animTable[animName].totalWeight)
  529. local origRoll = roll
  530. local idx = 1
  531. while (roll > animTable[animName][idx].weight) do
  532. roll = roll - animTable[animName][idx].weight
  533. idx = idx + 1
  534. end
  535. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  536. local anim = animTable[animName][idx].anim
  537.  
  538. if (toolAnimInstance ~= anim) then
  539.  
  540. if (toolAnimTrack ~= nil) then
  541. toolAnimTrack:Stop()
  542. toolAnimTrack:Destroy()
  543. transitionTime = 0
  544. end
  545.  
  546. -- load it to the humanoid; get AnimationTrack
  547. toolAnimTrack = humanoid:LoadAnimation(anim)
  548. if priority then
  549. toolAnimTrack.Priority = priority
  550. end
  551.  
  552. -- play the animation
  553. toolAnimTrack:Play(transitionTime)
  554. toolAnimName = animName
  555. toolAnimInstance = anim
  556.  
  557. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  558. end
  559. end
  560.  
  561. function stopToolAnimations()
  562. local oldAnim = toolAnimName
  563.  
  564. if (currentToolAnimKeyframeHandler ~= nil) then
  565. currentToolAnimKeyframeHandler:disconnect()
  566. end
  567.  
  568. toolAnimName = ""
  569. toolAnimInstance = nil
  570. if (toolAnimTrack ~= nil) then
  571. toolAnimTrack:Stop()
  572. toolAnimTrack:Destroy()
  573. toolAnimTrack = nil
  574. end
  575.  
  576.  
  577. return oldAnim
  578. end
  579.  
  580. -------------------------------------------------------------------------------------------
  581. -------------------------------------------------------------------------------------------
  582.  
  583.  
  584. function onRunning(speed)
  585. if speed > 0.01 then
  586. playAnimation("walk", 0.1, Humanoid)
  587. if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
  588. setAnimationSpeed(speed / 14.5)
  589. end
  590. pose = "Running"
  591. else
  592. if emoteNames[currentAnim] == nil then
  593. playAnimation("idle", 0.1, Humanoid)
  594. pose = "Standing"
  595. end
  596. end
  597. end
  598.  
  599. function onDied()
  600. pose = "Dead"
  601. end
  602.  
  603. function onJumping()
  604. playAnimation("jump", 0.1, Humanoid)
  605. jumpAnimTime = jumpAnimDuration
  606. pose = "Jumping"
  607. end
  608.  
  609. function onClimbing(speed)
  610. playAnimation("climb", 0.1, Humanoid)
  611. setAnimationSpeed(speed / 12.0)
  612. pose = "Climbing"
  613. end
  614.  
  615. function onGettingUp()
  616. pose = "GettingUp"
  617. end
  618.  
  619. function onFreeFall()
  620. if (jumpAnimTime <= 0) then
  621. playAnimation("fall", fallTransitionTime, Humanoid)
  622. end
  623. pose = "FreeFall"
  624. end
  625.  
  626. function onFallingDown()
  627. pose = "FallingDown"
  628. end
  629.  
  630. function onSeated()
  631. pose = "Seated"
  632. end
  633.  
  634. function onPlatformStanding()
  635. pose = "PlatformStanding"
  636. end
  637.  
  638. function onSwimming(speed)
  639. if speed > 0 then
  640. pose = "Running"
  641. else
  642. pose = "Standing"
  643. end
  644. end
  645.  
  646. function getTool()
  647. for _, kid in ipairs(Figure:GetChildren()) do
  648. if kid.className == "Tool" then return kid end
  649. end
  650. return nil
  651. end
  652.  
  653. function getToolAnim(tool)
  654. for _, c in ipairs(tool:GetChildren()) do
  655. if c.Name == "toolanim" and c.className == "StringValue" then
  656. return c
  657. end
  658. end
  659. return nil
  660. end
  661.  
  662. function animateTool()
  663.  
  664. if (toolAnim == "None") then
  665. playToolAnimation("toolnone", toolTransitionTime, Humanoid, Enum.AnimationPriority.Idle)
  666. return
  667. end
  668.  
  669. if (toolAnim == "Slash") then
  670. playToolAnimation("toolslash", 0, Humanoid, Enum.AnimationPriority.Action)
  671. return
  672. end
  673.  
  674. if (toolAnim == "Lunge") then
  675. playToolAnimation("toollunge", 0, Humanoid, Enum.AnimationPriority.Action)
  676. return
  677. end
  678. end
  679.  
  680. function moveSit()
  681. RightShoulder.MaxVelocity = 0.15
  682. LeftShoulder.MaxVelocity = 0.15
  683. RightShoulder:SetDesiredAngle(3.14 /2)
  684. LeftShoulder:SetDesiredAngle(-3.14 /2)
  685. RightHip:SetDesiredAngle(3.14 /2)
  686. LeftHip:SetDesiredAngle(-3.14 /2)
  687. end
  688.  
  689. local lastTick = 0
  690.  
  691. function move(time)
  692. local amplitude = 1
  693. local frequency = 1
  694. local deltaTime = time - lastTick
  695. lastTick = time
  696.  
  697. local climbFudge = 0
  698. local setAngles = false
  699.  
  700. if (jumpAnimTime > 0) then
  701. jumpAnimTime = jumpAnimTime - deltaTime
  702. end
  703.  
  704. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  705. playAnimation("fall", fallTransitionTime, Humanoid)
  706. elseif (pose == "Seated") then
  707. playAnimation("sit", 0.5, Humanoid)
  708. return
  709. elseif (pose == "Running") then
  710. playAnimation("walk", 0.1, Humanoid)
  711. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  712. -- print("Wha " .. pose)
  713. stopAllAnimations()
  714. amplitude = 0.1
  715. frequency = 1
  716. setAngles = true
  717. end
  718.  
  719. if (setAngles) then
  720. local desiredAngle = amplitude * math.sin(time * frequency)
  721.  
  722. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  723. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  724. RightHip:SetDesiredAngle(-desiredAngle)
  725. LeftHip:SetDesiredAngle(-desiredAngle)
  726. end
  727.  
  728. -- Tool Animation handling
  729. local tool = getTool()
  730. if tool and tool:FindFirstChild("Handle") then
  731.  
  732. local animStringValueObject = getToolAnim(tool)
  733.  
  734. if animStringValueObject then
  735. toolAnim = animStringValueObject.Value
  736. -- message recieved, delete StringValue
  737. animStringValueObject.Parent = nil
  738. toolAnimTime = time + .3
  739. end
  740.  
  741. if time > toolAnimTime then
  742. toolAnimTime = 0
  743. toolAnim = "None"
  744. end
  745.  
  746. animateTool()
  747. else
  748. stopToolAnimations()
  749. toolAnim = "None"
  750. toolAnimInstance = nil
  751. toolAnimTime = 0
  752. end
  753. end
  754.  
  755.  
  756. local events = {}
  757. local eventHum = Humanoid
  758.  
  759. local function onUnhook()
  760. for i = 1, #events do
  761. events[i]:Disconnect()
  762. end
  763. events = {}
  764. end
  765.  
  766. local function onHook()
  767. onUnhook()
  768.  
  769. pose = eventHum.Sit and "Seated" or "Standing"
  770.  
  771. events = {
  772. eventHum.Died:connect(onDied),
  773. eventHum.Running:connect(onRunning),
  774. eventHum.Jumping:connect(onJumping),
  775. eventHum.Climbing:connect(onClimbing),
  776. eventHum.GettingUp:connect(onGettingUp),
  777. eventHum.FreeFalling:connect(onFreeFall),
  778. eventHum.FallingDown:connect(onFallingDown),
  779. eventHum.Seated:connect(onSeated),
  780. eventHum.PlatformStanding:connect(onPlatformStanding),
  781. eventHum.Swimming:connect(onSwimming)
  782. }
  783. end
  784.  
  785.  
  786. onHook()
  787. --FOLDER:WaitForChild("Loaded").Value = true
  788.  
  789.  
  790. -- main program
  791.  
  792. -- initialize to idle
  793. playAnimation("idle", 0.1, Humanoid)
  794. pose = "Standing"
  795.  
  796. spawn(function()
  797. while Figure.Parent ~= nil do
  798. local _, time = wait(0.1)
  799. move(time)
  800. end
  801. end)
  802.  
  803. return {
  804. onRunning = onRunning,
  805. onDied = onDied,
  806. onJumping = onJumping,
  807. onClimbing = onClimbing,
  808. onGettingUp = onGettingUp,
  809. onFreeFall = onFreeFall,
  810. onFallingDown = onFallingDown,
  811. onSeated = onSeated,
  812. onPlatformStanding = onPlatformStanding,
  813. onHook = onHook,
  814. onUnhook = onUnhook
  815. }
  816.  
  817. end
  818. RUNANIMATESCRIPT(CloneChar.Animate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement