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
.
set_game_state{game_finished = …, player_won = …, next_level = …, can_continue = …, victorious_force = …} | Set scenario state. |
get_entity_by_tag(tag) → LuaEntity | |
show_message_dialog{text = …, image = …, point_to = …, style = …, wrapper_frame_style = …} | Show an in-game message dialog. |
is_demo() → boolean | Is this the demo version of Factorio? |
reload_script() | Forces a reload of the scenario script from the original scenario location. |
reload_mods() | Forces a reload of all mods. |
save_atlas() | Saves the current configuration of Atlas to a file. |
check_consistency() | Run internal consistency checks. |
regenerate_entity(entities) | Regenerate autoplacement of some entities on all surfaces. |
take_screenshot{player = …, by_player = …, surface = …, position = …, resolution = …, zoom = …, path = …, show_gui = …, show_entity_info = …, show_cursor_building_preview = …, anti_alias = …, quality = …, allow_in_replay = …, daytime = …, water_tick = …, force_render = …} | Take a screenshot and save it to a file. |
set_wait_for_screenshots_to_finish() | Forces the screenshot saving system to wait until all queued screenshots have been written to disk. |
take_technology_screenshot{force = …, path = …, by_player = …, selected_technology = …, skip_disabled = …, quality = …} | |
table_to_json(data) → string | Convert a table to a JSON string |
json_to_table(json) → AnyBasic | Convert a JSON string to a table. |
write_file(filename, data, append, for_player) | Write a string to a file. |
remove_path(path) | Remove file or directory. |
remove_offline_players(players) | Remove players who are currently not connected from the map. |
force_crc() | Force a CRC check. |
create_force(force) → LuaForce | Create a new force. |
merge_forces(source, destination) | Marks two forces to be merge together. |
create_surface(name, settings) → LuaSurface | Create a new surface |
server_save(name) | Instruct the server to save the map. |
auto_save(name) | Instruct the game to perform an auto-save. |
delete_surface(surface) | Deletes the given surface and all entities on it. |
disable_replay() | Disables replay saving for the current save file. |
disable_tutorial_triggers() | Disables tutorial triggers, that unlock new tutorials and show notices about unlocked tutorials. |
direction_to_string(direction) | Converts the given direction into the string version of the direction. |
print(message, color) | Print text to the chat console all players. |
create_random_generator(seed) → LuaRandomGenerator | Creates a deterministic standalone random generator with the given seed or if a seed is not provided the initial map seed is used. |
check_prototype_translations() | Goes over all items, entities, tiles, recipes, technologies among other things and logs if the locale is incorrect. |
play_sound{path = …, position = …, volume_modifier = …, override_sound_type = …} | Play a sound for every player in the game. |
is_valid_sound_path(sound_path) → boolean | Checks if the given SoundPath is valid. |
is_valid_sprite_path(sprite_path) → boolean | Checks if the given SpritePath is valid and contains a loaded sprite. |
kick_player(player, reason) | Kicks the given player from this multiplayer game. |
ban_player(player, reason) | Bans the given player from this multiplayer game. |
unban_player(player) | Unbans the given player from this multiplayer game. |
purge_player(player) | Purges the given players messages from the game. |
mute_player(player) | Mutes the given player. |
unmute_player(player) | Unmutes the given player. |
count_pipe_groups() | Counts how many distinct groups of pipes exist in the world. |
is_multiplayer() → boolean | Is the map loaded is multiplayer? |
get_active_entities_count(surface) → uint | Gets the number of entities that are active (updated each tick). |
get_map_exchange_string() → string | Gets the map exchange string for the map generation settings that were used to create this map. |
parse_map_exchange_string(map_exchange_string) → MapExchangeStringData | Convert a map exchange string to map gen settings and map settings. |
get_train_stops{name = …, surface = …, force = …} → array[LuaEntity] | Gets train stops matching the given filters. |
get_player(player) → LuaPlayer | Gets the given player or returns nil if no player is found. |
get_surface(surface) → LuaSurface | Gets the given surface or returns nil if no surface is found. |
create_profiler(stopped) → LuaProfiler | Creates a LuaProfiler, which is used for measuring script performance. |
evaluate_expression(expression, variables) → double | Evaluate an expression, substituting variables as provided. |
get_filtered_entity_prototypes(filters) → LuaCustomTable[string → LuaEntityPrototype] | Returns a dictionary of all LuaEntityPrototypes that fit the given filters. |
get_filtered_item_prototypes(filters) → LuaCustomTable[string → LuaItemPrototype] | Returns a dictionary of all LuaItemPrototypes that fit the given filters. |
get_filtered_equipment_prototypes(filters) → LuaCustomTable[string → LuaEquipmentPrototype] | Returns a dictionary of all LuaEquipmentPrototypes that fit the given filters. |
get_filtered_mod_setting_prototypes(filters) → LuaCustomTable[string → LuaModSettingPrototype] | Returns a dictionary of all LuaModSettingPrototypes that fit the given filters. |
get_filtered_achievement_prototypes(filters) → LuaCustomTable[string → LuaAchievementPrototype] | Returns a dictionary of all LuaAchievementPrototypes that fit the given filters. |
get_filtered_tile_prototypes(filters) → LuaCustomTable[string → LuaTilePrototype] | Returns a dictionary of all LuaTilePrototypes that fit the given filters. |
get_filtered_decorative_prototypes(filters) → LuaCustomTable[string → LuaDecorativePrototype] | Returns a dictionary of all LuaDecorativePrototypes that fit the given filters. |
get_filtered_fluid_prototypes(filters) → LuaCustomTable[string → LuaFluidPrototype] | Returns a dictionary of all LuaFluidPrototypes that fit the given filters. |
get_filtered_recipe_prototypes(filters) → LuaCustomTable[string → LuaRecipePrototype] | Returns a dictionary of all LuaRecipePrototypes that fit the given filters. |
get_filtered_technology_prototypes(filters) → LuaCustomTable[string → LuaTechnologyPrototype] | Returns a dictionary of all LuaTechnologyPrototypes that fit the given filters. |
create_inventory(size) → LuaInventory | Creates an inventory that is not owned by any game object. |
get_script_inventories(mod) → dictionary[string → array[LuaInventory]] | Gets the inventories created through LuaGameScript::create_inventory |
reset_time_played() | Resets the amount of time played for this map. |
encode_string(string) → string | Deflates and base64 encodes the given string. |
decode_string(string) → string | Base64 decodes and inflates the given string. |
object_name :: string [R] | This object's name. |
player :: LuaPlayer [R] | The player typing at the console - nil in all other instances. |
players :: LuaCustomTable[uint or string → LuaPlayer] [R] | Get a table of all the players that currently exist. |
map_settings :: MapSettings [R] | |
difficulty_settings :: DifficultySettings [R] | The currently active set of difficulty settings. |
difficulty :: defines.difficulty [R] | Current scenario difficulty. |
forces :: LuaCustomTable[uint or string → LuaForce] [R] | Get a table of all the forces that currently exist. |
entity_prototypes :: LuaCustomTable[string → LuaEntityPrototype] [R] | A dictionary containing every LuaEntityPrototype indexed by name . |
item_prototypes :: LuaCustomTable[string → LuaItemPrototype] [R] | A dictionary containing every LuaItemPrototype indexed by name . |
fluid_prototypes :: LuaCustomTable[string → LuaFluidPrototype] [R] | A dictionary containing every LuaFluidPrototype indexed by name . |
tile_prototypes :: LuaCustomTable[string → LuaTilePrototype] [R] | A dictionary containing every LuaTilePrototype indexed by name . |
equipment_prototypes :: LuaCustomTable[string → LuaEquipmentPrototype] [R] | A dictionary containing every LuaEquipmentPrototype indexed by name . |
damage_prototypes :: LuaCustomTable[string → LuaDamagePrototype] [R] | A dictionary containing every LuaDamagePrototype indexed by name . |
virtual_signal_prototypes :: LuaCustomTable[string → LuaVirtualSignalPrototype] [R] | A dictionary containing every LuaVirtualSignalPrototype indexed by name . |
equipment_grid_prototypes :: LuaCustomTable[string → LuaEquipmentGridPrototype] [R] | A dictionary containing every LuaEquipmentGridPrototype indexed by name . |
recipe_prototypes :: LuaCustomTable[string → LuaRecipePrototype] [R] | A dictionary containing every LuaRecipePrototype indexed by name . |
technology_prototypes :: LuaCustomTable[string → LuaTechnologyPrototype] [R] | A dictionary containing every LuaTechnologyPrototype indexed by name . |
decorative_prototypes :: LuaCustomTable[string → LuaDecorativePrototype] [R] | A dictionary containing every LuaDecorativePrototype indexed by name . |
particle_prototypes :: LuaCustomTable[string → LuaParticlePrototype] [R] | A dictionary containing every LuaParticlePrototype indexed by name . |
autoplace_control_prototypes :: LuaCustomTable[string → LuaAutoplaceControlPrototype] [R] | A dictionary containing every LuaAutoplaceControlPrototype indexed by name . |
noise_layer_prototypes :: LuaCustomTable[string → LuaNoiseLayerPrototype] [R] | A dictionary containing every LuaNoiseLayerPrototype indexed by name . |
mod_setting_prototypes :: LuaCustomTable[string → LuaModSettingPrototype] [R] | A dictionary containing every LuaModSettingPrototype indexed by name . |
custom_input_prototypes :: LuaCustomTable[string → LuaCustomInputPrototype] [R] | A dictionary containing every LuaCustomInputPrototype indexed by name . |
ammo_category_prototypes :: LuaCustomTable[string → LuaAmmoCategoryPrototype] [R] | A dictionary containing every LuaAmmoCategoryPrototype indexed by name . |
named_noise_expressions :: LuaCustomTable[string → LuaNamedNoiseExpression] [R] | A dictionary containing every LuaNamedNoiseExpression indexed by name . |
item_subgroup_prototypes :: LuaCustomTable[string → LuaGroup] [R] | A dictionary containing every ItemSubgroup indexed by name . |
item_group_prototypes :: LuaCustomTable[string → LuaGroup] [R] | A dictionary containing every ItemGroup indexed by name . |
fuel_category_prototypes :: LuaCustomTable[string → LuaFuelCategoryPrototype] [R] | A dictionary containing every LuaFuelCategoryPrototype indexed by name . |
resource_category_prototypes :: LuaCustomTable[string → LuaResourceCategoryPrototype] [R] | A dictionary containing every LuaResourceCategoryPrototype indexed by name . |
achievement_prototypes :: LuaCustomTable[string → LuaAchievementPrototype] [R] | A dictionary containing every LuaAchievementPrototype indexed by name . |
module_category_prototypes :: LuaCustomTable[string → LuaModuleCategoryPrototype] [R] | A dictionary containing every LuaModuleCategoryPrototype indexed by name . |
equipment_category_prototypes :: LuaCustomTable[string → LuaEquipmentCategoryPrototype] [R] | A dictionary containing every LuaEquipmentCategoryPrototype indexed by name . |
trivial_smoke_prototypes :: LuaCustomTable[string → LuaTrivialSmokePrototype] [R] | A dictionary containing every LuaTrivialSmokePrototype indexed by name . |
shortcut_prototypes :: LuaCustomTable[string → LuaShortcutPrototype] [R] | A dictionary containing every LuaShortcutPrototype indexed by name . |
recipe_category_prototypes :: LuaCustomTable[string → LuaRecipeCategoryPrototype] [R] | A dictionary containing every LuaRecipeCategoryPrototype indexed by name . |
font_prototypes :: LuaCustomTable[string → LuaFontPrototype] [R] | A dictionary containing every LuaFontPrototype indexed by name . |
map_gen_presets :: LuaCustomTable[string → MapGenPreset] [R] | A dictionary containing every MapGenPreset indexed by name . |
styles :: LuaCustomTable[string → string] [R] | The styles that LuaGuiElement can use, indexed by name . |
tick :: uint [R] | Current map tick. |
ticks_played :: uint [R] | The number of ticks since this game was 'created'. |
tick_paused :: boolean [RW] | If the tick has been paused. |
ticks_to_run :: uint [RW] | The number of ticks to be run while the tick is paused. |
finished :: boolean [R] | Is the scenario finished? |
speed :: float [RW] | Speed to update the map at. |
surfaces :: LuaCustomTable[uint or string → LuaSurface] [R] | Get a table of all the surfaces that currently exist. |
active_mods :: dictionary[string → string] [R] | The active mods versions. |
connected_players :: array[LuaPlayer] [R] | The players that are currently online. |
permissions :: LuaPermissionGroups [R] | |
backer_names :: LuaCustomTable[uint → string] [R] | Array of the names of all the backers that supported the game development early on. |
default_map_gen_settings :: MapGenSettings [R] | The default map gen settings for this save. |
enemy_has_vision_on_land_mines :: boolean [RW] | Determines if enemy land mines are completely invisible or not. |
autosave_enabled :: boolean [RW] | True by default. |
draw_resource_selection :: boolean [RW] | True by default. |
pollution_statistics :: LuaFlowStatistics [R] | The pollution statistics for this map. |
max_force_distraction_distance :: double [R] | |
max_force_distraction_chunk_distance :: uint [R] | |
max_electric_pole_supply_area_distance :: float [R] | |
max_electric_pole_connection_distance :: double [R] | |
max_beacon_supply_area_distance :: double [R] | |
max_gate_activation_distance :: double [R] | |
max_inserter_reach_distance :: double [R] | |
max_pipe_to_ground_distance :: uint8 [R] | |
max_underground_belt_distance :: uint8 [R] |
Set scenario state.
Show an in-game message dialog.
point_to={type="nowhere"}
to remove the arrow entirely.) The dialog itself will be placed near the arrow's target.Is this the demo version of Factorio?
Forces a reload of the scenario script from the original scenario location.
Forces a reload of all mods.
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.
Run internal consistency checks. Allegedly prints any errors it finds.
Take a screenshot and save it to a file.
Forces the screenshot saving system to wait until all queued screenshots have been written to disk.
"player
" force is used.true
, disabled technologies will be skipped. Their successors
will be attached to the disabled technology's parents. Defaults to false
.Convert a JSON string to a table.
nil
if the json was invalid.Write a string to a file.
true
, this will append to the end of the file. Defaults to false
, which will overwrite any pre-existing file with the new data.Remove file or directory. Given path is taken relative to the script output directory. Can be used to remove files created by LuaGameScript::write_file.
Force a CRC check. Tells all peers to calculate their current map CRC; these CRC are then compared against each other. If a mismatch is detected, the game is desynced and some peers are forced to reconnect.
Create a new force.
Marks two forces to be merge together. All entities in the source force will be reassigned to the target force. The source force will then be destroyed.
Create a new surface
Instruct the server to save the map.
Instruct the game to perform an auto-save.
Deletes the given surface and all entities on it.
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.
Disables tutorial triggers, that unlock new tutorials and show notices about unlocked tutorials.
Converts the given direction into the string version of the direction.
Print text to the chat console all players.
Creates a deterministic standalone random generator with the given seed or if a seed is not provided the initial map seed is used.
Goes over all items, entities, tiles, recipes, technologies among other things and logs if the locale is incorrect.
Play a sound for every player in the game.
Checks if the given SpritePath is valid and contains a loaded sprite.
file
.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.
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.
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.
Purges the given players messages from the game. Does nothing if the player running this isn't an admin.
Mutes the given player. Does nothing if the player running this isn't an admin.
Unmutes the given player. Does nothing if the player running this isn't an admin.
Counts how many distinct groups of pipes exist in the world.
Is the map loaded is multiplayer?
Gets the number of entities that are active (updated each tick).
Gets the map exchange string for the map generation settings that were used to create this map.
Convert a map exchange string to map gen settings and map settings.
Gets train stops matching the given filters.
Creates a LuaProfiler, which is used for measuring script performance.
Evaluate an expression, substituting variables as provided. For details on the formula, see the relevant page on the Factorio wiki.
local formula = game.forces["player"].technologies["mining-productivity-4"].research_unit_count_formula
local units = game.evaluate_expression(formula, { L = 10, l = 10 })
Returns a dictionary of all LuaEntityPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_entity_prototypes{{filter="crafting-category", crafting_category="crafting-with-fluid"}}
Returns a dictionary of all LuaItemPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_item_prototypes{{filter="has-rocket-launch-products"}}
Returns a dictionary of all LuaEquipmentPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_equipment_prototypes{{filter="type", type="battery-equipment"}}
Returns a dictionary of all LuaModSettingPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_mod_setting_prototypes{{filter="mod", mod="space-exploration"}}
Returns a dictionary of all LuaAchievementPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_achievement_prototypes{{filter="allowed-without-fight", invert=true}}
Returns a dictionary of all LuaTilePrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_tile_prototypes{{filter="walking-speed-modifier", comparison="≥", value=1.5}}
Returns a dictionary of all LuaDecorativePrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_decorative_prototypes{{filter="autoplace"}}
Returns a dictionary of all LuaFluidPrototypes that fit the given filters. The prototypes are indexed by name
.
100
.
local prototypes = game.get_filtered_fluid_prototypes{{filter="heat-capacity", comparison="=", value=100}}
Returns a dictionary of all LuaRecipePrototypes that fit the given filters. The prototypes are indexed by name
.
1
).
local prototypes = game.get_filtered_recipe_prototypes{{filter="energy", comparison="<", value=0.5}}
Returns a dictionary of all LuaTechnologyPrototypes that fit the given filters. The prototypes are indexed by name
.
local prototypes = game.get_filtered_technology_prototypes{{filter="has-prerequisites", invert=true}}
Creates an inventory that is not owned by any game object. It can be resized later with LuaInventory::resize.
Gets the inventories created through LuaGameScript::create_inventory
"core"
.Resets the amount of time played for this map.
Deflates and base64 encodes the given string.
nil
if the encode failed.Base64 decodes and inflates the given string.
nil
if the decode failed.This object's name.
The player typing at the console - nil
in all other instances. See LuaGameScript::players for
accessing all players.
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 only iterate the array
part of the table. Iterating with ipairs()
will not work at all.
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. This is however not recommended as different difficulties can have differing technology and recipe trees, which can cause problems for players.
game.difficulty_settings.technology_price_multiplier = 12
Current scenario difficulty.
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 only iterate the array
part of the table. Iterating with ipairs()
will not work at all.
A dictionary containing every LuaEntityPrototype indexed by name
.
A dictionary containing every LuaItemPrototype indexed by name
.
A dictionary containing every LuaFluidPrototype indexed by name
.
A dictionary containing every LuaTilePrototype indexed by name
.
A dictionary containing every LuaEquipmentPrototype indexed by name
.
A dictionary containing every LuaDamagePrototype indexed by name
.
A dictionary containing every LuaVirtualSignalPrototype indexed by name
.
A dictionary containing every LuaEquipmentGridPrototype indexed by name
.
A dictionary containing every LuaRecipePrototype indexed by name
.
A dictionary containing every LuaTechnologyPrototype indexed by name
.
A dictionary containing every LuaDecorativePrototype indexed by name
.
A dictionary containing every LuaParticlePrototype indexed by name
.
A dictionary containing every LuaAutoplaceControlPrototype indexed by name
.
A dictionary containing every LuaNoiseLayerPrototype indexed by name
.
A dictionary containing every LuaModSettingPrototype indexed by name
.
A dictionary containing every LuaCustomInputPrototype indexed by name
.
A dictionary containing every LuaAmmoCategoryPrototype indexed by name
.
A dictionary containing every LuaNamedNoiseExpression indexed by name
.
A dictionary containing every ItemSubgroup indexed by name
.
A dictionary containing every ItemGroup indexed by name
.
A dictionary containing every LuaFuelCategoryPrototype indexed by name
.
A dictionary containing every LuaResourceCategoryPrototype indexed by name
.
A dictionary containing every LuaAchievementPrototype indexed by name
.
A dictionary containing every LuaModuleCategoryPrototype indexed by name
.
A dictionary containing every LuaEquipmentCategoryPrototype indexed by name
.
A dictionary containing every LuaTrivialSmokePrototype indexed by name
.
A dictionary containing every LuaShortcutPrototype indexed by name
.
A dictionary containing every LuaRecipeCategoryPrototype indexed by name
.
A dictionary containing every LuaFontPrototype indexed by name
.
A dictionary containing every MapGenPreset indexed by name
.
The styles that LuaGuiElement can use, indexed by name
.
Current map tick.
The number of ticks since this game was 'created'. A game is 'created' either by using "new game" or "new game from scenario".
If the tick has been paused. This means that entity update has been paused.
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.
Is the scenario finished?
Speed to update the map at. 1.0 is normal speed -- 60 UPS.
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 only iterate the array
part of the table. Iterating with ipairs()
will not work at all.
The active mods versions. The keys are mod names, the values are the versions.
for name, version in pairs(game.active_mods) do
p.print(name .. " version " .. version)
end
The players that are currently online.
This is primarily useful when you want to do some action against all online players.
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.
The default map gen settings for this save.
Determines if enemy land mines are completely invisible or not.
True by default. Can be used to disable autosaving. Make sure to turn it back on soon after.
True by default. Can be used to disable the highlighting of resource patches when they are hovered on the map.
The pollution statistics for this map.