Skip to content

Commit

Permalink
removed inventory dependency, fixed craft item count bug, improved co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
Rencikas committed Nov 1, 2022
1 parent 9353559 commit 9183b78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
12 changes: 6 additions & 6 deletions config/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ 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
}
},
{
item = 'tosti',
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
}
}
}
Expand Down
40 changes: 26 additions & 14 deletions server/craft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

return true
end

0 comments on commit 9183b78

Please sign in to comment.