Making a spawnsystem using Vectors only

I am making a spawnsystem, but it is not working like I want it to.
At the moment I am doing ply:SetPos(Vector()) after GM:PlayerSpawn().

I’m wondering if there is any way to use without using Entitys, but Vectors?

This is a bit hacky and someone should suggest a better idea, but you could try putting the SetPos in a timer

I think I had issues before about moving someone just as they spawned

I tried with a Timer, but it was really “unsafe”. Sometimes it worked and sometimes it did not. Hopefully there’s a better solution.

Or if I really have to use a timer. Can anybody recommend a working time?

Use time 0.

Will this make any difference than running the code without a timer?

Yea, a big one.
It actually runs post Playerspawn.

If that does not work, try using 0.1.
I am using a 0 seconds timer for setting playermodels, but it should work the same for spawns.

hook.Add(“PlayerSpawn”, “PosCheckAMK”, function(ply)
timer.Simple(0, function()
if IsValid(ply) then

I think setting the timer to 0 makes it run the frame after the timer is created, so yeah

Will try that out, thanks :slight_smile:

Sure you dont wanna use entities, but I still would suggest removing all default spawn entities, and then placing the desired spawn points manually on those vectors on initialization of the enviorement? Would be way easier tbh.

The only reason why I don’t wanted to use entites is because I have no clue how to do a Spawn system based on entitys. Now it seems like using entitys would be better so I’m wondering if anybody has some tips on where to start and how it works in General.

If you use SetPos after the player has spawned you sometimes get the player seeing their original spawn and then instantly jumping to their new spawn. If you create a info_null entity and return it in PlayerSelectSpawn the player will never see the teleport. Info_null is a point entity that isn’t networked so it never takes up and edict and its automatically deleted next frame so you don’t have to worry about them.

function GM:PlayerSelectSpawn(ply)
    if (SpawnPositionIsClear(spawnPos)) then
        local ent = ents.Create("info_null") --
        return ent

This seems to be really useful, thank you!
I only have one problem where it says that GM is a nil value. I also tried GAMEMODE. Do I need to run this in a specific folder?

Make it a serverside hook.

How would I go about this?

[editline]4th March 2016[/editline]

Thought I need to overwrite the function. Thanks for the hint!

[editline]4th March 2016[/editline]

I just tried it with hook.Add(“PlayerSelectSpawn”, “swrp_spawnsystem”, SetPlayerPos) but this doesn’t seem to work.

        return spawn

This part is returning the spawn. I also made some prints to check some things.
The Entity and the Entity Position is printed correctly, but returning the entity is doing nothing.
Anybody got an idea?

Post your whole code please

This code SHOULD work, just quickly made it –

local spawnvecs = {
	Vector(0, 0, 0),
	Vector(1, 1, 1),
	Vector(69, 69, 69)
	Vector(1337, 1377, 1377)

hook.Add("Initialize", "CustomSpawnEnt", function()
	for k, v in pairs(ents.FindByClass("info_player_start")) do

	for k, v in pairs(spawnvecs) do
		local ent = ents.Create("info_player_start")

local function SetPlayerSpawn(ply)
    print(1) --this gets printed
    local pos = SWRP.SpawnSystem.Spawns[ply:getJobTable().command]
    print(pos) --this gets printed

    if pos then
    --check if spawn point is valid
    local tracedata = {}
    tracedata.start = pos
    tracedata.endpos = pos 
    tracedata.mins =  Vector(-16, -16, 0)
    tracedata.maxs = Vector(16, 16, 64)
    local trace = util.TraceHull(tracedata)
    if trace.Hit then
	print("Spawn blocked")
	print("Spawn Valid") --This gets printed
	local spawn = ents.Create("info_null")
	print(spawn) --this gets printed
	print(spawn:GetPos()) --and this gets printed too
        return spawn --spawn point did not changed.
hook.Add("PlayerSelectSpawn", "swrp_spawnsystem", SetPlayerSpawn)

I’ve never really worked with SelectSpawn thingy, so I don’t wanna look over it right now incase I somehow will be wrong, but I still would go with my method, its just less time consuming, and way easier/faster ingame

The problem I see with your method is that I can’t have different spawns for different player categories.