mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
refactor!(es_extended): move Items into core
This commit is contained in:
@@ -3,12 +3,12 @@ if Config.CustomInventory ~= "ox" then return end
|
||||
MySQL.ready(function()
|
||||
TriggerEvent("__cfx_export_ox_inventory_Items", function(ref)
|
||||
if ref then
|
||||
ESX.Items = ref()
|
||||
Core.Items = ref()
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler("ox_inventory:itemList", function(items)
|
||||
ESX.Items = items
|
||||
Core.Items = items
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
@@ -464,8 +464,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
---@param count number
|
||||
---@return boolean
|
||||
function self.canCarryItem(itemName, count)
|
||||
if ESX.Items[itemName] then
|
||||
local currentWeight, itemWeight = self.weight, ESX.Items[itemName].weight
|
||||
if Core.Items[itemName] then
|
||||
local currentWeight, itemWeight = self.weight, Core.Items[itemName].weight
|
||||
local newWeight = currentWeight + (itemWeight * count)
|
||||
|
||||
return newWeight <= self.maxWeight
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
ESX.Players = {}
|
||||
ESX.Items = {}
|
||||
Core = {}
|
||||
Core.Items = {}
|
||||
Core.Jobs = {}
|
||||
Core.JobsPlayerCount = {}
|
||||
Core.UsableItemsCallbacks = {}
|
||||
@@ -37,7 +37,7 @@ MySQL.ready(function()
|
||||
if not Config.CustomInventory then
|
||||
local items = MySQL.query.await("SELECT * FROM items")
|
||||
for _, v in ipairs(items) do
|
||||
ESX.Items[v.name] = { label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove }
|
||||
Core.Items[v.name] = { label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
||||
error = TranslateCap("commanderror_argumentmismatch_string", k)
|
||||
end
|
||||
elseif v.type == "item" then
|
||||
if ESX.Items[args[k]] then
|
||||
if Core.Items[args[k]] then
|
||||
newArgs[v.name] = args[k]
|
||||
else
|
||||
error = TranslateCap("commanderror_invaliditem")
|
||||
@@ -513,7 +513,7 @@ end
|
||||
---@param ... any
|
||||
---@return nil
|
||||
function ESX.UseItem(source, item, ...)
|
||||
if ESX.Items[item] then
|
||||
if Core.Items[item] then
|
||||
local itemCallback = Core.UsableItemsCallbacks[item]
|
||||
|
||||
if itemCallback then
|
||||
@@ -549,8 +549,8 @@ end
|
||||
---@return string?
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function ESX.GetItemLabel(item)
|
||||
if ESX.Items[item] then
|
||||
return ESX.Items[item].label
|
||||
if Core.Items[item] then
|
||||
return Core.Items[item].label
|
||||
else
|
||||
print(("[^3WARNING^7] Attemting to get invalid Item -> ^5%s^7"):format(item))
|
||||
end
|
||||
|
||||
@@ -191,7 +191,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
if not Config.CustomInventory then
|
||||
local inventory = (result.inventory and result.inventory ~= "") and json.decode(result.inventory) or {}
|
||||
|
||||
for name, item in pairs(ESX.Items) do
|
||||
for name, item in pairs(Core.Items) do
|
||||
local count = inventory[name] or 0
|
||||
userData.weight += (count * item.weight)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user