Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended/server/modules/commands.lua): Add Validation Number #1617

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions [core]/es_extended/server/classes/overrides/oxinventory.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Inventory
local MAX_AMOUNT = 1.79769e+308

if Config.CustomInventory ~= "ox" then return end

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -403,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best if we dont return


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ESX.Math.Round here

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
Expand Down
Loading