Inventory not showing after revive

hey guys,

I have the problem that after you go down and get revived, you are unable to acces your inventory.
You need to relog to fix that problem. Anybody who knows why this is happening?

Can you no open your inventory at all… or when you open it, it is emtpy. If it is the latter … you might have a setting set in your ambulancejob to remove items on rp death… so when they revive all items in the inventory are deleted.

SpikE

1 Like

the menu is just not showing up, when you relog it works again. So the player is not losing any items, he just can’t get the menu to open

which inventory system are you using… or is it the generic esx menu inventory system?

a bit more info could be helpful in trying to track it down if you can get it… after you die and revive do you see any error’s in your f8 console… or server console?

just the generic esx menu inventory, i see no errors anywhere.
mechanic police and ambu menu’s are working everything works, it’s only the inventory menu that does not want to pop up

It might be a flag set for isDead is not getting cleared… since i think esx has it set that you can not open your inventory when dead. look in your script which ever that handles your death… and see if it is setting a death flag… and if it is… make sure it is being cleared when you are revived.

SpikE

this is the part where die dies

function OnPlayerDeath()
    
	isDead = true
	TriggerServerEvent('esx_ambulancejob:setDeathStatus', true)

	StartDeathTimer()
	StartDistressSignal()

	ClearPedTasksImmediately(PlayerPedId())
	StartScreenEffect('DeathFailOut', 0, false)
end

this the part where he get’s revived

RegisterNetEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function()
	local playerPed = PlayerPedId()
	local coords = GetEntityCoords(playerPed)
	isDead = false
	TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)

	Citizen.CreateThread(function()
		DoScreenFadeOut(800)

		while not IsScreenFadedOut() do
			Citizen.Wait(50)
		end

		ESX.SetPlayerData('lastPosition', {
			x = coords.x,
			y = coords.y,
			z = coords.z
		})

		TriggerServerEvent('esx:updateLastPosition', {
			x = coords.x,
			y = coords.y,
			z = coords.z
		})

		RespawnPed(playerPed, {
			x = coords.x,
			y = coords.y,
			z = coords.z
		})

		StopScreenEffect('DeathFailOut')
		DoScreenFadeIn(800)
	end)
end)

seems like it should be removing the flag… but i would have a look at the esx inventory to see if it is checking to see if you are dead or not and setting another flag itself… which version of esx are you using… and i can have a look at it real quick… i haven’t used esx inventory for a bit so would need to look into it.

SpikE

well it has to be the ambulancescript, i updated to the newest version of esx ambulancejob and now it works again, however this is not the script i want.

This is my ambulancefile and me es extended.

esx_ambulancejob.7z (256.2 KB)
es_extended.7z (116.4 KB)

I wil take a look at the version you have to see where it might be going wrong… give me a few mins to have a look.

thanks man, i appreciate it!

looking at your es_extended you can find this in the client/main.lua

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		if IsControlJustReleased(0, 289) then
			if IsInputDisabled(0) and not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
				ESX.ShowInventory()
			end
		end
	end
end)

now researching the isDead in that script… it is being set when your player dies in game by this function:

AddEventHandler('esx:onPlayerDeath', function() isDead = true end)

and is only cleared by this function being called:


AddEventHandler('esx:onPlayerSpawn', function() isDead = false end)

So quick and easy fix… in your ambulancejob when you revive someone have it trigger the esx:onPlayerSpawn - just make sure this isn’t being used anywhere else that could cause issues. Another way you could fix it… would be to edit es_extended and add in a event handler for the event that your ambulancejob is calling to set death status… and in that event have it set isDead to the passed value.

SpikE

Thanks man triggering esx:onPlayerSpawn fixed it!

glad you got it sorted out :slight_smile:

Hello, where would I put that trigger in?

In your ambulancejob. Where ever the revive function in the client script … just make sure it clears the isDead in that function.

Yeah, I’m pretty sure it happens here

RegisterNetEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function()
	local playerPed = PlayerPedId()
	local coords = GetEntityCoords(playerPed)

	TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)
	

	Citizen.CreateThread(function()
		DoScreenFadeOut(800)

		while not IsScreenFadedOut() do
			Citizen.Wait(50)
		end

		local formattedCoords = {
			x = ESX.Math.Round(coords.x, 1),
			y = ESX.Math.Round(coords.y, 1),
			z = ESX.Math.Round(coords.z, 1)
		}

		ESX.SetPlayerData('lastPosition', formattedCoords)

		TriggerServerEvent('esx:updateLastPosition', formattedCoords)

		RespawnPed(playerPed, formattedCoords, 0.0)

		StopScreenEffect('DeathFailOut')
		DoScreenFadeIn(800)
	end)
end)

Would I trigger esx:PlayerSpawn where the revive function is on top?

without looking at all of the code… i would say you should be able to trigger it right after the ServerEvent in ambulancejob to set deathstatus

so something like:

RegisterNetEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function()
	local playerPed = PlayerPedId()
	local coords = GetEntityCoords(playerPed)

	TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)
	TriggerEvent('esx:onPlayerSpawn')

	Citizen.CreateThread(function()
		DoScreenFadeOut(800)

		while not IsScreenFadedOut() do
			Citizen.Wait(50)
		end

		local formattedCoords = {
			x = ESX.Math.Round(coords.x, 1),
			y = ESX.Math.Round(coords.y, 1),
			z = ESX.Math.Round(coords.z, 1)
		}

		ESX.SetPlayerData('lastPosition', formattedCoords)

		TriggerServerEvent('esx:updateLastPosition', formattedCoords)

		RespawnPed(playerPed, formattedCoords, 0.0)

		StopScreenEffect('DeathFailOut')
		DoScreenFadeIn(800)
	end)
end)


Thank you so much it worked!

glad it sorted it out for you.