mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 09:18:53 +00:00
refactor(es_extended/server/functions): implement requested changes
This commit is contained in:
@@ -65,6 +65,8 @@ return {
|
||||
["command_repair_success_target"] = "An admin repaired your vehicle",
|
||||
["command_clear"] = "Clear chat Text",
|
||||
["command_clearall"] = "Clear chat Text for all players",
|
||||
["command_refreshitems"] = "Reload all items from the database.",
|
||||
["command_refreshitems_success"] = "Successfully reloaded %d items.",
|
||||
["command_clearinventory"] = "Remove All items from the Players Inventory",
|
||||
["command_clearloadout"] = "Remove All weapons from the Players Loadout",
|
||||
["command_freeze"] = "Freeze a player",
|
||||
|
||||
@@ -637,7 +637,9 @@ if not Config.CustomInventory then
|
||||
end
|
||||
|
||||
local function refreshPlayerInventories()
|
||||
for i, xPlayer in ipairs(ESX.GetExtendedPlayers()) do
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for i = 1, #xPlayers do
|
||||
local xPlayer = xPlayers[i]
|
||||
local minimalInv = xPlayer.getInventory(true)
|
||||
|
||||
for itemName, itemCount in pairs(minimalInv) do
|
||||
@@ -648,8 +650,9 @@ if not Config.CustomInventory then
|
||||
end
|
||||
|
||||
xPlayer.inventory = {}
|
||||
local playerInvIndex = 1
|
||||
for itemName, itemData in pairs(ESX.Items) do
|
||||
xPlayer.inventory[#xPlayer.inventory+1] = {
|
||||
xPlayer.inventory[playerInvIndex] = {
|
||||
name = itemName,
|
||||
count = minimalInv[itemName] or 0,
|
||||
label = itemData.label,
|
||||
@@ -658,6 +661,7 @@ if not Config.CustomInventory then
|
||||
rare = itemData.rare,
|
||||
canRemove = itemData.canRemove,
|
||||
}
|
||||
playerInvIndex += 1
|
||||
end
|
||||
|
||||
TriggerClientEvent("esx:setInventory", xPlayer.source, xPlayer.inventory)
|
||||
@@ -668,16 +672,17 @@ if not Config.CustomInventory then
|
||||
ESX.Items = {}
|
||||
|
||||
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 }
|
||||
for i = 1, #items do
|
||||
local item = items[i]
|
||||
ESX.Items[item.name] = { label = item.label, weight = item.weight, rare = item.rare, canRemove = item.can_remove }
|
||||
end
|
||||
|
||||
refreshPlayerInventories()
|
||||
refreshPlayerInventories()
|
||||
end
|
||||
|
||||
---@param items { name: string, label: string, weight?: number, rare?: boolean, canRemove?: boolean }[]
|
||||
function ESX.AddItems(items)
|
||||
local toInsert = {}
|
||||
local toInsertIndex = 1
|
||||
|
||||
for _, item in ipairs(items) do
|
||||
local name = item.name
|
||||
@@ -691,6 +696,10 @@ if not Config.CustomInventory then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if ESX.Items[name] then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if type(label) ~= "string" then
|
||||
print(("^1[AddItems]^0 Invalid label for item '%s'"):format(name))
|
||||
goto continue
|
||||
@@ -711,29 +720,28 @@ if not Config.CustomInventory then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if not ESX.Items[name] then
|
||||
toInsert[#toInsert + 1] = {
|
||||
name,
|
||||
label,
|
||||
weight,
|
||||
rare,
|
||||
canRemove,
|
||||
}
|
||||
end
|
||||
toInsert[toInsertIndex] = {
|
||||
name = name,
|
||||
label = label,
|
||||
weight = weight,
|
||||
rare = rare,
|
||||
canRemove = canRemove,
|
||||
}
|
||||
toInsertIndex += 1
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
if #toInsert > 0 then
|
||||
MySQL.prepare("INSERT IGNORE INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES (?, ?, ?, ?, ?)", toInsert)
|
||||
MySQL.prepare.await("INSERT IGNORE INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES (?, ?, ?, ?, ?)", toInsert)
|
||||
|
||||
for _, row in ipairs(toInsert) do
|
||||
local name, label, weight, rare, canRemove = table.unpack(row)
|
||||
ESX.Items[name] = {
|
||||
label = label,
|
||||
weight = weight,
|
||||
rare = rare,
|
||||
canRemove = canRemove,
|
||||
for i = 1, #toInsert do
|
||||
local row = toInsert[i]
|
||||
ESX.Items[row.name] = {
|
||||
label = row.label,
|
||||
weight = row.weight,
|
||||
rare = row.rare,
|
||||
canRemove = row.canRemove,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -439,9 +439,11 @@ ESX.RegisterCommand("refreshjobs", "admin", function()
|
||||
end, true, { help = TranslateCap("command_clearall") })
|
||||
|
||||
if not Config.CustomInventory then
|
||||
ESX.RegisterCommand("refreshitems", "admin", function()
|
||||
ESX.RegisterCommand("refreshitems", "admin", function(xPlayer)
|
||||
ESX.RefreshItems()
|
||||
end, true, { help = TranslateCap("command_clearall") })
|
||||
|
||||
xPlayer.showNotification(TranslateCap("command_refreshitems_success", #ESX.Items), true, false, 140)
|
||||
end, true, { help = TranslateCap("command_refreshitems") })
|
||||
|
||||
ESX.RegisterCommand(
|
||||
"clearinventory",
|
||||
|
||||
Reference in New Issue
Block a user