ed
This commit is contained in:
parent
961260f3f5
commit
5f4adf5818
3 changed files with 177 additions and 72 deletions
|
@ -5,6 +5,31 @@ local function Debug(msg)
|
|||
print("^2[Grill Debug] ^7" .. msg)
|
||||
end
|
||||
|
||||
-- Function to check if player has an item
|
||||
local function HasItem(source, itemName, amount)
|
||||
local items = exports["tgiann-inventory"]:GetPlayerItems(source)
|
||||
if not items then return false end
|
||||
|
||||
local count = 0
|
||||
for _, item in pairs(items) do
|
||||
if item.name == itemName then
|
||||
count = count + item.count
|
||||
if count >= amount then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- Event for client to check if player has an item
|
||||
RegisterNetEvent('nordi_bbq:checkItem', function(itemName, amount, callbackEvent)
|
||||
local src = source
|
||||
local hasItem = HasItem(src, itemName, amount)
|
||||
TriggerClientEvent(callbackEvent, src, hasItem)
|
||||
end)
|
||||
|
||||
-- Event zum Geben des gegrillten Essens
|
||||
RegisterNetEvent('nordi_bbq:server:GiveGrilledFood', function(itemName, requirements)
|
||||
local src = source
|
||||
|
@ -33,7 +58,7 @@ RegisterNetEvent('nordi_bbq:server:GiveGrilledFood', function(itemName, requirem
|
|||
-- Überprüfe Zutaten
|
||||
local hasAllItems = true
|
||||
for _, requirement in pairs(requirements) do
|
||||
if not Player.Functions.HasItem(requirement.item, requirement.amount) then
|
||||
if not HasItem(src, requirement.item, requirement.amount) then
|
||||
hasAllItems = false
|
||||
break
|
||||
end
|
||||
|
@ -42,12 +67,12 @@ RegisterNetEvent('nordi_bbq:server:GiveGrilledFood', function(itemName, requirem
|
|||
if hasAllItems then
|
||||
-- Entferne Zutaten
|
||||
for _, requirement in pairs(requirements) do
|
||||
Player.Functions.RemoveItem(requirement.item, requirement.amount)
|
||||
exports["tgiann-inventory"]:RemoveItem(src, requirement.item, requirement.amount)
|
||||
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove")
|
||||
end
|
||||
|
||||
-- Gib das fertige Essen
|
||||
Player.Functions.AddItem(itemName, 1)
|
||||
exports["tgiann-inventory"]:AddItem(src, itemName, 1)
|
||||
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add")
|
||||
|
||||
local itemLabel = QBCore.Shared.Items[itemName] and QBCore.Shared.Items[itemName].label or itemName
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue