ryanswagg20

r15

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