Guest User

Untitled

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