Advertisement
RyanDaCoder

old animations

Nov 7th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. game.StarterPlayer.StarterCharacterScripts:connect(function()
  2. function waitForChild(parent, childName)
  3. local child = parent:findFirstChild(childName)
  4. if child then return child end
  5. while true do
  6. child = parent.ChildAdded:wait()
  7. if child.Name==childName then return child end
  8. end
  9. end
  10.  
  11. ----------------------------- TEAM COLORS
  12.  
  13.  
  14. function onTeamChanged(player)
  15.  
  16. wait(1)
  17.  
  18. local char = player.Character
  19. if char == nil then return end
  20.  
  21. if player.Neutral then
  22. -- Replacing the current BodyColor object will force a reset
  23. local old = char:findFirstChild("Body Colors")
  24. if not old then return end
  25. old:clone().Parent = char
  26. old.Parent = nil
  27. else
  28. local head = char:findFirstChild("Head")
  29. local torso = char:findFirstChild("Torso")
  30. local left_arm = char:findFirstChild("Left Arm")
  31. local right_arm = char:findFirstChild("Right Arm")
  32. local left_leg = char:findFirstChild("Left Leg")
  33. local right_leg = char:findFirstChild("Right Leg")
  34.  
  35. if head then head.BrickColor = BrickColor.new(24) end
  36. if torso then torso.BrickColor = player.TeamColor end
  37. if left_arm then left_arm.BrickColor = BrickColor.new(26) end
  38. if right_arm then right_arm.BrickColor = BrickColor.new(26) end
  39. if left_leg then left_leg.BrickColor = BrickColor.new(26) end
  40. if right_leg then right_leg.BrickColor = BrickColor.new(26) end
  41. end
  42. end
  43.  
  44. function onPlayerPropChanged(property, player)
  45. if property == "Character" then
  46. onTeamChanged(player)
  47. end
  48. if property== "TeamColor" or property == "Neutral" then
  49. onTeamChanged(player)
  50. end
  51. end
  52.  
  53.  
  54. local cPlayer = game.Players:GetPlayerFromCharacter(script.Parent)
  55. cPlayer.Changed:connect(function(property) onPlayerPropChanged(property, cPlayer) end )
  56. onTeamChanged(cPlayer)
  57.  
  58.  
  59. ----------------------------- ANIMATION
  60.  
  61. -- declarations
  62.  
  63. local Figure = script.Parent
  64. local Torso = waitForChild(Figure, "Torso")
  65. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  66. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  67. local RightHip = waitForChild(Torso, "Right Hip")
  68. local LeftHip = waitForChild(Torso, "Left Hip")
  69. local Neck = waitForChild(Torso, "Neck")
  70. local Humanoid = waitForChild(Figure, "Humanoid")
  71. local pose = "Standing"
  72.  
  73. local toolAnim = "None"
  74. local toolAnimTime = 0
  75.  
  76. local isSeated = false
  77.  
  78. -- functions
  79.  
  80. function onRunning(speed)
  81. if isSeated then return end
  82.  
  83. if speed>0 then
  84. pose = "Running"
  85. else
  86. pose = "Standing"
  87. end
  88. end
  89.  
  90. function onDied()
  91. pose = "Dead"
  92. end
  93.  
  94. function onJumping()
  95. isSeated = false
  96. pose = "Jumping"
  97. end
  98.  
  99. function onClimbing()
  100. pose = "Climbing"
  101. end
  102.  
  103. function onGettingUp()
  104. pose = "GettingUp"
  105. end
  106.  
  107. function onFreeFall()
  108. pose = "FreeFall"
  109. end
  110.  
  111. function onFallingDown()
  112. pose = "FallingDown"
  113. end
  114.  
  115. function onSeated()
  116. isSeated = true
  117. pose = "Seated"
  118. end
  119.  
  120. function moveJump()
  121. RightShoulder.MaxVelocity = 0.5
  122. LeftShoulder.MaxVelocity = 0.5
  123. RightShoulder.DesiredAngle = 3.14
  124. LeftShoulder.DesiredAngle = -3.14
  125. RightHip.DesiredAngle = 0
  126. LeftHip.DesiredAngle = 0
  127. end
  128.  
  129.  
  130. -- same as jump for now
  131.  
  132. function moveFreeFall()
  133. RightShoulder.MaxVelocity = 0.5
  134. LeftShoulder.MaxVelocity = 0.5
  135. RightShoulder.DesiredAngle = 3.14
  136. LeftShoulder.DesiredAngle = -3.14
  137. RightHip.DesiredAngle = 0
  138. LeftHip.DesiredAngle = 0
  139. end
  140.  
  141. function moveSit()
  142. RightShoulder.MaxVelocity = 0.15
  143. LeftShoulder.MaxVelocity = 0.15
  144. RightShoulder.DesiredAngle = 3.14 /2
  145. LeftShoulder.DesiredAngle = -3.14 /2
  146. RightHip.DesiredAngle = 3.14 /2
  147. LeftHip.DesiredAngle = -3.14 /2
  148. end
  149.  
  150. function getTool()
  151. for _, kid in ipairs(Figure:GetChildren()) do
  152. if kid.className == "Tool" then return kid end
  153. end
  154. return nil
  155. end
  156.  
  157. function getToolAnim(tool)
  158. for _, c in ipairs(tool:GetChildren()) do
  159. if c.Name == "toolanim" and c.className == "StringValue" then
  160. return c
  161. end
  162. end
  163. return nil
  164. end
  165.  
  166. function animateTool()
  167.  
  168. if (toolAnim == "None") then
  169. RightShoulder.DesiredAngle = 1.57
  170. return
  171. end
  172.  
  173. if (toolAnim == "Slash") then
  174. RightShoulder.MaxVelocity = 0.5
  175. RightShoulder.DesiredAngle = 0
  176. return
  177. end
  178.  
  179. if (toolAnim == "Lunge") then
  180. RightShoulder.MaxVelocity = 0.5
  181. LeftShoulder.MaxVelocity = 0.5
  182. RightHip.MaxVelocity = 0.5
  183. LeftHip.MaxVelocity = 0.5
  184. RightShoulder.DesiredAngle = 1.57
  185. LeftShoulder.DesiredAngle = 1.0
  186. RightHip.DesiredAngle = 1.57
  187. LeftHip.DesiredAngle = 1.0
  188. return
  189. end
  190. end
  191.  
  192. function move(time)
  193. local amplitude
  194. local frequency
  195.  
  196. if (pose == "Jumping") then
  197. moveJump()
  198. return
  199. end
  200.  
  201. if (pose == "FreeFall") then
  202. moveFreeFall()
  203. return
  204. end
  205.  
  206. if (pose == "Seated") then
  207. moveSit()
  208. return
  209. end
  210.  
  211. local climbFudge = 0
  212.  
  213. if (pose == "Running") then
  214. RightShoulder.MaxVelocity = 0.15
  215. LeftShoulder.MaxVelocity = 0.15
  216. amplitude = 1
  217. frequency = 9
  218. elseif (pose == "Climbing") then
  219. RightShoulder.MaxVelocity = 0.5
  220. LeftShoulder.MaxVelocity = 0.5
  221. amplitude = 1
  222. frequency = 9
  223. climbFudge = 3.14
  224. else
  225. amplitude = 0.1
  226. frequency = 1
  227. end
  228.  
  229. desiredAngle = amplitude * math.sin(time*frequency)
  230.  
  231. RightShoulder.DesiredAngle = desiredAngle + climbFudge
  232. LeftShoulder.DesiredAngle = desiredAngle - climbFudge
  233. RightHip.DesiredAngle = -desiredAngle
  234. LeftHip.DesiredAngle = -desiredAngle
  235.  
  236.  
  237. local tool = getTool()
  238.  
  239. if tool then
  240.  
  241. animStringValueObject = getToolAnim(tool)
  242.  
  243. if animStringValueObject then
  244. toolAnim = animStringValueObject.Value
  245. -- message recieved, delete StringValue
  246. animStringValueObject.Parent = nil
  247. toolAnimTime = time + .3
  248. end
  249.  
  250. if time > toolAnimTime then
  251. toolAnimTime = 0
  252. toolAnim = "None"
  253. end
  254.  
  255. animateTool()
  256.  
  257.  
  258. else
  259. toolAnim = "None"
  260. toolAnimTime = 0
  261. end
  262. end
  263.  
  264.  
  265. -- connect events
  266.  
  267. Humanoid.Died:connect(onDied)
  268. Humanoid.Running:connect(onRunning)
  269. Humanoid.Jumping:connect(onJumping)
  270. Humanoid.Climbing:connect(onClimbing)
  271. Humanoid.GettingUp:connect(onGettingUp)
  272. Humanoid.FreeFalling:connect(onFreeFall)
  273. Humanoid.FallingDown:connect(onFallingDown)
  274. Humanoid.Seated:connect(onSeated)
  275.  
  276. -- main program
  277.  
  278. local runService = game:service("RunService");
  279.  
  280. while Figure.Parent~=nil do
  281. local _, time = wait(0.1)
  282. move(time)
  283. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement