Skip to content

Commit

Permalink
refactor(server): extract money functions to config
Browse files Browse the repository at this point in the history
This allows for users to integrate with other resources without directly modifying code. This includes different banking resources and tax systems.
  • Loading branch information
solareon committed Sep 29, 2024
1 parent 53204a4 commit 69d7cd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 24 additions & 2 deletions config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ return {
preventSelling = false, -- prevents players from using /transfervehicle if financed
},
saleTimeout = 60000, -- Delay between attempts to sell/gift a vehicle. Prevents abuse
deleteUnpaidFinancedVehicle = false, -- true to delete unpaid vehicles from database, otherwise it will edit citizenid to hide from db select
deleteUnpaidFinancedVehicle = false,, -- true to delete unpaid vehicles from database, otherwise it will edit citizenid to hide from db select

---@param src number Player Server ID
---@param plate string Vehicle Plate
---@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 69d7cd7

Please sign in to comment.