diff --git a/server/main.lua b/server/main.lua index 7db15f56..c3e6ffb7 100644 --- a/server/main.lua +++ b/server/main.lua @@ -69,6 +69,8 @@ AddEventHandler('es:playerLoaded', function(source, _player) }, function(inventory) + local tasks2 = {} + for i=1, #inventory, 1 do table.insert(userData.inventory, { name = inventory[i].item, @@ -104,19 +106,34 @@ AddEventHandler('es:playerLoaded', function(source, _player) canRemove = ESX.Items[k].canRemove, }) - MySQL.Async.execute( - 'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)', - { - ['@identifier'] = player.getIdentifier(), - ['@item'] = k, - ['@count'] = 0 - } - ) + local scope = function(item, identifier) + + table.insert(tasks2, function(cb2) + + MySQL.Async.execute( + 'INSERT INTO user_inventory (identifier, item, count) VALUES (@identifier, @item, @count)', + { + ['@identifier'] = identifier, + ['@item'] = item, + ['@count'] = 0 + }, + function(rowsChanged) + cb2() + end + ) + + end) + + end + + scope(k, player.getIdentifier()) end end + Async.parallelLimit(tasks2, 5, function(results) end) + table.sort(userData.inventory, function(a,b) return a.label < b.label end)