Skip to content

Commit

Permalink
refactor(server): extract money functions to config (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon authored Sep 29, 2024
1 parent 53204a4 commit 4a4cb14
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
24 changes: 23 additions & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,27 @@ return {
---@param vehicle number Vehicle Entity ID
giveKeys = function(src, plate, vehicle)
exports.qbx_vehiclekeys:GiveKeys(src, vehicle)
end
end,

---@param society string Society name
---@param amount number Amount to add
---@return boolean
addSocietyFunds = function(society, amount) -- function to add funds to society
return exports['Renewed-Banking']:addAccountMoney(society, amount)
end,

---@param player any QBX Player object
---@param amount number Amount to add
---@param reason string? Reason for adding funds
---@return boolean
addPlayerFunds = function(player, account, amount, reason)
return player.Functions.AddMoney(account, amount, reason)
end,

---@param player any QBX Player object
---@param amount number Amount to remove
---@param reason string? Reason for removing funds
removePlayerFunds = function(player, account, amount, reason)
return player.Functions.RemoveMoney(account, amount, reason)
end,
}
10 changes: 5 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ local function removeMoney(src, amount, reason)
return false
end

return player.Functions.RemoveMoney(currencyType, amount, reason)
return config.removePlayerFunds(player, currencyType, amount, reason)
end

---@param paymentAmount number
Expand Down Expand Up @@ -489,10 +489,10 @@ local function sellShowroomVehicleTransact(src, target, price, downPayment)
end

local commission = lib.math.round(price * config.commissionRate)
player.Functions.AddMoney('bank', commission)
config.addPlayerFunds(player, 'bank', commission, 'vehicle-commission')
exports.qbx_core:Notify(src, locale('success.earned_commission', lib.math.groupdigits(commission)), 'success')

exports['Renewed-Banking']:addAccountMoney(player.PlayerData.job.name, price)
config.addSocietyFunds(player.player.PlayerData.job.name, price)
exports.qbx_core:Notify(target.PlayerData.source, locale('success.purchased'), 'success')

return true
Expand Down Expand Up @@ -702,8 +702,8 @@ lib.addCommand('transfervehicle', {
return exports.qbx_core:Notify(source, locale('error.buyertoopoor'), 'error')
end

player.Functions.AddMoney(currencyType, sellAmount)
target.Functions.RemoveMoney(currencyType, sellAmount)
config.addPlayerFunds(player, currencyType, sellAmount, 'vehicle-sold-to-player')
config.removePlayerFunds(target, currencyType, sellAmount, 'vehicle-bought-from-player')
end

qbx_vehicles:SetPlayerVehicleOwner(row.id, targetcid)
Expand Down

0 comments on commit 4a4cb14

Please sign in to comment.