diff --git a/[esx_addons]/esx_ambulancejob/client/main.lua b/[esx_addons]/esx_ambulancejob/client/main.lua index b99c8f12..da0fc419 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 7bd36288..7f49c7e4 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 = { diff --git a/[esx_addons]/esx_ambulancejob/server/main.lua b/[esx_addons]/esx_ambulancejob/server/main.lua index e8990264..3644809d 100644 --- a/[esx_addons]/esx_ambulancejob/server/main.lua +++ b/[esx_addons]/esx_ambulancejob/server/main.lua @@ -11,19 +11,6 @@ end RegisterNetEvent('esx_ambulancejob:revive') AddEventHandler('esx_ambulancejob:revive', function(playerId) playerId = tonumber(playerId) - if source == '' and GetInvokingResource() == 'monitor' then -- txAdmin support - local xTarget = ESX.GetPlayerFromId(playerId) - if xTarget then - if deadPlayers[playerId] then - print(_U('revive_complete', xTarget.name)) - xTarget.triggerEvent('esx_ambulancejob:revive') - else - print(_U('player_not_unconscious')) - end - else - print(_U('revive_fail_offline')) - end - else local xPlayer = source and ESX.GetPlayerFromId(source) if xPlayer and xPlayer.job.name == 'ambulance' then @@ -46,6 +33,14 @@ AddEventHandler('esx_ambulancejob:revive', function(playerId) xPlayer.showNotification(_U('revive_fail_offline')) end end +end) + +AddEventHandler('txAdmin:events:healedPlayer', function(eventData) + if GetInvokingResource() ~= "monitor" or type(eventData) ~= "table" or type(eventData.id) ~= "number" then + return + end + if deadPlayers[eventData.id] then + TriggerClientEvent('esx_ambulancejob:revive', eventData.id) end end)