Skip to content

Commit

Permalink
Split rewards into item and money & fix incorrect reward amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Giana committed Feb 17, 2023
1 parent 2449d78 commit e37fc15
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,21 @@ RegisterNetEvent('g-drugselling:server:sell', function(sellLocation)
local bundlesToSell = math.floor(hasItem.amount / v.sell_quantity)
local quantityToSell = bundlesToSell * v.sell_quantity
if player.Functions.RemoveItem(k, quantityToSell) then
for k2, v2 in pairs(v.rewards) do
local isMoneyType = false
for k3, v3 in pairs(QBConfig.Money.MoneyTypes) do
if tostring(k3) == k2 then
isMoneyType = true
end
for k2, v2 in pairs(v.money_rewards) do
local amountOwed = v2 * bundlesToSell
if not player.Functions.AddMoney(k2, amountOwed) then
player.Functions.AddItem(k, quantityToSell)
return
end
if isMoneyType then
if not player.Functions.AddMoney(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
else
if not player.Functions.AddItem(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
if sellLocation.itemNotificationsEnabled then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[k2], 'add', v2)
end
end
for k2, v2 in pairs(v.item_rewards) do
local amountOwed = v2 * bundlesToSell
if not player.Functions.AddItem(k2, amountOwed) then
player.Functions.AddItem(k, quantityToSell)
return
end
if sellLocation.itemNotificationsEnabled then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[k2], 'add', amountOwed)
end
end
local notifyPoliceRoll = math.random(1, 100)
Expand Down

0 comments on commit e37fc15

Please sign in to comment.