[0.14.21] Desync related to luaplayer.build_from_cursor()
Posted: Fri Jan 06, 2017 10:11 am
by Nexela
The below mod will desync if the on_built_event is raised by build_from_cursor()
After installing the mod just right click somewhere on the map.
See comments in hot key event
Raising the custom event from the command line or
Commenting out the build_from_cursor() line and uncommenting any of the game.raise event lines will not cause desyncs
script.on_event(defines.events.on_built_entity,
function(event)
if event.created_entity.name=="autorun" then
local player = game.players[event.player_index]
local entity = event.created_entity
game.raise_event(events.autorun_move_to, {player_index=player.index, position=entity.position})
-- global.runners[player.index] = { --Also Desyncs when build_from_cursor is used.
-- target=entity.position,
-- }
-- player.set_gui_arrow{type="position", position=entity.position}
entity.destroy()
end
end
)
--Move when manual move event is raised.
script.on_event(events.autorun_move_to,
function(event)
local player = game.players[event.player_index]
game.raise_event(events.autorun_stop, {player_index=player.index})
global.runners[player.index] = {target=event.position}
player.set_gui_arrow{type="position", position=event.position}
end
)
--Move when hotkey is pressed default "right-mouse-button"
script.on_event({"move"},
function(event)
local player=game.players[event.player_index]
debug("Moving player "..player.name)
--First stop any current automatic moving.
game.raise_event(events.autorun_stop, {player_index=event.player_index})
--Check for empty hands.
if (player.cursor_stack and not player.cursor_stack.valid_for_read) then
player.cursor_stack.set_stack({name="autorun", count=1})
player.character_build_distance_bonus = player.character_build_distance_bonus+2000
--[[
--#1 If replace player.build_from_cursor() with game.raise_event(events.autorun_move_to) no desyncs. (bypasses on_built_entity)
--#2 If replace player.build_from_cursor() with game.raise_event(defines.events.on_built_entity) no desyncs
--#3 if using console /c game.raise_event(remote.call("autorun", "get_id"), {player_index=game.player.index, position={x=5,y=0}}) no desyncs
--]]
--Used to build an entity from the cursor in order to get the position of the mouse.
player.build_from_cursor()
--game.raise_event(defines.events.on_built_entity, {player_index=player.index, created_entity=player.surface.create_entity{name="autorun", force=player.force, position={x=10, y=0}}})
--game.raise_event(remote.call("autorun", "get_id"), {player_index=game.player.index, position={x=10,y=0}}
player.character_build_distance_bonus = player.character_build_distance_bonus-2000
player.cursor_stack.clear()
end
end
)