Guest User

zombies

a guest
Jan 22nd, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.94 KB | None | 0 0
  1. myZombies = { }
  2. helmetzombies = { 27, 51, 52, 99, 27, 137, 153, 167, 205, 260, 277, 278, 279, 284, 285 }
  3. resourceRoot = getResourceRootElement()
  4.  
  5. --FORCES ZOMBIES TO MOVE ALONG AFTER THEIR TARGET PLAYER DIES
  6. function playerdead ()
  7.     setTimer ( Zomb_release, 4000, 1 )
  8. end
  9. addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), playerdead )
  10.  
  11. function Zomb_release ()
  12.     for k, ped in pairs( myZombies ) do
  13.         if (isElement(ped)) then
  14.             if (getElementData (ped, "zombie") == true) then
  15.                 setElementData ( ped, "target", nil )
  16.                 setElementData ( ped, "status", "idle" )
  17.                 table.remove(myZombies,k)
  18.             end
  19.         end
  20.     end
  21. end
  22.  
  23. --REMOVES A ZOMBIE FROM INFLUENCE AFTER ITS KILLED
  24. function pedkilled ( killer, weapon, bodypart )
  25.     if (getElementData (source, "zombie") == true) and (getElementData (source, "status") ~= "dead" ) then
  26.         setElementData ( source, "target", nil )
  27.         setElementData ( source, "status", "dead" )
  28.     end
  29. end
  30. addEventHandler ( "onClientPedWasted", getRootElement(), pedkilled )
  31.  
  32. --THIS CHECKS ALL ZOMBIES EVERY SECOND TO SEE IF THEY ARE IN SIGHT
  33. function zombie_check ()
  34.     if (getElementData (getLocalPlayer (), "zombie") ~= true) and ( isPlayerDead ( getLocalPlayer () ) == false ) then
  35.         local zombies = getElementsByType ( "ped",getRootElement(),true )
  36.         local Px,Py,Pz = getElementPosition( getLocalPlayer () )
  37.         if isPedDucked ( getLocalPlayer ()) then
  38.             local Pz = Pz-1
  39.         end    
  40.         for theKey,theZomb in ipairs(zombies) do
  41.             if (isElement(theZomb)) then
  42.                 local Zx,Zy,Zz = getElementPosition( theZomb )
  43.                 if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  44.                     if (getElementData (theZomb, "zombie") == true) then
  45.                         if ( getElementData ( theZomb, "status" ) == "idle" ) then --CHECKS IF AN IDLE ZOMBIE IS IN SIGHT
  46.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  47.                             if (isclear == true) then
  48.                                 setElementData ( theZomb, "status", "chasing" )
  49.                                 setElementData ( theZomb, "target", getLocalPlayer() )
  50.                                 table.insert( myZombies, theZomb ) --ADDS ZOMBIE TO PLAYERS COLLECTION
  51.                                 table.remove( zombies, theKey)
  52.                                 zombieradiusalert (theZomb)
  53.                             end
  54.                         elseif (getElementData(theZomb,"status") == "chasing") and (getElementData(theZomb,"target") == nil) then --CHECKS IF AN AGGRESSIVE LOST ZOMBIE IS IN SIGHT
  55.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  56.                             if (isclear == true) then
  57.                                 setElementData ( theZomb, "target", getLocalPlayer() )
  58.                                 isthere = "no"
  59.                                 for k, ped in pairs( myZombies ) do
  60.                                     if ped == theZomb then
  61.                                         isthere = "yes"
  62.                                     end
  63.                                 end
  64.                                 if isthere == "no" then
  65.                                     table.insert( myZombies, theZomb ) --ADDS THE WAYWARD ZOMBIE TO THE PLAYERS COLLECTION
  66.                                     table.remove( zombies, theKey)
  67.                                 end
  68.                             end
  69.                         elseif ( getElementData ( theZomb, "target" ) == getLocalPlayer() ) then --CHECKS IF AN ALREADY AGGRESSIVE ZOMBIE IS IN SIGHT
  70.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  71.                             if (isclear == false) then --IF YOUR ZOMBIE LOST YOU, MAKES IT REMEMBER YOUR LAST COORDS
  72.                                 setElementData ( theZomb, "target", nil )
  73.                                 triggerServerEvent ("onZombieLostPlayer", theZomb, oldPx, oldPy, oldPz)
  74.                             end
  75.                         end
  76.                     end
  77.                 end
  78.             end
  79.         end
  80.     --this second half is for checking peds and zombies
  81.    
  82.         local nonzombies = getElementsByType ( "ped",getRootElement(),true )
  83.         for theKey,theZomb in ipairs(zombies) do
  84.             if (isElement(theZomb)) then
  85.                 if (getElementData (theZomb, "zombie") == true) then
  86.                     local Zx,Zy,Zz = getElementPosition( theZomb )
  87.                     for theKey,theNonZomb in ipairs(nonzombies) do
  88.                         if (getElementData (theNonZomb, "zombie") ~= true) then -- if the ped isnt a zombie
  89.                             local Px,Py,Pz = getElementPosition( theNonZomb )
  90.                             if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  91.                                 local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false )
  92.                                 if (isclear == true) and ( getElementHealth ( theNonZomb ) > 0) then
  93.                                     if ( getElementData ( theZomb, "status" ) == "idle" ) then --CHECKS IF AN IDLE ZOMBIE IS IN SIGHT
  94.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)                                 
  95.                                         setElementData ( theZomb, "status", "chasing" )
  96.                                         setElementData ( theZomb, "target", theNonZomb )
  97.                                         zombieradiusalert (theZomb)
  98.                                     elseif ( getElementData ( theZomb, "status" ) == "chasing" ) and ( getElementData ( theZomb, "target" ) == nil) then
  99.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)
  100.                                         setElementData ( theZomb, "target", theNonZomb )                                   
  101.                                     end
  102.                                 end                
  103.                             end    
  104.                             if ( getElementData ( theZomb, "target" ) == theNonZomb ) then --CHECKS IF AN ALREADY AGGRESSIVE ZOMBIE IS IN SIGHT OF THE PED
  105.                                 local Px,Py,Pz = getElementPosition( theNonZomb )
  106.                                 if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  107.                                     local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz+1, true, false, false, true, false, false, false)
  108.                                     if (isclear == false) then --IF YOUR ZOMBIE LOST THE PED, MAKES IT REMEMBER the peds LAST COORDS
  109.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)                         
  110.                                         setElementData ( theZomb, "target", nil )
  111.                                     end
  112.                                 end
  113.                             end
  114.                         end
  115.                     end
  116.                 end
  117.             end
  118.         end
  119.     end
  120.     for k, ped in pairs( myZombies ) do
  121.         if (isElement(ped) == false) then
  122.             table.remove( myZombies, k)
  123.         end
  124.     end
  125.     oldPx,oldPy,oldPz = getElementPosition( getLocalPlayer () )
  126. end
  127.  
  128.  
  129. --INITAL SETUP
  130.  
  131. function clientsetupstarter(startedresource)
  132.     if startedresource == getThisResource() then
  133.         setTimer ( clientsetup, 1234, 1)
  134.         MainClientTimer1 = setTimer ( zombie_check, 1000, 0)  --STARTS THE TIMER TO CHECK FOR ZOMBIES
  135.     end
  136. end
  137. addEventHandler("onClientResourceStart", getRootElement(), clientsetupstarter)
  138.  
  139. function clientsetup()
  140.     oldPx,oldPy,oldPz = getElementPosition( getLocalPlayer () )
  141.     throatcol = createColSphere ( 0, 0, 0, .3)
  142.     woodpic = guiCreateStaticImage( .65, .06, .1, .12, "zombiewood.png", true )
  143.     guiSetVisible ( woodpic, false )
  144.  
  145. --ALL ZOMBIES STFU
  146.     local zombies = getElementsByType ( "ped" )
  147.     for theKey,theZomb in ipairs(zombies) do
  148.         if (isElement(theZomb)) then
  149.             if (getElementData (theZomb, "zombie") == true) then
  150.                 setPedVoice(theZomb, "PED_TYPE_DISABLED")
  151.             end
  152.         end
  153.     end
  154.    
  155. --SKIN REPLACEMENTS
  156.     local skin = engineLoadTXD ( "skins/13.txd" ) --Alien by Sairus
  157.     engineImportTXD ( skin, 13 )
  158.     local skin = engineLoadDFF("skins/13.dff", 13 )
  159.     engineReplaceModel(skin, 13)
  160.     local skin2 = engineLoadTXD ( "skins/22.txd" ) -- Alien Boss by Sairus
  161.     engineImportTXD ( skin2, 22 )
  162.     local skin2 = engineLoadDFF("skins/22.dff", 22 )
  163.     engineReplaceModel(skin2, 22)   
  164. end
  165.  
  166. --UPDATES PLAYERS COUNT OF AGGRESIVE ZOMBIES
  167. addEventHandler ( "onClientElementDataChange", getRootElement(),
  168. function ( dataName )
  169.     if getElementType ( source ) == "ped" and dataName == "status" then
  170.         local thestatus = (getElementData ( source, "status" ))
  171.         if (thestatus == "idle") or (thestatus == "dead") then     
  172.             for k, ped in pairs( myZombies ) do
  173.                 if ped == source and (getElementData (ped, "zombie") == true) then
  174.                     setElementData ( ped, "target", nil )
  175.                     table.remove( myZombies, k)
  176.                     setElementData ( getLocalPlayer(), "dangercount", tonumber(table.getn( myZombies )) )
  177.                 end
  178.             end
  179.         end
  180.     end
  181. end )
  182.  
  183. --MAKES A ZOMBIE JUMP
  184. addEvent( "Zomb_Jump", true )
  185. function Zjump ( ped )
  186.     if (isElement(ped)) then
  187.         setPedControlState( ped, "jump", true )
  188.         setTimer ( function (ped) if ( isElement ( ped ) ) then setPedControlState ( ped, "jump", false) end end, 800, 1, ped )
  189.     end
  190. end
  191. addEventHandler( "Zomb_Jump", getRootElement(), Zjump )
  192.  
  193. --MAKES A ZOMBIE PUNCH
  194. addEvent( "Zomb_Punch", true )
  195. function Zpunch ( ped )
  196.     if (isElement(ped)) then
  197.         setPedControlState( ped, "fire", true )
  198.         setTimer ( function (ped) if ( isElement ( ped ) ) then setPedControlState ( ped, "fire", false) end end, 800, 1, ped )
  199.     end
  200. end
  201. addEventHandler( "Zomb_Punch", getRootElement(), Zpunch )
  202.  
  203. --MAKES A ZOMBIE STFU
  204. addEvent( "Zomb_STFU", true )
  205. function Zstfu ( ped )
  206.     if (isElement(ped)) then
  207.         setPedVoice(ped, "PED_TYPE_DISABLED")
  208.     end
  209. end
  210. addEventHandler( "Zomb_STFU", getRootElement(), Zstfu )
  211.  
  212. --MAKES A ZOMBIE MOAN
  213. addEvent( "Zomb_Moan", true )
  214. function Zmoan ( ped, randnum )
  215.     if (isElement(ped)) then
  216.         local Zx,Zy,Zz = getElementPosition( ped )
  217.         local sound = playSound3D("sounds/mgroan"..randnum..".ogg", Zx, Zy, Zz, false)
  218.         setSoundMaxDistance(sound, 20)
  219.     end
  220. end
  221. addEventHandler( "Zomb_Moan", getRootElement(), Zmoan )
  222.  
  223. --ZOMBIE HEADSHOTS TO ALL BUT HELMETED ZOMBIES
  224. function zombiedamaged ( attacker, weapon, bodypart )
  225.     if getElementType ( source ) == "ped" then
  226.         if (getElementData (source, "zombie") == true) then
  227.             if ( bodypart == 9 ) then
  228.                 helmeted = "no"
  229.                 local zskin = getElementModel ( source )
  230.                 for k, skin in pairs( helmetzombies ) do
  231.                     if skin == zskin then
  232.                         helmeted = "yes"
  233.                     end
  234.                 end
  235.                 if helmeted == "no" then
  236.                     triggerServerEvent ("headboom", source, source, attacker, weapon, bodypart )
  237.                 end
  238.             end
  239.         end
  240.     end
  241. end
  242. addEventHandler ( "onClientPedDamage", getRootElement(), zombiedamaged )
  243.  
  244. function zombiedkilled(killer, weapon, bodypart)
  245.     if getElementType ( source ) == "ped" then
  246.         if (getElementData (source, "zombie") == true) then
  247.             setElementCollisionsEnabled(source, false)
  248.         end
  249.     end
  250. end
  251. addEventHandler ( "onClientPedWasted", getRootElement(), zombiedkilled )
  252.  
  253. --CAUSES MORE DAMAGE TO PLAYER WHEN ATTACKED BY A ZOMBIE
  254. function zombieattack ( attacker, weapon, bodypart )
  255.     if (attacker) then
  256.         if getElementType ( attacker ) == "ped" then
  257.             if (getElementData (attacker, "zombie") == true) then
  258.                 local playerHealth = getElementHealth ( getLocalPlayer() )
  259.                 if playerHealth > 15 then
  260.                     setElementHealth ( source, playerHealth - 15 )
  261.                 else
  262.                     triggerServerEvent ("playereaten", source, source, attacker, weapon, bodypart )
  263.                 end
  264.             end
  265.         end
  266.     end
  267. end
  268. addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), zombieattack )
  269.  
  270. --WOOD GUI
  271. function showwoodpic ( theElement, matchingDimension )
  272.     if ( theElement == getLocalPlayer() ) and (getElementData ( source, "purpose" ) == "zombiewood" ) then
  273.         guiSetVisible ( woodpic, true )
  274.     end
  275. end
  276. addEventHandler ( "onClientColShapeHit", getRootElement(), showwoodpic )
  277.  
  278. function hidewoodpic ( theElement, matchingDimension )
  279.     if ( theElement == getLocalPlayer() ) and (getElementData ( source, "purpose" ) == "zombiewood" ) then
  280.         guiSetVisible ( woodpic, false )
  281.     end
  282. end
  283. addEventHandler ( "onClientColShapeLeave", getRootElement(), hidewoodpic )
  284.  
  285. --ZOMBIES ATTACK FROM BEHIND AND GUI STUFF
  286. function movethroatcol ()
  287.     local screenWidth, screenHeight = guiGetScreenSize()
  288.     local dcount = tostring(table.getn( myZombies ))
  289.     dxDrawText( dcount, screenWidth-40, screenHeight -50, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.44, "pricedown" )
  290.     dxDrawText( dcount, screenWidth-42, screenHeight -52, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1.4, "pricedown" )
  291.    
  292.     if isElement(throatcol) then
  293.         local playerrot = getPedRotation ( getLocalPlayer () )
  294.         local radRot = math.rad ( playerrot )
  295.         local radius = 1
  296.         local px,py,pz = getElementPosition( getLocalPlayer () )
  297.         local tx = px + radius * math.sin(radRot)
  298.         local ty = py + -(radius) * math.cos(radRot)
  299.         local tz = pz
  300.         setElementPosition ( throatcol, tx, ty, tz )
  301.     end
  302. end
  303. addEventHandler ( "onClientRender", getRootElement(), movethroatcol )
  304.  
  305. function choketheplayer ( theElement, matchingDimension )
  306.     if getElementType ( theElement ) == "ped" and ( isPlayerDead ( getLocalPlayer () ) == false ) then
  307.         if ( getElementData ( theElement, "target" ) == getLocalPlayer () ) and (getElementData (theElement, "zombie") == true) then
  308.             local px,py,pz = getElementPosition( getLocalPlayer () )
  309.             setTimer ( checkplayermoved, 600, 1, theElement, px, py, pz)
  310.         end
  311.     end
  312. end
  313. addEventHandler ( "onClientColShapeHit", getRootElement(), choketheplayer )
  314.  
  315. function checkplayermoved (zomb, px, py, pz)
  316.     if (isElement(zomb)) then
  317.         local nx,ny,nz = getElementPosition( getLocalPlayer () )
  318.         local distance = (getDistanceBetweenPoints3D (px, py, pz, nx, ny, nz))
  319.         if (distance < .7) and ( isPlayerDead ( getLocalPlayer () ) == false ) then
  320.             setElementData ( zomb, "status", "throatslashing" )
  321.         end
  322.     end
  323. end
  324.  
  325. --ALERTS ANY IDLE ZOMBIES WITHIN A RADIUS OF 10 WHEN GUNSHOTS OCCUR OR OTHER ZOMBIES GET ALERTED
  326. function zombieradiusalert (theElement)
  327.     local Px,Py,Pz = getElementPosition( theElement )
  328.     local zombies = getElementsByType ( "ped" )
  329.     for theKey,theZomb in ipairs(zombies) do
  330.         if (isElement(theZomb)) then
  331.             if (getElementData (theZomb, "zombie") == true) then
  332.                 if ( getElementData ( theZomb, "status" ) == "idle" ) then
  333.                     local Zx,Zy,Zz = getElementPosition( theZomb )
  334.                     local distance = (getDistanceBetweenPoints3D (Px, Py, Pz, Zx, Zy, Zz))
  335.                     if (distance < 10) and ( isPlayerDead ( getLocalPlayer () ) == false ) then
  336.                         isthere = "no"
  337.                         for k, ped in pairs( myZombies ) do
  338.                             if ped == theZomb then
  339.                                 isthere = "yes"
  340.                             end
  341.                         end
  342.                         if isthere == "no" and (getElementData (getLocalPlayer (), "zombie") ~= true) then
  343.                             if (getElementType ( theElement ) == "ped") then
  344.                                 local isclear = isLineOfSightClear (Px, Py, Pz, Zx, Zy, Zz, true, false, false, true, false, false, false)
  345.                                 if (isclear == true) then
  346.                                     setElementData ( theZomb, "status", "chasing" )
  347.                                     setElementData ( theZomb, "target", getLocalPlayer () )
  348.                                     table.insert( myZombies, theZomb ) --ADDS ZOMBIE TO PLAYERS COLLECTION
  349.                                 end
  350.                             else
  351.                                 setElementData ( theZomb, "status", "chasing" )
  352.                                 setElementData ( theZomb, "target", getLocalPlayer () )
  353.                                 table.insert( myZombies, theZomb ) --ADDS ZOMBIE TO PLAYERS COLLECTION
  354.                             end
  355.                         end
  356.                     end
  357.                 end
  358.             end
  359.         end
  360.     end
  361. end
  362.  
  363. function shootingnoise ( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
  364.     if alertspacer ~= 1 then
  365.         if (weapon == 9) then
  366.             alertspacer = 1
  367.             setTimer ( resetalertspacer, 5000, 1 )
  368.             zombieradiusalert(getLocalPlayer ())
  369.         elseif (weapon > 21) and (weapon ~= 23) then
  370.             alertspacer = 1
  371.             setTimer ( resetalertspacer, 5000, 1 )
  372.             zombieradiusalert(getLocalPlayer ())
  373.         end
  374.     end
  375.     if hitElement then
  376.         if (getElementType ( hitElement ) == "ped") then
  377.             if (getElementData (hitElement, "zombie") == true) then        
  378.                 isthere = "no"
  379.                 for k, ped in pairs( myZombies ) do
  380.                     if ped == hitElement then
  381.                         isthere = "yes"
  382.                     end
  383.                 end
  384.                 if isthere == "no" and (getElementData (getLocalPlayer (), "zombie") ~= true) then
  385.                     setElementData ( hitElement, "status", "chasing" )
  386.                     setElementData ( hitElement, "target", getLocalPlayer () )
  387.                     table.insert( myZombies, hitElement ) --ADDS ZOMBIE TO PLAYERS COLLECTION
  388.                     zombieradiusalert (hitElement)
  389.                 end
  390.             end
  391.         end
  392.     end
  393. end
  394. addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer (), shootingnoise )
  395.  
  396. function resetalertspacer ()
  397.     alertspacer = nil
  398. end
  399.  
  400. function choketheplayer ( theElement, matchingDimension )
  401.     if getElementType ( theElement ) == "ped" and ( isPlayerDead ( getLocalPlayer () ) == false ) and (getElementData (theElement , "zombie") == true) then
  402.         if ( getElementData ( theElement, "target" ) == getLocalPlayer () ) then
  403.             local px,py,pz = getElementPosition( getLocalPlayer () )
  404.             setTimer ( checkplayermoved, 600, 1, theElement, px, py, pz)
  405.         end
  406.     end
  407. end
  408.  
  409. addEvent( "Spawn_Placement", true )
  410. function Spawn_Place(xcoord, ycoord)
  411.     local x,y,z = getElementPosition( getLocalPlayer() )
  412.     local posx = x+xcoord
  413.     local posy = y+ycoord
  414.     local gz = getGroundPosition ( posx, posy, z+500 )
  415.     triggerServerEvent ("onZombieSpawn", getLocalPlayer(), posx, posy, gz+1 )
  416. end
  417. addEventHandler("Spawn_Placement", getRootElement(), Spawn_Place)
Advertisement
Add Comment
Please, Sign In to add comment