Jump to content

Prevent zombies spawning in the water


Chaos

Recommended Posts

Just add a line after the createPed function like this:
  
if isElementInWater ( zomb ) then 
destroyElement( zomb ) 
end 

Remember to kill anything else that has to do with that ped.

there is no createPed function you mean here ?

  
--EXPORTED FUNCTIONS!!!!!!!!!!!!!! 
function createZombie ( x, y, z, rot, skin, interior, dimension ) 
    if (table.getn( everyZombie ) < newZombieLimit ) then 
    --this part handles the args 
        if not x then return false end 
        if not y then return false end 
        if not z then return false end 
        if not rot then 
            rot = math.random (1,359) 
        end 
        if not skin then 
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
            skin = ZombiePedSkins[randomZskin] 
        end 
        if not interior then interior = 0 end 
        if not dimension then dimension = 0 end 
    --this part spawns the ped 
        local zomb = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z))--spawns the ped 
  
    --if successful, this part applies the zombie settings/args 
        if (zomb ~= false) then 
            setTimer ( setElementInterior, 100, 1, zomb, tonumber(interior)) --sets interior 
            setTimer ( setElementDimension, 100, 1, zomb, tonumber(dimension)) --sets dimension 
            setElementData ( zomb, "zombie", true  ) 
            setElementData ( zomb, "forcedtoexist", true  ) 
            setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "forcedtoexist", true ) end end, 1000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then table.insert( everyZombie, zomb ) end end, 1000, 1, zomb ) 
            triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) 
            return zomb --returns the zombie element 
        else 
            return false --returns false if there was a problem 
        end 
    else 
        return false --returns false if there was a problem 
    end 
end 

Link to comment
Yes...Exactly after the createPed function as stated before.

it's not working

function createZombie ( x, y, z, rot, skin, interior, dimension ) 
    if (table.getn( everyZombie ) < newZombieLimit ) then 
    --this part handles the args 
        if not x then return false end 
        if not y then return false end 
        if not z then return false end 
        if not rot then 
            rot = math.random (1,359) 
        end 
        if not skin then 
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
            skin = ZombiePedSkins[randomZskin] 
        end 
        if not interior then interior = 0 end 
        if not dimension then dimension = 0 end 
    --this part spawns the ped 
        local zomb = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z))--spawns the ped 
        if isElementInWater ( zomb ) then 
        outputChatBox("it's Working",root) 
         destroyElement( zomb ) 
          end 
    --if successful, this part applies the zombie settings/args 
        if (zomb ~= false) then 
            setTimer ( setElementInterior, 100, 1, zomb, tonumber(interior)) --sets interior 
            setTimer ( setElementDimension, 100, 1, zomb, tonumber(dimension)) --sets dimension 
            setElementData ( zomb, "zombie", true  ) 
            setElementData ( zomb, "forcedtoexist", true  ) 
            setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "forcedtoexist", true ) end end, 1000, 1, zomb ) 
            setTimer ( function (zomb) if ( isElement ( zomb ) ) then table.insert( everyZombie, zomb ) end end, 1000, 1, zomb ) 
            triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) 
            return zomb --returns the zombie element 
        else 
            return false --returns false if there was a problem 
        end 
    else 
        return false --returns false if there was a problem 
    end 
end 
  

rTy4v3qDJ.png

Link to comment
  • Moderators

Clientside checks are more reliable, you should use clients to find the spawn-positions.

Those functions come in handy.

https://wiki.multitheftauto.com/wiki/Te ... ainstWater

https://wiki.multitheftauto.com/wiki/ProcessLineOfSight

It is more work, but it will use less network traffic because the zombies don't become useless when they spawn.

"Spawning them underwater will require the network from all players, while a simply secure check will only use 1 client."

@ .:HyPeX:.

Peds never have names.

Link to comment
Clientside checks are more reliable, you should use clients to find the spawn-positions.

Those functions come in handy.

https://wiki.multitheftauto.com/wiki/Te ... ainstWater

https://wiki.multitheftauto.com/wiki/ProcessLineOfSight

It is more work, but it will use less network traffic because the zombies don't become useless when they spawn.

"Spawning them underwater will require the network from all players, while a simply secure check will only use 1 client."

@ .:HyPeX:.

Peds never have names.

Understood i was wondering why my server lagging as hell i think because that.

is that what you mean?

addEvent( "Zomb_STFU", true ) 
function Zstfu ( ped ) 
    if (isElement(ped)) then 
        setPedVoice(ped, "PED_TYPE_DISABLED") 
    if isPedOnGround(ped) then 
        local px, py, pz = getElementPosition(ped) 
        if testLineAgainstWater(px, py, pz, px, py, pz - 500) then 
    destroyElement(ped) 
end 
end 
end 
end 
addEventHandler( "Zomb_STFU", getRootElement(), Zstfu ) 

Edited by Guest
Link to comment
  • Moderators

@Feche1320

Because preventing is better then fixing. If you disagree with that, then you are just stupid.

@Chaos

  
--(serverside) 
  
-- request positions x,y,z near the player 
triggerClientEvent(targetPlayer,"event",resourceRoot,x,y,z 
-- 
  
--(clientside) 
addEvent("event",true) 
addEventHandler("event",root, 
function(x,y,z) 
--... 
  
-- check the position 
testLineAgainstWater 
processLineOfSight 
  
-- if the position fails use a random positions near that point 
math.random() 
-- and check again until you find a right spot. Use a loop.  
testLineAgainstWater 
processLineOfSight 
  
  
-- if you found a point successfully, send it back to serverside so it can make a new zombie. 
triggerServerEvent("event2",localPlayer,x,y,z) 
  
-- if you didn't find a point, let the server know that there aren't spawn points. 
triggerServerEvent("event2",localPlayer,false) 
  

Link to comment

O_o

  
function createZombie ( x, y, z, rot, skin, interior, dimension ) 
  
    if (table.getn( everyZombie ) < newZombieLimit ) then 
  
    --this part handles the args 
  
        if not x then return false end 
  
        if not y then return false end 
  
        if not z then return false end 
  
        if not rot then 
  
            rot = math.random (1,359) 
  
        end 
  
  
if z < 0 then return end 
  
        if not skin then 
  
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
  
            skin = ZombiePedSkins[randomZskin] 
  
        end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...