forked from Simnation/Main
ed
This commit is contained in:
parent
208ecc8c0c
commit
38926664fb
2 changed files with 132 additions and 35 deletions
|
@ -5,6 +5,31 @@ local function Debug(msg)
|
|||
print("^2[Shisha 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('shisha-script:checkItem', function(itemName, amount, callbackEvent)
|
||||
local src = source
|
||||
local hasItem = HasItem(src, itemName, amount)
|
||||
TriggerClientEvent(callbackEvent, src, hasItem)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('shisha-script:consumeTobacco')
|
||||
AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
||||
Debug("Tabak-Verbrauch-Event ausgelöst")
|
||||
|
@ -15,7 +40,7 @@ AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
|||
-- Überprüfe nochmal die Zutaten
|
||||
local hasAllItems = true
|
||||
for _, requirement in ipairs(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
|
||||
|
@ -25,7 +50,7 @@ AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
|||
Debug("Spieler hat alle benötigten Items")
|
||||
-- Entferne die benötigten Items
|
||||
for _, requirement in ipairs(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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue