2022-04-13 20:01:09 +01:00
local QBCore = exports [ ' qb-core ' ] : GetCoreObject ( )
2022-08-24 09:23:43 +01:00
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
2022-12-15 22:30:42 -05:00
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
2022-08-24 09:23:43 +01:00
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
2022-08-15 10:06:30 +01:00
end
2022-08-26 06:10:20 +06:00
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 )
2022-12-15 22:30:42 -05:00
end )