Entity spawn points on server start? (Not a hire thread)

Hi there,

firstly, I feel it important to mention this is not a hire thread, if I could afford to hire a lua coder I would most certainly, and I’m not asking anyone to code anything for me,
but I’m interested in the idea of entity spawnpoints - so upon server start, it would spawn all the given entities at the given co-ordinates.

Is there an existing script that can do this for me?

if not, how difficult do you think it would be to script?

thanks for taking the time to read this.

Lots of people are in need of a script that does this. I think I might consider releasing mine which does exactly what you want and is quite simple as well. Ill see what I can do later, I’m a bit busy today but this afternoon I should be able to help.

Thanks, that sounds fantastic if you are willing, if you decide not to, fair enough, perhaps you could point me in the direction to start instead? thanks :v:

You hook into InitPostEntity and when that runs, spawn your props. You would probably want to store a list of different props for different maps. This is a very simple start, hopefully it is easy to understand.

[lua]local MapData = {

gm_construct = {
	{model="models/hunter/plates/plate.mdl", pos=Vector(0,0,0), ang=Angle(0,90,0)},
	{model="models/hunter/plates/plate.mdl", pos=Vector(100,0,-100), ang=Angle(22,35,15)},
},

gm_flatgrass = {
	{model="models/hunter/plates/plate.mdl", pos=Vector(0,0,0), ang=Angle(0,90,0)},
	{type="weapon_smg1", pos=Vector(100,0,-100), ang=Angle(22,35,15),}, --We can set a 'type' to spawn an entity instead of a physics prop
},

}

local function AutospawnProps()

local mapName = game.GetMap()	--Get the name of the map
local mapData = MapData[mapName] --Check we have data for this map

if mapData then --If we have data for this map

	--Loop through the stuff
	for _,v in pairs(mapData) do
	
		--get the type of entity, or default to a physics prop
		local entType = v.type or "prop_physics"
		--spawn it
		local newEnt = ents.Create(entType)
		if v.model then newEnt:SetModel(v.model) end --set model
		if v.ang then newEnt:SetAngle(v.ang) end --set angle
		if v.pos then newEnt:SetPos(v.pos) end --set position
		newEnt:Spawn()
		newEnt:Activate()
	
	end --End of for-loop

end --End of check for map data

end

hook.Add(“InitPostEntity”, “Autospawn Props On Load”, AutospawnProps)[/lua]

Ah brilliant, thank-you very much for taking the time to help me out,
I think I understand it but I can’t be sure,
in terms of spawning entities would I be able to use type=“entity_example”?

and lastly, in order to run this on server start up, I’m guessing I should put this into lua/autorun/server?

apologies if I sound dumb, I’m still very new to lua, and I’m doing my best to learn.

Yep.

Yep. Call it anything.lua

Thanks very much, I’ll try this out in the morning. :smile:

Unfortunately this didn’t seem to work for me,

this is my code:


 

local MapData = {

	gm_aftermath_rc1a = {
		{model="models/hunter/plates/plate.mdl", pos=Vector(367.977661,-231.534073,-959.968750 ), ang=Angle(0,90,0)},

		
	},

}

local function AutospawnProps()
	
	local mapName = game.GetMap()	--Get the name of the map
	local mapData = MapData[mapName] --Check we have data for this map
	
	if mapData then --If we have data for this map
	
		--Loop through the stuff
		for _,v in pairs(mapData) do
		
			--get the type of entity, or default to a physics prop
			local entType = v.type or "prop_physics"
			--spawn it
			local newEnt = ents.Create(entType)
			if v.model then newEnt:SetModel(v.model) end --set model
			if v.ang then newEnt:SetAngle(v.ang) end --set angle
			if v.pos then newEnt:SetPos(v.pos) end --set position
			newEnt:Spawn()
			newEnt:Activate()
		
		end --End of for-loop
	
	end --End of check for map data
	
end

hook.Add("InitPostEntity", "Autospawn Props On Load", AutospawnProps)



am I doing it right?

Is your gamemode derived from sandbox? Or is the gamemode - sandbox?

The gamemode is currently DarkRP, which I believe is derived from sandbox, I may be mistaken, I’m using it as it’s a pretty simple and easy to use gamemode to start out with.

Then your problem is persistence. The script from sandbox does game.CleanUpMap() from InitPostEntity. You will have to either use a timer or force sbox_persist 0 upon server start.

I understand, but I don’t understand how to avoid that,

are you saying that adding sbox_persist 0 to the Server.cfg would help?

secondly, I’m not familiar with timers yet, that would be something useful to learn, would you happen
to have a link to a tutorial on what you mean?

Thanks.

Have a look at timer.Create and timer.Simple on the wiki. Should get you basic knowledge. I believe sbox_persist 0 in server.cfg will work, but I am not sure.

Thanks, I’ll give it a shot.