[HELP] ESX_STATUS Modification doesn't work

Hi, i’m trying to add a notification when a user gets thirsty or hungry but idk why it doesn’t work when i add these lines.

  	if Status[i].val <= 900000 and Status[i].name == "hunger" then
  		ESX.ShowNotification("faim")
  	else
  		return
  	end
  	if Status[i].val <= 900000 and Status[i].name == "thirst" then
  		ESX.ShowNotification("soif")

Here is the Event, i only modified esx_status. I think i made a syntax error or something like that.

RegisterNetEvent(‘esx_status:set’)
AddEventHandler(‘esx_status:set’, function(name, val)
for i=1, status, 1 do
if Status[i].name == name then
Status[i].set(val)
if Status[i].val <= 900000 and Status[i].name == “hunger” then
ESX.ShowNotification(“faim”)
else
return
end
if Status[i].val <= 900000 and Status[i].name == “thirst” then
ESX.ShowNotification(“soif”)
else
return
end
break
end
end

SendNUIMessage({
update = true,
status = GetStatusData()
})

TriggerServerEvent(‘esx_status:update’, GetStatusData(true))
end)

Thx for future help

As I can see its because all of your return in your if,
I will give you an exemple, if the val is 100 000 and the name is “thirst”, your first verification is on “hunger”, so its goes straitght to the return and does enter the “thrist” if

EDIT: After some research, you should look in the script called esx_basicneeds, as I can see in less than 5 minutes is that, the event called “esx_status:set” is called only on a status reset or on a heal player.

Men if you look at esx_status in the end of the client script there is some code who have goal to decrease the food overtime with a predefined tickrate and this code trigger a server event, this server event trigger another client side event who update the ui (to view the food decreasing) so i think its where i need to place my code. Also i tried to do it with only the hunger and no return and it doesn’t work. but thx for the help though

Try this:

RegisterNetEvent('esx_status:set')
AddEventHandler('esx_status:set', function(name, val)
	for i=1, #Status, 1 do
		if Status[i].name == name then
			Status[i].set(val)
			if Status[i].val <= 900000 and Status[i].name == "hunger" then
				ESX.ShowNotification("faim")			
			elseif Status[i].val <= 900000 and Status[i].name == "thirst" then
				ESX.ShowNotification("soif")
			end
			break
		end
	end

	SendNUIMessage({
		update = true,
		status = GetStatusData()
	})

	TriggerServerEvent('esx_status:update', GetStatusData(true))
end)

Doesn’t work

EDIT: Tried also with prints but doesn’t work too ;( so i think we a do something wrong but idk what is it

UP :wave:

Do you have any error in console?

And where did you try to print?

I replaced the ESX.ShowNotification with a print(“test”) and no i don’t have error in client console or server console

Try this debug:

if Status[i].name == name then
	Status[i].set(val)
	print(Status[i].name)
	print(Status[i].val)
	if Status[i].val <= 900000 and Status[i].name == "hunger" then
		ESX.ShowNotification("faim")			
	elseif Status[i].val <= 900000 and Status[i].name == "thirst" then
		ESX.ShowNotification("soif")
	end
	break
end

To see all status

1 Like

Yup at the end it send a Server event with a status update, esx_status:set won’t work but if you check as I told you, esx_basicneeds at line 62 to 80, this is exacly where you want to put your code, or you can also use a while true, with the event esx:status:getStatus, to do your things but the easiest way to do it its in esx:basicneeds

Because in esx_status:set, its when the player respawn or reset, so its never gonna be under 500 000, that’s why its didn’t work at all

You can also dm me for more information or to get my dicord to have more help

3 Likes

Try this:

AddEventHandler('esx_status:loaded', function(status)

	TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function(status)
		return true
	end, function(status)
		status.remove(100)
	end)

	TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1', function(status)
		return true
	end, function(status)
		status.remove(75)
	end)

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

			local playerPed  = PlayerPedId()
			local prevHealth = GetEntityHealth(playerPed)
			local health     = prevHealth

			TriggerEvent('esx_status:getStatus', 'hunger', function(status)
				if status.val < 90000 then
					ESX.ShowNotification("faim")
				end
				if status.val == 0 then
					if prevHealth <= 150 then
						health = health - 5
					else
						health = health - 1
					end
				end
			end)

			TriggerEvent('esx_status:getStatus', 'thirst', function(status)
				if status.val < 90000 then
					ESX.ShowNotification("soif")
				end
				if status.val == 0 then
					if prevHealth <= 150 then
						health = health - 5
					else
						health = health - 1
					end
				end
			end)

			if health ~= prevHealth then
				SetEntityHealth(playerPed, health)
			end
		end
	end)
end)

It work perfecly on me
Replace in ESX_BASICNEEDS from line 40 to line 93

2 Likes

And please just told me if it work or not, so I will be able to provide more help

Thx it works yur the best in the past i checked this resource and i was thinking there is nothing to do here but it’s where i needed to modify. Anyways thx and thx also to @fauconjona for helping.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.