George148

r15test1

Jun 9th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.12 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.  
  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 LowerTorso = CreateLimb("LowerTorso",BrickColor.new("Bright blue"),Vector3.new(1,1,1),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),"rbxassetid://387941715")
  68. local UpperTorso = CreateLimb("UpperTorso",BrickColor.new("Bright blue"),Vector3.new(1,1,1),0.001,LowerTorso,"Waist",CFrame.new(0, 0.404105991, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941468")
  69. local Head = CreateLimb("Head",BrickColor.new("Bright yellow"),Vector3.new(1,1,1),0,UpperTorso,"Neck",CFrame.new(0, 1.26949596, 0.0428609997, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, -0.635110021, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941905")
  70. local LeftUpperArm = CreateLimb("LeftUpperArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.672, 1),0.001,UpperTorso,"LeftShoulder",CFrame.new(-1.50177097, 0.924546003, 0, 1, 0, -0, 0, 0.999044001, 0.0437170006, 0, -0.0437170006, 0.999044001),CFrame.new(0, 0.336115986, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387938468")
  71. local LeftLowerArm = CreateLimb("LeftLowerArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.703, 1),0.001,LeftUpperArm,"LeftElbow",CFrame.new(0, -0.336115986, 0, 1, 0, 0, 0, 0.999044001, -0.0437170006, 0, 0.0437170006, 0.999044001),CFrame.new(0, 0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387938971")
  72. local LeftHand = CreateLimb("LeftHand",BrickColor.new("Bright yellow"),Vector3.new(1, 0.352, 1),0.001,LeftLowerArm,"LeftWrist",CFrame.new(0, -0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.175756007, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939233")
  73. local RightUpperArm = CreateLimb("RightUpperArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.671, 1),0.001,UpperTorso,"RightShoulder",CFrame.new(1.50049305, 0.923726022, 0, 1, 0, -0, 0, 0.999041617, 0.0437709838, 0, -0.0437709838, 0.999041617),CFrame.new(0, 0.335705996, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940113")
  74. local RightLowerArm = CreateLimb("RightLowerArm",BrickColor.new("Bright yellow"),Vector3.new(1, 0.703, 1),0.001,RightUpperArm,"RightElbow",CFrame.new(0, -0.335705996, 0, 1, 0, 0, 0, 0.999041617, -0.0437709838, 0, 0.0437709838, 0.999041617),CFrame.new(0, 0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940356")
  75. local RightHand = CreateLimb("RightHand",BrickColor.new("Bright yellow"),Vector3.new(1, 0.352, 1),0.001,RightLowerArm,"RightWrist",CFrame.new(0, -0.351512015, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.175756007, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940548")
  76. local LeftUpperLeg = CreateLimb("LeftUpperLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.775, 1),0.001,LowerTorso,"LeftHip",CFrame.new(-0.457044005, -0.498115987, 0, 1, 0, -0, 0, 1, 0.000100999998, 0, -0.000100999998, 1),CFrame.new(0, 0.387418985, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939645")
  77. local LeftLowerLeg = CreateLimb("LeftLowerLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.829, 1),0.001,LeftUpperLeg,"LeftKnee",CFrame.new(0, -0.387418985, 0, 1, 9.95820074e-007, 9.13360125e-008, -9.99999997e-007, 0.995820105, 0.0913360119, 0, -0.0913360119, 0.995820105),CFrame.new(0, 0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939489")
  78. local LeftFoot = CreateLimb("LeftFoot",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.415, 1),0.001,LeftLowerLeg,"LeftAnkle",CFrame.new(0, -0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.207286, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387939912")
  79. local RightUpperLeg = CreateLimb("RightUpperLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.775, 1),0.001,LowerTorso,"RightHip",CFrame.new(0.451141, -0.498115987, 0, 1, 0, -0, 0, 1, 0.000100999998, 0, -0.000100999998, 1),CFrame.new(0, 0.387418985, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940976")
  80. local RightLowerLeg = CreateLimb("RightLowerLeg",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.829, 1),0.001,RightUpperLeg,"RightKnee",CFrame.new(0, -0.387418985, 0, 1, 0, -0, 0, 0.995820105, 0.0913360119, 0, -0.0913360119, 0.995820105),CFrame.new(0, 0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387940802")
  81. local RightFoot = CreateLimb("RightFoot",BrickColor.new("Br. yellowish green"),Vector3.new(1, 0.415, 1),0.001,RightLowerLeg,"RightAnkle",CFrame.new(0, -0.414570987, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),CFrame.new(0, 0.207286, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1),"rbxassetid://387941196")
  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. script.NewAnimate:Clone().Parent = Character
  89.  
  90. local function Clear(Name,Alternative,ColorParts)
  91. local Part = Character:WaitForChild(Name)
  92. Part.Transparency = 1--(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,0.05) * Ins.C1
  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,{LowerTorso,UpperTorso})
  132. Clear("Left Arm",nil,{LeftLowerArm,LeftUpperArm,LeftHand})
  133. Clear("Right Arm",nil,{RightLowerArm,RightUpperArm,RightHand})
  134. Clear("Left Leg",nil,{LeftLowerLeg,LeftUpperLeg,LeftFoot})
  135. Clear("Right Leg",nil,{RightLowerLeg,RightUpperLeg,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. LowerTorso.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  149. UpperTorso.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  150. LeftLowerArm.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  151. LeftUpperArm.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  152. LeftHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  153. RightLowerArm.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  154. RightUpperArm.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  155. RightHand.ShirtTexturePart.Mesh.TextureId = Ins.ShirtTemplate
  156. elseif Ins:IsA("Pants") then
  157. LeftUpperLeg.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  158. LeftLowerLeg.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  159. LeftFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  160. RightUpperLeg.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  161. RightLowerLeg.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  162. RightFoot.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  163. if LowerTorso.ShirtTexturePart.Mesh.TextureId == "" then
  164. LowerTorso.ShirtTexturePart.Mesh.TextureId = Ins.PantsTemplate
  165. UpperTorso.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.  
  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 = "rbxasset://R15021216/idle_stretch.xml", weight = 1 },
  203. { id = "rbxasset://R15021216/idle_look.xml", weight = 1 },
  204. { id = "rbxasset://R15021216/idle.xml", weight = 9 }
  205. },
  206. walk = {
  207. { id = "rbxasset://R15021216/run.xml", weight = 10 }
  208. },
  209. run = {
  210. { id = "rbxasset://R15021216/run.xml", weight = 10 }
  211. },
  212. jump = {
  213. { id = "rbxasset://R15021216/jump.xml", weight = 10 }
  214. },
  215. fall = {
  216. { id = "rbxasset://R15021216/falling.xml", weight = 10 }
  217. },
  218. climb = {
  219. { id = "rbxasset://R15021216/climb.xml", weight = 10 }
  220. },
  221. sit = {
  222. { id = "http://www.roblox.com/asset/?id=393915321", weight = 10 }
  223. },
  224. toolnone = {
  225. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  226. },
  227. toolslash = {
  228. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  229. -- { id = "slash.xml", weight = 10 }
  230. },
  231. toollunge = {
  232. { id = "http://www.roblox.com/asset/?id=393915542", weight = 10 }
  233. },
  234. wave = {
  235. { id = "http://www.roblox.com/asset/?id=393915710", weight = 10 }
  236. },
  237. point = {
  238. { id = "http://www.roblox.com/asset/?id=393915866", weight = 10 }
  239. },
  240. dance = {
  241. { id = "http://www.roblox.com/asset/?id=393916260", weight = 10 },
  242. { id = "http://www.roblox.com/asset/?id=393916456", weight = 10 },
  243. { id = "http://www.roblox.com/asset/?id=393916635", weight = 10 }
  244. },
  245. dance2 = {
  246. { id = "http://www.roblox.com/asset/?id=393916791", weight = 10 },
  247. { id = "http://www.roblox.com/asset/?id=393916989", weight = 10 },
  248. { id = "http://www.roblox.com/asset/?id=393917195", weight = 10 }
  249. },
  250. dance3 = {
  251. { id = "http://www.roblox.com/asset/?id=393917375", weight = 10 },
  252. { id = "http://www.roblox.com/asset/?id=393917556", weight = 10 },
  253. { id = "http://www.roblox.com/asset/?id=393917721", weight = 10 }
  254. },
  255. laugh = {
  256. { id = "http://www.roblox.com/asset/?id=393916166", weight = 10 }
  257. },
  258. cheer = {
  259. { id = "http://www.roblox.com/asset/?id=393916016", 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.31
  344.  
  345. local toolTransitionTime = 0.1
  346. local fallTransitionTime = 0.2
  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.15, 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. local scale = 15.0
  512. playAnimation("walk", 0.1, Humanoid)
  513. setAnimationSpeed(speed / scale)
  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. stopAllAnimations()
  636. amplitude = 0.1
  637. frequency = 1
  638. setAngles = true
  639. end
  640.  
  641. -- Tool Animation handling
  642. local tool = getTool()
  643. if tool then
  644.  
  645. animStringValueObject = getToolAnim(tool)
  646.  
  647. if animStringValueObject then
  648. toolAnim = animStringValueObject.Value
  649. -- message recieved, delete StringValue
  650. animStringValueObject.Parent = nil
  651. toolAnimTime = time + .3
  652. end
  653.  
  654. if time > toolAnimTime then
  655. toolAnimTime = 0
  656. toolAnim = "None"
  657. end
  658.  
  659. animateTool()
  660. else
  661. stopToolAnimations()
  662. toolAnim = "None"
  663. toolAnimInstance = nil
  664. toolAnimTime = 0
  665. end
  666. end
  667.  
  668. -- connect events
  669. Humanoid.Died:connect(onDied)
  670. Humanoid.Running:connect(onRunning)
  671. Humanoid.Jumping:connect(onJumping)
  672. Humanoid.Climbing:connect(onClimbing)
  673. Humanoid.GettingUp:connect(onGettingUp)
  674. Humanoid.FreeFalling:connect(onFreeFall)
  675. Humanoid.FallingDown:connect(onFallingDown)
  676. Humanoid.Seated:connect(onSeated)
  677. Humanoid.PlatformStanding:connect(onPlatformStanding)
  678. Humanoid.Swimming:connect(onSwimming)
  679.  
  680. -- setup emote chat hook
  681. Game.Players.LocalPlayer.Chatted:connect(function(msg)
  682. local emote = ""
  683. if (string.sub(msg, 1, 3) == "/e ") then
  684. emote = string.sub(msg, 4)
  685. elseif (string.sub(msg, 1, 7) == "/emote ") then
  686. emote = string.sub(msg, 8)
  687. end
  688.  
  689. if (pose == "Standing" and emoteNames[emote] ~= nil) then
  690. playAnimation(emote, 0.1, Humanoid)
  691. end
  692. -- print("===> " .. string.sub(msg, 1, 3) .. "(" .. emote .. ")")
  693. end)
  694.  
  695.  
  696. -- main program
  697.  
  698. local runService = game:service("RunService");
  699.  
  700. -- print("bottom")
  701.  
  702. -- initialize to idle
  703. playAnimation("idle", 0.1, Humanoid)
  704. pose = "Standing"
  705.  
  706. while Figure.Parent~=nil do
  707. local _, time = wait(0.1)
  708. move(time)
  709. end
Advertisement
Add Comment
Please, Sign In to add comment