Hi, I just wondered if someone knew how to TP a player back to the spawn
function TP_To_Spawn(player) if player:IsPlayer() then player:SetPos(ents.FindByClass("info_player_spawn")[math.random(1,#ents.FindByClass("info_player_spawn"))]:GetPos()) end end
Thanks mate ;D but do you have any ideas like how do I setup the position of the player ?
[editline]13th October 2015[/editline]
Thanks guys you’re awesome
That’s a terrible solution because it doesn’t take into account what entity the player uses as spawnpoints.
You mean the angle/vector?
How do you use it exactly ?
In a lua file somewhere in your addons’s folder
Something like this?
local spawn = GM:PlayerSelectSpawn( ply ) ply:SetPos( spawn:GetPos() )
Can I use this in the shared file ?
would b really weird if you would, i dont think you want to use SetPos on the player clientsided.
I don’t know why this is so fucking funny to me.
Ideally, you should use
hook.Call if there is no GM:* function) to do this, as it supports hooks added through hook.Add. Also, that code won’t work if it is not in a gamemode file because the GM table is not available after the gamemode has initialized.
Same here, wasn’t suppose to be funny
You guys are over complicating this, there’s a neat method called player:Spawn()
It skips the death hook and triggers the spawning hook so other addons can displace the player if needed.
But it also resets all of his stats.
If you run ply:Spawn() on a poisoned ignited player with 23 hp and no weapons on (modded) Sandbox, he’ll have 100hp and the default weapons.