|
|
@ -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 ) |
|
|
|
hook.Add( "PlayerSpawn", "Quantum_Player_Respawn", function( pl ) |
|
|
|
if( pl.isloaded && pl.deathpos ) then |
|
|
|
if( pl.isloaded && pl.deathpos ) then |
|
|
|
local spawnposdist = {} |
|
|
|
local spawnposdist = {} |
|
|
|
for id, pos in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do |
|
|
|
for id, spawnpoint in pairs( Quantum.Server.Settings.SpawnLocations[ game.GetMap() ] ) do |
|
|
|
print( id, pos ) |
|
|
|
spawnposdist[id] = { dist = spawnpoint.pos:Distance( pl.deathpos ), spawnpos = spawnpoint.pos, angle = spawnpoint.ang } |
|
|
|
spawnposdist[id] = { dist = pos:Distance( pl.deathpos ), spawnpos = pos } |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local maxdist, spawnpos, spawnangle |
|
|
|
local maxdist |
|
|
|
for id, spawn in pairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint |
|
|
|
local spawnpos |
|
|
|
|
|
|
|
for i, spawnpos in ipairs( spawnposdist ) do -- Loop through everything and pick the nearest spawnpoint |
|
|
|
|
|
|
|
if( maxdist ~= nil ) then |
|
|
|
if( maxdist ~= nil ) then |
|
|
|
if( maxdist <= spawnpos.dist ) then |
|
|
|
if( maxdist >= spawn.dist ) then |
|
|
|
maxdist = spawnpos.dist |
|
|
|
maxdist = spawn.dist |
|
|
|
spawnpos = spawnpos.pos |
|
|
|
spawnpos = spawn.spawnpos |
|
|
|
|
|
|
|
spawnangle = spawn.angle |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
maxdist = spawnpos.dist |
|
|
|
maxdist = spawn.dist |
|
|
|
spawnpos = spawnpos.pos |
|
|
|
spawnpos = spawn.spawnpos |
|
|
|
|
|
|
|
spawnangle = spawn.angle |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
Quantum.Debug( "Respawning player at nearest spawnpoint... ( " .. tostring( spawnpos ) .. " )" ) |
|
|
|
Quantum.Debug( "Respawning player at nearest spawnpoint." ) |
|
|
|
pl:SetPos( spawnpos ) |
|
|
|
pl:SetPos( spawnpos ) |
|
|
|
|
|
|
|
pl:SetAngles( spawnangle ) |
|
|
|
end |
|
|
|
end |
|
|
|
end) |
|
|
|
end) |