Preserve entered vehicle on inventory sync

Save vehicle the player is driving before downloading the inventory and
restore the player position to this vehicle if possible.
This commit is contained in:
Hornwitser committed 2022-06-19 19:51:22 +02:00
1 parent 430a64722e
commit 105f99ced3
2 files changed
+37 -12

No files matched your search

@@ -310,13 +310,16 @@ function inventory_sync.initiate_inventory_download(player, player_record, gener
-- If this is a synced player turn them into a spectator while the
-- player data is downloading
if player_record.sync then
local character = player.character
player.set_controller({ type = defines.controllers.spectator })
if character ~= nil then character.destroy() end
-- Store original position to teleport back to
record.surface = player.surface
record.position = player.position
if player.driving then
record.vehicle = player.vehicle
end
local character = player.character
player.set_controller({ type = defines.controllers.spectator })
if character ~= nil then character.destroy() end
-- Indicate this state shouldn't be persisted
player_record.dirty = false