• Keeping DarkRP zombies enabled after restart.
    2 replies, posted
I'd like to be able to have zombies continue to spawn after a restart with the DarkRP gamemode, because when the server restarts they don't spawn by default. (When the server restarts, you must type /enablezombie in chat to re-enable the zombie spawns.) Below is the part of the lua file for the zombie event: [code]/*--------------------------------------------------------- Variables ---------------------------------------------------------*/ local timeLeft = 10 local timeLeft2 = 10 local stormOn = false local zombieOn = false local maxZombie = 70 /*--------------------------------------------------------- Zombie ---------------------------------------------------------*/ local ZombieStart, ZombieEnd local function ControlZombie() timeLeft2 = timeLeft2 - 1 if timeLeft2 < 1 then if zombieOn then timeLeft2 = math.random(5,10) zombieOn = false timer.Stop("start2") ZombieEnd() else timeLeft2 = math.random(5,12) zombieOn = true timer.Start("start2") DB.RetrieveZombies(function() ZombieStart() end) end end end ZombieStart = function() for k, v in pairs(player.GetAll()) do if v:Alive() then v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_approaching) v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_approaching) end end end ZombieEnd = function() for k, v in pairs(player.GetAll()) do if v:Alive() then v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_leaving) v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_leaving) end end end local function LoadTable(ply) ply:SetSelfDarkRPVar("numPoints", table.getn(zombieSpawns)) for k, v in pairs(zombieSpawns) do ply:SetSelfDarkRPVar("zPoints" .. k, v) end end local function ReMoveZombie(ply, index) if ply:HasPriv("rp_commands") then if not index or zombieSpawns[tonumber(index)] == nil then GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.zombie_spawn_not_exist, tostring(index))) else DB.RetrieveZombies(function() GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_removed) table.remove(zombieSpawns, index) DB.StoreZombies() if ply.DarkRPVars.zombieToggle then LoadTable(ply) end end) end else GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, "/removezombie")) end return "" end AddChatCommand("/removezombie", ReMoveZombie) local function AddZombie(ply) if ply:HasPriv("rp_commands") then DB.RetrieveZombies(function() table.insert(zombieSpawns, ply:GetPos()) DB.StoreZombies() if ply.DarkRPVars.zombieToggle then LoadTable(ply) end GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_added) end) else GAMEMODE:Notify(ply, 1, 6, string.format(LANGUAGE.need_admin, "/addzombie")) end return "" end AddChatCommand("/addzombie", AddZombie) local function ToggleZombie(ply) if ply:HasPriv("rp_commands") then if not ply.DarkRPVars.zombieToggle then DB.RetrieveZombies(function() ply:SetSelfDarkRPVar("zombieToggle", true) LoadTable(ply) end) else ply:SetSelfDarkRPVar("zombieToggle", false) end else GAMEMODE:Notify(ply, 1, 6, LANGUAGE.string.format(LANGUAGE.need_admin, "/showzombie")) end return "" end AddChatCommand("/showzombie", ToggleZombie) local function GetAliveZombie() local zombieCount = 0 local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_headcrab_fast"} for _, Type in pairs(ZombieTypes) do zombieCount = zombieCount + #ents.FindByClass(Type) end return zombieCount end local function SpawnZombie() timer.Start("move") if GetAliveZombie() >= maxZombie then return end if table.getn(zombieSpawns) <= 0 then return end local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_headcrab_fast"} local zombieType = math.random(1, #ZombieTypes) local Zombie = ents.Create(ZombieTypes[zombieType]) Zombie.nodupe = true Zombie:Spawn() Zombie:Activate() Zombie:SetPos(DB.RetrieveRandomZombieSpawnPos()) end local function ZombieMax(ply, args) if ply:HasPriv("rp_commands") then if not tonumber(args) then GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.invalid_x, "argument", "")) return "" end maxZombie = tonumber(args) GAMEMODE:Notify(ply, 0, 4, string.format(LANGUAGE.zombie_maxset, args)) end return "" end AddChatCommand("/zombiemax", ZombieMax) AddChatCommand("/maxzombie", ZombieMax) AddChatCommand("/maxzombies", ZombieMax) local function StartZombie(ply) if ply:HasPriv("rp_commands") then timer.Start("zombieControl") GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_enabled) end return "" end AddChatCommand("/enablezombie", StartZombie) local function StopZombie(ply) if ply:HasPriv("rp_commands") then timer.Stop("zombieControl") zombieOn = false timer.Stop("start2") ZombieEnd() GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_disabled) end return "" end AddChatCommand("/disablezombie", StopZombie) timer.Create("start2", 1, 0, SpawnZombie) timer.Create("zombieControl", 1, 0, ControlZombie) timer.Stop("start2") timer.Stop("zombieControl") [/code]
Remove the last line.
[QUOTE=.\\Shadow};38749905]Remove the last line.[/QUOTE] <3 My savior.
Sorry, you need to Log In to post a reply to this thread.