About "disc-inventoryhud" that kill server issue and how to fix it

hello guys, here the tips to fix “disc-inventoryhud” : saveInventories this function that kill your server,
and you will need this async resoruce

1 step : find the code line or function
disc-inventoryhud/server/inventory.lua

function saveInventories()
 for type, inventories in pairs(loadedInventories) do
     for identifier, inventory in pairs(inventories) do
         if inventory ~= nil then
             if table.length(inventory) > 0 then
                 saveLoadedInventory(identifier, type, inventory)
             else
                 deleteInventory(identifier, type)
             end
         end
     end
 end
 RconPrint('[Disc-InventoryHud][SAVED] All Inventories' .. "\n")
end

or line : 656
Replace the funciton with

function saveInventories(cb)
    local SaveAll = {}
    for type, inventories in pairs(loadedInventories) do
        for identifier, inventory in pairs(inventories) do
            if inventory ~= nil then
                if table.length(inventory) > 0 then
                    table.insert(SaveAll, function(cb)
                        local data = inventory
                        if table.length(data) > 0 then
                            MySQL.Async.execute('UPDATE disc_inventory SET data = @data WHERE owner = @owner AND type = @type', {
                                ['@owner'] = identifier,
                                ['@type'] = type,
                                ['@data'] = json.encode(data)
                            }, function(result)
                                if result == 0 then
                                    MySQL.Async.execute('INSERT INTO disc_inventory (owner, type, data) VALUES (@owner, @type, @data)', {
                                        ['@owner'] = identifier,
                                        ['@type'] = type,
                                        ['@data'] = json.encode(data)
                                    }, function()
                                        cb()
                                        TriggerEvent('wm_inventoryhud:createdInventory', identifier, type, data)
                                    end)
                                else
                                    cb()
                                    loadedInventories[type][identifier] = nil
                                    TriggerEvent('wm_inventoryhud:savedInventory', identifier, type, data)
                                end
                            end)
                        else
                            cb()
                        end
                    end)

                else
                    table.insert(SaveAll, function(cb)
                        MySQL.Async.execute('DELETE FROM disc_inventory WHERE owner = @owner AND type = @type', {
                            ['@owner'] = identifier,
                            ['@type'] = type
                        }, function()
                            cb()
                            TriggerEvent('wm_inventoryhud:deletedInventory', identifier, type)
                        end)
                    end)
                end
            end
        end
    end
    Async.parallelLimit(SaveAll, 8, function(results)
        print('[Disc Inventory - SAVED] All players')
        if cb ~= nil then
            cb('ok')
        end
    end)
end
1 Like

an error pop up.