Skip to content

Commit

Permalink
Fixed register bills not deleting, added ability to configure what it…
Browse files Browse the repository at this point in the history
…ems can be received when finished crafting, fixed AlowCuts config function
  • Loading branch information
Rencikas committed Jan 4, 2023
1 parent 0111d67 commit ecef928
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 30 deletions.
4 changes: 2 additions & 2 deletions client/craft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions client/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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)
Expand Down
24 changes: 15 additions & 9 deletions config/config.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
},
}
}
},
Expand Down
16 changes: 9 additions & 7 deletions server/craft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
27 changes: 19 additions & 8 deletions server/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

0 comments on commit ecef928

Please sign in to comment.