mirror of
https://github.com/jimathy/jim-consumables.git
synced 2026-08-17 14:36:03 +01:00
37 lines
1.8 KiB
Lua
37 lines
1.8 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
for k, v in pairs(Config.Consumables) do
|
|
QBCore.Functions.CreateUseableItem(k, function(source, item) TriggerClientEvent('jim-consumables:Consume', source, item.name) end)
|
|
if not QBCore.Shared.Items[k] then print("Item check - '"..k.."' not found in the shared lua") end
|
|
if not Config.Emotes[v.emote] then print("Emote check - '"..k.."' requested emote '"..v.emote.."' - not found in config.lua") end
|
|
end
|
|
|
|
RegisterNetEvent('jim-consumables:server:toggleItem', function(give, item, amount)
|
|
local src = source
|
|
if give == 0 or give == false then
|
|
if QBCore.Functions.GetPlayer(src).Functions.RemoveItem(item, amount or 1) then
|
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "remove", amount or 1)
|
|
end
|
|
else
|
|
if not Config.Consumables[give] then print(('%s may have potentially attempted an item exploit to gain %s %s'):format(src, amount, item)) return end -- cancel if item does not exist in config
|
|
|
|
if QBCore.Functions.GetPlayer(src).Functions.AddItem(item, amount or 1) then
|
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "add", amount or 1)
|
|
end
|
|
end
|
|
end)
|
|
|
|
RegisterNetEvent('jim-consumables:server:addThirst', function(amount)
|
|
local Player = QBCore.Functions.GetPlayer(source)
|
|
if not Player then return end
|
|
Player.Functions.SetMetaData('thirst', amount)
|
|
TriggerClientEvent('hud:client:UpdateNeeds', source, Player.PlayerData.metadata.hunger, amount)
|
|
end)
|
|
|
|
RegisterNetEvent('jim-consumables:server:addHunger', function(amount)
|
|
local Player = QBCore.Functions.GetPlayer(source)
|
|
if not Player then return end
|
|
Player.Functions.SetMetaData('hunger', amount)
|
|
TriggerClientEvent('hud:client:UpdateNeeds', source, amount, Player.PlayerData.metadata.thirst)
|
|
end)
|