Advertisement
Guest User

Sample

a guest
Jun 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. local SearchDistance = 10000
  2.  
  3. local ZombieDamage = 25
  4. local DamageWait = 2
  5.  
  6. local WanderX, WanderZ = 30, 30
  7.  
  8. function getHumanoid(model)
  9. for _, v in pairs(model:GetChildren())do
  10. if v:IsA'Humanoid' then
  11. return v
  12. end
  13. end
  14. end
  15.  
  16.  
  17. local zombie = script.Parent
  18. local human = getHumanoid(zombie)
  19. local hroot = zombie.HumanoidRootPart
  20. local zspeed = hroot.Velocity.magnitude
  21. local head = zombie:FindFirstChild'Head'
  22. local vars = script.vars
  23.  
  24. local pfs = game:GetService("PathfindingService")
  25. local players = game:GetService('Players')
  26.  
  27.  
  28. local path
  29. local waypoint
  30.  
  31. local chaseName = nil
  32.  
  33. function GetTorso(part)
  34. local chars = game.Workspace:GetChildren()
  35. local chaseRoot = nil
  36. local chaseTorso = nil
  37. local chasePlr = nil
  38. local chaseHuman = nil
  39. local mag = SearchDistance
  40. for i = 1, #chars do
  41. chasePlr = chars[i]
  42. if chasePlr:IsA'Model' and chasePlr ~= zombie then
  43. chaseHuman = getHumanoid(chasePlr)
  44. chaseRoot = chasePlr:FindFirstChild'HumanoidRootPart'
  45. if chaseRoot ~= nil and chaseHuman ~= nil and chaseHuman.Health > 0 and chaseHuman.Name ~= "Zombie" then
  46. if (chaseRoot.Position - part).magnitude < mag then
  47. chaseName = chasePlr.Name
  48. chaseTorso = chaseRoot
  49. mag = (chaseRoot.Position - part).magnitude
  50. end
  51. end
  52. end
  53. end
  54. return chaseTorso
  55. end
  56.  
  57. function GetPlayersBodyParts(t)
  58. local torso = t
  59. if torso then
  60. local figure = torso.Parent
  61. for _, v in pairs(figure:GetChildren())do
  62. if v:IsA'Part' then
  63. return v.Name
  64. end
  65. end
  66. else
  67. return "HumanoidRootPart"
  68. end
  69. end
  70.  
  71.  
  72. local damagetime
  73. local damagedb = false
  74.  
  75. for _, zambieparts in pairs(zombie:GetChildren())do
  76. if zambieparts:IsA'Part' and human.Health > 0 then
  77. zambieparts.Touched:connect(function(p)
  78. if p.Parent.Name == chaseName and p.Parent.Name ~= zombie.Name and not damagedb then -- damage
  79. damagedb = true
  80. damagetime = time()
  81. local enemy = p.Parent
  82. local enemyhuman = getHumanoid(enemy)
  83. vars.Attacking.Value = true
  84. enemyhuman:TakeDamage(ZombieDamage)
  85. vars.Attacking.Value = false
  86. while wait() do
  87. if damagetime ~= nil and time() >= (damagetime + DamageWait) then
  88. damagedb = false
  89. damagetime = nil
  90. end
  91. end
  92. end
  93. end)
  94. end
  95. end
  96.  
  97. spawn(function()
  98. while vars.Wandering.Value == false and human.Health > 0 do
  99. vars.Chasing.Value = false
  100. vars.Wandering.Value = true
  101. local desgx, desgz = hroot.Position.x+math.random(-WanderX,WanderX), hroot.Position.z+math.random(-WanderZ,WanderZ)
  102. local function checkw(t)
  103. local ci = 3
  104. if ci > #t then
  105. ci = 3
  106. end
  107. if t[ci] == nil and ci < #t then
  108. repeat ci = ci + 1 wait() until t[ci] ~= nil
  109. return Vector3.new(1,0,0) + t[ci]
  110. else
  111. ci = 3
  112. return t[ci]
  113. end
  114. end
  115.  
  116. path = pfs:FindPathAsync(hroot.Position, Vector3.new(desgx, 0, desgz))
  117. waypoint = path:GetWaypoints()
  118. local connection;
  119.  
  120. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  121. local ncf = hroot.CFrame * CFrame.new(direct)
  122. direct = ncf.p.unit
  123. local rootr = Ray.new(hroot.Position, direct)
  124. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  125.  
  126. if path and waypoint or checkw(waypoint) then
  127. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  128. human:MoveTo( checkw(waypoint).Position )
  129. human.Jump = false
  130. end
  131.  
  132. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  133. connection = human.Changed:connect(function()
  134. human.Jump = true
  135. end)
  136. human:MoveTo( waypoint[4].Position )
  137. else
  138. human.Jump = false
  139. end
  140.  
  141. if connection then
  142. connection:Disconnect()
  143. end
  144.  
  145. else
  146. for i = 3, #waypoint do
  147. human:MoveTo( waypoint[i].Position )
  148. end
  149. end
  150. wait(math.random(4,6))
  151. vars.Wandering.Value = false
  152. end
  153. end)
  154.  
  155.  
  156. while wait() do
  157. local nrstt = GetTorso(hroot.Position)
  158. if nrstt ~= nil and human.Health > 0 then
  159. vars.Wandering.Value = false
  160. vars.Chasing.Value = true
  161. local function checkw(t)
  162. local ci = 3
  163. if ci > #t then
  164. ci = 3
  165. end
  166. if t[ci] == nil and ci < #t then
  167. repeat ci = ci + 1 wait() until t[ci] ~= nil
  168. return Vector3.new(1,0,0) + t[ci]
  169. else
  170. ci = 3
  171. return t[ci]
  172. end
  173. end
  174.  
  175. path = pfs:FindPathAsync(hroot.Position, nrstt.Position)
  176. waypoint = path:GetWaypoints()
  177. local connection;
  178.  
  179. local direct = Vector3.FromNormalId(Enum.NormalId.Front)
  180. local ncf = hroot.CFrame * CFrame.new(direct)
  181. direct = ncf.p.unit
  182. local rootr = Ray.new(hroot.Position, direct)
  183. local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
  184.  
  185. if path and waypoint or checkw(waypoint) then
  186. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
  187. human:MoveTo( checkw(waypoint).Position )
  188. human.Jump = false
  189. end
  190.  
  191. if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
  192. connection = human.Changed:connect(function()
  193. human.Jump = true
  194. end)
  195. human:MoveTo( waypoint[4].Position )
  196. else
  197. human.Jump = false
  198. end
  199.  
  200. hroot.Touched:connect(function(p)
  201. local bodypartnames = GetPlayersBodyParts(nrstt)
  202. if p:IsA'Part' and not p.Name == bodypartnames and phit and phit.Name ~= bodypartnames and phit:IsA'Part' and rootr:Distance(phit.Position) < 5 then
  203. connection = human.Changed:connect(function()
  204. human.Jump = true
  205. end)
  206. else
  207. human.Jump = false
  208. end
  209. end)
  210.  
  211. if connection then
  212. connection:Disconnect()
  213. end
  214.  
  215. else
  216. for i = 3, #waypoint do
  217. human:MoveTo( waypoint[i].Position )
  218. end
  219. end
  220. path = nil
  221. waypoint = nil
  222. elseif nrstt == nil then
  223. vars.Wandering.Value = false
  224. vars.Chasing.Value = false
  225. CchaseName = nil
  226. path = nil
  227. waypoint = nil
  228. human.MoveToFinished:Wait()
  229. end
  230. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement