Skip to content

Commit

Permalink
fix(server/money): setMoney
Browse files Browse the repository at this point in the history
  • Loading branch information
Frowmza authored Dec 26, 2024
1 parent f95bc2d commit 691849d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1189,14 +1189,17 @@ exports('SetCharInfo', SetCharInfo)
---@param moneyType MoneyType
---@param amount number
---@param actionType 'add' | 'remove' | 'set'
---@param direction boolean
---@param difference number
---@param reason? string
local function emitMoneyEvents(source, playerMoney, moneyType, amount, actionType, direction, reason)
TriggerClientEvent('hud:client:OnMoneyChange', source, moneyType, amount, direction)
local function emitMoneyEvents(source, playerMoney, moneyType, amount, actionType, difference, reason)
local isSet = actionType == 'set'
local isRemove = actionType == 'remove'

TriggerClientEvent('hud:client:OnMoneyChange', source, moneyType, isSet and difference or amount, isSet and difference < 0 or isRemove and true or false, reason)
TriggerClientEvent('QBCore:Client:OnMoneyChange', source, moneyType, amount, actionType, reason)
TriggerEvent('QBCore:Server:OnMoneyChange', source, moneyType, amount, actionType, reason)

if moneyType == 'bank' and actionType == 'remove' then
if moneyType == 'bank' and isRemove then
TriggerClientEvent('qb-phone:client:RemoveBankMoney', source, amount)
end

Expand Down Expand Up @@ -1321,22 +1324,22 @@ function SetMoney(identifier, moneyType, amount, reason)

reason = reason or 'unknown'
amount = qbx.math.round(tonumber(amount) --[[@as number]])
local oldAmount = player.PlayerData.money[moneyType]

if amount < 0 or not player.PlayerData.money[moneyType] then return false end
if amount < 0 or not oldAmount then return false end

if not triggerEventHooks('setMoney', {
source = player.PlayerData.source,
moneyType = moneyType,
amount = amount
}) then return false end

local difference = amount - player.PlayerData.money[moneyType]

player.PlayerData.money[moneyType] = amount

if not player.Offline then
UpdatePlayerData(identifier)

local difference = amount - oldAmount
local dirChange = difference < 0 and 'removed' or 'added'
local absDifference = math.abs(difference)
local tags = absDifference > 50000 and config.logging.role or {}
Expand All @@ -1349,10 +1352,9 @@ function SetMoney(identifier, moneyType, amount, reason)
color = difference < 0 and 'red' or 'green',
tags = tags,
message = ('**%s (citizenid: %s | id: %s)** $%s (%s) %s, new %s balance: $%s reason: %s'):format(GetPlayerName(player.PlayerData.source), player.PlayerData.citizenid, player.PlayerData.source, absDifference, moneyType, dirChange, moneyType, player.PlayerData.money[moneyType], reason),
--oxLibTags = ('script:%s,playerName:%s,citizenId:%s,playerSource:%s,amount:%s,moneyType:%s,newBalance:%s,reason:%s,direction:%s'):format(resource, GetPlayerName(player.PlayerData.source), player.PlayerData.citizenid, player.PlayerData.source, absDifference, moneyType, player.PlayerData.money[moneyType], reason, dirChange)
})

emitMoneyEvents(player.PlayerData.source, player.PlayerData.money, moneyType, absDifference, 'set', difference < 0, reason)
emitMoneyEvents(player.PlayerData.source, player.PlayerData.money, moneyType, amount, 'set', absDifference, reason)
end

return true
Expand Down

0 comments on commit 691849d

Please sign in to comment.