From 2851032034f93eb48863b909f2bfdb9c7b3fa76f Mon Sep 17 00:00:00 2001 From: Mycroft Date: Fri, 9 Sep 2022 22:14:08 +0100 Subject: [PATCH] feat(es_extended): New Server Events for account syncing --- .../server/classes/overrides/oxinventory.lua | 15 +++++++++------ [esx]/es_extended/server/classes/player.lua | 12 +++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/[esx]/es_extended/server/classes/overrides/oxinventory.lua b/[esx]/es_extended/server/classes/overrides/oxinventory.lua index ae8a5029..d983b714 100644 --- a/[esx]/es_extended/server/classes/overrides/oxinventory.lua +++ b/[esx]/es_extended/server/classes/overrides/oxinventory.lua @@ -43,7 +43,8 @@ Core.PlayerFunctionOverrides.OxInventory = { end, setAccountMoney = function(self) - return function(accountName,money) + return function(accountName,money, reason) + reason = reason or 'unknown' if money >= 0 then local account = self.getAccount(accountName) @@ -52,7 +53,7 @@ Core.PlayerFunctionOverrides.OxInventory = { self.accounts[account.index].money = money self.triggerEvent('esx:setAccountMoney', account) - + TriggerEvent('esx:setAccountMoney', self.source, accountName, money, reason) if Inventory.accounts[accountName] then Inventory.SetItem(self.source, accountName, money) end @@ -62,7 +63,8 @@ Core.PlayerFunctionOverrides.OxInventory = { end, addAccountMoney = function(self) - return function(accountName,money) + return function(accountName,money, reason) + reason = reason or 'unknown' if money > 0 then local account = self.getAccount(accountName) @@ -70,7 +72,7 @@ Core.PlayerFunctionOverrides.OxInventory = { money = account.round and ESX.Math.Round(money) or money self.accounts[account.index].money += money self.triggerEvent('esx:setAccountMoney', account) - + TriggerEvent('esx:addAccountMoney', self.source, accountName, money, reason) if Inventory.accounts[accountName] then Inventory.AddItem(self.source, accountName, money) end @@ -80,7 +82,8 @@ Core.PlayerFunctionOverrides.OxInventory = { end, removeAccountMoney = function(self) - return function(accountName,money) + return function(accountName,money, reason) + reason = reason or 'unknown' if money > 0 then local account = self.getAccount(accountName) @@ -88,7 +91,7 @@ Core.PlayerFunctionOverrides.OxInventory = { money = account.round and ESX.Math.Round(money) or money self.accounts[account.index].money -= money self.triggerEvent('esx:setAccountMoney', account) - + TriggerEvent('esx:removeAccountMoney', self.source, accountName, money, reason) if Inventory.accounts[accountName] then Inventory.RemoveItem(self.source, accountName, money) end diff --git a/[esx]/es_extended/server/classes/player.lua b/[esx]/es_extended/server/classes/player.lua index 071cce15..6361537f 100644 --- a/[esx]/es_extended/server/classes/player.lua +++ b/[esx]/es_extended/server/classes/player.lua @@ -171,7 +171,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.name = newName end - function self.setAccountMoney(accountName, money) + function self.setAccountMoney(accountName, money, reason) + reason = reason or 'unknown' if not tonumber(money) then print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId)) return @@ -184,6 +185,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.accounts[account.index].money = money self.triggerEvent('esx:setAccountMoney', account) + TriggerEvent('esx:setAccountMoney', self.source, accountName, money, reason) else print(('[^1ERROR^7] Tried To Set Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId)) end @@ -192,7 +194,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, end end - function self.addAccountMoney(accountName, money) + function self.addAccountMoney(accountName, money, reason) + reason = reason or 'Unknown' if not tonumber(money) then print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId)) return @@ -204,6 +207,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.accounts[account.index].money += money self.triggerEvent('esx:setAccountMoney', account) + TriggerEvent('esx:addAccountMoney', self.source, accountName, money, reason) else print(('[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId)) end @@ -212,7 +216,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, end end - function self.removeAccountMoney(accountName, money) + function self.removeAccountMoney(accountName, money, reason) + reason = reason or 'Unknown' if not tonumber(money) then print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId)) return @@ -225,6 +230,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.accounts[account.index].money -= money self.triggerEvent('esx:setAccountMoney', account) + TriggerEvent('esx:removeAccountMoney', self.source, accountName, money, reason) else print(('[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId)) end