diff --git a/gamemode/core/server/sv_player_init.lua b/gamemode/core/server/sv_player_init.lua index 3fee045..01eec40 100644 --- a/gamemode/core/server/sv_player_init.lua +++ b/gamemode/core/server/sv_player_init.lua @@ -7,6 +7,10 @@ local ply = FindMetaTable( "Player" ) +function GM:PlayerInitialSpawn( ply ) + ply.isloaded = true -- REMOVE THIS WHEN MYSQL DB IS ADDED +end + function GM:PlayerSpawn( ply ) ply:SetModel( "models/player/Group03/male_04.mdl" ) diff --git a/gamemode/core/server/sv_player_spawning.lua b/gamemode/core/server/sv_player_spawning.lua index b7d7c01..79d6228 100644 --- a/gamemode/core/server/sv_player_spawning.lua +++ b/gamemode/core/server/sv_player_spawning.lua @@ -5,31 +5,34 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ +hook.Add( "PlayerDeath", "Quantum_Player_SaveDeathPos", function( pl ) + pl.deathpos = pl:GetPos() +end) + hook.Add( "PlayerSpawn", "Quantum_Player_Respawn", function( pl ) if( pl.isloaded && pl.deathpos ) then local spawnposdist = {} - for id, pos in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do - print( id, pos ) - spawnposdist[id] = { dist = pos:Distance( pl.deathpos ), spawnpos = pos } + for id, spawnpoint in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do + spawnposdist[id] = { dist = spawnpoint.pos:Distance( pl.deathpos ), spawnpos = spawnpoint.pos, angle = spawnpoint.ang } end - - local maxdist - local spawnpos - for i, spawnpos in ipairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint + local maxdist, spawnpos, spawnangle + for id, spawn in pairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint if( maxdist ~= nil ) then - if( maxdist <= spawnpos.dist ) then - maxdist = spawnpos.dist - spawnpos = spawnpos.pos + if( maxdist >= spawn.dist ) then + maxdist = spawn.dist + spawnpos = spawn.spawnpos + spawnangle = spawn.angle end else - maxdist = spawnpos.dist - spawnpos = spawnpos.pos + maxdist = spawn.dist + spawnpos = spawn.spawnpos + spawnangle = spawn.angle end end - Quantum.Debug( "Respawning player at nearest spawnpoint... ( " .. tostring( spawnpos ) .. " )" ) + Quantum.Debug( "Respawning player at nearest spawnpoint." ) pl:SetPos( spawnpos ) - + pl:SetAngles( spawnangle ) end end) \ No newline at end of file