From 430a64722e5947270806812de1e71ff6bfa67bc6 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 19 Jun 2022 17:03:08 +0200 Subject: [PATCH] Use empty slots as end for logistics requests Count up to 100 empty slots past the last seen slot with data in it before stopping to look for personal logistics slots in inventory_sync. Allows unlimeted amount of logistics request slots to be used for heavily modded games. --- plugins/inventory_sync/module/serialize.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/inventory_sync/module/serialize.lua b/plugins/inventory_sync/module/serialize.lua index 820d4559..e0e264a8 100644 --- a/plugins/inventory_sync/module/serialize.lua +++ b/plugins/inventory_sync/module/serialize.lua @@ -75,9 +75,11 @@ function serialize.serialize_personal_logistic_slots(player) local serialized = nil -- Serialize personal logistic slots - for i = 1, 200 do -- Nobody will have more than 200 logistic slots, right? + local last_valid = 0 + for i = 1, 65536 do local slot = player.get_personal_logistic_slot(i) - if slot.name ~= nil then + if slot.name then + last_valid = i if not serialized then serialized = {} end @@ -86,6 +88,10 @@ function serialize.serialize_personal_logistic_slots(player) min = slot.min, max = slot.max, } + + -- Stop after 100 empty slots + elseif last_valid + 100 <= i then + break end end @@ -98,10 +104,9 @@ function serialize.deserialize_personal_logistic_slots(player, serialized) end -- Load personal logistic slots - for i = 1, 200 do - local slot = serialized[tostring(i)] -- 1 is empty to force array to be spare + for i, slot in pairs(serialized) do if slot ~= nil then - player.set_personal_logistic_slot(i, slot) + player.set_personal_logistic_slot(tonumber(i), slot) end end end