Skip to main content

LuaGameScript

Struct LuaGameScript 

Source
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

Source

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"

Source

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.)

Source

pub fn autosave_enabled(&self) -> bool

True by default. Can be used to disable autosaving. Make sure to turn it back on soon after.

Source

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.

Source

pub fn blueprints(&self) -> Vec<LuaRecord>

Records contained in the “game blueprints” tab of the blueprint library.

Source

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.

Source

pub fn console_command_used(&self) -> bool

Whether a console command has been used.

Source

pub fn default_map_gen_settings(&self) -> MapGenSettings

The default map gen settings for this save.

Source

pub fn difficulty(&self) -> &str

Current scenario difficulty.

Source

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.

Source

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.

Source

pub fn enemy_has_vision_on_land_mines(&self) -> bool

Determines if enemy land mines are completely invisible or not.

Source

pub fn finished(&self) -> bool

True while the victory screen is shown.

Source

pub fn finished_but_continuing(&self) -> bool

True after players finished the game and clicked “continue”.

Source

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.

Source

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.

Source

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.

Source

pub fn permissions(&self) -> LuaPermissionGroups

Source

pub fn planets(&self) -> HashMap<String, Box<LuaPlanet>>

Source

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.

Source

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.

Source

pub fn simulation(&self) -> LuaSimulation

Simulation-related functions, or nil if the current game is not a simulation.

Source

pub fn speed(&self) -> f32

Speed to update the map at. 1.0 is normal speed – 60 UPS. Minimum value is 0.01.

Source

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.

Source

pub fn technology_notifications_enabled(&self) -> bool

True by default. Can be used to prevent the game engine from printing certain messages.

Source

pub fn tick(&self) -> u32

Current map tick.

Source

pub fn tick_paused(&self) -> bool

If the tick has been paused. This means that entity update has been paused.

Source

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.

Source

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.

Source

pub fn train_manager(&self) -> LuaTrainManager

Source

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.

Source

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.

Source

pub fn check_consistency(&self)

Run internal consistency checks. Allegedly prints any errors it finds.

Exists mainly for debugging reasons.

Source

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.

Source

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.

Source

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(…).

Source

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.

Source

pub fn delete_blueprint_library(&self, player: LuaAny)

Deletes the blueprint library of the given player.

Note: the player must be offline (disconnected).

Source

pub fn delete_surface(&self, surface: LuaAny) -> bool

Deletes the given surface and all entities on it if possible.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_player(&self, player: LuaAny) -> Option<LuaPlayer>

Gets the given player or returns nil if no player is found.

Source

pub fn get_pollution_statistics(&self, surface: LuaAny) -> LuaFlowStatistics

The pollution statistics for this the given surface.

Source

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".

Source

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.

Source

pub fn get_vehicles( &self, params: LuaGameScriptGetVehiclesParams, ) -> Vec<LuaEntity>

Returns vehicles in game.

Source

pub fn is_demo(&self) -> bool

Is this the demo version of Factorio?

Source

pub fn is_multiplayer(&self) -> bool

Whether the save is loaded as a multiplayer map.

Source

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.

Source

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.

Source

pub fn mute_player(&self, player: LuaAny)

Mutes the given player. Does nothing if the player running this isn’t an admin.

Source

pub fn play_music(&self, music_specification: PlayMusicSpecification)

Play a music track for every player in the game.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remove_offline_players(&self, players: Option<Vec<LuaAny>>)

Remove players who are currently not connected from the map.

Source

pub fn reset_game_state(&self)

Reset scenario state (game_finished, player_won, etc.).

Source

pub fn reset_time_played(&self)

Resets the amount of time played for this map.

Source

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.

Source

pub fn server_save(&self, name: Option<&str>)

Instruct the server to save the map. Only actually saves when in multiplayer.

Source

pub fn set_game_state(&self, params: LuaGameScriptSetGameStateParams)

Set scenario state. Any parameters not provided do not change the current state.

Source

pub fn set_lose_ending_info(&self, params: LuaGameScriptSetLoseEndingInfoParams)

Set losing ending information for the current scenario.

Source

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.

Source

pub fn set_win_ending_info(&self, params: LuaGameScriptSetWinEndingInfoParams)

Set winning ending information for the current scenario.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LuaGameScript

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaGameScript

Source§

impl Debug for LuaGameScript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaGameScript

Source§

fn default() -> LuaGameScript

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaGameScript

Source§

impl From<LuaGameScript> for LuaAny

Source§

fn from(_: LuaGameScript) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaGameScript

Source§

impl PartialEq for LuaGameScript

Source§

fn eq(&self, other: &LuaGameScript) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaGameScript

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.