local spawns = {
[1] = {1829.65564,-1842.47327,13.57813,178}; -- x , y ,z , and z rotation
[2] = {2083.15747,-1844.75122,12.79247,359};
[3] = {2893.39746,-1638.96423,10.45679,333};
}
local distances = {}
respawn = function(ammo, attacker, weapon, bodypart)
local x,y,z = getElementPosition(source)
for k,v in ipairs(spawns) do
distances[k] = getDistanceBetweenPoints3D(x,y,z,spawns[k][1],spawns[k][2],spawns[k][3])
end
local a = math.min(distances[1],distances[2],distances[3])
for i=1,#distances do
if distances[i] == a then
spawnPlayer(source,spawns[i][1],spawns[i][2],spawns[i][3],spawns[i][4])
end
end
distances = nil
distances = {}
end
addEventHandler("onPlayerWasted",getRootElement(),respawn)
-- my spawns are random coordinates to test the script, they are not hospital spawns and also u have to change the z rotation to your wanted rotation.
also if u have in spawns table more indexes u need to add more distances in local a = math.min()
if u have 5 then u add five distances, here i have 3 spawns so 3 distances