Team_Alex

Untitled

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