Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.41 KB | None | 0 0
  1. function zombie_check ()
  2.     if (getElementData (getLocalPlayer (), "zombie") ~= true) and ( isPedDead ( getLocalPlayer () ) == false ) and (getElementModel(getLocalPlayer()) ~= 293) then
  3.         local zombies = getElementsByType ( "ped",getRootElement(),true )
  4.         local id = getElementModel (localPlayer)
  5.         local Px,Py,Pz = getElementPosition( getLocalPlayer () )
  6.         if isPedDucked ( getLocalPlayer ()) then
  7.             local Pz = Pz-1
  8.         end    
  9.         for theKey,theZomb in ipairs(zombies) do
  10.             if (isElement(theZomb)) then
  11.                 local Zx,Zy,Zz = getElementPosition( theZomb )
  12.                 if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  13.                     if (getElementData (theZomb, "zombie") == true) then
  14.                         if ( getElementData ( theZomb, "status" ) == "idle" ) then
  15.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  16.                             if (isclear == true) then
  17.                                 setElementData ( theZomb, "status", "chasing" )
  18.                                 setElementData ( theZomb, "target", getLocalPlayer() )
  19.                                 table.insert( myZombies, theZomb )
  20.                                 table.remove( zombies, theKey)
  21.                                 zombieradiusalert (theZomb)
  22.                             end
  23.                         elseif (getElementData(theZomb,"status") == "chasing") and (getElementData(theZomb,"target") == nil) then --
  24.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  25.                             if (isclear == true) then
  26.                                 setElementData ( theZomb, "target", getLocalPlayer() )
  27.                                 isthere = "no"
  28.                                 for k, ped in pairs( myZombies ) do
  29.                                     if ped == theZomb then
  30.                                         isthere = "yes"
  31.                                     end
  32.                                 end
  33.                                 if isthere == "no" then
  34.                                     table.insert( myZombies, theZomb )
  35.                                     if id = 293 then
  36.                                     table.insert( myZombies, id )
  37.                                     end
  38.                                     table.remove( zombies, theKey)
  39.                                 end
  40.                             end
  41.                         elseif ( getElementData ( theZomb, "target" ) == getLocalPlayer() ) then
  42.                             local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false)
  43.                             if (isclear == false) then
  44.                                 setElementData ( theZomb, "target", nil )
  45.                                 triggerServerEvent ("onZombieLostPlayer", theZomb, oldPx, oldPy, oldPz)
  46.                             end
  47.                         end
  48.                     end
  49.                 end
  50.             end
  51.         end
  52.  
  53.    
  54.         local nonzombies = getElementsByType ( "ped",getRootElement(),true )
  55.         local id = getElementModel (localPlayer)
  56.         for theKey,theZomb in ipairs(zombies) do
  57.             if (isElement(theZomb)) then
  58.                 if (getElementData (theZomb, "zombie") == true) then
  59.                     local Zx,Zy,Zz = getElementPosition( theZomb )
  60.                     for theKey,theNonZomb in ipairs(nonzombies) do
  61.                         if (getElementData (theNonZomb, "zombie") ~= true) and (id ~= 293)  then -- if the ped isnt a zombie
  62.                             local Px,Py,Pz = getElementPosition( theNonZomb )
  63.                             if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  64.                                 local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz +1, true, false, false, true, false, false, false )
  65.                                 if (isclear == true) and ( getElementHealth ( theNonZomb ) > 0) then
  66.                                     if ( getElementData ( theZomb, "status" ) == "idle" ) then
  67.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)                                 
  68.                                         setElementData ( theZomb, "status", "chasing" )
  69.                                         setElementData ( theZomb, "target", theNonZomb )
  70.                                         zombieradiusalert (theZomb)
  71.                                     elseif ( getElementData ( theZomb, "status" ) == "chasing" ) and ( getElementData ( theZomb, "target" ) == nil) then
  72.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)
  73.                                         setElementData ( theZomb, "target", theNonZomb )                                   
  74.                                     end
  75.                                 end                
  76.                             end    
  77.                             if ( getElementData ( theZomb, "target" ) == theNonZomb ) then
  78.                                 local Px,Py,Pz = getElementPosition( theNonZomb )
  79.                                 if (getDistanceBetweenPoints3D(Px, Py, Pz, Zx, Zy, Zz) < 45 ) then
  80.                                     local isclear = isLineOfSightClear (Px, Py, Pz+1, Zx, Zy, Zz+1, true, false, false, true, false, false, false)
  81.                                     if (isclear == false) then
  82.                                         triggerServerEvent ("onZombieLostPlayer", theZomb, Px, Py, Pz)                         
  83.                                         setElementData ( theZomb, "target", nil )
  84.                                     end
  85.                                 end
  86.                             end
  87.                         end
  88.                     end
  89.                 end
  90.             end
  91.         end
  92.     end
  93.     for k, ped in pairs( myZombies ) do
  94.         if (isElement(ped) == false) then
  95.             table.remove( myZombies, k)
  96.         end
  97.     end
  98.     oldPx,oldPy,oldPz = getElementPosition( getLocalPlayer () )
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement