2023-03-02 15:06:30 +00:00
|
|
|
local Consumables = Config.Consumables
|
|
|
|
|
local Emotes = Config.Emotes
|
2022-04-13 20:01:09 +01:00
|
|
|
|
2025-05-12 22:52:03 +01:00
|
|
|
onResourceStart(function()
|
|
|
|
|
for k, v in pairs(Config.Consumables) do
|
|
|
|
|
createUseableItem(k, function(source, item) TriggerClientEvent(getScript()..':Consume', source, item.name) end)
|
|
|
|
|
if not Items[k] then print("^1Debug^7: ^2Item check ^7- '^1"..k.."^7' ^2not found in the shared lua^7") end
|
|
|
|
|
if not Config.Emotes[v.emote] then print("^1Debug^7: ^2Emote check ^7- '^1"..k.."^7' ^2requested emote ^7'^6"..v.emote.."^7' - ^2not found in config^7.^2lua^7") end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--Export Import System--
|
2025-05-22 14:10:30 +01:00
|
|
|
GlobalState.jimConsumableItems = Consumables
|
|
|
|
|
GlobalState.jimConsumableEmotes = Emotes
|
2025-05-12 22:52:03 +01:00
|
|
|
end, true)
|
2022-08-24 09:23:43 +01:00
|
|
|
|
2025-05-22 14:10:30 +01:00
|
|
|
onResourceStop(function()
|
|
|
|
|
GlobalState.jimConsumableItems = Consumables
|
|
|
|
|
GlobalState.jimConsumableEmotes = Emotes
|
|
|
|
|
end)
|
|
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
RegisterNetEvent(getScript()..':server:addNeed', function(amount, type)
|
2025-05-22 14:12:27 +01:00
|
|
|
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
|
2022-12-15 22:30:42 -05:00
|
|
|
end)
|
2023-02-14 14:40:09 +00:00
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
local syncScheduled = false
|
|
|
|
|
function syncConsumables()
|
2025-05-22 14:10:30 +01:00
|
|
|
debugPrint("^5Statebag^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7")
|
|
|
|
|
GlobalState.jimConsumableItems = Consumables
|
2025-04-01 19:34:44 +01:00
|
|
|
syncScheduled = false
|
|
|
|
|
end
|
2025-05-22 14:10:30 +01:00
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
local emoteSyncScheduled = false
|
|
|
|
|
function syncEmotes()
|
2025-05-22 14:10:30 +01:00
|
|
|
debugPrint("^5Statebag^7: ^2Sending ^6"..countTable(Emotes).." ^3Emotes to all clients^7")
|
|
|
|
|
GlobalState.jimConsumableEmotes = Emotes
|
2025-04-01 19:34:44 +01:00
|
|
|
emoteSyncScheduled = false
|
2023-02-14 14:52:57 +00:00
|
|
|
end
|
|
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
RegisterNetEvent(getScript()..':server:syncAddItem', function(itemName, data)
|
|
|
|
|
if not Consumables[itemName] then
|
|
|
|
|
Consumables[itemName] = data
|
2025-05-22 14:23:12 +01:00
|
|
|
--createUseableItem(itemName, function(source, item) TriggerClientEvent(getScript()..':Consume', source, itemName) end)
|
2025-05-12 22:52:03 +01:00
|
|
|
debugPrint("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Item^7: '"..itemName.."'")
|
2025-04-01 19:34:44 +01:00
|
|
|
if not syncScheduled then
|
|
|
|
|
syncScheduled = true
|
2025-05-22 14:10:30 +01:00
|
|
|
SetTimeout(5000, syncConsumables)
|
2025-04-01 19:34:44 +01:00
|
|
|
end
|
|
|
|
|
else
|
2025-05-12 22:52:03 +01:00
|
|
|
debugPrint("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Item^7: '"..itemName.."'")
|
2025-04-01 19:34:44 +01:00
|
|
|
end
|
|
|
|
|
end)
|
2023-02-14 14:40:09 +00:00
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
RegisterNetEvent(getScript()..':server:syncAddEmote', function(emoteName, data)
|
|
|
|
|
if not Emotes[emoteName] then
|
|
|
|
|
Emotes[emoteName] = data
|
2025-05-12 22:52:03 +01:00
|
|
|
debugPrint("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Emote^7: '"..emoteName.."'")
|
2025-04-01 19:34:44 +01:00
|
|
|
if not emoteSyncScheduled then
|
|
|
|
|
emoteSyncScheduled = true
|
2025-05-22 14:10:30 +01:00
|
|
|
SetTimeout(5000, syncEmotes)
|
2025-04-01 19:34:44 +01:00
|
|
|
end
|
|
|
|
|
else
|
2025-05-12 22:52:03 +01:00
|
|
|
debugPrint("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Emote^7: '"..emoteName.."'")
|
2025-04-01 19:34:44 +01:00
|
|
|
end
|
2023-03-02 15:06:30 +00:00
|
|
|
end)
|
2023-02-14 14:40:09 +00:00
|
|
|
|
2025-05-12 22:52:03 +01:00
|
|
|
--[[
|
2025-04-01 19:34:44 +01:00
|
|
|
Core.Commands.Add('consumableCreator', "Create consumables (admin only)", {}, false, function(source)
|
|
|
|
|
if source > 0 then return TriggerClientEvent(getScript()..":client:consumableCreator", source) end
|
|
|
|
|
end, 'admin')
|
2023-03-02 15:06:30 +00:00
|
|
|
|
2025-04-01 19:34:44 +01:00
|
|
|
Core.Commands.Add('testConsumableEmotes', "Test consumables Emotes (admin only)", {}, false, function(source)
|
|
|
|
|
if source > 0 then return TriggerClientEvent(getScript()..":client:testEmotes", source) end
|
2025-05-12 22:52:03 +01:00
|
|
|
end, 'admin')
|
|
|
|
|
]]
|