Advertisement
Guest User

Untitled

a guest
Jun 9th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.57 KB | None | 0 0
  1. local root = getRootElement()
  2. local scoresRoot = getResourceRootElement(getThisResource())
  3.  
  4. local scoreColumns = {"kills", "deaths", "self", "ratio", "status"}
  5. local isColumnActive = {}
  6. ZombieLimit = get("zombies.MaxZombies")-- HOW MANY ZOMBIES SHOULD EXIST AT MAXIMUM?
  7. ZombieStreaming = get("zombies.StreamMethod") -- 1 to constantly stream zombies, 0 to only allow zombies to spawn via createZombie function, 2 to only allow spawning at set spawnpoints
  8. ZombiePedSkins = {13,22,56,67,68,69,70,92,97,105,107,108,126,127,128,152,162,167,188,195,206,209,212,229,230,258,264,277,280,287 } --ALTERNATE SKIN LISTS FOR ZOMBIES (SHORTER LIST IS TEXTURED ZOMBIES ONLY)
  9. --ZombiePedSkins = {7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,36,37,38,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,66,67,68,69,70,71,72,73,75,76,77,78,79,80,81,82,83,85,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,112,113,114,115,116,117,118,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,150,151,152,153,154,155,156,157,158,159,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,209,210,211,212,213,214,215,216,217,218,219,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,275,276,277,278,279,280,281,282,283,284,285,286,287,288 }
  10. ZombieSpeed = get("zombies.Speed")
  11. if ZombieSpeed == 0 then --super slow zombies (goofy looking)
  12. chaseanim = "WALK_drunk"
  13. checkspeed = 2000
  14. elseif ZombieSpeed == 1 then -- normal speed
  15. chaseanim = "run_old"
  16. checkspeed = 1000
  17. elseif ZombieSpeed == 2 then -- rocket zombies (possibly stressful on server)
  18. chaseanim = "Run_Wuzi"
  19. checkspeed = 680
  20. else -- defaults back to normal
  21. chaseanim = "run_old"
  22. checkspeed = 1000
  23. end
  24. resourceRoot = getResourceRootElement()
  25. moancount =0
  26. moanlimit = 10
  27. everyZombie = { }
  28.  
  29. --IDLE BEHAVIOUR OF A ZOMBIE
  30. function Zomb_Idle (ped)
  31. if isElement(ped) then
  32. if ( getElementData ( ped, "status" ) == "idle" ) and ( isPedDead ( ped ) == false ) and (getElementData (ped, "zombie") == true) then
  33. local action = math.random( 1, 6 )
  34. if action < 4 then -- walk a random direction
  35. local rdmangle = math.random( 1, 359 )
  36. setPedRotation( ped, rdmangle )
  37. setPedAnimation ( ped, "PED", "Player_Sneak", -1, true, true, true)
  38. setTimer ( Zomb_Idle, 7000, 1, ped )
  39. elseif action == 4 then -- get on the ground
  40. setPedAnimation ( ped, "MEDIC", "cpr", -1, false, true, true)
  41. setTimer ( Zomb_Idle, 4000, 1, ped )
  42. elseif action == 5 then -- stand still doing nothing
  43. setPedAnimation ( ped )
  44. setTimer ( Zomb_Idle, 4000, 1, ped )
  45. end
  46. end
  47. end
  48. end
  49.  
  50. --BEHAVIOUR WHILE CHASING PLAYERS
  51. function Zomb_chase (ped, Zx, Zy, Zz )
  52. if isElement(ped) then
  53. if (getElementData ( ped, "status" ) == "chasing") and (getElementData (ped, "zombie") == true) then
  54. local x, y, z = getElementPosition( ped )
  55. if (getElementData ( ped, "target" ) == nil) and getElementData ( ped, "Tx" ) ~= false then
  56. local Px = getElementData ( ped, "Tx" )
  57. local Py = getElementData ( ped, "Ty" )
  58. local Pz = getElementData ( ped, "Tz" )
  59. local Pdistance = (getDistanceBetweenPoints3D( Px, Py, Pz, x, y, z ))
  60. if (Pdistance < 1.5 ) then
  61. setTimer ( function (ped) if ( isElement ( ped ) ) then setElementData ( ped, "status", "idle" ) end end, 2000, 1, ped )
  62. end
  63. end
  64. local distance = (getDistanceBetweenPoints3D( x, y, z, Zx, Zy, Zz ))
  65. if (distance < 1 ) then -- IF THE PED HASNT MOVED
  66. if (getElementData ( ped, "target" ) == nil) then
  67. local giveup = math.random( 1, 15 )
  68. if giveup == 1 then
  69. setElementData ( ped, "status", "idle" )
  70. else
  71. local action = math.random( 1, 2 )
  72. if action == 1 then
  73. setPedAnimation ( ped )
  74. triggerClientEvent ( "Zomb_Punch", getRootElement(), ped )
  75. setTimer ( function (ped) if ( isElement ( ped ) ) then setPedAnimation ( ped, "ped", chaseanim, -1, true, true, true ) end end, 800, 1, ped )
  76. setTimer ( Zomb_chase, 2000, 1, ped, x, y, z )
  77. elseif action == 2 then
  78. setPedAnimation ( ped )
  79. triggerClientEvent ( "Zomb_Jump", getRootElement(), ped )
  80. setTimer ( Zomb_chase, 3500, 1, ped, x, y, z )
  81. end
  82. end
  83. else
  84. local Ptarget = (getElementData ( ped, "target" ))
  85. if isElement(Ptarget) then
  86. local Px, Py, Pz = getElementPosition( Ptarget )
  87. local Pdistance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  88. if (Pdistance < 1.2 ) then -- ATTACK A PLAYER IF THEY ARE CLOSE
  89. if ( isPedDead ( Ptarget ) ) then --EAT A DEAD PLAYER
  90. setPedAnimation ( ped )
  91. setPedAnimation ( ped, "MEDIC", "cpr", -1, false, true, false)
  92. setTimer ( function (ped) if ( isElement ( ped ) ) then setElementData ( ped, "status", "idle" ) end end, 10000, 1, ped )
  93. setTimer ( function (ped) if ( isElement ( ped ) ) then setPedRotation ( ped, getPedRotation(ped)-180) end end, 10000, 1, ped )
  94. zmoan(ped)
  95. else
  96. local action = math.random( 1, 6 )
  97. if action == 1 then
  98. setPedAnimation ( ped)
  99. triggerClientEvent ( "Zomb_Jump", getRootElement(), ped )
  100. setTimer ( Zomb_chase, 2000, 1, ped, x, y, z )
  101. else
  102. setPedAnimation ( ped)
  103. triggerClientEvent ( "Zomb_Punch", getRootElement(), ped )
  104. setTimer ( function (ped) if ( isElement ( ped ) ) then setPedAnimation ( ped, "ped", chaseanim, -1, true, true, true ) end end, 800, 1, ped )
  105. setTimer ( Zomb_chase, 2000, 1, ped, x, y, z )
  106. end
  107. end
  108. else
  109. if ( isPedDead (Ptarget) ) then
  110. setTimer ( function (ped) if ( isElement ( ped ) ) then setElementData ( ped, "status", "idle" ) end end, 2000, 1, ped )
  111. setTimer ( function (ped) if ( isElement ( ped ) ) then setPedRotation ( ped, getPedRotation(ped)-180) end end, 1800, 1, ped )
  112. else
  113. local action = math.random( 1, 2 )
  114. if action == 1 then
  115. setPedAnimation ( ped)
  116. triggerClientEvent ( "Zomb_Punch", getRootElement(), ped )
  117. setTimer ( function (ped) if ( isElement ( ped ) ) then setPedAnimation ( ped, "ped", chaseanim, -1, true, true, true ) end end, 800, 1, ped )
  118. setTimer ( Zomb_chase, 2000, 1, ped, x, y, z )
  119. elseif action == 2 then
  120. setPedAnimation ( ped)
  121. triggerClientEvent ( "Zomb_Jump", getRootElement(), ped )
  122. setTimer ( Zomb_chase, 2000, 1, ped, x, y, z )
  123. end
  124. end
  125. end
  126. else
  127. setElementData ( ped, "status", "idle" )
  128. end
  129. end
  130. else
  131. setPedAnimation ( ped, "ped", chaseanim, -1, true, true, true) --KEEP WALKING
  132. setTimer ( Zomb_chase, checkspeed, 1, ped, x, y, z ) --CHECK AGAIN
  133. end
  134. end
  135. end
  136. end
  137.  
  138. --SET THE DIRECTION OF THE ZOMBIE
  139. function setangle ()
  140. for theKey,ped in ipairs(everyZombie) do
  141. if isElement(ped) then
  142. if ( getElementData ( ped, "status" ) == "chasing" ) then
  143. local x
  144. local y
  145. local z
  146. local px
  147. local py
  148. local pz
  149. if ( getElementData ( ped, "target" ) ~= nil ) then
  150. local ptarget = getElementData ( ped, "target" )
  151. if isElement(ptarget) then
  152. x, y, z = getElementPosition( ptarget )
  153. px, py, pz = getElementPosition( ped )
  154. else
  155. setElementData ( ped, "status", "idle" )
  156. x, y, z = getElementPosition( ped )
  157. px, py, pz = getElementPosition( ped )
  158. end
  159. zombangle = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 --MAGIC SPELL TO MAKE PEDS LOOK AT YOU
  160. setPedRotation( ped, zombangle )
  161. elseif ( getElementData ( ped, "target" ) == nil ) and (getElementData ( ped, "Tx" ) ~= false) then --IF THE PED IS AFTER THE PLAYERS LAST KNOWN WHEREABOUTS
  162. x = getElementData ( ped, "Tx" )
  163. y = getElementData ( ped, "Ty" )
  164. z = getElementData ( ped, "Tz" )
  165. px, py, pz = getElementPosition( ped )
  166. zombangle = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 --MAGIC SPELL TO MAKE PEDS LOOK AT YOU
  167. setPedRotation( ped, zombangle )
  168. end
  169. end
  170. end
  171. end
  172. end
  173.  
  174. --SETS THE ZOMBIE ACTIVITY WHEN STATUS CHANGES
  175. addEventHandler ( "onElementDataChange", getRootElement(),
  176. function ( dataName )
  177. if getElementType ( source ) == "ped" and dataName == "status" then
  178. if (getElementData (source, "zombie") == true) then
  179. if ( isPedDead ( source ) == false ) then
  180. if (getElementData ( source, "status" ) == "chasing" ) then
  181. local Zx, Zy, Zz = getElementPosition( source )
  182. setTimer ( Zomb_chase, 1000, 1, source, Zx, Zy, Zz )
  183. local newtarget = (getElementData ( source, "target" ))
  184. if isElement (newtarget) then
  185. if getElementType ( newtarget ) == "player" then
  186. setElementSyncer ( source, newtarget )
  187. end
  188. end
  189. zmoan(source)
  190. elseif (getElementData ( source, "status" ) == "idle" ) then
  191. setTimer ( Zomb_Idle, 1000, 1, source)
  192. elseif (getElementData ( source, "status" ) == "throatslashing" ) then
  193. local tx,ty,tz = getElementPosition( source )
  194. local ptarget = getElementData ( source, "target" )
  195. if isElement(ptarget) then
  196. local vx,vy,vz = getElementPosition( ptarget )
  197. local zombdistance = (getDistanceBetweenPoints3D (tx, ty, tz, vx, vy, vz))
  198. if (zombdistance < .8) then
  199. zmoan(source)
  200. setPedAnimation ( source, "knife", "KILL_Knife_Player", -1, false, false, true)
  201. setPedAnimation ( ptarget, "knife", "KILL_Knife_Ped_Damage", -1, false, false, true)
  202. setTimer ( Playerthroatbitten, 2300, 1, ptarget, source)
  203. setTimer ( function (source) if ( isElement ( source ) ) then setElementData ( source, "status", "idle" ) end end, 5000, 1, source )
  204. else
  205. setElementData ( source, "status", "idle" )
  206. end
  207. else
  208. setElementData ( source, "status", "idle" )
  209. end
  210. end
  211. elseif (getElementData ( source, "status" ) == "dead" ) then
  212. setTimer ( Zomb_delete, 10000, 1, source)
  213. end
  214. end
  215. end
  216. end)
  217.  
  218. --RESOURCE START/INITIAL SETUP
  219. function outbreak(startedResource)
  220. newZombieLimit = get("" .. getResourceName(startedResource) .. ".Zlimit")
  221. if newZombieLimit ~= false then
  222. if newZombieLimit > ZombieLimit then
  223. newZombieLimit = ZombieLimit
  224. end
  225. else
  226. newZombieLimit = ZombieLimit
  227. end
  228. WoodTimer = setTimer ( WoodSetup, 2000, 1) -- CHECKS FOR BARRIERS
  229. if startedResource == getThisResource() then
  230. -- call(getResourceFromName("scoreboard"), "scoreboardAddColumn", "Zombie kills") --ADDS TO SCOREBOARD
  231. local allplayers = getElementsByType ( "player" )
  232. for pKey,thep in ipairs(allplayers) do
  233. setElementData ( thep, "dangercount", 0 )
  234. end
  235. local alivePlayers = getAlivePlayers ()
  236. for playerKey, playerValue in ipairs(alivePlayers) do
  237. setElementData ( playerValue, "alreadyspawned", true )
  238. end
  239. if ZombieSpeed == 2 then
  240. MainTimer1 = setTimer ( setangle, 200, 0) -- KEEPS ZOMBIES FACING THE RIGHT DIRECTION (fast)
  241. else
  242. MainTimer1 = setTimer ( setangle, 400, 0) -- KEEPS ZOMBIES FACING THE RIGHT DIRECTION
  243. end
  244. MainTimer3 = setTimer ( clearFarZombies, 3000, 0) --KEEPS ALL THE ZOMBIES CLOSE TO PLAYERS
  245. if ZombieStreaming == 1 then
  246. MainTimer2 = setTimer ( SpawnZombie, 2500, 0 ) --Spawns zombies in random locations
  247. elseif ZombieStreaming == 2 then
  248. MainTimer2 = setTimer ( SpawnpointZombie, 2500, 0 ) --spawns zombies in zombie spawnpoints
  249. end
  250. end
  251. end
  252. addEventHandler("onResourceStart", getRootElement(), outbreak)
  253.  
  254. function player_Connect()
  255. setElementData ( source, "dangercount", 0 )
  256. end
  257. addEventHandler ( "onPlayerConnect", getRootElement(), player_Connect )
  258.  
  259. function WoodSetup()
  260. local allcols = getElementsByType ( "colshape" ) --clears off old wood cols
  261. for colKey, colValue in ipairs(allcols) do
  262. if ( getElementData ( colValue, "purpose" ) =="zombiewood" ) then
  263. destroyElement(colValue)
  264. end
  265. end
  266. local allobjects = getElementsByType ( "object" ) --SETS UP ALL THE WOOD BARRIERS
  267. for objectKey, objectValue in ipairs(allobjects) do
  268. if ( getElementData ( objectValue, "purpose" ) =="zombiewood" ) then
  269. setElementDimension ( objectValue, 26 )
  270. local x,y,z = getElementPosition( objectValue )
  271. local thecol = createColSphere ( x, y, z, 1.6 )
  272. setElementData ( thecol, "purpose", "zombiewood" )
  273. setElementParent ( thecol, objectValue )
  274. end
  275. end
  276. end
  277.  
  278. function ReduceMoancount()
  279. moancount = moancount-1
  280. end
  281.  
  282. function zmoan(zombie)
  283. if moancount < moanlimit then
  284. moancount = moancount+1
  285. local randnum = math.random( 1, 10 )
  286. triggerClientEvent ( "Zomb_Moan", getRootElement(), zombie, randnum )
  287. setTimer ( ReduceMoancount, 800, 1 )
  288. end
  289. end
  290.  
  291. --CLEARS A DEAD ZOMBIE
  292. function Zomb_delete (ped)
  293. if isElement(ped) then
  294. if (getElementData (ped, "zombie") == true) then
  295. for theKey,thePed in ipairs(everyZombie) do
  296. if ped == thePed then
  297. table.remove( everyZombie, theKey )
  298. break
  299. end
  300. end
  301. destroyElement ( ped )
  302. end
  303. end
  304. end
  305.  
  306. --HEADSHOTS
  307. addEvent( "headboom", true )
  308. function Zheadhit ( ped,attacker, weapon, bodypart)
  309. if (getElementData (ped, "zombie") == true) then
  310. killPed ( ped, attacker, weapon, bodypart )
  311. setPedHeadless ( ped, true )
  312. end
  313. end
  314. addEventHandler( "headboom", getRootElement(), Zheadhit )
  315.  
  316. --KILL FROM ZOMBIE ATTACK
  317. addEvent( "playereaten", true )
  318. function Playerinfected ( player, attacker, weapon, bodypart)
  319. killPed ( player, attacker, weapon, bodypart )
  320. end
  321. addEventHandler( "playereaten", getRootElement(), Playerinfected )
  322.  
  323. --CHECKS FOR ZOMBIE GRABBING FROM BEHIND
  324. function Playerthroatbitten ( player, attacker)
  325. local Zx, Zy, Zz = getElementPosition( attacker )
  326. local Px, Py, Pz = getElementPosition( player )
  327. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  328. if (distance < 1) then
  329. killPed ( player, attacker, weapon, bodypart )
  330. else
  331. setPedAnimation (player)
  332. end
  333. end
  334.  
  335. --ADJUSTS PLAYERS ZOMBIE KILL SCORE
  336. function deanimated( ammo, attacker, weapon, bodypart )
  337. if (attacker) then
  338. if (getElementType ( attacker ) == "player") and (getElementType ( source ) == "ped") then
  339. if (getElementData (source, "zombie") == true) then
  340. local oldZcount = getElementData ( attacker, "Zombie kills" )
  341. if oldZcount ~= false then
  342. setElementData ( attacker, "Zombie kills", oldZcount+1 )
  343. givePlayerMoney(attacker,20)
  344. triggerEvent ( "onZombieWasted", source, attacker, weapon, bodypart )
  345. else
  346. setElementData ( attacker, "Zombie kills", 1 )
  347. triggerEvent ( "onZombieWasted", source, attacker, weapon, bodypart )
  348. end
  349. end
  350. end
  351. end
  352. end
  353. addEventHandler("onPedWasted", resourceRoot, deanimated)
  354.  
  355. --STUFF TO ALLOW PLAYERS TO PLACE BOARDS
  356. function boarditup( player, key, keyState )
  357. local rightspot = 0
  358. local allcols = getElementsByType ( "colshape" )
  359. for ColKey,theCol in ipairs(allcols) do
  360. if (getElementData ( theCol, "purpose" ) == "zombiewood" ) then
  361. if (isElementWithinColShape ( player, theCol )) then
  362. local rightcol = theCol
  363. local Cx, Cy, Cz = getElementPosition( rightcol )
  364. local Bx, By, Bz = getElementPosition( player )
  365. woodangle = ( 360 - math.deg ( math.atan2 ( ( Cx - Bx ), ( Cy - By ) ) ) ) % 360
  366. setPedRotation( player, woodangle )
  367. setPedAnimation(player, "riot", "RIOT_PUNCHES", 3000, true, true, true )
  368. local wx, wy, wz = getElementPosition( player )
  369. setTimer( doneboarding, 2000, 1, player, rightcol, wx, wy, wz )
  370. end
  371. end
  372. end
  373. end
  374. addCommandHandler ( "construct", boarditup )
  375.  
  376. function doneboarding(player, rightcol, wx, wy, wz)
  377. setPedAnimation(player)
  378. local newx, newy, newz = getElementPosition( player )
  379. local distance = (getDistanceBetweenPoints3D( wx, wy, wz, newx, newy, newz ))
  380. if (distance < .7 ) then
  381. newwood = getElementParent ( rightcol )
  382. setElementDimension ( newwood, 25 )
  383. setTimer( setElementDimension, 50, 1, newwood, 0)
  384. end
  385. end
  386.  
  387.  
  388. --SPAWN ZOMBIE (now can be cancelled!)
  389.  
  390. addEvent( "onZombieSpawn", true )
  391. function RanSpawn_Z ( gx, gy, gz, rot)
  392. local safezone = 0
  393. local allradars = getElementsByType("radararea")
  394. for theKey,theradar in ipairs(allradars) do
  395. if getElementData(theradar, "zombieProof") == true then
  396. if isInsideRadarArea ( theradar, gx, gy ) then
  397. safezone = 1
  398. end
  399. end
  400. end
  401. if safezone == 0 then
  402. if table.getn ( everyZombie ) < newZombieLimit then
  403. if not rot then
  404. rot = math.random (1,359)
  405. end
  406. randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )
  407. local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz )
  408. if zomb ~= false then
  409. setElementData ( zomb, "zombie", true )
  410. table.insert( everyZombie, zomb )
  411. setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot )
  412. setTimer ( function (zomb) if ( isElement ( zomb ) ) then setPedAnimation ( zomb, "ped", chaseanim, -1, true, true, true ) end end, 1000, 1, zomb )
  413. setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb )
  414. triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb )
  415. end
  416. end
  417. end
  418. end
  419. addEventHandler( "onZombieSpawn", getRootElement(), RanSpawn_Z )
  420.  
  421.  
  422. --SPAWNS ZOMBIES RANDOMLY NEAR PLAYERS
  423. function SpawnZombie ()
  424. local pacecount = 0
  425. while pacecount < 5 do --4 ZOMBIES AT A TIME TO PREVENT FPS DROP
  426. if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 1) then
  427. local xcoord = 0
  428. local ycoord = 0
  429. local xdirection = math.random(1,2)
  430. if xdirection == 1 then
  431. xcoord = math.random(15,40)
  432. else
  433. xcoord = math.random(-40,-15)
  434. end
  435. local ydirection = math.random(1,2)
  436. if ydirection == 1 then
  437. ycoord = math.random(15,40)
  438. else
  439. ycoord = math.random(-40,-15)
  440. end
  441. local liveplayers = getAlivePlayers ()
  442. if (table.getn( liveplayers ) > 0 ) then
  443. local lowestcount = 99999
  444. local lowestguy = nil
  445. for PKey,thePlayer in ipairs(liveplayers) do
  446. if isElement(thePlayer) then
  447. if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned" ) == true) then
  448. if (getElementData (thePlayer, "dangercount") < lowestcount) then
  449. local safezone = 0
  450. local gx, gy, gz = getElementPosition( thePlayer )
  451. local allradars = getElementsByType("radararea")
  452. for theKey,theradar in ipairs(allradars) do
  453. if getElementData(theradar, "zombieProof") == true then
  454. if isInsideRadarArea ( theradar, gx, gy ) then
  455. safezone = 1
  456. end
  457. end
  458. end
  459. if safezone == 0 then
  460. lowestguy = thePlayer
  461. lowestcount = getElementData (thePlayer, "dangercount")
  462. end
  463. end
  464. end
  465. end
  466. end
  467. pacecount = pacecount+1
  468. if isElement(lowestguy) then
  469. triggerClientEvent ( "Spawn_Placement", lowestguy, ycoord, xcoord )
  470. else
  471. pacecount = pacecount+1
  472. end
  473. else
  474. pacecount = pacecount+1
  475. end
  476. else
  477. pacecount = pacecount+1
  478. end
  479. end
  480. end
  481.  
  482. --SPAWNS ZOMBIES IN SPAWNPOINTS NEAR PLAYERS
  483. function SpawnpointZombie ()
  484. local pacecount = 0
  485. while pacecount < 6 do --5 ZOMBIES AT A TIME TO PREVENT FPS DROP
  486. if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 2) then
  487. local liveplayers = getAlivePlayers ()
  488. if (table.getn( liveplayers ) > 0 ) then
  489. local lowestcount = 99999
  490. local lowestguy = nil
  491. for PKey,thePlayer in ipairs(liveplayers) do --THIS PART GETS THE PLAYER WITH THE LEAST ZOMBIES ATTACKING
  492. if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) then
  493. if (getElementData (thePlayer, "dangercount") < lowestcount) then
  494. lowestguy = thePlayer
  495. lowestcount = getElementData (thePlayer, "dangercount")
  496. end
  497. end
  498. end
  499. if isElement(lowestguy) then
  500. local zombiespawns = { }
  501. local possiblezombies = getElementsByType ( "Zombie_spawn" )
  502. local Px, Py, Pz = getElementPosition( lowestguy )
  503. for ZombKey,theZomb in ipairs(possiblezombies) do
  504. local Zx, Zy, Zz = getElementPosition( theZomb )
  505. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  506. if (distance < 8) then
  507. table.remove( possiblezombies, ZombKey) --IF SPAWN IS TOO CLOSE TO ANY PLAYER
  508. end
  509. end
  510. local Px, Py, Pz = getElementPosition( lowestguy )
  511. for ZombKey2,theZomb2 in ipairs(possiblezombies) do
  512. local Zx, Zy, Zz = getElementPosition( theZomb2 )
  513. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  514. if (distance < 60) then --AS LONG AS THE SPAWN IS CLOSE ENOUGH TO A PLAYER
  515. table.insert( zombiespawns, theZomb2 )
  516. end
  517. end
  518. if (table.getn( zombiespawns ) >0 ) then--IF THE LOWEST PLAYER HAS ANY CLOSE SPAWNS,USE ONE
  519. local random = math.random ( 1, table.getn ( zombiespawns ) )
  520. local posX = getElementData(zombiespawns[random], "posX")
  521. local posY = getElementData(zombiespawns[random], "posY")
  522. local posZ = getElementData(zombiespawns[random], "posZ")
  523. local rot = getElementData(zombiespawns[random], "rotZ")
  524. pacecount = pacecount+1
  525. triggerEvent ( "onZombieSpawn",zombiespawns[random], posX, posY, posZ, rot )
  526. else--IF THE LOWEST PLAYERS DOESNT HAVE ANY SPAWNS, THEN SEE IF ANYONE HAS ANY
  527. local zombiespawns = { }
  528. local possiblezombies = getElementsByType ( "Zombie_spawn" )
  529. local allplayers = getAlivePlayers ()
  530. for theKey,thePlayer in ipairs(allplayers) do
  531. local Px, Py, Pz = getElementPosition( thePlayer )
  532. for ZombKey,theZomb in ipairs(possiblezombies) do
  533. local Zx, Zy, Zz = getElementPosition( theZomb )
  534. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  535. if (distance < 8) then
  536. table.remove( possiblezombies, ZombKey) --IF SPAWN IS TOO CLOSE TO ANY PLAYER
  537. end
  538. end
  539. end
  540. for theKey,thePlayer in ipairs(allplayers) do
  541. local Px, Py, Pz = getElementPosition( thePlayer )
  542. for ZombKey2,theZomb2 in ipairs(possiblezombies) do
  543. local Zx, Zy, Zz = getElementPosition( theZomb2 )
  544. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  545. if (distance < 60) then --AS LONG AS THE SPAWN IS CLOSE ENOUGH TO A PLAYER
  546. table.insert( zombiespawns, theZomb2 )
  547. end
  548. end
  549. end
  550. if (table.getn( zombiespawns ) >1 ) then
  551. local random = math.random ( 1, table.getn ( zombiespawns ) )
  552. local posX = getElementData(zombiespawns[random], "posX")
  553. local posY = getElementData(zombiespawns[random], "posY")
  554. local posZ = getElementData(zombiespawns[random], "posZ")
  555. local rot = getElementData(zombiespawns[random], "rotZ")
  556. pacecount = pacecount+1
  557. triggerEvent ( "onZombieSpawn",zombiespawns[random], posX, posY, posZ, rot )
  558. else
  559. pacecount = pacecount+1
  560. end
  561. end
  562. else
  563. pacecount = pacecount+1
  564. end
  565. else
  566. pacecount = pacecount+1
  567. end
  568. else
  569. pacecount = pacecount+1
  570. end
  571. end
  572. end
  573.  
  574. --DELETES ZOMBIES THAT ARE TOO FAR FROM ANY PLAYERS TO KEEP THEM MORE CONCENTRATED WHILE STREAMING ZOMBIES
  575. function clearFarZombies ()
  576. if newZombieLimit ~= false then
  577. local toofarzombies = { }
  578. local allplayers = getElementsByType ( "player" )
  579. for ZombKey,theZomb in ipairs(everyZombie) do
  580. if isElement(theZomb) then
  581. if (getElementData (theZomb, "zombie") == true) then
  582. far = 1
  583. local Zx, Zy, Zz = getElementPosition( theZomb )
  584. for theKey,thePlayer in ipairs(allplayers) do
  585. local Px, Py, Pz = getElementPosition( thePlayer )
  586. local distance = (getDistanceBetweenPoints3D( Px, Py, Pz, Zx, Zy, Zz ))
  587. if (distance < 75) then
  588. far = 0
  589. end
  590. end
  591. if far == 1 then
  592. table.insert( toofarzombies, theZomb )
  593. end
  594. end
  595. else
  596. table.remove( everyZombie, ZombKey )
  597. end
  598. end
  599. if (table.getn( toofarzombies ) >1 ) then
  600. for ZombKey,theZomb in ipairs(toofarzombies) do
  601. if (getElementData (theZomb, "zombie") == true) and ( getElementData ( theZomb, "forcedtoexist" ) ~= true) then
  602. Zomb_delete (theZomb)
  603. end
  604. end
  605. end
  606. end
  607. end
  608.  
  609. -- DESTROYS UP TO 13 ZOMBIES THAT ARE IDLE WHEN A PLAYER SPAWNS (TO FORCE NEW ZOMBIES TO SPAWN NEAR THE NEW GUY)
  610. function player_Spawn ()
  611. if ZombieStreaming == 1 or ZombieStreaming == 2 then
  612. local relocatecount = 0
  613. for ZombKey,theZomb in ipairs(everyZombie) do
  614. if relocatecount < 14 then
  615. if ( getElementData ( theZomb, "forcedtoexist" ) ~= true) then
  616. if ( getElementData ( theZomb, "status" ) == "idle" ) and ( isPedDead ( theZomb ) == false ) and (getElementData (theZomb, "zombie") == true) then
  617. relocatecount = relocatecount+1
  618. Zomb_delete (theZomb)
  619. end
  620. end
  621. end
  622. end
  623. end
  624. if ( getElementData ( source, "alreadyspawned" ) ~= true) then
  625. setElementData ( source, "alreadyspawned", true )
  626. end
  627. end
  628. addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn )
  629.  
  630. --EXPORTED FUNCTIONS!!!!!!!!!!!!!!
  631. function createZombie ( x, y, z, rot, skin, interior, dimension )
  632. if (table.getn( everyZombie ) < newZombieLimit ) then
  633. --this part handles the args
  634. if not x then return false end
  635. if not y then return false end
  636. if not z then return false end
  637. if not rot then
  638. rot = math.random (1,359)
  639. end
  640. if not skin then
  641. randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )
  642. skin = ZombiePedSkins[randomZskin]
  643. end
  644. if not interior then interior = 0 end
  645. if not dimension then dimension = 0 end
  646. --this part spawns the ped
  647. local zomb = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z))--spawns the ped
  648. --if successful, this part applies the zombie settings/args
  649. if (zomb ~= false) then
  650. setTimer ( setElementInterior, 100, 1, zomb, tonumber(interior)) --sets interior
  651. setTimer ( setElementDimension, 100, 1, zomb, tonumber(dimension)) --sets dimension
  652. setElementData ( zomb, "zombie", true )
  653. setElementData ( zomb, "forcedtoexist", true )
  654. setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot )
  655. setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb )
  656. setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "forcedtoexist", true ) end end, 1000, 1, zomb )
  657. setTimer ( function (zomb) if ( isElement ( zomb ) ) then table.insert( everyZombie, zomb ) end end, 1000, 1, zomb )
  658. triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb )
  659. return zomb --returns the zombie element
  660. else
  661. return false --returns false if there was a problem
  662. end
  663. else
  664. return false --returns false if there was a problem
  665. end
  666. end
  667.  
  668. --check if a ped is a zombie or not
  669. function isPedZombie(ped)
  670. if (isElement(ped)) then
  671. if (getElementData (ped, "zombie") == true) then
  672. return true
  673. else
  674. return false
  675. end
  676. else
  677. return false
  678. end
  679. end
  680.  
  681. addEvent( "onZombieLostPlayer", true )
  682. function ZombieTargetCoords ( x,y,z )
  683. setElementData ( source, "Tx", x, false )
  684. setElementData ( source, "Ty", y, false )
  685. setElementData ( source, "Tz", z, false )
  686. end
  687. addEventHandler( "onZombieLostPlayer", getRootElement(), ZombieTargetCoords )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement