[Request] Hungry effect script

Someone knows a script witch activates a similar effect like the collision one, when the food and the thirst level is very low?

Esx

Hey :slightly_smiling_face: !
No need to have a full script to do so, you can just tweek ‘esx_basicneeds’.

Like this for example :

Add the following function at in ‘esx_addons/esx_basicneeds/client/main.lua’ (pretty much where you want)

local isBlackedOut = false
local blackoutTime = 2000
local function blackout()
	-- Only blackout once to prevent an extended blackout if both speed and damage thresholds were met
	if not isBlackedOut then
		isBlackedOut = true
		-- This thread will black out the user's screen for the specified time
		Citizen.CreateThread(function()
			DoScreenFadeOut(100)
			while not IsScreenFadedOut() do
				Citizen.Wait(0)
			end
			Citizen.Wait(blackoutTime)
			DoScreenFadeIn(250)
			isBlackedOut = false
		end)
	end
end

This function was written by @SaltyGrandpa (cause we all need a little bit of salt :p)

Then still in ‘esx_addons/esx_basicneeds/client/main.lua’ you hook the function in the ‘esx_status:onTick’ event, by adding something like :

2 Likes

Thanks can you send full main.lua
https://forum.cfx.re/uploads/default/original/4X/8/3/3/8337100dace0e770ba152ed0f4e459bdf86710c0.png

Because my script now

AddEventHandler(‘esx_status:loaded’, function(status)

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

TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1', function(status)
	return Config.Visible
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 == 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 == 0 then
				if prevHealth <= 150 then
					health = health - 5
				else
					health = health - 1
				end
			end
		end
		
		if v.name == 'hunger' and ( v.percent == 10 or v.percent == 5 ) then
		   blackout()
		   
		elseif v.name == 'thirst' and ( v.percent == 10 or v.percent == 5 ) then
           blackout()
        end			   

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

end)

main.lua (4.2 KB)

1 Like

Thank you!

Anyone of doing a thirst and hunger alert like this but with a belly growl sound effect? Ive seen it in other servers just not sure how to go about adding it to my esx city.