Revamp hunger and thirst events

Realised I made a mistake, and the server function wasn't working fully on ESX

moved it to use the jim_bridge `setNeed` trigger and made the function smarter
This commit is contained in:
Jim Shield
2025-06-14 22:29:40 +01:00
parent 518c5204ae
commit 4b015e5efa
2 changed files with 19 additions and 44 deletions

View File

@@ -18,40 +18,6 @@ onResourceStop(function()
GlobalState.jimConsumableEmotes = Emotes
end)
RegisterNetEvent(getScript()..':server:addNeed', function(amount, type)
local src = source
if Core.Functions and Core.Functions.GetPlayer then -- QBCore/QBox
local Player = Core.Functions.GetPlayer(src)
if not Player then return end
if type == "thirst" then
Player.Functions.SetMetaData('thirst', amount)
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata.hunger, amount)
elseif type == "hunger" then
Player.Functions.SetMetaData('hunger', amount)
TriggerClientEvent('hud:client:UpdateNeeds', src, amount, Player.PlayerData.metadata.thirst)
end
elseif ESX and ESX.GetPlayerFromId then -- ESX
local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local hunger = xPlayer.get('hunger') or 0
local thirst = xPlayer.get('thirst') or 0
if type == "thirst" then
thirst = amount
xPlayer.set('thirst', thirst)
elseif type == "hunger" then
hunger = amount
xPlayer.set('hunger', hunger)
end
TriggerClientEvent('hud:client:UpdateNeeds', src, hunger, thirst)
end
end)
local syncScheduled = false
function syncConsumables()
debugPrint("^5Statebag^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7")