Jump to content

Prevent zombies spawning in the water


Chaos

Recommended Posts

Posted

hey guys,

i want to prevent zombies keep spawning in the water it's really annoying and most of zombies are spawning in water. I'm using default zombies script..

10579747_1567019436862500_821302010_o.jpg?oh=b390b015630568893a43547d9d7fa8d9&oe=54836EDD&__gda__=1417844237_c452f3782ff8550694bd11b034877042

any idea ?

  • MTA Team
Posted

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.

Posted
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 

Posted
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

  • MTA Team
Posted

It should work, though i'm not sure that's the function that uses when you spawn zombies randomly. You could use a timer, maybe when the conditional is passed, the zombie is not yet created.

Posted
  
setTimer(function() 
for i,v in ipairs(getElementsByType("ped")) do 
 if not getPlayerName(v) then 
if isElementInWater(v) then 
destroyElement(v) 
end 
 end 
end 
end, 1000,0) 
  

Maybe..?

  • Moderators
Posted

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.

Posted (edited)
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
  • Moderators
Posted

You can't destroy serverside peds, clientside.

and use this before you spawn the ped, not when you already created it.

Posted
You can't destroy serverside peds, clientside.

and use this before you spawn the ped, not when you already created it.

testLineAgainstWater  

function is client side and the spawn function in the server side how can i do it then ?

  • Moderators
Posted

@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) 
  

Posted

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

HAHAHAHAHAHAHAHAHAH thanks god that 2014 didn't end yet.

You sir, are in the 2014 #1 ranking of stupids persons.

You-just-went-full-retard-never-go-full-retard.png

Posted

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 

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...