From e8e3eaa4d1c84f5833d92e16878224f8a3fb865f Mon Sep 17 00:00:00 2001 From: Alex Garcio Date: Thu, 13 Feb 2020 16:44:14 -0500 Subject: [PATCH] Added ability to find an invisible dead player https://github.com/ESX-Org/esx_ambulancejob/issues/20 --- client/job.lua | 7 +++++-- client/main.lua | 37 ++++++++++++++++++++++++++++++++++++- locales/br.lua | 1 + locales/cs.lua | 1 + locales/en.lua | 1 + locales/es.lua | 1 + locales/fi.lua | 1 + locales/fr.lua | 1 + locales/pl.lua | 1 + locales/sv.lua | 1 + server/main.lua | 5 +++++ 11 files changed, 54 insertions(+), 3 deletions(-) diff --git a/client/job.lua b/client/job.lua index 6802391e..c2d977f2 100644 --- a/client/job.lua +++ b/client/job.lua @@ -46,13 +46,16 @@ function OpenMobileAmbulanceActionsMenu() {label = _U('ems_menu_revive'), value = 'revive'}, {label = _U('ems_menu_small'), value = 'small'}, {label = _U('ems_menu_big'), value = 'big'}, - {label = _U('ems_menu_putincar'), value = 'put_in_vehicle'} + {label = _U('ems_menu_putincar'), value = 'put_in_vehicle'}, + {label = _U('ems_menu_search'), value = 'search'} }}, function(data, menu) if isBusy then return end local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - if closestPlayer == -1 or closestDistance > 1.0 then + if data.current.value == 'search' then + TriggerServerEvent('esx_ambulancejob:svsearch') + elseif closestPlayer == -1 or closestDistance > 1.0 then ESX.ShowNotification(_U('no_players')) else if data.current.value == 'revive' then diff --git a/client/main.lua b/client/main.lua index 3b8dcdae..3746ee40 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,6 +1,6 @@ local firstSpawn, PlayerLoaded = true, false -isDead = false +isDead, isSearched, medic = false, false, 0 ESX = nil Citizen.CreateThread(function() @@ -81,6 +81,41 @@ Citizen.CreateThread(function() end end) +Citizen.CreateThread(function() + while true do + Citizen.Wait(0) + if isDead and isSearched then + local playerPed = PlayerPedId() + local ped = GetPlayerPed(GetPlayerFromServerId(medic)) + isSearched = false + + AttachEntityToEntity(playerPed, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true) + Citizen.Wait(1000) + DetachEntity(playerPed, true, false) + ClearPedTasksImmediately(playerPed) + end + end +end) + +RegisterNetEvent('esx_ambulancejob:clsearch') +AddEventHandler('esx_ambulancejob:clsearch', function(medicId) + local playerPed = PlayerPedId() + + if isDead then + local coords = GetEntityCoords(playerPed) + local playersInArea = ESX.Game.GetPlayersInArea(coords, 50.0) + + for i=1, #playersInArea, 1 do + local player = playersInArea[i] + if player == GetPlayerFromServerId(medicId) then + medic = tonumber(medicId) + isSearched = true + break + end + end + end +end) + function OnPlayerDeath() isDead = true ESX.UI.Menu.CloseAll() diff --git a/locales/br.lua b/locales/br.lua index 9e3147d0..dead693d 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -60,6 +60,7 @@ Locales['br'] = { ['ems_menu_putincar'] = 'colocar no veiculo', ['ems_menu_small'] = 'curar pequenas feridas', ['ems_menu_big'] = 'tratando lesões graves', + ['ems_menu_search'] = 'paciente não encontrado', -- Phone ['alert_ambulance'] = 'alerta socorrista', -- Death diff --git a/locales/cs.lua b/locales/cs.lua index 37d65c5a..dfc9a125 100644 --- a/locales/cs.lua +++ b/locales/cs.lua @@ -60,6 +60,7 @@ Locales['cs'] = { ['ems_menu_putincar'] = 'naložit do vozidla', ['ems_menu_small'] = 'ošetřit malé zranění', ['ems_menu_big'] = 'ošetřit vážné zranění', + ['ems_menu_search'] = 'pacient nebyl nalezen', -- Phone ['alert_ambulance'] = 'zdravotnický poplach', -- Death diff --git a/locales/en.lua b/locales/en.lua index 5b5f6d24..d00b4ab4 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -60,6 +60,7 @@ Locales['en'] = { ['ems_menu_putincar'] = 'put in Vehicle', ['ems_menu_small'] = 'heal small wounds', ['ems_menu_big'] = 'treat serious injuries', + ['ems_menu_search'] = 'patient not found', -- Phone ['alert_ambulance'] = 'alert Ambulance', -- Death diff --git a/locales/es.lua b/locales/es.lua index e231db54..afd81dac 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -60,6 +60,7 @@ Locales['es'] = { ['ems_menu_putincar'] = 'meter en el vehículo', ['ems_menu_small'] = 'heal small wounds', ['ems_menu_big'] = 'treat serious injuries', + ['ems_menu_search'] = 'Paciente no encontrado', -- Phone ['alert_ambulance'] = 'Alerta de ambulancia', -- Death diff --git a/locales/fi.lua b/locales/fi.lua index 9ef6caf8..bc100b14 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -60,6 +60,7 @@ Locales['fi'] = { ['ems_menu_putincar'] = 'Laita ajoneuvoon', ['ems_menu_small'] = 'hoida pieniä haavoja', ['ems_menu_big'] = 'hoida isoja haavoja', + ['ems_menu_search'] = 'potilasta ei löydy', -- Phone ['alert_ambulance'] = 'hälyytys Ensihoidolle', -- Death diff --git a/locales/fr.lua b/locales/fr.lua index fb750289..ce6c7e83 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -60,6 +60,7 @@ Locales['fr'] = { ['ems_menu_putincar'] = 'mettre dans véhicule', ['ems_menu_small'] = 'soigner petites blessures', ['ems_menu_big'] = 'soigner blessures graves', + ['ems_menu_search'] = 'patient introuvable', -- Phone ['alert_ambulance'] = 'alerte Ambulance', -- Death diff --git a/locales/pl.lua b/locales/pl.lua index ebf082c1..80b1378b 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -60,6 +60,7 @@ Locales['pl'] = { ['ems_menu_putincar'] = 'umieścić w pojeździe', ['ems_menu_small'] = 'ulecz małe rany', ['ems_menu_big'] = 'ulecz poważne obrażenia', + ['ems_menu_search'] = 'nie znaleziono pacjenta', -- Phone ['alert_ambulance'] = 'wezwij ambulans', -- Death diff --git a/locales/sv.lua b/locales/sv.lua index b0d736aa..71f4740e 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -60,6 +60,7 @@ Locales['sv'] = { ['ems_menu_putincar'] = 'sätt i fordon', ['ems_menu_small'] = 'behandla mindre skador', ['ems_menu_big'] = 'behandla svåra skador', + ['ems_menu_search'] = 'patienten hittades inte', -- Phone ['alert_ambulance'] = 'ambulanssamtal', -- Death diff --git a/server/main.lua b/server/main.lua index 4b24fb5e..eb92dfdc 100644 --- a/server/main.lua +++ b/server/main.lua @@ -35,6 +35,11 @@ AddEventHandler('esx:onPlayerDeath', function(data) TriggerClientEvent('esx_ambulancejob:setDeadPlayers', -1, deadPlayers) end) +RegisterServerEvent('esx_ambulancejob:svsearch') +AddEventHandler('esx_ambulancejob:svsearch', function() + TriggerClientEvent('esx_ambulancejob:clsearch', -1, source) +end) + RegisterNetEvent('esx_ambulancejob:onPlayerDistress') AddEventHandler('esx_ambulancejob:onPlayerDistress', function() if deadPlayers[source] then