Advertisement
lafur

Untitled

Jan 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.91 KB | None | 0 0
  1. local zombie = script.Parent
  2.  
  3. for _, script in pairs(zombie.ModuleScripts:GetChildren()) do
  4. if not game.ServerStorage:FindFirstChild(script.Name) then
  5. script:Clone().Parent = game.ServerStorage
  6. end
  7. end
  8.  
  9. local AI = require(game.ServerStorage.ROBLOX_ZombieAI).new(zombie)
  10. local DestroyService = require(game.ServerStorage.ROBLOX_DestroyService)
  11.  
  12.  
  13. local function clearParts(parent)
  14. for _, part in pairs(parent:GetChildren()) do
  15. clearParts(part)
  16. end
  17. local delay
  18. if parent:IsA("Part") then
  19. delay = math.random(5,10)
  20. else
  21. delay = 11
  22. end
  23. DestroyService:AddItem(parent, delay)
  24. end
  25.  
  26. zombie.Humanoid.Died:connect(function()
  27. AI.Stop()
  28. math.randomseed(tick())
  29. clearParts(zombie)
  30. script.Disabled = true
  31. end)
  32.  
  33. local lastMoan = os.time()
  34. math.randomseed(os.time())
  35. while true do
  36. local animationTrack = zombie.Humanoid:LoadAnimation(zombie.Animations.Arms)
  37. animationTrack:Play()
  38. -- local now = os.time()
  39. -- if now - lastMoan > 5 then
  40. -- if math.random() > .3 then
  41. -- zombie.Moan:Play()
  42. ---- print("playing moan")
  43. -- lastMoan = now
  44. -- end
  45. -- end
  46. wait(2)
  47. end
  48.  
  49. function waitForChild(parent, childName)
  50. local child = parent:findFirstChild(childName)
  51. if child then return child end
  52. while true do
  53. child = parent.ChildAdded:wait()
  54. if child.Name==childName then return child end
  55. end
  56. end
  57.  
  58. local Figure = script.Parent
  59. local Torso = waitForChild(Figure, "Torso")
  60. local RightShoulder = waitForChild(Torso, "Right Shoulder")
  61. local LeftShoulder = waitForChild(Torso, "Left Shoulder")
  62. local RightHip = waitForChild(Torso, "Right Hip")
  63. local LeftHip = waitForChild(Torso, "Left Hip")
  64. local Neck = waitForChild(Torso, "Neck")
  65. local Humanoid = waitForChild(Figure, "Humanoid")
  66. local pose = "Standing"
  67.  
  68. local currentAnim = ""
  69. local currentAnimTrack = nil
  70. local currentAnimKeyframeHandler = nil
  71. local currentAnimSpeed = 1.0
  72. local animTable = {}
  73. local animNames = {
  74. idle = {
  75. { id = "http://www.roblox.com/asset/?id=125750544", weight = 9 },
  76. { id = "http://www.roblox.com/asset/?id=125750618", weight = 1 }
  77. },
  78. walk = {
  79. { id = "http://www.roblox.com/asset/?id=125749145", weight = 10 }
  80. },
  81. run = {
  82. { id = "run.xml", weight = 10 }
  83. },
  84. jump = {
  85. { id = "http://www.roblox.com/asset/?id=125750702", weight = 10 }
  86. },
  87. fall = {
  88. { id = "http://www.roblox.com/asset/?id=125750759", weight = 10 }
  89. },
  90. climb = {
  91. { id = "http://www.roblox.com/asset/?id=125750800", weight = 10 }
  92. },
  93. toolnone = {
  94. { id = "http://www.roblox.com/asset/?id=125750867", weight = 10 }
  95. },
  96. toolslash = {
  97. { id = "http://www.roblox.com/asset/?id=129967390", weight = 10 }
  98. -- { id = "slash.xml", weight = 10 }
  99. },
  100. toollunge = {
  101. { id = "http://www.roblox.com/asset/?id=129967478", weight = 10 }
  102. },
  103. wave = {
  104. { id = "http://www.roblox.com/asset/?id=128777973", weight = 10 }
  105. },
  106. point = {
  107. { id = "http://www.roblox.com/asset/?id=128853357", weight = 10 }
  108. },
  109. dance = {
  110. { id = "http://www.roblox.com/asset/?id=130018893", weight = 10 },
  111. { id = "http://www.roblox.com/asset/?id=132546839", weight = 10 },
  112. { id = "http://www.roblox.com/asset/?id=132546884", weight = 10 }
  113. },
  114. dance2 = {
  115. { id = "http://www.roblox.com/asset/?id=160934142", weight = 10 },
  116. { id = "http://www.roblox.com/asset/?id=160934298", weight = 10 },
  117. { id = "http://www.roblox.com/asset/?id=160934376", weight = 10 }
  118. },
  119. dance3 = {
  120. { id = "http://www.roblox.com/asset/?id=160934458", weight = 10 },
  121. { id = "http://www.roblox.com/asset/?id=160934530", weight = 10 },
  122. { id = "http://www.roblox.com/asset/?id=160934593", weight = 10 }
  123. },
  124. laugh = {
  125. { id = "http://www.roblox.com/asset/?id=129423131", weight = 10 }
  126. },
  127. cheer = {
  128. { id = "http://www.roblox.com/asset/?id=129423030", weight = 10 }
  129. },
  130. }
  131.  
  132. -- Existance in this list signifies that it is an emote, the value indicates if it is a looping emote
  133. local emoteNames = { wave = false, point = false, dance = true, dance2 = true, dance3 = true, laugh = false, cheer = false}
  134.  
  135. math.randomseed(tick())
  136.  
  137. function configureAnimationSet(name, fileList)
  138. if (animTable[name] ~= nil) then
  139. for _, connection in pairs(animTable[name].connections) do
  140. connection:disconnect()
  141. end
  142. end
  143. animTable[name] = {}
  144. animTable[name].count = 0
  145. animTable[name].totalWeight = 0
  146. animTable[name].connections = {}
  147.  
  148. -- check for config values
  149. local config = script:FindFirstChild(name)
  150. if (config ~= nil) then
  151. -- print("Loading anims " .. name)
  152. table.insert(animTable[name].connections, config.ChildAdded:connect(function(child) configureAnimationSet(name, fileList) end))
  153. table.insert(animTable[name].connections, config.ChildRemoved:connect(function(child) configureAnimationSet(name, fileList) end))
  154. local idx = 1
  155. for _, childPart in pairs(config:GetChildren()) do
  156. if (childPart:IsA("Animation")) then
  157. table.insert(animTable[name].connections, childPart.Changed:connect(function(property) configureAnimationSet(name, fileList) end))
  158. animTable[name][idx] = {}
  159. animTable[name][idx].anim = childPart
  160. local weightObject = childPart:FindFirstChild("Weight")
  161. if (weightObject == nil) then
  162. animTable[name][idx].weight = 1
  163. else
  164. animTable[name][idx].weight = weightObject.Value
  165. end
  166. animTable[name].count = animTable[name].count + 1
  167. animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
  168. -- print(name .. " [" .. idx .. "] " .. animTable[name][idx].anim.AnimationId .. " (" .. animTable[name][idx].weight .. ")")
  169. idx = idx + 1
  170. end
  171. end
  172. end
  173.  
  174. -- fallback to defaults
  175. if (animTable[name].count <= 0) then
  176. for idx, anim in pairs(fileList) do
  177. animTable[name][idx] = {}
  178. animTable[name][idx].anim = Instance.new("Animation")
  179. animTable[name][idx].anim.Name = name
  180. animTable[name][idx].anim.AnimationId = anim.id
  181. animTable[name][idx].weight = anim.weight
  182. animTable[name].count = animTable[name].count + 1
  183. animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
  184. -- print(name .. " [" .. idx .. "] " .. anim.id .. " (" .. anim.weight .. ")")
  185. end
  186. end
  187. end
  188.  
  189. -- Setup animation objects
  190. function scriptChildModified(child)
  191. local fileList = animNames[child.Name]
  192. if (fileList ~= nil) then
  193. configureAnimationSet(child.Name, fileList)
  194. end
  195. end
  196.  
  197. script.ChildAdded:connect(scriptChildModified)
  198. script.ChildRemoved:connect(scriptChildModified)
  199.  
  200.  
  201. for name, fileList in pairs(animNames) do
  202. configureAnimationSet(name, fileList)
  203. end
  204.  
  205. -- ANIMATION
  206.  
  207. -- declarations
  208. local toolAnim = "None"
  209. local toolAnimTime = 0
  210.  
  211. local jumpAnimTime = 0
  212. local jumpAnimDuration = 0.3
  213.  
  214. local toolTransitionTime = 0.1
  215. local fallTransitionTime = 0.3
  216. local jumpMaxLimbVelocity = 0.75
  217.  
  218. -- functions
  219.  
  220. function stopAllAnimations()
  221. local oldAnim = currentAnim
  222.  
  223. -- return to idle if finishing an emote
  224. if (emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false) then
  225. oldAnim = "idle"
  226. end
  227.  
  228. currentAnim = ""
  229. if (currentAnimKeyframeHandler ~= nil) then
  230. currentAnimKeyframeHandler:disconnect()
  231. end
  232.  
  233. if (currentAnimTrack ~= nil) then
  234. currentAnimTrack:Stop()
  235. currentAnimTrack:Destroy()
  236. currentAnimTrack = nil
  237. end
  238. return oldAnim
  239. end
  240.  
  241. function setAnimationSpeed(speed)
  242. if speed ~= currentAnimSpeed then
  243. currentAnimSpeed = speed
  244. currentAnimTrack:AdjustSpeed(currentAnimSpeed)
  245. end
  246. end
  247.  
  248. function keyFrameReachedFunc(frameName)
  249. if (frameName == "End") then
  250. -- print("Keyframe : ".. frameName)
  251. local repeatAnim = stopAllAnimations()
  252. local animSpeed = currentAnimSpeed
  253. playAnimation(repeatAnim, 0.0, Humanoid)
  254. setAnimationSpeed(animSpeed)
  255. end
  256. end
  257.  
  258. -- Preload animations
  259. function playAnimation(animName, transitionTime, humanoid)
  260. local idleFromEmote = (animName == "idle" and emoteNames[currentAnim] ~= nil)
  261. if (animName ~= currentAnim and not idleFromEmote) then
  262.  
  263. if (currentAnimTrack ~= nil) then
  264. currentAnimTrack:Stop(transitionTime)
  265. currentAnimTrack:Destroy()
  266. end
  267.  
  268. currentAnimSpeed = 1.0
  269. local roll = math.random(1, animTable[animName].totalWeight)
  270. local origRoll = roll
  271. local idx = 1
  272. while (roll > animTable[animName][idx].weight) do
  273. roll = roll - animTable[animName][idx].weight
  274. idx = idx + 1
  275. end
  276. -- print(animName .. " " .. idx .. " [" .. origRoll .. "]")
  277. local anim = animTable[animName][idx].anim
  278.  
  279. -- load it to the humanoid; get AnimationTrack
  280. currentAnimTrack = humanoid:LoadAnimation(anim)
  281.  
  282. -- play the animation
  283. currentAnimTrack:Play(transitionTime)
  284. currentAnim = animName
  285.  
  286. -- set up keyframe name triggers
  287. if (currentAnimKeyframeHandler ~= nil) then
  288. currentAnimKeyframeHandler:disconnect()
  289. end
  290. currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
  291. end
  292. end
  293.  
  294. -------------------------------------------------------------------------------------------
  295. -------------------------------------------------------------------------------------------
  296.  
  297. local toolAnimName = ""
  298. local toolAnimTrack = nil
  299. local currentToolAnimKeyframeHandler = nil
  300.  
  301. function toolKeyFrameReachedFunc(frameName)
  302. if (frameName == "End") then
  303. -- print("Keyframe : ".. frameName)
  304. local repeatAnim = stopToolAnimations()
  305. playToolAnimation(repeatAnim, 0.0, Humanoid)
  306. end
  307. end
  308.  
  309.  
  310. function playToolAnimation(animName, transitionTime, humanoid)
  311. if (animName ~= toolAnimName) then
  312.  
  313. if (toolAnimTrack ~= nil) then
  314. toolAnimTrack:Stop()
  315. toolAnimTrack:Destroy()
  316. transitionTime = 0
  317. end
  318.  
  319. local roll = math.random(1, animTable[animName].totalWeight)
  320. local origRoll = roll
  321. local idx = 1
  322. while (roll > animTable[animName][idx].weight) do
  323. roll = roll - animTable[animName][idx].weight
  324. idx = idx + 1
  325. end
  326. -- print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
  327. local anim = animTable[animName][idx].anim
  328.  
  329. -- load it to the humanoid; get AnimationTrack
  330. toolAnimTrack = humanoid:LoadAnimation(anim)
  331.  
  332. -- play the animation
  333. toolAnimTrack:Play(transitionTime)
  334. toolAnimName = animName
  335.  
  336. currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
  337. end
  338. end
  339.  
  340. function stopToolAnimations()
  341. local oldAnim = toolAnimName
  342.  
  343. if (currentToolAnimKeyframeHandler ~= nil) then
  344. currentToolAnimKeyframeHandler:disconnect()
  345. end
  346.  
  347. toolAnimName = ""
  348. if (toolAnimTrack ~= nil) then
  349. toolAnimTrack:Stop()
  350. toolAnimTrack:Destroy()
  351. toolAnimTrack = nil
  352. end
  353.  
  354.  
  355. return oldAnim
  356. end
  357.  
  358. -------------------------------------------------------------------------------------------
  359. -------------------------------------------------------------------------------------------
  360.  
  361.  
  362. function onRunning(speed)
  363. if speed>0.01 then
  364. playAnimation("walk", 0.1, Humanoid)
  365. pose = "Running"
  366. else
  367. playAnimation("idle", 0.1, Humanoid)
  368. pose = "Standing"
  369. end
  370. end
  371.  
  372. function onDied()
  373. pose = "Dead"
  374. end
  375.  
  376. function onJumping()
  377. playAnimation("jump", 0.1, Humanoid)
  378. jumpAnimTime = jumpAnimDuration
  379. pose = "Jumping"
  380. end
  381.  
  382. function onClimbing(speed)
  383. playAnimation("climb", 0.1, Humanoid)
  384. setAnimationSpeed(speed / 12.0)
  385. pose = "Climbing"
  386. end
  387.  
  388. function onGettingUp()
  389. pose = "GettingUp"
  390. end
  391.  
  392. function onFreeFall()
  393. if (jumpAnimTime <= 0) then
  394. playAnimation("fall", fallTransitionTime, Humanoid)
  395. end
  396. pose = "FreeFall"
  397. end
  398.  
  399. function onFallingDown()
  400. pose = "FallingDown"
  401. end
  402.  
  403. function onSeated()
  404. pose = "Seated"
  405. end
  406.  
  407. function onPlatformStanding()
  408. pose = "PlatformStanding"
  409. end
  410.  
  411. function onSwimming(speed)
  412. if speed>0 then
  413. pose = "Running"
  414. else
  415. pose = "Standing"
  416. end
  417. end
  418.  
  419. function getTool()
  420. for _, kid in ipairs(Figure:GetChildren()) do
  421. if kid.className == "Tool" then return kid end
  422. end
  423. return nil
  424. end
  425.  
  426. function getToolAnim(tool)
  427. for _, c in ipairs(tool:GetChildren()) do
  428. if c.Name == "toolanim" and c.className == "StringValue" then
  429. return c
  430. end
  431. end
  432. return nil
  433. end
  434.  
  435. function animateTool()
  436.  
  437. if (toolAnim == "None") then
  438. playToolAnimation("toolnone", toolTransitionTime, Humanoid)
  439. return
  440. end
  441.  
  442. if (toolAnim == "Slash") then
  443. playToolAnimation("toolslash", 0, Humanoid)
  444. return
  445. end
  446.  
  447. if (toolAnim == "Lunge") then
  448. playToolAnimation("toollunge", 0, Humanoid)
  449. return
  450. end
  451. end
  452.  
  453. function moveSit()
  454. RightShoulder.MaxVelocity = 0.15
  455. LeftShoulder.MaxVelocity = 0.15
  456. RightShoulder:SetDesiredAngle(3.14 /2)
  457. LeftShoulder:SetDesiredAngle(-3.14 /2)
  458. RightHip:SetDesiredAngle(3.14 /2)
  459. LeftHip:SetDesiredAngle(-3.14 /2)
  460. end
  461.  
  462. local lastTick = 0
  463.  
  464. function move(time)
  465. local amplitude = 1
  466. local frequency = 1
  467. local deltaTime = time - lastTick
  468. lastTick = time
  469.  
  470. local climbFudge = 0
  471. local setAngles = false
  472.  
  473. if (jumpAnimTime > 0) then
  474. jumpAnimTime = jumpAnimTime - deltaTime
  475. end
  476.  
  477. if (pose == "FreeFall" and jumpAnimTime <= 0) then
  478. playAnimation("fall", fallTransitionTime, Humanoid)
  479. elseif (pose == "Seated") then
  480. stopAllAnimations()
  481. moveSit()
  482. return
  483. elseif (pose == "Running") then
  484. playAnimation("walk", 0.1, Humanoid)
  485. elseif (pose == "Dead" or pose == "GettingUp" or pose == "FallingDown" or pose == "Seated" or pose == "PlatformStanding") then
  486. -- print("Wha " .. pose)
  487. amplitude = 0.1
  488. frequency = 1
  489. setAngles = true
  490. end
  491.  
  492. if (setAngles) then
  493. desiredAngle = amplitude * math.sin(time * frequency)
  494.  
  495. RightShoulder:SetDesiredAngle(desiredAngle + climbFudge)
  496. LeftShoulder:SetDesiredAngle(desiredAngle - climbFudge)
  497. RightHip:SetDesiredAngle(-desiredAngle)
  498. LeftHip:SetDesiredAngle(-desiredAngle)
  499. end
  500.  
  501. -- Tool Animation handling
  502. local tool = getTool()
  503. if tool then
  504.  
  505. animStringValueObject = getToolAnim(tool)
  506.  
  507. if animStringValueObject then
  508. toolAnim = animStringValueObject.Value
  509. -- message recieved, delete StringValue
  510. animStringValueObject.Parent = nil
  511. toolAnimTime = time + .3
  512. end
  513.  
  514. if time > toolAnimTime then
  515. toolAnimTime = 0
  516. toolAnim = "None"
  517. end
  518.  
  519. animateTool()
  520. else
  521. stopToolAnimations()
  522. toolAnim = "None"
  523. toolAnimTime = 0
  524. end
  525. end
  526.  
  527. -- connect events
  528. Humanoid.Died:connect(onDied)
  529. Humanoid.Running:connect(onRunning)
  530. Humanoid.Jumping:connect(onJumping)
  531. Humanoid.Climbing:connect(onClimbing)
  532. Humanoid.GettingUp:connect(onGettingUp)
  533. Humanoid.FreeFalling:connect(onFreeFall)
  534. Humanoid.FallingDown:connect(onFallingDown)
  535. Humanoid.Seated:connect(onSeated)
  536. Humanoid.PlatformStanding:connect(onPlatformStanding)
  537. Humanoid.Swimming:connect(onSwimming)
  538.  
  539. -- main program
  540.  
  541. local runService = game:service("RunService");
  542.  
  543. -- initialize to idle
  544. playAnimation("idle", 0.1, Humanoid)
  545. pose = "Standing"
  546.  
  547. while Figure.Parent~=nil do
  548. local _, time = wait(0.1)
  549. move(time)
  550. end
  551.  
  552.  
  553. name="Humanoid"
  554.  
  555. robo=script.Parent:clone()
  556.  
  557. while true do
  558. wait(7)
  559. if script.Parent.Humanoid.Health<1 then
  560. robot=robo:clone()
  561. robot.Parent=script.Parent.Parent
  562. robot:makeJoints()
  563. script.Parent:remove()
  564. end
  565. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement