hi everybody ,actually i'm creating a gamemode, everything works good, but i'm in front a problem that i can't understand :
so, my gamemod is a kind of survival,
for example : there are 5 players on the game, when player die, he still died and can't respawn until there only 1 player alive, at this time a function start and respawn every player on the game like this :
[CODE]function GM:NEW_ROUND()
PrintMessage( 4, "Round Restart" )
local ExtraFilters = {}
game.CleanUpMap( true, ExtraFilters )
for k, v in pairs( player.GetAll() ) do
v:SetTeam( 1002 )
v:Spectate( OBS_MODE_ROAMING ) -- when you spawn them call UnSpectate( ) on them
end
ACTIVE_PLAYERS = {}
DEAD_PLAYERS = {}
-- respawning
for k, v in pairs( player.GetAll() ) do
net.Start( "CleanMap" )
net.Send(v)
v:SetTeam( 42 )
v:UnSpectate()
v:Spawn()
end
end[/CODE]
so that work but not really, when the player spawn, he respawn at the same location where he die, and sometimes the player respawn in air or at unexpected location ...
but i think i have miss something like this : [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSelectSpawn]GM:PlayerSelectSpawn[/url]
but i dont understand when i need to call this ?
so if you can explain me ! this could be nice :)
thanks :v:
so, i have created a spawn creator ...
[CODE] hook.Add("Think" , "cancreatespawn", function()
if ply:KeyReleased( IN_ZOOM ) then
net.Start( "CreateSpawn")
net.SendToServer()
end
end)
[/CODE]
[CODE]
util.AddNetworkString( "CreateSpawn" )
net.Receive( "CreateSpawn", function( ln, pl )
if pl:IsAdmin() then
if file.Exists( "mapsspawnpoint/"..game.GetMap()..".txt" , "DATA" ) then
file.Open( "mapsspawnpoint/"..game.GetMap()..".txt" , "a" , "DATA" )
local spwnPos = pl:GetPos()
local frmpos = {}
frmpos[1] = math.Round( spwnPos[1], 2 )
frmpos[2] = math.Round( spwnPos[2], 2 )
frmpos[3] = math.Round( spwnPos[3], 2 )
local str = table.ToString( frmpos )
str = string.Replace( str, "{", "" )
str = string.Replace( str, ",}", "\n" )
file.Append( "mapsspawnpoint/"..game.GetMap()..".txt" , str )
end
end
end)[/CODE]
[CODE] function GetSpawnLocations()
Spawns = {}
if file.Exists( "mapsspawnpoint/"..game.GetMap()..".txt" , "DATA" ) then
local str = file.Read( "mapsspawnpoint/"..game.GetMap()..".txt" , "DATA" )
local line = string.Explode( "\n", str )
for k , v in pairs(line) do
if v != "" then
local vecs = string.Explode( ",", v )
local tempvec = {}
tempvec[1] = tonumber( vecs[1] , 10 )
tempvec[2] = tonumber( vecs[2] , 10 )
tempvec[3] = tonumber( vecs[3] , 10 )
local onespawnpos = Vector(tempvec[1] , tempvec[2] , tempvec[3] )
table.insert( Spawns, onespawnpos )
end
end
end
end
GetSpawnLocations()
[/CODE]
and call that after player spawn :
[CODE] function lolTheSpawn(pl)
local random_entry = math.random( #Spawns )
local spwnPos = Spawns[random_entry]
pl:SetPos(spwnPos)
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.