mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Optimize shop object loading
This commit is contained in:
+8
-20
@@ -5,35 +5,23 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
-- Load items
|
||||
MySQL.ready(function()
|
||||
local itemResult = MySQL.Sync.fetchAll('SELECT * FROM items')
|
||||
local shopResult = MySQL.Sync.fetchAll('SELECT * FROM shops')
|
||||
|
||||
local itemInformation = {}
|
||||
for i=1, #itemResult, 1 do
|
||||
|
||||
if itemInformation[itemResult[i].name] == nil then
|
||||
itemInformation[itemResult[i].name] = {}
|
||||
end
|
||||
|
||||
itemInformation[itemResult[i].name].label = itemResult[i].label
|
||||
itemInformation[itemResult[i].name].limit = itemResult[i].limit
|
||||
end
|
||||
local shopResult = MySQL.Sync.fetchAll('SELECT * FROM shops LEFT JOIN items ON items.name = shops.item')
|
||||
|
||||
for i=1, #shopResult, 1 do
|
||||
if itemInformation[shopResult[i].item] then
|
||||
if ShopItems[shopResult[i].store] == nil then
|
||||
if shopResult[i].name ~= NULL then
|
||||
if ShopItems[shopResult[i].name] == nil then
|
||||
ShopItems[shopResult[i].store] = {}
|
||||
end
|
||||
|
||||
if itemInformation[shopResult[i].item].limit == -1 then
|
||||
itemInformation[shopResult[i].item].limit = 30
|
||||
if shopResult[i].limit == -1 then
|
||||
shopResult[i].limit = 30
|
||||
end
|
||||
|
||||
table.insert(ShopItems[shopResult[i].store], {
|
||||
label = itemInformation[shopResult[i].item].label,
|
||||
label = shopResult[i].label,
|
||||
item = shopResult[i].item,
|
||||
price = shopResult[i].price,
|
||||
limit = itemInformation[shopResult[i].item].limit
|
||||
limit = shopResult[i].limit
|
||||
})
|
||||
else
|
||||
print(('esx_shops: invalid item "%s" found!'):format(shopResult[i].item))
|
||||
@@ -87,4 +75,4 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
|
||||
local missingMoney = price - xPlayer.getMoney()
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough', ESX.Math.GroupDigits(missingMoney)))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user