You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
-- __ _ _______ _ __
|
|
-- / / /\ | | |__ __| | | \ \
|
|
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
|
|
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
|
|
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
|
|
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
|
|
|
|
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 }
|
|
end
|
|
|
|
|
|
local maxdist
|
|
local spawnpos
|
|
for i, spawnpos in ipairs( 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
|
|
end
|
|
else
|
|
maxdist = spawnpos.dist
|
|
spawnpos = spawnpos.pos
|
|
end
|
|
end
|
|
|
|
Quantum.Debug( "Respawning player at nearest spawnpoint... ( " .. tostring( spawnpos ) .. " )" )
|
|
pl:SetPos( spawnpos )
|
|
|
|
end
|
|
end) |