Police ability to revive without /revive [esx_policejob]

This is the updated version for the most current esx_police job as of 7/26/18

Requires esx_ambulance job obviously

Add this to your police menu in the client main.lua

			  {label = _U('revive player'),       value = 'revive'},

Remember if it is at the end of this list you need to remove the comma.

Then add this

if action == 'revive' then
	local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
	local closestPlayerPed = GetPlayerPed(closestPlayer)
	local health = GetEntityHealth(closestPlayerPed)
	if health == 0 then
	    local playerPed = GetPlayerPed(-1)
	    Citizen.CreateThread(function()
		   ESX.ShowNotification(_U('revive_inprogress'))
		   TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
		   Wait(10000)
		   ClearPedTasks(playerPed)
		   if GetEntityHealth(closestPlayerPed) == 0 then
			   TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
			   ESX.ShowNotification(_U('revive_complete'))
		   else
			ESX.ShowNotification(_U('isdead'))
		   end
		end)
     end
elseif action == 'identity_card' then
    OpenIdentityCardMenu(closestPlayer)
elseif action == 'body_search' then
    TriggerServerEvent('esx_policejob:message', GetPlayerServerId(closestPlayer), _U('being_searched'))
elseif.... 

It should look like this after.

local action = data2.current.value
					
if action == 'revive' then
	local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
	local closestPlayerPed = GetPlayerPed(closestPlayer)
	local health = GetEntityHealth(closestPlayerPed)
	if health == 0 then
		local playerPed = GetPlayerPed(-1)
		Citizen.CreateThread(function()
			ESX.ShowNotification(_U('revive_inprogress'))
			TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
			Wait(10000)
			ClearPedTasks(playerPed)
			if GetEntityHealth(closestPlayerPed) == 0 then
				TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
				ESX.ShowNotification(_U('revive_complete'))
				     else
					  ESX.ShowNotification(_U('isdead'))
				     end
			end)
	 end
elseif action == 'identity_card' then
	OpenIdentityCardMenu(closestPlayer)
elseif action == 'body_search' then
	TriggerServerEvent('esx_policejob:message', GetPlayerServerId(closestPlayer), _U('being_searched'))
	OpenBodySearchMenu(closestPlayer)
elseif action == 'handcuff' then
	TriggerServerEvent('esx_policejob:handcuff', GetPlayerServerId(closestPlayer))
elseif action == 'drag' then
	TriggerServerEvent('esx_policejob:drag', GetPlayerServerId(closestPlayer))
elseif action == 'put_in_vehicle' then
	TriggerServerEvent('esx_policejob:putInVehicle', GetPlayerServerId(closestPlayer))
elseif action == 'out_the_vehicle' then
	TriggerServerEvent('esx_policejob:OutVehicle', GetPlayerServerId(closestPlayer))
elseif action == 'fine' then
	OpenFineMenu(closestPlayer)
elseif action == 'license' then
	ShowPlayerLicense(closestPlayer)
elseif action == 'unpaid_bills' then
	OpenUnpaidBillsMenu(closestPlayer)
end

NEXT

Add this to your server main.lua

RegisterServerEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function(target)
  TriggerClientEvent('esx_ambulancejob:revive', target)
end)

LASTLY

Add these to your locales.lua

--Revive
['revive player'] = 'revive player',
['revive_inprogress'] = 'revive in progress',
['revive_complete'] = 'revive complete',
['isdead'] = 'Player Dead',
5 Likes

Not working, when I added it it’s not worked and I tried put it in the end of the script and nothing worked it didn’t displayed any Error message or anything. I can’t even open F6. Can you please send me the full script?

I cannot get it to work either. Mine just simply breaks the F6 menu script completely

1 Like

this still working?, can we have a gif or something about the set up, thank you

I never got the ambulance revive to work, so we have esx_pharmacy. Just remove all stores and put the only buy points in the armory at mission row and in the hosptial.

Have the police use the defibs, which only work when no medics are online.

1 Like

1 Like

Update,

Got the defibs to work all the time, we decided to remove the pharmacy locations from the public, put them in Mission Row and the hospital so both jobs can use them.

Thank you @Emono!

I want to add a check for a medikit before the police officer is able to revive first. I’ve tried a few different ways but they just aren’t working. Any ideas?

I actually removed that for the police revive I would have to look at the code again.

I got the this working aging by adding one bit of text …

I missed this in the examples above might help someone later down the road.

if action == 'identity_card' then

Needs to be

elseif action == 'identity_card' then

Here is my section as it is now.

					local action = data2.current.value
					
					if action == 'revive' then
					local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
					local closestPlayerPed = GetPlayerPed(closestPlayer)
	                local health = GetEntityHealth(closestPlayerPed)
					if health == 0 then
		                local playerPed = GetPlayerPed(-1)
		                Citizen.CreateThread(function()
						ESX.ShowNotification(_U('revive_inprogress'))
						TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
						Wait(10000)
						ClearPedTasks(playerPed)
							if GetEntityHealth(closestPlayerPed) == 0 then
							TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
							ESX.ShowNotification(_U('revive_complete'))
							else
							ESX.ShowNotification(_U('isdead'))
							end
						end)
					end

					elseif action == 'identity_card' then
						OpenIdentityCardMenu(closestPlayer)
					elseif action == 'body_search' then
						TriggerServerEvent('esx_policejob:message', GetPlayerServerId(closestPlayer), _U('being_searched'))
						OpenBodySearchMenu(closestPlayer)
					elseif action == 'handcuff' then
						TriggerServerEvent('esx_policejob:handcuff', GetPlayerServerId(closestPlayer))
					elseif action == 'drag' then
						TriggerServerEvent('esx_policejob:drag', GetPlayerServerId(closestPlayer))
					elseif action == 'put_in_vehicle' then
						TriggerServerEvent('esx_policejob:putInVehicle', GetPlayerServerId(closestPlayer))
					elseif action == 'out_the_vehicle' then
						TriggerServerEvent('esx_policejob:OutVehicle', GetPlayerServerId(closestPlayer))
					elseif action == 'fine' then
						OpenFineMenu(closestPlayer)
					elseif action == 'license' then
						ShowPlayerLicense(closestPlayer)
					elseif action == 'unpaid_bills' then
						OpenUnpaidBillsMenu(closestPlayer)
					end
					else
					ESX.ShowNotification(_U('no_players_nearby'))
				end
			end, function(data2, menu2)
				menu2.close()
			end)

Hi i made it work but the thing is that i could’t use anything els, so i decided to make a new meny. So now i have " F5 > Medical assistance > Revive " but it all shows up in the Police meny under Object spawner, but the Script dont start to revive closes dead player. it worked before when added the way u did but it made everything els stop working due to distance… i think i just missing a end or , or ) but dont know where… any idees?

	  if data.current.value == 'Medical_assistance' then

        ESX.UI.Menu.Open(
          'default', GetCurrentResourceName(), 'Medical_assistance',
          {
            title    = _U('Medical_assistance'),
            align    = 'bottom-right',
            elements = {

              {label = _U('revive player'),       value = 'revive'}
            },
          },
          function(data2, menu2)
			
			if action == 'revive' then
				local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
				local closestPlayerPed = GetPlayerPed(closestPlayer)
				local health = GetEntityHealth(closestPlayerPed)
					if health == 0 then
						local playerPed = GetPlayerPed(-1)
							Citizen.CreateThread(function()
							ESX.ShowNotification(_U('revive_inprogress'))
							TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
							Wait(10000)
							ClearPedTasks(playerPed)
						if GetEntityHealth(closestPlayerPed) == 0 then
							TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
							ESX.ShowNotification(_U('revive_complete'))
							else
							ESX.ShowNotification(_U('isdead'))
							end
					end)
			    end
             end
          end,
          function(data2, menu2)
            menu2.close()
          end
        )
      end

I have it working using EMT ability but it takes 1 medkit.

Like everyone else that posted help on this, this goes below data2 line and right above identity line in the client.

				if closestPlayer ~= -1 and closestDistance <= 3.0 then
					local action = data2.current.value
       --Revive Start             
					if action == 'revive' then
						IsBusy = true
						ESX.TriggerServerCallback('esx_ambulancejob:getItemAmount', function(quantity)
							if quantity > 0 then
								local closestPlayerPed = GetPlayerPed(closestPlayer)
								if IsPedDeadOrDying(closestPlayerPed, 1) then
									local playerPed = PlayerPedId()
									ESX.ShowNotification(_U('revive_inprogress'))
									local lib, anim = 'mini@cpr@char_a@cpr_str', 'cpr_pumpchest'
									for i=1, 15, 1 do
										Citizen.Wait(900)
								
										ESX.Streaming.RequestAnimDict(lib, function()
											TaskPlayAnim(PlayerPedId(), lib, anim, 8.0, -8.0, -1, 0, 0, false, false, false)
										end)
									end

									TriggerServerEvent('esx_ambulancejob:removeItem', 'medikit')
									TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))

									-- Show revive award?
									if Config.ReviveReward > 0 then
										ESX.ShowNotification(_U('revive_complete_award', GetPlayerName(closestPlayer), Config.ReviveReward))
									else
										ESX.ShowNotification(_U('revive_complete', GetPlayerName(closestPlayer)))
									end
								else
									ESX.ShowNotification(_U('player_not_unconscious'))
								end
							else
								ESX.ShowNotification(_U('not_enough_medikit'))
							end

							IsBusy = false

						end, 'medikit')
-- Revive End
					elseif action == 'identity_card' then
						OpenIdentityCardMenu(closestPlayer)

These next ones go in the server.lua

RegisterServerEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function(target)
  TriggerClientEvent('esx_ambulancejob:revive', target)
end)

ESX.RegisterServerCallback('esx_ambulancejob:getItemAmount', function(source, cb, item)
	local xPlayer = ESX.GetPlayerFromId(source)
	local quantity = xPlayer.getInventoryItem(item).count

	cb(quantity)
end)

RegisterServerEvent('esx_ambulancejob:removeItem')
AddEventHandler('esx_ambulancejob:removeItem', function(item)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)

	if item == 'medikit' then
		TriggerClientEvent('esx:showNotification', _source, _U('used_medikit'))
	end
end)

Hope it helps, this is also the latest versions of Ambulance and Police Job.

2 Likes

This is not working for me. On the latest police/ambulance job. Have my script exactly as you have it

1 Like

It works on mine, but as you probably know, Scripts don’t always work like they should everywhere. I have issues with them sometimes too when others say they work. I spend a lot of time editing code and pissing around to get it going.

there is a bug, when police take weapon of the body, and you revive him with police menu. then he will get the weapon back

i really love this fivem community, they really help each other

and thank you barren for the snippet

@stor_asna If you can’ get it working, just DM me and I will send you my whole police file.

acually i tried some hours ago and it didnt work, i will gladly look at your police file

i couldnt get it to work neither :frowning: