From 3dae29d7dc49f14c29248949152dc47d641ac8aa Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:44:09 -0500 Subject: [PATCH 01/11] Fix ox crash --- [core]/es_extended/server/modules/commands.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 628e85ea8..a040f44d1 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -204,9 +204,13 @@ ESX.RegisterCommand( "setaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.setAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Set Account Money /setaccountmoney Triggered!", "pink", { @@ -234,9 +238,13 @@ ESX.RegisterCommand( "giveaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Account Money /giveaccountmoney Triggered!", "pink", { From d9fe2d8051c82c4769b7b66502f969afd8be9d4a Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:45:27 -0500 Subject: [PATCH 02/11] Fix oc crash and the impossibility to give anymore money --- [core]/es_extended/server/modules/commands.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index a040f44d1..44cd4699d 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -272,9 +272,13 @@ ESX.RegisterCommand( "removeaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_removeaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.removeAccountMoney(args.account, args.amount, "Government Tax") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Remove Account Money /removeaccountmoney Triggered!", "pink", { From 5e91bad5c4b61b37675c4752f39fa8da1e7c3b52 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:47:32 -0500 Subject: [PATCH 03/11] feat(commands): add maximum amount validation for giveitem, giveweapon, and giveammo commands --- [core]/es_extended/server/modules/commands.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 44cd4699d..98c9fff67 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -307,6 +307,10 @@ if not Config.CustomInventory then "giveitem", "admin", function(xPlayer, args) + local MAX_AMOUNT = 1.79769e+308 + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addInventoryItem(args.item, args.count) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Item /giveitem Triggered!", "pink", { @@ -334,9 +338,13 @@ if not Config.CustomInventory then "giveweapon", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveweapon_hasalready")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addWeapon(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Weapon /giveweapon Triggered!", "pink", { @@ -364,9 +372,13 @@ if not Config.CustomInventory then "giveammo", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveammo_noweapon_found")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addWeaponAmmo(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Ammunition /giveammo Triggered!", "pink", { From 221e23b2b7289701f10ff85f297447728c4ce4d5 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:44:09 -0500 Subject: [PATCH 04/11] feat(commands): prevent Ox from breaking due to money overflow --- [core]/es_extended/server/modules/commands.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 628e85ea8..a040f44d1 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -204,9 +204,13 @@ ESX.RegisterCommand( "setaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.setAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Set Account Money /setaccountmoney Triggered!", "pink", { @@ -234,9 +238,13 @@ ESX.RegisterCommand( "giveaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Account Money /giveaccountmoney Triggered!", "pink", { From 91e783c9e96eca907151858e805b4b5337b81b82 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:45:27 -0500 Subject: [PATCH 05/11] feat(commands): prevent money overflow from blocking further transactions --- [core]/es_extended/server/modules/commands.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index a040f44d1..44cd4699d 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -272,9 +272,13 @@ ESX.RegisterCommand( "removeaccountmoney", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_removeaccountmoney_invalid")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.removeAccountMoney(args.account, args.amount, "Government Tax") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Remove Account Money /removeaccountmoney Triggered!", "pink", { From a0389d7e511caf3e5c861685f743639968a3b3d3 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 15:47:32 -0500 Subject: [PATCH 06/11] feat(commands): add max amount validation for giveitem, giveweapon, and giveammo --- [core]/es_extended/server/modules/commands.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 44cd4699d..98c9fff67 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -307,6 +307,10 @@ if not Config.CustomInventory then "giveitem", "admin", function(xPlayer, args) + local MAX_AMOUNT = 1.79769e+308 + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addInventoryItem(args.item, args.count) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Item /giveitem Triggered!", "pink", { @@ -334,9 +338,13 @@ if not Config.CustomInventory then "giveweapon", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveweapon_hasalready")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addWeapon(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Weapon /giveweapon Triggered!", "pink", { @@ -364,9 +372,13 @@ if not Config.CustomInventory then "giveammo", "admin", function(xPlayer, args, showError) + local MAX_AMOUNT = 1.79769e+308 if not args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveammo_noweapon_found")) end + if args.amount > MAX_AMOUNT then + return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + end args.playerId.addWeaponAmmo(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Ammunition /giveammo Triggered!", "pink", { From b60eb3b43cac288f1a0894c05609bc8c181d5fdb Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 17:05:23 -0500 Subject: [PATCH 07/11] feat(commands): rename amount to count for giveitem and update ammo validation for giveweapon and giveammo --- [core]/es_extended/server/modules/commands.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 98c9fff67..5216b2f33 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -307,9 +307,9 @@ if not Config.CustomInventory then "giveitem", "admin", function(xPlayer, args) - local MAX_AMOUNT = 1.79769e+308 - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + local MAX_COUNT = 1.79769e+308 + if args.count > MAX_COUNT then + return showError(("Count must be between 1 and %s"):format(MAX_COUNT)) end args.playerId.addInventoryItem(args.item, args.count) if Config.AdminLogging then @@ -338,12 +338,12 @@ if not Config.CustomInventory then "giveweapon", "admin", function(xPlayer, args, showError) - local MAX_AMOUNT = 1.79769e+308 + local MAX_AMMO = 1.79769e+308 if args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveweapon_hasalready")) end - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + if args.ammo > MAX_AMMO then + return showError(("Ammo must be between 1 and %s"):format(MAX_AMMO)) end args.playerId.addWeapon(args.weapon, args.ammo) if Config.AdminLogging then @@ -372,12 +372,12 @@ if not Config.CustomInventory then "giveammo", "admin", function(xPlayer, args, showError) - local MAX_AMOUNT = 1.79769e+308 + local MAX_AMMO = 1.79769e+308 if not args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveammo_noweapon_found")) end - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) + if args.ammo > MAX_AMMO then + return showError(("Ammo must be between 1 and %s"):format(MAX_AMMO)) end args.playerId.addWeaponAmmo(args.weapon, args.ammo) if Config.AdminLogging then From f2cde312514d47ab3891a2473c8b46657b47023b Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 21:55:24 -0500 Subject: [PATCH 08/11] feat(commands): remove maximum amount validation for account money and item commands --- .../es_extended/server/modules/commands.lua | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/[core]/es_extended/server/modules/commands.lua b/[core]/es_extended/server/modules/commands.lua index 5216b2f33..628e85ea8 100644 --- a/[core]/es_extended/server/modules/commands.lua +++ b/[core]/es_extended/server/modules/commands.lua @@ -204,13 +204,9 @@ ESX.RegisterCommand( "setaccountmoney", "admin", function(xPlayer, args, showError) - local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) - end args.playerId.setAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Set Account Money /setaccountmoney Triggered!", "pink", { @@ -238,13 +234,9 @@ ESX.RegisterCommand( "giveaccountmoney", "admin", function(xPlayer, args, showError) - local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_giveaccountmoney_invalid")) end - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) - end args.playerId.addAccountMoney(args.account, args.amount, "Government Grant") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Account Money /giveaccountmoney Triggered!", "pink", { @@ -272,13 +264,9 @@ ESX.RegisterCommand( "removeaccountmoney", "admin", function(xPlayer, args, showError) - local MAX_AMOUNT = 1.79769e+308 if not args.playerId.getAccount(args.account) then return showError(TranslateCap("command_removeaccountmoney_invalid")) end - if args.amount > MAX_AMOUNT then - return showError(("Amount must be between 1 and %s"):format(MAX_AMOUNT)) - end args.playerId.removeAccountMoney(args.account, args.amount, "Government Tax") if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Remove Account Money /removeaccountmoney Triggered!", "pink", { @@ -307,10 +295,6 @@ if not Config.CustomInventory then "giveitem", "admin", function(xPlayer, args) - local MAX_COUNT = 1.79769e+308 - if args.count > MAX_COUNT then - return showError(("Count must be between 1 and %s"):format(MAX_COUNT)) - end args.playerId.addInventoryItem(args.item, args.count) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Item /giveitem Triggered!", "pink", { @@ -338,13 +322,9 @@ if not Config.CustomInventory then "giveweapon", "admin", function(xPlayer, args, showError) - local MAX_AMMO = 1.79769e+308 if args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveweapon_hasalready")) end - if args.ammo > MAX_AMMO then - return showError(("Ammo must be between 1 and %s"):format(MAX_AMMO)) - end args.playerId.addWeapon(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Weapon /giveweapon Triggered!", "pink", { @@ -372,13 +352,9 @@ if not Config.CustomInventory then "giveammo", "admin", function(xPlayer, args, showError) - local MAX_AMMO = 1.79769e+308 if not args.playerId.hasWeapon(args.weapon) then return showError(TranslateCap("command_giveammo_noweapon_found")) end - if args.ammo > MAX_AMMO then - return showError(("Ammo must be between 1 and %s"):format(MAX_AMMO)) - end args.playerId.addWeaponAmmo(args.weapon, args.ammo) if Config.AdminLogging then ESX.DiscordLogFields("UserActions", "Give Ammunition /giveammo Triggered!", "pink", { From 7877d9e40a5a9f72d7f898a5a4ab9f751e723256 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 21:58:23 -0500 Subject: [PATCH 09/11] feat(inventory): implement maximum amount cap for account money transactions --- [core]/es_extended/server/classes/overrides/oxinventory.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[core]/es_extended/server/classes/overrides/oxinventory.lua b/[core]/es_extended/server/classes/overrides/oxinventory.lua index c3be26a81..64bdd5501 100644 --- a/[core]/es_extended/server/classes/overrides/oxinventory.lua +++ b/[core]/es_extended/server/classes/overrides/oxinventory.lua @@ -1,4 +1,5 @@ local Inventory +local MAX_AMOUNT = 1.79769e+308 if Config.CustomInventory ~= "ox" then return end @@ -45,6 +46,7 @@ Core.PlayerFunctionOverrides.OxInventory = { setAccountMoney = function(self) return function(accountName, money, reason) reason = reason or "unknown" + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money < 0 then return end local account = self.getAccount(accountName) @@ -64,6 +66,7 @@ Core.PlayerFunctionOverrides.OxInventory = { addAccountMoney = function(self) return function(accountName, money, reason) reason = reason or "unknown" + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money < 1 then return end local account = self.getAccount(accountName) @@ -82,6 +85,7 @@ Core.PlayerFunctionOverrides.OxInventory = { removeAccountMoney = function(self) return function(accountName, money, reason) reason = reason or "unknown" + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money < 1 then return end local account = self.getAccount(accountName) From 90ba45075ef1e0e36e6367716fbb4b50d7a173e6 Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 22:01:15 -0500 Subject: [PATCH 10/11] feat(player): enforce maximum amount limit for account money transactions --- [core]/es_extended/server/classes/player.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index b4682df7b..a454cbfc7 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -31,6 +31,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, metadata) ---@class xPlayer local self = {} + local MAX_AMOUNT = 1.79769e+308 self.accounts = accounts self.coords = coords @@ -313,6 +314,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, error(("Tried To Set Account ^5%s^1 For Player ^5%s^1 To An Invalid Number -> ^5%s^1"):format(accountName, self.playerId, money)) return end + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money >= 0 then local account = self.getAccount(accountName) @@ -340,6 +342,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, error(("Tried To Set Account ^5%s^1 For Player ^5%s^1 To An Invalid Number -> ^5%s^1"):format(accountName, self.playerId, money)) return end + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money > 0 then local account = self.getAccount(accountName) if account then @@ -366,6 +369,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, error(("Tried To Set Account ^5%s^1 For Player ^5%s^1 To An Invalid Number -> ^5%s^1"):format(accountName, self.playerId, money)) return end + money = money <= MAX_AMOUNT and money or MAX_AMOUNT if money > 0 then local account = self.getAccount(accountName) From 6693a7f5034d4e86e60fb23a6d1386003767b74d Mon Sep 17 00:00:00 2001 From: YOMAN1792 Date: Tue, 25 Feb 2025 22:59:31 -0500 Subject: [PATCH 11/11] feat(player): update inventory item addition to enforce maximum count limit --- [core]/es_extended/server/classes/player.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index a454cbfc7..49e5cfa45 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -407,15 +407,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, ---@return nil function self.addInventoryItem(itemName, count) local item = self.getInventoryItem(itemName) + if not item then return end - if item then - count = ESX.Math.Round(count) - item.count = item.count + count - self.weight = self.weight + (item.weight * count) + count += item.count + item.count = (count <= MAX_AMOUNT and count) or MAX_AMOUNT + self.weight += (item.weight * count) - TriggerEvent("esx:onAddInventoryItem", self.source, item.name, item.count) - self.triggerEvent("esx:addInventoryItem", item.name, item.count) - end + TriggerEvent("esx:onAddInventoryItem", self.source, item.name, item.count) + self.triggerEvent("esx:addInventoryItem", item.name, item.count) end ---@param itemName string