Advertisement
xDDx

Untitled

Aug 22nd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.00 KB | None | 0 0
  1.  
  2. wait(2)
  3.  
  4. Player = game.Players.localPlayer
  5.  
  6.  
  7. local function CharacterAdded(Character)
  8. if Character then
  9.  
  10. local R15Model = Instance.new("Model")
  11. R15Model.Name = "R15Model"
  12. R15Model.Parent = Character
  13.  
  14. local function CreateLimb(Name,Color,Size,Transparency,ConnectToLimb,MotorName,C0,C1,MeshId)
  15. local Part = Instance.new("Part")
  16. Part.FormFactor = "Custom"
  17. Part.Size = Size
  18. Part.BrickColor = Color
  19. Part.CanCollide = false
  20. Part.Name = Name
  21. Part.Transparency = (Transparency == 0.001 and 0 or Transparency)
  22. Part.TopSurface = "Smooth"
  23. Part.BottomSurface = "Smooth"
  24.  
  25. local Motor = Instance.new("Motor6D")
  26. Motor.C0 = C0
  27. Motor.C1 = C1
  28. Motor.Part0 = ConnectToLimb
  29. Motor.Part1 = Part
  30. Motor.Name = MotorName
  31. Motor.MaxVelocity = 0.1
  32. Motor.Parent = ConnectToLimb
  33.  
  34. if MeshId then
  35. local Mesh = Instance.new("SpecialMesh")
  36. Mesh.MeshType = "FileMesh"
  37. Mesh.MeshId = MeshId
  38. Mesh.Scale = Vector3.new(0.99,0.99,0.99)
  39. Mesh.Parent = Part
  40. end
  41.  
  42. if MeshId and Transparency == 0.001 then
  43. local ShirtTexturePart = Instance.new("Part")
  44. ShirtTexturePart.FormFactor = "Custom"
  45. ShirtTexturePart.Size = Size
  46. ShirtTexturePart.BrickColor = Color
  47. ShirtTexturePart.CanCollide = false
  48. ShirtTexturePart.Name = "ShirtTexturePart"
  49. ShirtTexturePart.Transparency = Transparency
  50. ShirtTexturePart.TopSurface = "Smooth"
  51. ShirtTexturePart.BottomSurface = "Smooth"
  52.  
  53. local Mesh = Instance.new("SpecialMesh")
  54. Mesh.MeshType = "FileMesh"
  55. Mesh.MeshId = MeshId
  56. Mesh.Parent = ShirtTexturePart
  57.  
  58. local Weld = Instance.new("Weld")
  59. Weld.Part0 = Part
  60. Weld.Part1 = ShirtTexturePart
  61. Weld.Parent = ShirtTexturePart
  62.  
  63. ShirtTexturePart.Parent = Part
  64. end
  65. Part.Parent = R15Model
  66. return Part
  67. end
  68.  
  69. local HumanoidRootPart = CreateLimb("HumanoidRootPart",BrickColor.new("Medium stone grey"),Vector3.new(1,1,1),1,Character.HumanoidRootPart,"RootConnector",CFrame.new(),CFrame.new(0,0.7,0))
  70. local TorsoLower = CreateLimb("TorsoLower",BrickColor.new("Bright blue"),Vector3.new(0.5,0.5,0.5),0.001,HumanoidRootPart,"Root",CFrame.new(0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, -1),CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190286")
  71. local TorsoUpper = CreateLimb("TorsoUpper",BrickColor.new("Bright blue"),Vector3.new(0.2,0.74,0.2),0.001,TorsoLower,"Waist",CFrame.new(0, 0.739968002, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, -0.369984001, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190087")
  72. local Head = CreateLimb("FakeHead",BrickColor.new("Bright yellow"),Vector3.new(1,1,1),0,TorsoUpper,"Neck",CFrame.new(0, 0.566236973, -0.0666489974, 1, 0, 0, 0, 0.993143976, 0.116898, 0, -0.116898, 0.993143976),CFrame.new(0, -0.285073012, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366190426")
  73. local LeftArmUpper = CreateLimb("LeftArmUpper",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.536,0.2),0.001,TorsoUpper,"LeftShoulder",CFrame.new(1.50177097, 0.220340997, 0, 0, -0.999044001, -0.0437170006, -1, 0, 0, 0, 0.0437170006, -0.999044001),CFrame.new(0, 0.336115986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366186808")
  74. local LeftArmLower = CreateLimb("LeftArmLower",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.739,0.2),0.001,LeftArmUpper,"LeftElbow",CFrame.new(0, -0.267791986, 0, 1, 0, 0, 0, 0.998493016, -0.0548710003, 0, 0.0548710003, 0.998493016),CFrame.new(0, 0.369605988, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187079")
  75. local LeftHand = CreateLimb("LeftHand",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.37,0.2),0.001,LeftArmLower,"LeftWrist",CFrame.new(0, -0.369605988, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.184802994, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187331")
  76. local RightArmUpper = CreateLimb("RightArmUpper",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.536,0.2),0.001,TorsoUpper,"RightShoulder",CFrame.new(-1.50049305, 0.219521001, 0, 0, 0.999041975, -0.0437709987, -1, 0, 0, 0, 0.0437709987, 0.999041975),CFrame.new(0, 0.335705996, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188623")
  77. local RightArmLower = CreateLimb("RightArmLower",BrickColor.new("Bright yellow"),Vector3.new(0.2,0.739,0.2),0.001,RightArmUpper,"RightElbow",CFrame.new(0, -0.296110988, 0, 1, 0, 0, 0, 0.998767972, 0.0496239997, 0, -0.0496239997, 0.998767972),CFrame.new(0, 0.337754011, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188798")
  78. local RightHand = CreateLimb("RightHand",BrickColor.new("Bright yellow"),Vector3.new(),0.001,RightArmLower,"RightWrist",CFrame.new(0, -0.337754011, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.168877006, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189081")
  79. local LeftLegUpper = CreateLimb("LeftLegUpper",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.784,0.2),0.001,TorsoLower,"LeftHip",CFrame.new(0.457044005, -0.495086014, 0, 1, 0, 0, 0, 1, -0.000100999998, 0, 0.000100999998, 1),CFrame.new(0, 0.388933986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366187724")
  80. local LeftLegLower = CreateLimb("LeftLegLower",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.803,0.2),0.001,LeftLegUpper,"LeftKnee",CFrame.new(0, -0.388933986, 0, 1, 9.99999997e-007, 0, -9.99999997e-007, 0.991840005, -0.127486005, 0, 0.127486005, 0.991840005),CFrame.new(0, 0.401580006, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188102")
  81. local LeftFoot = CreateLimb("LeftFoot",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.402,0.2),0.001,LeftLegLower,"LeftAnkle",CFrame.new(0, -0.401578993, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.200790003, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366188387")
  82. local RightLegUpper = CreateLimb("RightLegUpper",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.784,0.2),0.001,TorsoLower,"RightHip",CFrame.new(-0.451141, -0.498115987, 0, 1, 0, 0, 0, 0.999954998, 0.0095180003, 0, -0.0095180003, 0.999954998),CFrame.new(0, 0.391921997, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189770")
  83. local RightLegLower = CreateLimb("RightLegLower",BrickColor.new("Br. yellowish green"),Vector3.new(0.2,0.796,0.2),0.001,RightLegUpper,"RightKnee",CFrame.new(0, -0.391921997, 0, 1, 0, 0, 0, 0.992762029, -0.120096996, 0, 0.120096996, 0.992762029),CFrame.new(0, 0.39814499, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189509")
  84. local RightFoot = CreateLimb("RightFoot",BrickColor.new("Br. yellowish green"),Vector3.new(0.2, 0.398, 0.2),0.001,RightLegLower,"RightAnkle",CFrame.new(0, -0.39814499, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1),CFrame.new(0, -0.199073002, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"http://www.roblox.com/asset/?id=366189977")
  85.  
  86. --if Character:WaitForChild("Head"):WaitForChild("Mesh").MeshId ~= "" then
  87. -- Head.MeshId = Character.Head.Mesh.MeshId
  88. --end
  89.  
  90. spawn(function() Character:WaitForChild("Animate").Disabled = false end)
  91.  
  92.  
  93. local function Clear(Name,Alternative,ColorParts)
  94. local Part = Character:WaitForChild(Name)
  95. Part.Transparency = (Name == "Head" and 0.99 or 1)
  96. local function ChildAdded(Ins)
  97. delay(0.05,function()
  98. if Ins.Name == "face" then
  99. if Alternative:FindFirstChild("face") then Alternative:FindFirstChild("face"):Destroy() end
  100. Ins.Parent = Alternative
  101. elseif Ins:IsA("Motor6D") and string.sub(Ins.Name,1,5) ~= "Fake_" then
  102. Ins.Name = "Fake_"..Ins.Name
  103. elseif Ins.Name == "HeadWeld" then
  104. delay(0.05,function()
  105. Ins.Parent = Head
  106. Ins.Part0 = Head
  107. Ins.C1 = CFrame.new(0,-0.15,0.125) * Ins.C1 * CFrame.Angles(0,math.pi,0)
  108. end)
  109. elseif not Ins:IsA("Weld") then
  110. Ins:Destroy()
  111. end
  112. end)
  113. end
  114. for _,Sub in pairs(Part:GetChildren()) do
  115. ChildAdded(Sub)
  116. end
  117. Part.ChildAdded:connect(ChildAdded)
  118.  
  119. local function Color()
  120. for _,Sub in pairs(ColorParts) do
  121. Sub.BrickColor = Part.BrickColor
  122. local TexturePart = Sub:FindFirstChild("ShirtTexturePart")
  123. if TexturePart then
  124. TexturePart.BrickColor = Part.BrickColor
  125. end
  126. end
  127. end
  128. Color()
  129. Part.Changed:connect(Color)
  130. end
  131.  
  132. Clear("HumanoidRootPart",HumanoidRootPart,{HumanoidRootPart})
  133. Clear("Head",Head,{Head})
  134. Clear("Torso",nil,{TorsoLower,TorsoUpper})
  135. Clear("Left Arm",nil,{LeftArmLower,LeftArmUpper,LeftHand})
  136. Clear("Right Arm",nil,{RightArmLower,RightArmUpper,RightHand})
  137. Clear("Left Leg",nil,{LeftLegLower,LeftLegUpper,LeftFoot})
  138. Clear("Right Leg",nil,{RightLegLower,RightLegUpper,RightFoot})
  139.  
  140. local ShirtUsed = false
  141. local function ChildAdded(Ins)
  142. if Ins:IsA("Hat") and string.sub(Ins.Name,1,7) ~= "Scaled_" then
  143. delay(0.05,function()
  144. local Mesh = Ins:WaitForChild("Handle"):WaitForChild("Mesh")
  145. Ins.AttachmentPos = Ins.AttachmentPos
  146. Mesh.Scale = Mesh.Scale
  147. Ins.Name = "Scaled_"..Ins.Name
  148. end)
  149. elseif Ins:IsA("Shirt") then
  150. ShirtUsed = true
  151. TorsoLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  152. TorsoUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  153. LeftArmLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  154. LeftArmUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  155. LeftHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  156. RightArmLower.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  157. RightArmUpper.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  158. RightHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  159. elseif Ins:IsA("Pants") then
  160. LeftLegUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  161. LeftLegLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  162. LeftFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  163. RightLegUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  164. RightLegLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  165. RightFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  166. if ShirtUsed ~= true then
  167. TorsoLower.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  168. TorsoUpper.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  169. end
  170. end
  171. end
  172.  
  173. for _,Sub in pairs(Character:GetChildren()) do
  174. ChildAdded(Sub)
  175. end
  176. Character.ChildAdded:connect(ChildAdded)
  177. end
  178. end
  179.  
  180. CharacterAdded(Player.Character)
  181. Player.CharacterAdded:connect(CharacterAdded)
  182.  
  183. script.Parent = game.Players.LocalPlayer.Character
  184. function waitForChild(parent, childName)
  185. local child = parent:findFirstChild(childName)
  186. if child then return child end
  187. while true do
  188. child = parent.ChildAdded:wait()
  189. if child.Name==childName then return child end
  190. end
  191. end
  192.  
  193. local Figure = script.Parent
  194. local Humanoid = waitForChild(Figure, "Humanoid")
  195. local pose = "Standing"
  196.  
  197. local currentAnim = ""
  198. local currentAnimInstance = nil
  199. local currentAnimTrack = nil
  200. local currentAnimKeyframeHandler = nil
  201. local currentAnimSpeed = 1.0
  202. local animTable = {}
  203. local animNames = {
  204. idle = {
  205. { id = "http://www.roblox.com/asset/?id=361250879", weight = 1 },
  206. { id = "http://www.roblox.com/asset/?id=361250964", weight = 1 },
  207. { id = "http://www.roblox.com/asset/?id=361250801", weight = 9 }
  208. },
  209. walk = {
  210. { id = "http://www.roblox.com/asset/?id=361250532", weight = 10 }
  211. },
  212. run = {
  213. { id = "http://www.roblox.com/asset/?id=361250532", weight = 10 }
  214. },
  215. jump = {
  216. { id = "http://www.roblox.com/asset/?id=361251250", weight = 10 }
  217. },
  218. fall = {
  219. { id = "http://www.roblox.com/asset/?id=361259102", weight = 10 }
  220. },
  221. climb = {
  222. { id = "http://www.roblox.com/asset/?id=361251073", weight = 10 }
  223. },
  224. sit = {
  225. { id = "http://www.roblox.com/asset/?id=178130996", weight = 10 }
  226. },
  227. toolnone = {
  228. { id = "http://www.roblox.com/asset/?id=182393478", weight = 10 }
  229. },
  230. toolslash = {
  231. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  232. -- { id = "slash.xml", weight = 10 }
  233. },
  234. toollunge = {
  235. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  236. },
  237. wave = {
  238. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  239. },
  240. point = {
  241. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  242. },
  243. dance = {
  244. { id = "http://www.roblox.com/asset/?id=182435998", weight = 10 },
  245. { id = "http://www.roblox.com/asset/?id=182491037", weight = 10 },
  246. { id = "http://www.roblox.com/asset/?id=182491065", weight = 10 }
  247. },
  248. dance2 = {
  249. { id = "http://www.roblox.com/asset/?id=182436842", weight = 10 },
  250. { id = "http://www.roblox.com/asset/?id=182491248", weight = 10 },
  251. { id = "http://www.roblox.com/asset/?id=182491277", weight = 10 }
  252. },
  253. dance3 = {
  254. { id = "http://www.roblox.com/asset/?id=182436935", weight = 10 },
  255. { id = "http://www.roblox.com/asset/?id=182491368", weight = 10 },
  256. { id = "http://www.roblox.com/asset/?id=182491423", weight = 10 }
  257. },
  258. laugh = {
  259. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  260. },
  261. cheer = {
  262. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  263. },
  264. }
  265.  
  266. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  267. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  268.  
  269. math.randomseed(tick())
  270.  
  271. function configureAnimationSet(name, fileList)
  272. if (animTable[name] ~= nil) then
  273. for _, connection in pairs(animTable[name].connections) do
  274. connection:disconnect()
  275. end
  276. end
  277. animTable[name] = {}
  278. animTable[name].count = 0
  279. animTable[name].totalWeight = 0
  280. animTable[name].connections = {}
  281.  
  282. -- check for config values
  283. local config = script:FindFirstChild(name)
  284. if (config ~= nil) then
  285. -- print("Loading anims " .. name)
  286. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  287. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  288. local idx = 1
  289. for _, childPart in pairs(config:GetChildren()) do
  290. if (childPart:IsA("Animation")) then
  291. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  292. animTable[name][idx] = {}
  293. animTable[name][idx].anim = childPart
  294. local weightObject = childPart:FindFirstChild("Weight")
  295. if (weightObject == nil) then
  296. animTable[name][idx].weight = 1
  297. else
  298. animTable[name][idx].weight = weightObject.Value
  299. end
  300. animTable[name].count = animTable[name].count + 1
  301. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  302. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  303. idx = idx + 1
  304. end
  305. end
  306. end
  307.  
  308. -- fallback to defaults
  309. if (animTable[name].count <= 0) then
  310. for idx, anim in pairs(fileList) do
  311. animTable[name][idx] = {}
  312. animTable[name][idx].anim = Instance.new("Animation")
  313. animTable[name][idx].anim.Name = name
  314. animTable[name][idx].anim.AnimationId = anim.id
  315. animTable[name][idx].weight = anim.weight
  316. animTable[name].count = animTable[name].count + 1
  317. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  318. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  319. end
  320. end
  321. end
  322.  
  323. -- Setup animation objects
  324. function scriptChildModified(child)
  325. local fileList = animNames[child.Name]
  326. if (fileList ~= nil) then
  327. configureAnimationSet(child.Name, fileList)
  328. end
  329. end
  330.  
  331. script.ChildAdded:connect(scriptChildModified)
  332. script.ChildRemoved:connect(scriptChildModified)
  333.  
  334.  
  335. for name, fileList in pairs(animNames) do
  336. configureAnimationSet(name, fileList)
  337. end
  338.  
  339. -- ANIMATION
  340.  
  341. -- declarations
  342. local toolAnim = "None"
  343. local toolAnimTime = 0
  344.  
  345. local jumpAnimTime = 0
  346. local jumpAnimDuration = 0.3
  347.  
  348. local toolTransitionTime = 0.1
  349. local fallTransitionTime = 0.0
  350.  
  351. -- functions
  352.  
  353. function stopAllAnimations()
  354. local oldAnim = currentAnim
  355.  
  356. -- return to idle if finishing an emote
  357. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  358. oldAnim = "idle"
  359. end
  360.  
  361. currentAnim = ""
  362. currentAnimInstance = nil
  363. if (currentAnimKeyframeHandler ~= nil) then
  364. currentAnimKeyframeHandler:disconnect()
  365. end
  366.  
  367. if (currentAnimTrack ~= nil) then
  368. currentAnimTrack:Stop()
  369. currentAnimTrack:Destroy()
  370. currentAnimTrack = nil
  371. end
  372. return oldAnim
  373. end
  374.  
  375. function setAnimationSpeed(speed)
  376. if speed ~= currentAnimSpeed then
  377. currentAnimSpeed = speed
  378. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  379. end
  380. end
  381.  
  382. function keyFrameReachedFunc(frameName)
  383. if (frameName == "End") then
  384. -- print("Keyframe : ".. frameName)
  385.  
  386. local repeatAnim = currentAnim
  387. -- return to idle if finishing an emote
  388. if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
  389. repeatAnim = "idle"
  390. end
  391.  
  392. local animSpeed = currentAnimSpeed
  393. playAnimation(repeatAnim, 0.05, Humanoid)
  394. setAnimationSpeed(animSpeed)
  395. end
  396. end
  397.  
  398. -- Preload animations
  399. function playAnimation(animName, transitionTime, humanoid)
  400.  
  401. local roll = math.random(1, animTable[animName].totalWeight)
  402. local origRoll = roll
  403. local idx = 1
  404. while (roll > animTable[animName][idx].weight) do
  405. roll = roll - animTable[animName][idx].weight
  406. idx = idx + 1
  407. end
  408.  
  409. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  410.  
  411. local anim = animTable[animName][idx].anim
  412.  
  413. -- switch animation
  414. if (anim ~= currentAnimInstance) then
  415.  
  416. if (currentAnimTrack ~= nil) then
  417. currentAnimTrack:Stop(transitionTime)
  418. currentAnimTrack:Destroy()
  419. end
  420.  
  421. currentAnimSpeed = 1.0
  422.  
  423. -- load it to the humanoid; get AnimationTrack
  424. currentAnimTrack = humanoid:LoadAnimation(anim)
  425.  
  426. -- play the animation
  427. currentAnimTrack:Play(transitionTime)
  428. currentAnim = animName
  429. currentAnimInstance = anim
  430.  
  431. -- set up keyframe name triggers
  432. if (currentAnimKeyframeHandler ~= nil) then
  433. currentAnimKeyframeHandler:disconnect()
  434. end
  435. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  436.  
  437. end
  438.  
  439. end
  440.  
  441. -------------------------------------------------------------------------------------------
  442. -------------------------------------------------------------------------------------------
  443.  
  444. local toolAnimName = ""
  445. local toolAnimTrack = nil
  446. local toolAnimInstance = nil
  447. local currentToolAnimKeyframeHandler = nil
  448.  
  449. function toolKeyFrameReachedFunc(frameName)
  450. if (frameName == "End") then
  451. -- print("Keyframe : ".. frameName)
  452. playToolAnimation(toolAnimName, 0.0, Humanoid)
  453. end
  454. end
  455.  
  456.  
  457. function playToolAnimation(animName, transitionTime, humanoid)
  458.  
  459. local roll = math.random(1, animTable[animName].totalWeight)
  460. local origRoll = roll
  461. local idx = 1
  462. while (roll > animTable[animName][idx].weight) do
  463. roll = roll - animTable[animName][idx].weight
  464. idx = idx + 1
  465. end
  466. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  467. local anim = animTable[animName][idx].anim
  468.  
  469. if (toolAnimInstance ~= anim) then
  470.  
  471. if (toolAnimTrack ~= nil) then
  472. toolAnimTrack:Stop()
  473. toolAnimTrack:Destroy()
  474. transitionTime = 0
  475. end
  476.  
  477. -- load it to the humanoid; get AnimationTrack
  478. toolAnimTrack = humanoid:LoadAnimation(anim)
  479.  
  480. -- play the animation
  481. toolAnimTrack:Play(transitionTime)
  482. toolAnimName = animName
  483. toolAnimInstance = anim
  484.  
  485. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  486. end
  487. end
  488.  
  489. function stopToolAnimations()
  490. local oldAnim = toolAnimName
  491.  
  492. if (currentToolAnimKeyframeHandler ~= nil) then
  493. currentToolAnimKeyframeHandler:disconnect()
  494. end
  495.  
  496. toolAnimName = ""
  497. toolAnimInstance = nil
  498. if (toolAnimTrack ~= nil) then
  499. toolAnimTrack:Stop()
  500. toolAnimTrack:Destroy()
  501. toolAnimTrack = nil
  502. end
  503.  
  504.  
  505. return oldAnim
  506. end
  507.  
  508. -------------------------------------------------------------------------------------------
  509. -------------------------------------------------------------------------------------------
  510.  
  511.  
  512. function onRunning(speed)
  513. if speed > 0.01 then
  514. playAnimation("walk", 0.1, Humanoid)
  515. if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=361250532" then
  516. setAnimationSpeed(speed / 14.5)
  517. end
  518. pose = "Running"
  519. else
  520. playAnimation("idle", 0.1, Humanoid)
  521. pose = "Standing"
  522. end
  523. end
  524.  
  525. function onDied()
  526. pose = "Dead"
  527. end
  528.  
  529. function onJumping()
  530. playAnimation("jump", 0.1, Humanoid)
  531. jumpAnimTime = jumpAnimDuration
  532. pose = "Jumping"
  533. end
  534.  
  535. function onClimbing(speed)
  536. local scale = 2.0
  537. playAnimation("climb", 0.1, Humanoid)
  538. setAnimationSpeed(speed / scale)
  539. pose = "Climbing"
  540. end
  541.  
  542. function onGettingUp()
  543. pose = "GettingUp"
  544. end
  545.  
  546. function onFreeFall()
  547. if (jumpAnimTime <= 0) then
  548. playAnimation("fall", fallTransitionTime, Humanoid)
  549. end
  550. pose = "FreeFall"
  551. end
  552.  
  553. function onFallingDown()
  554. pose = "FallingDown"
  555. end
  556.  
  557. function onSeated()
  558. pose = "Seated"
  559. end
  560.  
  561. function onPlatformStanding()
  562. pose = "PlatformStanding"
  563. end
  564.  
  565. function onSwimming(speed)
  566. if speed>0 then
  567. pose = "Running"
  568. else
  569. pose = "Standing"
  570. end
  571. end
  572.  
  573. function getTool()
  574. for _, kid in ipairs(Figure:GetChildren()) do
  575. if kid.className == "Tool" then return kid end
  576. end
  577. return nil
  578. end
  579.  
  580. function getToolAnim(tool)
  581. for _, c in ipairs(tool:GetChildren()) do
  582. if c.Name == "toolanim" and c.className == "StringValue" then
  583. return c
  584. end
  585. end
  586. return nil
  587. end
  588.  
  589. function animateTool()
  590.  
  591. if (toolAnim == "None") then
  592. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  593. return
  594. end
  595.  
  596. if (toolAnim == "Slash") then
  597. playToolAnimation("toolslash", 0, Humanoid)
  598. return
  599. end
  600.  
  601. if (toolAnim == "Lunge") then
  602. playToolAnimation("toollunge", 0, Humanoid)
  603. return
  604. end
  605. end
  606.  
  607. function moveSit()
  608. RightShoulder.MaxVelocity = 0.15
  609. LeftShoulder.MaxVelocity = 0.15
  610. RightShoulder:SetDesiredAngle(3.14 /2)
  611. LeftShoulder:SetDesiredAngle(-3.14 /2)
  612. RightHip:SetDesiredAngle(3.14 /2)
  613. LeftHip:SetDesiredAngle(-3.14 /2)
  614. end
  615.  
  616. local lastTick = 0
  617.  
  618. function move(time)
  619. local amplitude = 1
  620. local frequency = 1
  621. local deltaTime = time - lastTick
  622. lastTick = time
  623.  
  624. local climbFudge = 0
  625. local setAngles = false
  626.  
  627. if (jumpAnimTime > 0) then
  628. jumpAnimTime = jumpAnimTime - deltaTime
  629. end
  630.  
  631. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  632. playAnimation("fall", fallTransitionTime, Humanoid)
  633. elseif (pose == "Seated") then
  634. playAnimation("sit", 0.5, Humanoid)
  635. return
  636. elseif (pose == "Running") then
  637. playAnimation("walk", 0.1, Humanoid)
  638. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  639. -- print("Wha " .. pose)
  640. stopAllAnimations()
  641. amplitude = 0.1
  642. frequency = 1
  643. setAngles = true
  644. end
  645.  
  646. -- if (setAngles) then
  647. if (false) then
  648. desiredAngle = amplitude * math.sin(time * frequency)
  649.  
  650. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  651. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  652. RightHip:SetDesiredAngle(-desiredAngle)
  653. LeftHip:SetDesiredAngle(-desiredAngle)
  654. end
  655.  
  656. -- Tool Animation handling
  657. local tool = getTool()
  658. if tool then
  659.  
  660. animStringValueObject = getToolAnim(tool)
  661.  
  662. if animStringValueObject then
  663. toolAnim = animStringValueObject.Value
  664. -- message recieved, delete StringValue
  665. animStringValueObject.Parent = nil
  666. toolAnimTime = time + .3
  667. end
  668.  
  669. if time > toolAnimTime then
  670. toolAnimTime = 0
  671. toolAnim = "None"
  672. end
  673.  
  674. animateTool()
  675. else
  676. stopToolAnimations()
  677. toolAnim = "None"
  678. toolAnimInstance = nil
  679. toolAnimTime = 0
  680. end
  681. end
  682.  
  683. -- connect events
  684. Humanoid.Died:connect(onDied)
  685. Humanoid.Running:connect(onRunning)
  686. Humanoid.Jumping:connect(onJumping)
  687. Humanoid.Climbing:connect(onClimbing)
  688. Humanoid.GettingUp:connect(onGettingUp)
  689. Humanoid.FreeFalling:connect(onFreeFall)
  690. Humanoid.FallingDown:connect(onFallingDown)
  691. Humanoid.Seated:connect(onSeated)
  692. Humanoid.PlatformStanding:connect(onPlatformStanding)
  693. Humanoid.Swimming:connect(onSwimming)
  694.  
  695. -- setup emote chat hook
  696. Game.Players.LocalPlayer.Chatted:connect(function(msg)
  697. local emote = ""
  698. if (string.sub(msg, 1, 3) == "/e ") then
  699. emote = string.sub(msg, 4)
  700. elseif (string.sub(msg, 1, 7) == "/emote ") then
  701. emote = string.sub(msg, 8)
  702. end
  703.  
  704. if (pose == "Standing" and emoteNames[emote] ~= nil) then
  705. playAnimation(emote, 0.1, Humanoid)
  706. end
  707. -- print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
  708. end)
  709.  
  710.  
  711. -- main program
  712.  
  713. local runService = game:service("RunService");
  714.  
  715. -- print("bottom")
  716.  
  717. -- initialize to idle
  718. playAnimation("idle", 0.1, Humanoid)
  719. pose = "Standing"
  720.  
  721. while Figure.Parent~=nil do
  722. local _, time = wait(0.1)
  723. move(time)
  724. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement