This commit is contained in:
Nordi98 2025-08-02 13:51:31 +02:00
parent d734800a74
commit a700c6d796
3 changed files with 124 additions and 142 deletions

View file

@ -33,7 +33,7 @@ RegisterNetEvent('pet-bowls:server:requestBowls', function()
TriggerClientEvent('pet-bowls:client:loadBowls', src, bowls)
end)
-- Place a new bowl
-- Place a new bowl (register an existing prop as a bowl)
RegisterNetEvent('pet-bowls:server:placeBowl', function(bowlId, model, bowlType, coords)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
@ -69,16 +69,17 @@ RegisterNetEvent('pet-bowls:server:fillBowl', function(bowlId, itemName, fillAmo
if not Player then return end
-- Check if player has the item
local hasItem = exports["tgiann-inventory"]:GetItemByName(src, itemName)
-- Check if player has the item using standard QBCore function
local item = Player.Functions.GetItemByName(itemName)
if not hasItem or hasItem.amount < 1 then
if not item or item.amount < 1 then
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.noItem)
return
end
-- Remove the item
exports["tgiann-inventory"]:RemoveItem(src, itemName, 1)
-- Remove the item using standard QBCore function
Player.Functions.RemoveItem(itemName, 1)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove")
-- Update bowl fill level
local bowl = bowls[bowlId]
@ -163,7 +164,7 @@ RegisterNetEvent('pet-bowls:server:consumeBowl', function(bowlId)
TriggerClientEvent('ox_lib:notify', src, Config.Notifications.consumed)
end)
-- Remove a bowl
-- Remove a bowl from database (if needed)
RegisterNetEvent('pet-bowls:server:removeBowl', function(bowlId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
@ -175,9 +176,7 @@ RegisterNetEvent('pet-bowls:server:removeBowl', function(bowlId)
-- Remove from memory
bowls[bowlId] = nil
end)
-- Register command to place bowls
QBCore.Commands.Add('placebowl', 'Place a pet bowl', {}, false, function(source, args)
TriggerClientEvent('pet-bowls:client:openPlaceBowlMenu', source)
-- Notify all clients
TriggerClientEvent('pet-bowls:client:bowlRemoved', -1, bowlId)
end)