From f5c030c19a27cde6ec9eb9d0c1efabd21585a906 Mon Sep 17 00:00:00 2001 From: coblyox <55489629+coblyox@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:47:14 +0200 Subject: [PATCH] feat(server/player): add hooks for add/remove/set money methods --- server/player.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/player.lua b/server/player.lua index 9e8e23dc6..867abd507 100644 --- a/server/player.lua +++ b/server/player.lua @@ -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' @@ -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 @@ -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 @@ -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