Guest User

Untitled

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