Guest User

server side

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