Jump to content

How to dynamic zombies limit?


Recommended Posts

This's my Spawn script. Have any suggestion? please help

  
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 = setTimer(createPed, 8000, 0, 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 
  
--SPAWN ZOMBIE (now can be cancelled!) 
  
addEvent( "onZombieSpawn", true ) 
function RanSpawn_Z ( gx, gy, gz, rot) 
    local safezone = 0 
    local allradars = getElementsByType("radararea") 
    for theKey,theradar in ipairs(allradars) do 
        if getElementData(theradar, "zombieProof") == true then 
            if isInsideRadarArea ( theradar, gx, gy ) or ( isElementInWater ( getLocalPlayer() ) == true )  then 
                safezone = 1 
            end 
        end 
    end 
    if safezone == 0 then 
        if table.getn ( everyZombie ) < newZombieLimit then 
            if not rot then 
                rot = math.random (1,359) 
            end 
            randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) )           
            local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) 
            if zomb ~= false then 
                setElementData ( zomb, "zombie", true  ) 
                table.insert( everyZombie, zomb )     
                setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) 
                setTimer ( function (zomb) if ( isElement ( zomb ) ) then setPedAnimation ( zomb, "ped" ) end end, 200, 1, zomb )--, chaseanim, -1, true, true, true ) end end, 1000, 1, zomb ) 
                setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) 
                if ( randomZskin == 28 ) then giveWeapon( zomb, 8, 1) end 
                if ( randomZskin == 8 ) then setElementAlpha( zomb, 30) end 
                triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) 
            end 
        end 
    end 
end 
addEventHandler( "onZombieSpawn", getRootElement(), RanSpawn_Z ) 
  
  
--SPAWNS ZOMBIES RANDOMLY NEAR PLAYERS 
function SpawnZombie () 
    local pacecount = 0 
    while pacecount < 3 do  --2 ZOMBIES AT A TIME TO PREVENT FPS DROP 
    if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 1) then  
            local xcoord = 0 
            local ycoord = 0 
            local xdirection = math.random(1,2) 
            if xdirection == 1 then 
                xcoord = math.random(25,60) --defualt (15,40) 
            else 
                xcoord = math.random(-60,-25) --defualt = (-40,-15) 
            end 
            local ydirection = math.random(1,2) 
            if ydirection == 1 then 
                ycoord = math.random(25,60) --defualt = (15,45) 
            else 
                ycoord = math.random(-60,-25) --defualt = (-40,-15) 
            end 
            local liveplayers = getAlivePlayers () 
            if (table.getn( liveplayers ) > 0 ) then 
                local lowestcount = 99999 -- defualt = 99999 
                local lowestguy = nil 
                for PKey,thePlayer in ipairs(liveplayers) do 
                    if isElement(thePlayer) then 
                        if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned" ) == true) then 
                            if (getElementData (thePlayer, "dangercount") < lowestcount) then 
                                local safezone = 0 
                                local gx, gy, gz = getElementPosition( thePlayer ) 
                                local allradars = getElementsByType("radararea") 
                                for theKey,theradar in ipairs(allradars) do 
                                    if getElementData(theradar, "zombieProof") == true then 
                                        if isInsideRadarArea ( theradar, gx, gy ) then 
                                            safezone = 1 
                                        end 
                                    end 
                                end 
                                if safezone == 0 then 
                                    lowestguy = thePlayer 
                                    lowestcount = getElementData (thePlayer, "dangercount") 
                                end 
                            end 
                        end 
                    end 
                end 
                pacecount = pacecount+1 
                if isElement(lowestguy) then 
                    triggerClientEvent ( "Spawn_Placement", lowestguy, ycoord, xcoord ) 
                else 
                    pacecount = pacecount+1 
                end 
            else 
                pacecount = pacecount+1 
            end 
        else 
            pacecount = pacecount+1 
        end 
    end 
end 

Link to comment
Well, now you have to make an script which will update "newZombieLimit" when a new player joins and when the resource starts depending on the players online.

thx . Did you mean automatic restart resource when player join? how to do that?

Link to comment
No, I mean when a player joins, set the "newZombieLimit" variable to the new variable depending on the amount of players, and also do it when the resource starts.

i do that but newZombieLimit update only one time when resource starts . how to make newZombieLimit update auto after resource starts?

Link to comment
No, I mean when a player joins, set the "newZombieLimit" variable to the new variable depending on the amount of players, and also do it when the resource starts.

i do that but newZombieLimit update only one time when resource starts . how to make newZombieLimit update auto after resource starts?

just use onClientResourceStart event with a timer

Link to comment
No, I mean when a player joins, set the "newZombieLimit" variable to the new variable depending on the amount of players, and also do it when the resource starts.

i do that but newZombieLimit update only one time when resource starts . how to make newZombieLimit update auto after resource starts?

just use onClientResourceStart event with a timer

show me an example please. thx

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