Advertisement
Alishan555

Untitled

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