mirror of
https://github.com/jimathy/jim-consumables.git
synced 2026-08-17 06:26:03 +01:00
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:
@@ -313,24 +313,33 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if needStats then
|
if needStats then
|
||||||
if needStats.hunger then
|
jsonPrint(needStats)
|
||||||
|
if needStats.hunger > 0 then
|
||||||
local hunger = 0
|
local hunger = 0
|
||||||
if Core.Functions and Core.Functions.GetPlayerData then
|
if Core and Core.Functions then
|
||||||
hunger = Core.Functions.GetPlayerData().metadata["hunger"] or 0
|
hunger = (Core.Functions.GetPlayerData().metadata["hunger"] or 0) + needStats.hunger
|
||||||
|
hunger = hunger > 100 and 100 or hunger
|
||||||
|
|
||||||
elseif ESX and ESX.GetPlayerData then
|
elseif ESX and ESX.GetPlayerData then
|
||||||
hunger = ESX.GetPlayerData().hunger or 0
|
hunger = (needStats.thirst / 100) * 1000000
|
||||||
|
hunger = hunger > 1000000 and 1000000 or hunger
|
||||||
end
|
end
|
||||||
TriggerServerEvent(getScript()..":server:addNeed", hunger + needStats.hunger, "hunger")
|
|
||||||
|
TriggerServerEvent(getScript()..":server:setNeed", "hunger", hunger)
|
||||||
end
|
end
|
||||||
|
|
||||||
if needStats.thirst then
|
if needStats.thirst > 0 then
|
||||||
local thirst = 0
|
local thirst = 0
|
||||||
if Core.Functions and Core.Functions.GetPlayerData then
|
if Core and Core.Functions then
|
||||||
thirst = Core.Functions.GetPlayerData().metadata["thirst"] or 0
|
thirst = (Core.Functions.GetPlayerData().metadata["thirst"] or 0) + needStats.thirst
|
||||||
|
thirst = thirst > 100 and 100 or thirst
|
||||||
|
|
||||||
elseif ESX and ESX.GetPlayerData then
|
elseif ESX and ESX.GetPlayerData then
|
||||||
thirst = ESX.GetPlayerData().thirst or 0
|
thirst = (needStats.thirst / 100) * 1000000
|
||||||
|
thirst = thirst > 1000000 and 1000000 or thirst
|
||||||
end
|
end
|
||||||
TriggerServerEvent(getScript()..":server:addNeed", thirst + needStats.thirst, "thirst")
|
|
||||||
|
TriggerServerEvent(getScript()..":server:setNeed", "thirst", thirst)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
debugPrint("^5Debug^7: ^2Hunger^7: [^6"..(needStats.hunger or 0).."^7] ^2Thrist^7: [^6"..(needStats.thirst or 0).."^7]" )
|
debugPrint("^5Debug^7: ^2Hunger^7: [^6"..(needStats.hunger or 0).."^7] ^2Thrist^7: [^6"..(needStats.thirst or 0).."^7]" )
|
||||||
|
|||||||
@@ -18,40 +18,6 @@ onResourceStop(function()
|
|||||||
GlobalState.jimConsumableEmotes = Emotes
|
GlobalState.jimConsumableEmotes = Emotes
|
||||||
end)
|
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
|
local syncScheduled = false
|
||||||
function syncConsumables()
|
function syncConsumables()
|
||||||
debugPrint("^5Statebag^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7")
|
debugPrint("^5Statebag^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7")
|
||||||
|
|||||||
Reference in New Issue
Block a user