pub struct LuaGameScript;Expand description
Main toplevel type, provides access to most of the API though its members. An instance of LuaGameScript is available as the global object named game.
Implementations§
Source§impl LuaGameScript
impl LuaGameScript
Sourcepub fn allow_debug_settings(&self) -> bool
pub fn allow_debug_settings(&self) -> bool
Whether players who are not admins can access all debug settings. Set this to false to disallow access to most debug settings for non-admins.
The following debug settings are always available to all players: "show-fps", "show-playtime", "show-clock", "show-time-to-next-autosave", "show-detailed-info", "show-time-usage", "show-entity-time-usage", "show-gpu-time-usage", "show-sprite-counts", "show-particle-counts", "show-collector-navmesh-time-usage", "show-lua-object-statistics", "show-heat-buffer-info", "show-multiplayer-ups", "show-multiplayer-waiting-icon", "show-multiplayer-statistics", "show-multiplayer-server-name", "show-debug-info-in-tooltips", "show-resistances-in-tooltips-always", "hide-mod-guis", "show-tile-grid", "show-blueprint-grid", "show-intermediate-volume-of-working-sounds", "show-decorative-names", "allow-increased-zoom", "show-train-no-path-details", "show-entity-tick", "show-update-tick"
Sourcepub fn allow_tip_activation(&self) -> bool
pub fn allow_tip_activation(&self) -> bool
If the tips are allowed to be activated in this scenario, it is false by default.
Can’t be modified in a simulation (menu screen, tips and tricks simulation, factoriopedia simulation etc.)
Sourcepub fn autosave_enabled(&self) -> bool
pub fn autosave_enabled(&self) -> bool
True by default. Can be used to disable autosaving. Make sure to turn it back on soon after.
Sourcepub fn backer_names(&self) -> LuaAny
pub fn backer_names(&self) -> LuaAny
Array of the names of all the backers that supported the game development early on. These are used as names for labs, locomotives, radars, roboports, and train stops.
Sourcepub fn blueprints(&self) -> Vec<LuaRecord>
pub fn blueprints(&self) -> Vec<LuaRecord>
Records contained in the “game blueprints” tab of the blueprint library.
Sourcepub fn connected_players(&self) -> Vec<LuaPlayer>
pub fn connected_players(&self) -> Vec<LuaPlayer>
The players that are currently online.
This does not index using player index. See LuaPlayer::index on each player instance for the player index. This is primarily useful when you want to do some action against all online players.
Sourcepub fn console_command_used(&self) -> bool
pub fn console_command_used(&self) -> bool
Whether a console command has been used.
Sourcepub fn default_map_gen_settings(&self) -> MapGenSettings
pub fn default_map_gen_settings(&self) -> MapGenSettings
The default map gen settings for this save.
Sourcepub fn difficulty(&self) -> &str
pub fn difficulty(&self) -> &str
Current scenario difficulty.
Sourcepub fn difficulty_settings(&self) -> LuaAny
pub fn difficulty_settings(&self) -> LuaAny
The currently active set of difficulty settings. Even though this property is marked as read-only, the members of the dictionary that is returned can be modified mid-game.
Sourcepub fn draw_resource_selection(&self) -> bool
pub fn draw_resource_selection(&self) -> bool
True by default. Can be used to disable the highlighting of resource patches when they are hovered on the map.
Sourcepub fn enemy_has_vision_on_land_mines(&self) -> bool
pub fn enemy_has_vision_on_land_mines(&self) -> bool
Determines if enemy land mines are completely invisible or not.
Sourcepub fn finished_but_continuing(&self) -> bool
pub fn finished_but_continuing(&self) -> bool
True after players finished the game and clicked “continue”.
Sourcepub fn forces(&self) -> LuaAny
pub fn forces(&self) -> LuaAny
Get a table of all the forces that currently exist. This sparse table allows you to find forces by indexing it with either their name or index. Iterating this table with pairs() will provide the names as the keys. Iterating with ipairs() will not work at all.
Sourcepub fn map_settings(&self) -> LuaAny
pub fn map_settings(&self) -> LuaAny
The currently active set of map settings. Even though this property is marked as read-only, the members of the dictionary that is returned can be modified mid-game.
This does not contain difficulty settings, use LuaGameScript::difficulty_settings instead.
Sourcepub fn object_name(&self) -> &str
pub fn object_name(&self) -> &str
The class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
pub fn permissions(&self) -> LuaPermissionGroups
pub fn planets(&self) -> HashMap<String, Box<LuaPlanet>>
Sourcepub fn player(&self) -> LuaPlayer
pub fn player(&self) -> LuaPlayer
This property is only populated inside custom command handlers and when writing Lua console commands. Returns the player that is typing the command, nil in all other instances.
See LuaGameScript::players for accessing all players.
Sourcepub fn players(&self) -> LuaAny
pub fn players(&self) -> LuaAny
Get a table of all the players that currently exist. This sparse table allows you to find players by indexing it with either their name or index. Iterating this table with pairs() will provide the indexes as the keys. Iterating with ipairs() will not work at all.
If only a single player is required, LuaGameScript::get_player should be used instead, as it avoids the unnecessary overhead of passing the whole table to Lua.
Sourcepub fn simulation(&self) -> LuaSimulation
pub fn simulation(&self) -> LuaSimulation
Simulation-related functions, or nil if the current game is not a simulation.
Sourcepub fn speed(&self) -> f32
pub fn speed(&self) -> f32
Speed to update the map at. 1.0 is normal speed – 60 UPS. Minimum value is 0.01.
Sourcepub fn surfaces(&self) -> LuaAny
pub fn surfaces(&self) -> LuaAny
Get a table of all the surfaces that currently exist. This sparse table allows you to find surfaces by indexing it with either their name or index. Iterating this table with pairs() will provide the names as the keys. Iterating with ipairs() will not work at all.
Sourcepub fn technology_notifications_enabled(&self) -> bool
pub fn technology_notifications_enabled(&self) -> bool
True by default. Can be used to prevent the game engine from printing certain messages.
Sourcepub fn tick_paused(&self) -> bool
pub fn tick_paused(&self) -> bool
If the tick has been paused. This means that entity update has been paused.
Sourcepub fn ticks_played(&self) -> u32
pub fn ticks_played(&self) -> u32
The number of ticks since this game was created using either “new game” or “new game from scenario”. Notably, this number progresses even when the game is tick_paused.
This differs from LuaGameScript::tick in that creating a game from a scenario always starts with this value at 0, even if the scenario has its own level data where the tick has progressed past 0.
Sourcepub fn ticks_to_run(&self) -> u32
pub fn ticks_to_run(&self) -> u32
The number of ticks to be run while the tick is paused.
When LuaGameScript::tick_paused is true, ticks_to_run behaves the following way: While this is > 0, the entity update is running normally and this value is decremented every tick. When this reaches 0, the game will pause again.
pub fn train_manager(&self) -> LuaTrainManager
Sourcepub fn auto_save(&self, allow_in_replay: Option<bool>, name: Option<&str>)
pub fn auto_save(&self, allow_in_replay: Option<bool>, name: Option<&str>)
Instruct the game to perform an auto-save.
Only the server will save in multiplayer. In single player a standard auto-save is triggered.
Sourcepub fn ban_player(&self, player: LuaAny, reason: Option<&str>)
pub fn ban_player(&self, player: LuaAny, reason: Option<&str>)
Bans the given player from this multiplayer game. Does nothing if this is a single player game of if the player running this isn’t an admin.
Sourcepub fn check_consistency(&self)
pub fn check_consistency(&self)
Run internal consistency checks. Allegedly prints any errors it finds.
Exists mainly for debugging reasons.
Sourcepub fn create_force(&self, force: &str) -> LuaForce
pub fn create_force(&self, force: &str) -> LuaForce
Create a new force.
The game currently supports a maximum of 64 forces, including the three built-in forces. This means that a maximum of 61 new forces may be created. Force names must be unique.
Sourcepub fn create_inventory(
&self,
gui_title: Option<&str>,
size: u16,
) -> LuaInventory
pub fn create_inventory( &self, gui_title: Option<&str>, size: u16, ) -> LuaInventory
Creates an inventory that is not owned by any game object.
It can be resized later with LuaInventory::resize.
Make sure to destroy it when you are done with it using LuaInventory::destroy.
Sourcepub fn create_random_generator(&self, seed: Option<u32>) -> LuaRandomGenerator
pub fn create_random_generator(&self, seed: Option<u32>) -> LuaRandomGenerator
Creates a deterministic standalone random generator with the given seed or if a seed is not provided the initial map seed is used.
Make sure you actually want to use this over math.random(…) as this provides entirely different functionality over math.random(…).
Sourcepub fn create_surface(
&self,
name: &str,
settings: Option<MapGenSettings>,
) -> LuaSurface
pub fn create_surface( &self, name: &str, settings: Option<MapGenSettings>, ) -> LuaSurface
Create a new surface.
The game currently supports a maximum of 4 294 967 295 surfaces, including the default surface. Surface names must be unique.
Sourcepub fn delete_blueprint_library(&self, player: LuaAny)
pub fn delete_blueprint_library(&self, player: LuaAny)
Deletes the blueprint library of the given player.
Note: the player must be offline (disconnected).
Sourcepub fn delete_surface(&self, surface: LuaAny) -> bool
pub fn delete_surface(&self, surface: LuaAny) -> bool
Deletes the given surface and all entities on it if possible.
Sourcepub fn disable_replay(&self)
pub fn disable_replay(&self)
Disables replay saving for the current save file. Once done there’s no way to re-enable replay saving for the save file without loading an old save.
Sourcepub fn force_crc(&self)
pub fn force_crc(&self)
Force a CRC check. Tells all peers to calculate their current CRC, which are then compared to each other. If a mismatch is detected, the game desyncs and some peers are forced to reconnect.
Sourcepub fn get_entity_by_tag(&self, tag: &str) -> Option<LuaEntity>
pub fn get_entity_by_tag(&self, tag: &str) -> Option<LuaEntity>
Gets an entity by its name tag. Entity name tags can also be set in the entity “extra settings” GUI in the map editor.
Sourcepub fn get_entity_by_unit_number(&self, unit_number: u32) -> Option<LuaEntity>
pub fn get_entity_by_unit_number(&self, unit_number: u32) -> Option<LuaEntity>
Returns entity with a specified unit number or nil if entity with such number was not found or prototype does not have EntityPrototypeFlags::get-by-unit-number flag set.
Sourcepub fn get_map_exchange_string(&self) -> &str
pub fn get_map_exchange_string(&self) -> &str
Gets the map exchange string for the map generation settings that were used to create this map.
Sourcepub fn get_player(&self, player: LuaAny) -> Option<LuaPlayer>
pub fn get_player(&self, player: LuaAny) -> Option<LuaPlayer>
Gets the given player or returns nil if no player is found.
Sourcepub fn get_pollution_statistics(&self, surface: LuaAny) -> LuaFlowStatistics
pub fn get_pollution_statistics(&self, surface: LuaAny) -> LuaFlowStatistics
The pollution statistics for this the given surface.
Sourcepub fn get_script_inventories(
&self,
mod: Option<&str>,
) -> HashMap<String, Vec<Box<LuaInventory>>>
pub fn get_script_inventories( &self, mod: Option<&str>, ) -> HashMap<String, Vec<Box<LuaInventory>>>
Gets the inventories created through LuaGameScript::create_inventory.
Inventories created through console commands will be owned by "core".
Sourcepub fn get_surface(&self, surface: LuaAny) -> Option<LuaSurface>
pub fn get_surface(&self, surface: LuaAny) -> Option<LuaSurface>
Gets the given surface or returns nil if no surface is found.
This is a shortcut for LuaGameScript::surfaces.
Sourcepub fn get_vehicles(
&self,
params: LuaGameScriptGetVehiclesParams,
) -> Vec<LuaEntity>
pub fn get_vehicles( &self, params: LuaGameScriptGetVehiclesParams, ) -> Vec<LuaEntity>
Returns vehicles in game.
Sourcepub fn is_multiplayer(&self) -> bool
pub fn is_multiplayer(&self) -> bool
Whether the save is loaded as a multiplayer map.
Sourcepub fn kick_player(&self, player: LuaAny, reason: Option<&str>)
pub fn kick_player(&self, player: LuaAny, reason: Option<&str>)
Kicks the given player from this multiplayer game. Does nothing if this is a single player game or if the player running this isn’t an admin.
Sourcepub fn merge_forces(&self, destination: LuaAny, source: LuaAny)
pub fn merge_forces(&self, destination: LuaAny, source: LuaAny)
Marks two forces to be merged together. All players and entities in the source force will be reassigned to the target force. The source force will then be destroyed. Importantly, this does not merge technologies or bonuses, which are instead retained from the target force.
The three built-in forces (player, enemy and neutral) can’t be destroyed, meaning they can’t be used as the source argument to this function.
The source force is not removed until the end of the current tick, or if called during the on_forces_merging or on_forces_merged event, the end of the next tick.
Sourcepub fn mute_player(&self, player: LuaAny)
pub fn mute_player(&self, player: LuaAny)
Mutes the given player. Does nothing if the player running this isn’t an admin.
Sourcepub fn play_music(&self, music_specification: PlayMusicSpecification)
pub fn play_music(&self, music_specification: PlayMusicSpecification)
Play a music track for every player in the game.
Sourcepub fn play_sound(&self, sound_specification: PlaySoundSpecification)
pub fn play_sound(&self, sound_specification: PlaySoundSpecification)
Play a sound for every player in the game.
The sound is not played if its location is not charted for that player.
Sourcepub fn print(&self, message: &str, print_settings: Option<PrintSettings>)
pub fn print(&self, message: &str, print_settings: Option<PrintSettings>)
Print text to the chat console all players.
By default, messages that are identical to a message sent in the last 60 ticks are not printed again.
Sourcepub fn purge_player(&self, player: LuaAny)
pub fn purge_player(&self, player: LuaAny)
Purges the given players messages from the game. Does nothing if the player running this isn’t an admin.
Sourcepub fn regenerate_entity(&self, entities: LuaAny)
pub fn regenerate_entity(&self, entities: LuaAny)
Regenerate autoplacement of some entities on all surfaces. This can be used to autoplace newly-added entities.
All specified entity prototypes must be autoplacable.
Sourcepub fn reload_mods(&self)
pub fn reload_mods(&self)
Forces a reload of all mods.
This will act like saving and loading from the mod(s) perspective.
This will do nothing if run in multiplayer.
This disables the replay if replay is enabled.
Sourcepub fn reload_script(&self)
pub fn reload_script(&self)
Forces a reload of the scenario script from the original scenario location.
This disables the replay if replay is enabled.
Sourcepub fn remove_offline_players(&self, players: Option<Vec<LuaAny>>)
pub fn remove_offline_players(&self, players: Option<Vec<LuaAny>>)
Remove players who are currently not connected from the map.
Sourcepub fn reset_game_state(&self)
pub fn reset_game_state(&self)
Reset scenario state (game_finished, player_won, etc.).
Sourcepub fn reset_time_played(&self)
pub fn reset_time_played(&self)
Resets the amount of time played for this map.
Sourcepub fn save_atlas(&self)
pub fn save_atlas(&self)
Saves the current configuration of Atlas to a file. This will result in huge file containing all of the game graphics moved to as small space as possible.
Exists mainly for debugging reasons.
Sourcepub fn server_save(&self, name: Option<&str>)
pub fn server_save(&self, name: Option<&str>)
Instruct the server to save the map. Only actually saves when in multiplayer.
Sourcepub fn set_game_state(&self, params: LuaGameScriptSetGameStateParams)
pub fn set_game_state(&self, params: LuaGameScriptSetGameStateParams)
Set scenario state. Any parameters not provided do not change the current state.
Sourcepub fn set_lose_ending_info(&self, params: LuaGameScriptSetLoseEndingInfoParams)
pub fn set_lose_ending_info(&self, params: LuaGameScriptSetLoseEndingInfoParams)
Set losing ending information for the current scenario.
Sourcepub fn set_wait_for_screenshots_to_finish(&self)
pub fn set_wait_for_screenshots_to_finish(&self)
Forces the screenshot saving system to wait until all queued screenshots have been written to disk.
Sourcepub fn set_win_ending_info(&self, params: LuaGameScriptSetWinEndingInfoParams)
pub fn set_win_ending_info(&self, params: LuaGameScriptSetWinEndingInfoParams)
Set winning ending information for the current scenario.
Sourcepub fn show_message_dialog(&self, params: LuaGameScriptShowMessageDialogParams)
pub fn show_message_dialog(&self, params: LuaGameScriptShowMessageDialogParams)
Show an in-game message dialog.
Can only be used when the map contains exactly one player.
Sourcepub fn take_screenshot(&self, params: LuaGameScriptTakeScreenshotParams)
pub fn take_screenshot(&self, params: LuaGameScriptTakeScreenshotParams)
Take a screenshot of the game and save it to the script-output folder, located in the game’s user data directory. The name of the image file can be specified via the path parameter.
If Factorio is running headless, this function will do nothing.
Sourcepub fn take_technology_screenshot(
&self,
params: LuaGameScriptTakeTechnologyScreenshotParams,
)
pub fn take_technology_screenshot( &self, params: LuaGameScriptTakeTechnologyScreenshotParams, )
Take a screenshot of the technology screen and save it to the script-output folder, located in the game’s user data directory. The name of the image file can be specified via the path parameter.
Sourcepub fn unban_player(&self, player: LuaAny)
pub fn unban_player(&self, player: LuaAny)
Unbans the given player from this multiplayer game. Does nothing if this is a single player game of if the player running this isn’t an admin.
Sourcepub fn unmute_player(&self, player: LuaAny)
pub fn unmute_player(&self, player: LuaAny)
Unmutes the given player. Does nothing if the player running this isn’t an admin.
Trait Implementations§
Source§impl Clone for LuaGameScript
impl Clone for LuaGameScript
Source§fn clone(&self) -> LuaGameScript
fn clone(&self) -> LuaGameScript
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more