Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. local Model = script.Parent
  2. local Backup = Model:clone()
  3.  
  4. function Respawn()
  5. Model:breakJoints()
  6.  
  7. wait(5)
  8.  
  9. script.Parent = Model.Parent
  10.  
  11. Model:remove()
  12. Model = Backup:clone()
  13. Model.Parent = script.Parent
  14. Model:makeJoints()
  15.  
  16. script:remove()
  17. end
  18.  
  19. Model.Humanoid.Died:connect(Respawn)
  20.  
  21. function waitForChild(parent, childName)
  22. local child = parent:findFirstChild(childName)
  23.  
  24. if child then
  25. return child
  26. end
  27.  
  28. while true do
  29. print(childName)
  30.  
  31. child = parent.ChildAdded:wait()
  32.  
  33. if child.Name==childName then
  34. return child
  35. end
  36. end
  37. end
  38.  
  39. -- declarations
  40.  
  41. local Figure = script.Parent
  42. local Head = waitForChild(Figure, "Head")
  43. local Humanoid = waitForChild(Figure, "Humanoid")
  44.  
  45. Figure.PrimaryPart = Head
  46.  
  47. -- ANIMATION
  48.  
  49. function Joint(Name, Part0, Part1, C0, C1, MaxVelocity)
  50. local Motor = Instance.new("Motor")
  51.  
  52. Motor.C0 = C0
  53. Motor.C1 = C1
  54. Motor.MaxVelocity = MaxVelocity
  55. Motor.Name = Name
  56. Motor.Parent = Part0
  57. Motor.Part0 = Part0
  58. Motor.Part1 = Part1
  59. end
  60.  
  61. -- declarations
  62.  
  63. local Torso = waitForChild(Figure, "Torso")
  64. local LeftArm = waitForChild(Figure, "Left Arm")
  65. local LeftLeg = waitForChild(Figure, "Left Leg")
  66. local RightArm = waitForChild(Figure, "Right Arm")
  67. local RightLeg = waitForChild(Figure, "Right Leg")
  68.  
  69. local Joints = {
  70. {"Right Shoulder", Torso, RightArm, CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), 0.5},
  71. {"Left Shoulder", Torso, LeftArm, CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), 0.5},
  72. {"Right Hip", Torso, RightLeg, CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0), 0.10000000149012},
  73. {"Left Hip", Torso, LeftLeg, CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0), 0.10000000149012},
  74. {"Neck", Torso, Head, CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0), CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0), 0.10000000149012}}
  75.  
  76. Torso:breakJoints()
  77.  
  78. for _, v in pairs(Joints) do
  79. Joint(unpack(v))
  80. end
  81.  
  82. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  83. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  84. local RightHip = waitForChild(Torso, "Right Hip")
  85. local LeftHip = waitForChild(Torso, "Left Hip")
  86. local Neck = waitForChild(Torso, "Neck")
  87. local Humanoid = waitForChild(Figure, "Humanoid")
  88. local pose = "Standing"
  89.  
  90. local toolAnim = "None"
  91. local toolAnimTime = 0
  92.  
  93. -- functions
  94.  
  95. function onRunning(speed)
  96. if speed>0 then
  97. pose = "Running"
  98. else
  99. pose = "Standing"
  100. end
  101. end
  102.  
  103. function onDied()
  104. pose = "Dead"
  105. end
  106.  
  107. function onJumping()
  108. pose = "Jumping"
  109. end
  110.  
  111. function onClimbing()
  112. pose = "Climbing"
  113. end
  114.  
  115. function onGettingUp()
  116. pose = "GettingUp"
  117. end
  118.  
  119. function onFreeFall()
  120. pose = "FreeFall"
  121. end
  122.  
  123. function onFallingDown()
  124. pose = "FallingDown"
  125. end
  126.  
  127. function onSeated()
  128. pose = "Seated"
  129. end
  130.  
  131. function onPlatformStanding()
  132. pose = "PlatformStanding"
  133. end
  134.  
  135. function moveJump()
  136. RightShoulder.MaxVelocity = 0.5
  137. LeftShoulder.MaxVelocity = 0.5
  138. RightShoulder.DesiredAngle = 3.14
  139. LeftShoulder.DesiredAngle = -3.14
  140. RightHip.DesiredAngle = 0
  141. LeftHip.DesiredAngle = 0
  142. end
  143.  
  144.  
  145. -- same as jump for now
  146.  
  147. function moveFreeFall()
  148. RightShoulder.MaxVelocity = 0.5
  149. LeftShoulder.MaxVelocity = 0.5
  150. RightShoulder.DesiredAngle = 3.14
  151. LeftShoulder.DesiredAngle = -3.14
  152. RightHip.DesiredAngle = 0
  153. LeftHip.DesiredAngle = 0
  154. end
  155.  
  156. function moveSit()
  157. RightShoulder.MaxVelocity = 0.15
  158. LeftShoulder.MaxVelocity = 0.15
  159. RightShoulder.DesiredAngle = 3.14 /2
  160. LeftShoulder.DesiredAngle = -3.14 /2
  161. RightHip.DesiredAngle = 3.14 /2
  162. LeftHip.DesiredAngle = -3.14 /2
  163. end
  164.  
  165. function getTool()
  166. for _, kid in ipairs(Figure:GetChildren()) do
  167. if kid.className == "Tool" then return kid end
  168. end
  169. return nil
  170. end
  171.  
  172. function getToolAnim(tool)
  173. for _, c in ipairs(tool:GetChildren()) do
  174. if c.Name == "toolanim" and c.className == "StringValue" then
  175. return c
  176. end
  177. end
  178. return nil
  179. end
  180.  
  181. function animateTool()
  182.  
  183. if (toolAnim == "None") then
  184. RightShoulder.DesiredAngle = 1.57
  185. return
  186. end
  187.  
  188. if (toolAnim == "Slash") then
  189. RightShoulder.MaxVelocity = 0.5
  190. RightShoulder.DesiredAngle = 0
  191. return
  192. end
  193.  
  194. if (toolAnim == "Lunge") then
  195. RightShoulder.MaxVelocity = 0.5
  196. LeftShoulder.MaxVelocity = 0.5
  197. RightHip.MaxVelocity = 0.5
  198. LeftHip.MaxVelocity = 0.5
  199. RightShoulder.DesiredAngle = 1.57
  200. LeftShoulder.DesiredAngle = 1.0
  201. RightHip.DesiredAngle = 1.57
  202. LeftHip.DesiredAngle = 1.0
  203. return
  204. end
  205. end
  206.  
  207. function move(time)
  208. local amplitude
  209. local frequency
  210.  
  211. if (pose == "Jumping") then
  212. moveJump()
  213. return
  214. end
  215.  
  216. if (pose == "FreeFall") then
  217. moveFreeFall()
  218. return
  219. end
  220.  
  221. if (pose == "Seated") then
  222. moveSit()
  223. return
  224. end
  225.  
  226. local climbFudge = 0
  227.  
  228. if (pose == "Running") then
  229. RightShoulder.MaxVelocity = 0.15
  230. LeftShoulder.MaxVelocity = 0.15
  231. amplitude = 1
  232. frequency = 9
  233. elseif (pose == "Climbing") then
  234. RightShoulder.MaxVelocity = 0.5
  235. LeftShoulder.MaxVelocity = 0.5
  236. amplitude = 1
  237. frequency = 9
  238. climbFudge = 3.14
  239. else
  240. amplitude = 0.1
  241. frequency = 1
  242. end
  243.  
  244. desiredAngle = amplitude * math.sin(time*frequency)
  245.  
  246. RightShoulder.DesiredAngle = desiredAngle + climbFudge
  247. LeftShoulder.DesiredAngle = desiredAngle - climbFudge
  248. RightHip.DesiredAngle = -desiredAngle
  249. LeftHip.DesiredAngle = -desiredAngle
  250.  
  251.  
  252. local tool = getTool()
  253.  
  254. if tool then
  255.  
  256. animStringValueObject = getToolAnim(tool)
  257.  
  258. if animStringValueObject then
  259. toolAnim = animStringValueObject.Value
  260. -- message recieved, delete StringValue
  261. animStringValueObject.Parent = nil
  262. toolAnimTime = time + .3
  263. end
  264.  
  265. if time > toolAnimTime then
  266. toolAnimTime = 0
  267. toolAnim = "None"
  268. end
  269.  
  270. animateTool()
  271.  
  272.  
  273. else
  274. toolAnim = "None"
  275. toolAnimTime = 0
  276. end
  277. end
  278.  
  279.  
  280. -- connect events
  281.  
  282. Humanoid.Died:connect(onDied)
  283. Humanoid.Running:connect(onRunning)
  284. Humanoid.Jumping:connect(onJumping)
  285. Humanoid.Climbing:connect(onClimbing)
  286. Humanoid.GettingUp:connect(onGettingUp)
  287. Humanoid.FreeFalling:connect(onFreeFall)
  288. Humanoid.FallingDown:connect(onFallingDown)
  289. Humanoid.Seated:connect(onSeated)
  290. Humanoid.PlatformStanding:connect(onPlatformStanding)
  291.  
  292. -- util
  293.  
  294. function waitForChild(parent, childName)
  295. local child = parent:findFirstChild(childName)
  296. if child then return child end
  297. while true do
  298. child = parent.ChildAdded:wait()
  299. if child.Name==childName then return child end
  300. end
  301. end
  302.  
  303. function newSound(id)
  304. local sound = Instance.new("Sound")
  305. sound.SoundId = id
  306. sound.archivable = false
  307. sound.Parent = script.Parent.Head
  308. return sound
  309. end
  310.  
  311. -- declarations
  312.  
  313. local sDied = newSound("rbxasset://sounds/uuhhh.wav")
  314. local sFallingDown = newSound("rbxasset://sounds/splat.wav")
  315. local sFreeFalling = newSound("rbxasset://sounds/swoosh.wav")
  316. local sGettingUp = newSound("rbxasset://sounds/hit.wav")
  317. local sJumping = newSound("rbxasset://sounds/button.wav")
  318. local sRunning = newSound("rbxasset://sounds/bfsl-minifigfoots1.mp3")
  319. sRunning.Looped = true
  320.  
  321. -- functions
  322.  
  323. function onSoundDied()
  324. sDied:Play()
  325. end
  326.  
  327. function onState(state, sound)
  328. if state then
  329. sound:Play()
  330. else
  331. sound:Pause()
  332. end
  333. end
  334.  
  335. function onSoundRunning(speed)
  336. if speed>0 then
  337. sRunning:Play()
  338. else
  339. sRunning:Pause()
  340. end
  341. end
  342.  
  343. -- connect up
  344.  
  345. Humanoid.Died:connect(onSoundDied)
  346. Humanoid.Running:connect(onSoundRunning)
  347. Humanoid.Jumping:connect(function(state) onState(state, sJumping) end)
  348. Humanoid.GettingUp:connect(function(state) onState(state, sGettingUp) end)
  349. Humanoid.FreeFalling:connect(function(state) onState(state, sFreeFalling) end)
  350. Humanoid.FallingDown:connect(function(state) onState(state, sFallingDown) end)
  351.  
  352. local runService = game:service("RunService");
  353.  
  354. delay(0, function()
  355. while Figure.Parent~=nil do
  356. local _, time = wait(0.1)
  357. move(time)
  358. end
  359. end)
  360.  
  361. -- regeneration
  362. while true do
  363. local s = wait(1)
  364. local health = Humanoid.Health
  365.  
  366. if health > 0 and health < Humanoid.MaxHealth then
  367. health = health + 0.01 * s * Humanoid.MaxHealth
  368.  
  369. if health * 1.05 < Humanoid.MaxHealth then
  370. Humanoid.Health = health
  371. else
  372. Humanoid.Health = Humanoid.MaxHealth
  373. end
  374. end
  375. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement