Here is my code...
-- Zombie Spawning --
function ZombieSpawnsToFile( ply, hfZombieSpawnLocations )
local g = glon.encode(hfZombieSpawnLocations)
file.Write( "zombiepos.txt", g )
end
function hfZombieSpawnersHelp(ply)
ply:ChatPrint("*Zombie Spawner Help*")
ply:ChatPrint("hf_zm_spawn r | Will remove all current spawn points and make a spawn point where you are standing.")
ply:ChatPrint("hf_zm_spawn a | Adds a spawn point.")
ply:ChatPrint("hf_zm_spawn p | Lists all current spawn points.")
ply:ChatPrint("hf_zm 1 <time in secounds> | Spawns zombies, and controls how fast they spawn.")
ply:ChatPrint("hf_zm 0 | Stops all zombies from spawning.")
ply:ChatPrint("*Zombie Spawner Help End*")
end
function hfCZombieSpawns( ply, command, args )
if( ply:IsAdmin() or ply:IsSuperAdmin() ) then
if( ply and ply:IsValid() and file.Exists("zombiepos.txt") ) then
local File = file.Read("zombiepos.txt")
local g = glon.decode(File)
local hfZombieSpawnLocations = {}
if( args[1] == "r" ) then
table.Empty( hfZombieSpawnLocations )
table.insert( hfZombieSpawnLocations, ply:GetPos() )
ZombieSpawnsToFile( ply, hfZombieSpawnLocations )
ply:ChatPrint("Zombie spawn position set at " .. tostring(ply:GetPos()) .. ". Other spawn points have been removed.")
elseif ( args[1] == "a" ) then
for i,item in pairs(g) do
table.insert( hfZombieSpawnLocations, g[i] )
end
table.insert( hfZombieSpawnLocations, ply:GetPos() )
ZombieSpawnsToFile( ply, hfZombieSpawnLocations )
ply:ChatPrint("Zombie spawn position set at " .. tostring(ply:GetPos()))
elseif( args[1] == "p" ) then
for i,p in pairs(g) do
ply:ChatPrint("Zombie_Spawn_" .. tostring(i) .. " located at " .. tostring(p))
end
else
hfZombieSpawnersHelp(ply)
end
elseif( ply and ply:IsValid() ) then
ply:ChatPrint("Error File Not Found.")
else
print("Player Invalid. ( If you are in the console join the server. )")
end
else
ply:ChatPrint("You are not allowed to do that " .. ply:Name())
end
end
function hfZombieSpawn( ply, command, args )
if( ply:IsAdmin() or ply:IsSuperAdmin() ) then
if( file.Exists("zombiepos.txt") ) then
local run = 1
timer.Destroy( "ZombieSpawnTimer" )
if( args[1] and args[1] != "0" ) then
run = 0
for _,plys in pairs(player.GetAll()) do
plys:ChatPrint( ply:Name() .. " Enabled Zombie Spawning." )
end
else
for _,plys in pairs(player.GetAll()) do
plys:ChatPrint( ply:Name() .. " Disabled Zombie Spawning." )
end
end
local time = tonumber(args[2])
if( time < 5 ) then
time = 5
end
if( run and run != 1 and time and time >= 5 ) then
ply:ChatPrint("Zombies will spawn every " .. tostring(time) .. " secounds.")
timer.Create( "ZombieSpawnTimer", time, 0, function( ply, args )
if( file.Exists("zombiepos.txt") and args[1] and args[1] != 0 ) then
local zombieTypes = { "npc_fastzombie", "npc_zombie", "npc_poisonzombie" }
local Read = file.Read("zombiepos.txt")
local positions = glon.decode(Read)
for _, pos in pairs(positions) do
local ent = ents.Create(zombieTypes[math.random(1,table.getn(zombieTypes))])
if( ent and ent:IsValid() ) then
ent:SetPos(pos)
ent:Spawn()
ent:Activate()
end
end
else
timer.Destroy( "ZombieSpawnTimer" )
if not ( file.Exists("zombiepos.txt") ) then
ply:ChatPrint("Error File Not Found.")
end
end
end, ply, args)
end
else
ply:ChatPrint("Error File Not Found.")
end
else
ply:ChatPrint("You are not allowed to do that " .. ply:Name())
end
end
concommand.Add("hf_zm_help",hfZombieSpawnersHelp)
concommand.Add("hf_zm_spawn",hfCZombieSpawns)
concommand.Add("hf_zm",hfZombieSpawn)
It works, but it needs allot of cleaning up. Please help. The main problem is that it lags very, badly.