diff --git a/[esx_addons]/esx_ambulancejob/client/main.lua b/[esx_addons]/esx_ambulancejob/client/main.lua index b99c8f12d..da0fc4198 100644 --- a/[esx_addons]/esx_ambulancejob/client/main.lua +++ b/[esx_addons]/esx_ambulancejob/client/main.lua @@ -290,6 +290,22 @@ function StartDeathTimer() end) end +function GetClosestRespawnPoint() + local PlyCoords = GetEntityCoords(PlayerPedId()) + local ClosestDist,ClosestHosptial, ClostestCoord = 10000, {}, nil + + for k,v in pairs(Config.RespawnPoints) do + local Distance = #(PlyCoords - vector3(v.coords.x, v.coords.y, v.coords.z)) + if Distance <= ClosestDist then + ClosestDist = Distance + ClosestHosptial = v + ClostestCoord = vector3(v.coords.x, v.coords.y, v.coords.z) + end + end + + return ClostestCoord, ClosestHosptial +end + function RemoveItemsAfterRPDeath() TriggerServerEvent('esx_ambulancejob:setDeathStatus', false) @@ -301,14 +317,10 @@ function RemoveItemsAfterRPDeath() end ESX.TriggerServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function() - local formattedCoords = { - x = Config.RespawnPoint.coords.x, - y = Config.RespawnPoint.coords.y, - z = Config.RespawnPoint.coords.z - } + local RepspawnCoords, ClosestHosptial = GetClosestRespawnPoint() ESX.SetPlayerData('loadout', {}) - RespawnPed(PlayerPedId(), formattedCoords, Config.RespawnPoint.heading) + RespawnPed(PlayerPedId(), RepspawnCoords, ClosestHosptial.heading) AnimpostfxStop('DeathFailOut') DoScreenFadeIn(800) diff --git a/[esx_addons]/esx_ambulancejob/config.lua b/[esx_addons]/esx_ambulancejob/config.lua index 7bd362886..7f49c7e47 100644 --- a/[esx_addons]/esx_ambulancejob/config.lua +++ b/[esx_addons]/esx_ambulancejob/config.lua @@ -24,8 +24,9 @@ Config.EarlyRespawnFine = false Config.EarlyRespawnFineAmount = 5000 Config.OxInventory = ESX.GetConfig().OxInventory - -Config.RespawnPoint = {coords = vector3(341.0, -1397.3, 32.5), heading = 48.5} +Config.RespawnPoints = { + {coords = vector3(341.0, -1397.3, 32.5), heading = 48.5} +} Config.Hospitals = {