[lua]
local SpawnZone = {};
local CheckFor = {
“prop_physics”,
“npc_”,
“player”
};
function AddSpawnZone(vector, class, open, id)
local tab = {};
tab.Vector = vector;
tab.Class = class;
tab.Open = open;
tab.ID = id
table.insert(SpawnZone, tab);
PrintTable(SpawnZone);
end
AddSpawnZone(Vector(0,0,0), “npc_zombie”, false, #SpawnZone + 1);
---------------------------------
/*
For the lolz
*/
local RandomX = math.random(-100,100);
local RandomY = math.random(-100,100);
local RandomZ = math.random(20,50);
---------------------------------
function ResetSpawn(ply, cmd, args)
for k, v in pairs(SpawnZone) do
ents.FindByClass(tostring(v.Class)):Remove();
end
end
concommand.Add(“reset_spawnpoints”, ResetSpawn);
function CreateSpawn(ply,cmd, args)
local trace = ply:GetEyeTrace();
if (trace.HitWorld) && (#args == 2) then
AddSpawnZone(trace.HitPos, args[1], args[2], #SpawnZone + 1);
else
Log(“You must enter two arguments and look at the world!
I.E. create_spawnpoints ‘class’ ‘true/false’”);
end
end
concommand.Add(“create_spawnpoints”, CreateSpawn);
/*if (#SpawnZone > 0) then
timer.Create("SpawnZoneThink", 1, 0, function()
for k, v in pairs(SpawnZone) do
Log("tick");
if (CheckSpawnZones()) && (v.Open == true) then
CreateNPC(v.Class, v.Vector + Vector(RandomX,RandomY,RandomZ))
Log("NPC spawned!");
end
end
end);
end*/
function CreateNPC(class, vector)
local ent = ents.Create(class);
ent:SetPos(vector);
ent:Spawn();
end
function CheckSpawnZones()
for _, vector in pairs(SpawnZone) do
local entity = ents.FindInSphere(vector.Vector,100);
local Class = entity:GetClass();
for _, class in pairs(CheckFor) do
local ent = string.find(CheckFor, class);
if (Class == ent) then
return;
end
end
end
return true;
end
[/lua]
Meh, I’ll update this later I guess. It works except for the CheckSpawnZones(), I’ll have a stab at it in a few hours.
It still doesn’t totally work, but it’s getting there I hope.