diff --git a/config/config.lua b/config/config.lua index cd6d86e..ce5de88 100644 --- a/config/config.lua +++ b/config/config.lua @@ -90,12 +90,12 @@ Config = { maxZ = 22.56,--// box zone max height items = {--// all the items you can craft { - item = 'phone',--//this is the items spawn name - label = 'Phone',--//this is the items label name + item = 'kurkakola',--//this is the items spawn name + label = 'Cola',--//this is the items label name requiredLabel = 'Phone: 1x, Water: 2x',--//this displays on the menu what items are required to make this item required = {--//required item list - {item = 'phone', count = 2}, - {item = 'water_bottle', count = 1} + ['phone'] = 1,--// [item spawn name] = item count + ['water_bottle'] = 2--// [item spawn name] = item count } }, { @@ -103,8 +103,8 @@ Config = { label = 'SandWich', requiredLabel = 'SandWich: 1x, Water: 2x', required = { - {item = 'tosti', count = 2}, - {item = 'water_bottle', count = 1} + ['tosti'] = 1,--// [item spawn name] = item count + ['water_bottle'] = 2--// [item spawn name] = item count } } } diff --git a/server/craft.lua b/server/craft.lua index 64ae89c..393772a 100644 --- a/server/craft.lua +++ b/server/craft.lua @@ -3,11 +3,8 @@ local QBCore = exports['qb-core']:GetCoreObject() QBCore.Functions.CreateCallback('ren-businesses:can:craft:item', function(source, cb, data) local pData = QBCore.Functions.GetPlayer(source) - for k,v in pairs(data.craft) do - local item = exports[Config.QBinventory]:HasItem(source, v.item, v.count) - if item then - cb(true) - end + if HasCraftItems(source, data.craft) then + cb(true) end cb(false) @@ -16,14 +13,29 @@ end) RegisterNetEvent('ren-business:craft:item', function(data) local pData = QBCore.Functions.GetPlayer(source) - for k,v in pairs(data.craft) do - local item = exports[Config.QBinventory]:HasItem(source, v.item, v.count) - if item then - pData.Functions.RemoveItem(v.item, v.count) + if HasCraftItems(source, data.craft) then + + for k,v in pairs(data.craft) do + pData.Functions.RemoveItem(k, v) pData.Functions.AddItem(data.item, 1) - - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[v.item], "remove", v.count) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[data.item], "add", 1) - end + + TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[k], "remove", v) + TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[data.item], "add", 1) + end + + end +end) + +HasCraftItems = function(src, items) + local pData = QBCore.Functions.GetPlayer(src) + + for k, v in pairs(items) do + local item = pData.Functions.GetItemByName(k) + + if not item then return false end + + if item.amount < v then return false end end -end) \ No newline at end of file + + return true +end \ No newline at end of file