Skip to content

Commit

Permalink
feat(server/player): add hooks for add/remove/set money methods
Browse files Browse the repository at this point in the history
  • Loading branch information
coblyox authored Dec 1, 2024
1 parent e4b36f4 commit f5c030c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local config = require 'config.server'
local defaultSpawn = require 'config.shared'.defaultSpawn
local logger = require 'modules.logger'
local storage = require 'server.storage.main'
local triggerEventHooks = require 'modules.hooks'
local maxJobsPerPlayer = GetConvarInt('qbx:max_jobs_per_player', 1)
local maxGangsPerPlayer = GetConvarInt('qbx:max_gangs_per_player', 1)
local setJobReplaces = GetConvar('qbx:setjob_replaces', 'true') == 'true'
Expand Down Expand Up @@ -1208,6 +1209,12 @@ function AddMoney(identifier, moneyType, amount, reason)

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

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

player.PlayerData.money[moneyType] += amount

if not player.Offline then
Expand Down Expand Up @@ -1249,6 +1256,12 @@ function RemoveMoney(identifier, moneyType, amount, reason)

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

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

for _, mType in pairs(config.money.dontAllowMinus) do
if mType == moneyType then
if (player.PlayerData.money[moneyType] - amount) < 0 then
Expand Down Expand Up @@ -1298,6 +1311,12 @@ function SetMoney(identifier, moneyType, amount, reason)

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

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

player.PlayerData.money[moneyType] = amount

if not player.Offline then
Expand Down

0 comments on commit f5c030c

Please sign in to comment.