From ecef928fbfaa3f9cb8b1c5d1ced4923d908b563f Mon Sep 17 00:00:00 2001 From: Rencikas <85559163+Rencikas@users.noreply.github.com> Date: Wed, 4 Jan 2023 18:14:36 +0200 Subject: [PATCH] Fixed register bills not deleting, added ability to configure what items can be received when finished crafting, fixed AlowCuts config function --- client/craft.lua | 4 ++-- client/register.lua | 9 +++++---- config/config.lua | 24 +++++++++++++++--------- server/craft.lua | 16 +++++++++------- server/register.lua | 27 +++++++++++++++++++-------- 5 files changed, 50 insertions(+), 30 deletions(-) diff --git a/client/craft.lua b/client/craft.lua index 62c3f15..34b9757 100644 --- a/client/craft.lua +++ b/client/craft.lua @@ -15,8 +15,8 @@ RegisterNetEvent('ren-businesses:open:craft', function(data) params = { event = "ren-businesses:craft:item", args = { - craft = v.required, - item = v.item + required = v.required, + result = v.result } } } diff --git a/client/register.lua b/client/register.lua index f1967d4..62569d7 100644 --- a/client/register.lua +++ b/client/register.lua @@ -37,7 +37,7 @@ RegisterNetEvent("ren-businesses:create:bill", function(data) end) RegisterNetEvent('ren-businesses:pay:bill', function(data) - QBCore.Functions.TriggerCallback("ren-businesses:is:bill:created", function(result, bData) + QBCore.Functions.TriggerCallback("ren-businesses:get:bill:data", function(result) if not result then QBCore.Functions.Notify("There are no bills to pay", 'error', 6000) else @@ -49,7 +49,7 @@ RegisterNetEvent('ren-businesses:pay:bill', function(data) }, { header = "Pay with bank", - txt = "You need to pay "..bData.price.."$ for: "..bData.reason, + txt = "You need to pay "..result.price.."$ for: "..result.reason, params = { isServer = true, event = "ren-business:pay:bills", @@ -62,7 +62,7 @@ RegisterNetEvent('ren-businesses:pay:bill', function(data) }, { header = "Pay with cash", - txt = "You need to pay "..bData.price.."$ for: "..bData.reason, + txt = "You need to pay "..result.price.."$ for: "..result.reason, params = { isServer = true, event = "ren-business:pay:bills", @@ -86,10 +86,11 @@ RegisterNetEvent('ren-businesses:pay:bill', function(data) end) RegisterNetEvent('ren-businesses:delete:bill', function(data) - QBCore.Functions.TriggerCallback("ren-businesses:is:bill:created", function(result, data) + QBCore.Functions.TriggerCallback("ren-businesses:is:bill:created", function(result) if not result then QBCore.Functions.Notify('There are no bills to be deleted!', 'error', 6000) else + QBCore.Functions.Notify('Bill successfully deleted!', 'success', 6000) TriggerServerEvent("ren-business:clear:bill", data) end end, data) diff --git a/config/config.lua b/config/config.lua index bc4f947..866ceb6 100644 --- a/config/config.lua +++ b/config/config.lua @@ -1,6 +1,6 @@ Config = { AlowCuts = true,--// if this is true this means that all businesses have to take a cut from a employee sale - PayoutSplit = 40,--// the cut procentage what the business takes what the rest is left for the employee + PayoutSplit = 40,--// the cut procentage what the business takes and the rest is left for the employee Debug = false,--//if true it will enable polyzone debug businesses = { --//Default preset business @@ -89,23 +89,29 @@ Config = { maxZ = 22.56,--// box zone max height items = {--// all the items you can craft { - 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 ['phone'] = 1,--// [item spawn name] = item count ['water_bottle'] = 2--// [item spawn name] = item count + }, + result = {--//The items you get when you finish crafting + ['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 = { - ['tosti'] = 1,--// [item spawn name] = item count + label = 'tosti',--//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 + ['phone'] = 1,--// [item spawn name] = item count + ['water_bottle'] = 2--// [item spawn name] = item count + }, + result = {--//The items you get when you finish crafting + ['phone'] = 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 8a48f74..95e1ca7 100644 --- a/server/craft.lua +++ b/server/craft.lua @@ -3,7 +3,7 @@ local QBCore = exports['qb-core']:GetCoreObject() QBCore.Functions.CreateCallback('ren-businesses:can:craft:item', function(source, cb, data) local pData = QBCore.Functions.GetPlayer(source) - if HasCraftItems(source, data.craft) then + if HasCraftItems(source, data.required) then return cb(true) end @@ -13,16 +13,18 @@ end) RegisterNetEvent('ren-business:craft:item', function(data) local pData = QBCore.Functions.GetPlayer(source) - if HasCraftItems(source, data.craft) then - - for k,v in pairs(data.craft) do + if HasCraftItems(source, data.required) then + + for k,v in pairs(data.required) do pData.Functions.RemoveItem(k, v) TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[k], "remove", v) end - pData.Functions.AddItem(data.item, 1) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[data.item], "add", 1) - + for k,v in pairs(data.result) do + pData.Functions.AddItem(k, v) + TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[k], "add", v) + end + TriggerClientEvent('QBCore:Notify', source, 'Crafting process was successfull!', 'success') end end) diff --git a/server/register.lua b/server/register.lua index 8f83e36..e60851b 100644 --- a/server/register.lua +++ b/server/register.lua @@ -28,23 +28,33 @@ end) QBCore.Functions.CreateCallback('ren-businesses:is:bill:created', function(source, cb, data) local pData = QBCore.Functions.GetPlayer(source) - if Bills[data.business..data.register] then - return cb(true, Bills[data.business..data.register]) - end + if Bills[data.business..data.register] then return cb(true) end + + cb(false) +end) + +QBCore.Functions.CreateCallback('ren-businesses:get:bill:data', function(source, cb, data) + local pData = QBCore.Functions.GetPlayer(source) + + if Bills[data.business..data.register] then return cb(Bills[data.business..data.register]) end - cb(false, nil) + cb(false) end) RegisterNetEvent('ren-business:pay:bills', function(data) local bill = Bills[data.job..data.register] local pData = QBCore.Functions.GetPlayer(source) local dWorker = QBCore.Functions.GetPlayerByCitizenId(bill.biller) - local cut = CutPayOut(bill.price) + local cut = CutPayOut(bill.price) if pData.Functions.RemoveMoney(data.type, bill.price, bill.reason) then - dWorker.Functions.AddMoney("bank", bill.price - cut) - exports['qb-management']:AddMoney(data.job, cut) + if Config.AlowCuts then + exports['qb-management']:AddMoney(data.job, cut) + dWorker.Functions.AddMoney("bank", math.floor(bill.price - cut)) + else + dWorker.Functions.AddMoney("bank", bill.price) + end TriggerClientEvent('QBCore:Notify', source, "You have paid the bill!", "success", 6000) TriggerClientEvent('QBCore:Notify', dWorker.PlayerData.source, "Player has payed your bill", "success", 6000) @@ -57,6 +67,7 @@ end) RegisterNetEvent('ren-business:clear:bill', function(data) local pData = QBCore.Functions.GetPlayer(source) + print(json.encode(data)) if not pData.PlayerData.job.name == data.job then return end if Bills[data.job..data.register] then @@ -68,5 +79,5 @@ CutPayOut = function(price) value = tonumber(price) percent = tonumber(Config.PayoutSplit) if not value and not percent then return end - return value * (percent / 100) + return math.floor(value * (percent / 100)) end \ No newline at end of file