Hi, I just wondered if someone knew how to TP a player back to the spawn
-SNIP-
[CODE]
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
[/CODE]
Thanks mate ;D but do you have any ideas like how do I setup the position of the player ? :D
[editline]13th October 2015[/editline]
Thanks guys you're awesome :)
[QUOTE=Gedo789;48894493][CODE]
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
[/CODE][/QUOTE]
That's a terrible solution because it doesn't take into account what entity the player uses as spawnpoints.
Something like this?
[CODE]
local spawn = GM:PlayerSelectSpawn( ply )
ply:SetPos( spawn:GetPos() )
[/CODE]
[QUOTE=Zapk;48897456]Something like this?
[CODE]
local spawn = GM:PlayerSelectSpawn( ply )
ply:SetPos( spawn:GetPos() )
[/CODE][/QUOTE]
Can I use this in the shared file ?
[QUOTE=DJlive34;48901146]Can I use this in the shared file ?[/QUOTE]
would b really weird if you would, i dont think you want to use SetPos on the player clientsided.
[QUOTE=tzahush;48901461]would b really weird if you would, i dont think you want to use SetPos on the player clientsided.[/QUOTE]
I don't know why this is so fucking funny to me.
[QUOTE=Zapk;48897456]Something like this?
[CODE]
local spawn = GM:PlayerSelectSpawn( ply )
ply:SetPos( spawn:GetPos() )
[/CODE][/QUOTE]
Ideally, you should use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/gamemode/Call]gamemode.Call[/url] (or [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Call]hook.Call[/url] 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.
[QUOTE=Sweepyoface;48901643]I don't know why this is so fucking funny to me.[/QUOTE]
Same here, wasn't suppose to be funny
You guys are over complicating this, there's a neat method called [B]player:Spawn()[/B]
It skips the death hook and triggers the spawning hook so other addons can displace the player if needed.
[QUOTE=Potatofactory;48919425]You guys are over complicating this, there's a neat method called [B]player:Spawn()[/B]
It skips the death hook and triggers the spawning hook so other addons can displace the player if needed.[/QUOTE]
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.
Sorry, you need to Log In to post a reply to this thread.