Basically, I'm looking to have certain locations on the map where these entities I've created will spawn and I want them to spawn on a loop but I don't want them to spawn if there is already an entity there. Right now, I just need to know how to set it up so it will keep spawning entities at that location on a timer/loop, I think I could probably figure the rest out myself.
init: [CODE]AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
hook.Add("InitPostEntity", "spawnplants", function()
local plant = ents.Create("cocaine")
plant:Spawn()
end)
function createPlants()
local plant1 = ents.Create("cocaine")
plant1:Spawn()
end
function ENT:Initialize()
self:SetModel( "models/props/cs_office/plant01.mdl" )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
self:SetPos(Vector(-2268, -250, -132))
end
[/CODE]
BTW: shared and cl_init have nothing important.
It seems pretty simple xD I would think someone would know how to do it. xP
[QUOTE=Skashh;49376611]It seems pretty simple xD I would think someone would know how to do it. xP[/QUOTE]
Have a table of all the vectors, make a timer to run every so often, spawn the ent at all the vectors using a for loop.
It's not difficult.
Do a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/FindInSphere]ents.FindInSphere[/url] around the spawn vector and loop through ents found and if there the type you want to spawn the skip or if there is none found skip.
[B]Edit:[/B]
This function should work (havent tested it)
[LUA]
function CheckEntExists( class, vec, radius )
for k,v in pairs(ents.FindInSphere(vec, radius)) do
if v:GetClass() == class then
return true
end
end
return false
end
[/LUA]
Sorry, you need to Log In to post a reply to this thread.