Looks like something like this
local respawnPoints = {
{0, 0, 3},
}
local function findNearestRespawnPoint(x, y, z)
local nearestPoint = { distance = 99999, index = 1 }
for i, v in ipairs(respawnPoints) do
local distance = getDistanceBetweenPoints3D(x, y, z, v[1], v[2], v[3])
if distance < nearestPoint.distance then
nearestPoint = { distance = distance, index = i }
end
end
return respawnPoints[nearestPoint.index]
end
local function respawnPlayer(player)
local x, y, z = getElementPosition(player)
local point = findNearestRespawnPoint(x, y, z)
spawnPlayer(player, point[1], point[2], point[3])
end
addEventHandler("onPlayerWasted", root, function()
setTimer(respawnPlayer, 1000, 1, source)
end)