Hello,
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 [url]http://wiki.garrysmod.com/page/GM/PlayerSelectSpawn[/url] 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.
[QUOTE=deinemudda32;49864665]Use time 0.[/QUOTE]
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.
[lua]
hook.Add("PlayerSpawn", "PosCheckAMK", function(ply)
timer.Simple(0, function()
if IsValid(ply) then
ply:SetPos(Vector(0,0,0))
end
end)
end)
[/lua]
[QUOTE=P4sca1;49864674]Will this make any difference than running the code without a timer?[/QUOTE]
I think setting the timer to 0 makes it run the frame after the timer is created, so yeah
Will try that out, thanks :)
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 [url=https://developer.valvesoftware.com/wiki/Info_null]info_null[/url] 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.
[code]
function GM:PlayerSelectSpawn(ply)
...
if (SpawnPositionIsClear(spawnPos)) then
local ent = ents.Create("info_null") -- https://developer.valvesoftware.com/wiki/Info_null
ent:SetPos(spawnPos)
ent:Spawn()
ent:Activate()
return ent
end
end
[/code]
[QUOTE=mcd1992;49865714]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 [url=https://developer.valvesoftware.com/wiki/Info_null]info_null[/url] 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.
[code]
function GM:PlayerSelectSpawn(ply)
...
if (SpawnPositionIsClear(spawnPos)) then
local ent = ents.Create("info_null") -- https://developer.valvesoftware.com/wiki/Info_null
ent:SetPos(spawnPos)
ent:Spawn()
ent:Activate()
return ent
end
end
[/code][/QUOTE]
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?
[QUOTE=P4sca1;49865996]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?[/QUOTE]
Make it a serverside hook.
[QUOTE=whitestar;49865017]I still would suggest removing all default spawn entities[/QUOTE]
How would I go about this?
[editline]4th March 2016[/editline]
[QUOTE=DanielHershey;49866083]Make it a serverside hook.[/QUOTE]
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.
[CODE]
print(spawn)
print(spawn:GetPos())
return spawn
[/CODE]
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 --
[code]
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
v:Remove()
end
for k, v in pairs(spawnvecs) do
local ent = ents.Create("info_player_start")
ent:SetPos(v)
ent:Spawn()
end
end)
[/code]
[CODE]
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")
return
else
print("Spawn Valid") --This gets printed
local spawn = ents.Create("info_null")
spawn:SetPos(pos)
spawn:Spawn()
spawn:Activate()
print(spawn) --this gets printed
print(spawn:GetPos()) --and this gets printed too
return spawn --spawn point did not changed.
end
end
end
hook.Add("PlayerSelectSpawn", "swrp_spawnsystem", SetPlayerSpawn)
[/CODE]
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
[QUOTE=whitestar;49866805]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[/QUOTE]
The problem I see with your method is that I can't have different spawns for different player categories.
[QUOTE=P4sca1;49866819]The problem I see with your method is that I can't have different spawns for different player categories.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSelectTeamSpawn]GM/PlayerSelectTeamSpawn[/url]?
Edit:
Make a table for each team you want, put there their different locations and return a random key.
[QUOTE=whitestar;49866841][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSelectTeamSpawn]GM/PlayerSelectTeamSpawn[/url]?
Edit:
Make a table for each team you want, put there their different locations and return a random key.[/QUOTE]
I don't use team numbers.
I have a function ply:regiment() which returns a string. I want to have a different spawn point for every 'regiment'.
[QUOTE=P4sca1;49866851]I don't use team numbers.
I have a function ply:regiment() which returns a string. I want to have a different spawn point for every 'regiment'.[/QUOTE]
then... do that in PlayerSelectSpawn thingy? ._.
[QUOTE=whitestar;49866859]then... do that in PlayerSelectSpawn thingy? ._.[/QUOTE]
That's what I'm trying to do, but after returning the spawnentity, it is doing nothing.
[code]
local spawnvecs = {
Vector(0, 0, 0),
Vector(1, 1, 1),
Vector(69, 69, 69)
Vector(1337, 1377, 1377)
}
hook.Add("SelectPlayerSpawn", "Spawnthingy", function(ply)
if ply:regiment() == "stringhere" then
return table.Random(spawnvecs)
end
end)
[/code]
Didn't test ingame.
[QUOTE=whitestar;49866894][code]
local spawnvecs = {
Vector(0, 0, 0),
Vector(1, 1, 1),
Vector(69, 69, 69)
Vector(1337, 1377, 1377)
}
hook.Add("SelectPlayerSpawn", "Spawnthingy", function(ply)
if ply:regiment() == "stringhere" then
return table.Random(spawnvecs)
end
end)
[/code]
Didn't test ingame.[/QUOTE]
Did you mean PlayerSelectSpawn? This function wants an entity as return and is not possible because of that.
[QUOTE=P4sca1;49866930]Did you mean PlayerSelectSpawn? This function wants an entity as return and is not possible because of that.[/QUOTE]
what about... using my method, setting a local var on it, like ent.regiment = 'string' and then checking each entity if they have that, put it inside a table, and return a random one of it? ;o
[QUOTE=whitestar;49866984]what about... using my method, setting a local var on it, like ent.regiment = 'string' and then checking each entity if they have that, put it inside a table, and return a random one of it? ;o[/QUOTE]
The problem is that no matter what I am returning in the PlayerSelectSpawn Hook, the spawnpoint is not changing. I just tried with your method but it still doesn't work.
I think I have to overwrite this funtion, but I don't know how.
[code]
function GM:PlayerSelectSpawn(ply)
-- Shit
end
[/code]
[CODE]
[ERROR] addons/egm_misc_swrp/lua/autorun/server/sv_spawnsystem.lua:53: attempt to index global 'GM' (a nil value)
1. unknown - addons/egm_misc_swrp/lua/autorun/server/sv_spawnsystem.lua:53
[/CODE]
Sorry, you need to Log In to post a reply to this thread.