Factorio Runtime Docs

Class LuaPlayer extends LuaControl

A player in the game. Pay attention that a player may or may not have a character, which is the LuaEntity of the little guy running around the world doing things.

Members

set_ending_screen_data(message, file?)

Setup the screen to be shown when the game is finished.

Setup the screen to be shown when the game is finished.

print(message, color?)

Print text to the chat console.

Print text to the chat console.

clear_console()

Clear the chat console.

Clear the chat console.

get_goal_description()  → LocalisedString

Get the current goal description, as a localised string.

Get the current goal description, as a localised string.

set_goal_description(text?, only_update?)

Set the text in the goal window (top left).

Set the text in the goal window (top left).

set_controller{type=…, character?=…, waypoints?=…, start_position?=…, start_zoom?=…, final_transition_time?=…, chart_mode_cutoff?=…}

Set the controller type of the player.

Set the controller type of the player.

drag_wire{position=…}  → boolean

Start/end wire dragging at the specified location, wire type is based on the cursor contents

Start/end wire dragging at the specified location, wire type is based on the cursor contents

disable_recipe_groups()

Disable recipe groups.

Disable recipe groups.

enable_recipe_groups()

Enable recipe groups.

Enable recipe groups.

disable_recipe_subgroups()

Disable recipe subgroups.

Disable recipe subgroups.

enable_recipe_subgroups()

Enable recipe subgroups.

Enable recipe subgroups.

print_entity_statistics(entities?)

Print entity statistics to the player's console.

Print entity statistics to the player's console.

print_robot_jobs()

Print construction robot job counts to the players console.

Print construction robot job counts to the players console.

print_lua_object_statistics()

Print LuaObject counts per mod.

Print LuaObject counts per mod.

log_active_entity_chunk_counts()

Logs a dictionary of chunks -> active entities for the surface this player is on.

Logs a dictionary of chunks -> active entities for the surface this player is on.

log_active_entity_counts()

Logs a dictionary of active entities -> count for the surface this player is on.

Logs a dictionary of active entities -> count for the surface this player is on.

unlock_achievement(name)

Unlock the achievements of the given player.

Unlock the achievements of the given player.

clear_cursor()  → boolean

Invokes the "clear cursor" action on the player as if the user pressed it.

Invokes the "clear cursor" action on the player as if the user pressed it.

create_character(character?)  → boolean

Creates and attaches a character entity to this player.

Creates and attaches a character entity to this player.

add_alert(entity, type)

Adds an alert to this player for the given entity of the given alert type.

Adds an alert to this player for the given entity of the given alert type.

add_custom_alert(entity, icon, message, show_on_map)

Adds a custom alert to this player.

Adds a custom alert to this player.

remove_alert{entity?=…, prototype?=…, position?=…, type?=…, surface?=…, icon?=…, message?=…}

Removes all alerts matching the given filters or if an empty filters table is given all alerts are removed.

Removes all alerts matching the given filters or if an empty filters table is given all alerts are removed.

get_alerts{entity?=…, prototype?=…, position?=…, type?=…, surface?=…}  → dictionary[uint → dictionary[defines.alert_type → array[Alert]]]

Get all alerts matching the given filters, or all alerts if no filters are given.

Get all alerts matching the given filters, or all alerts if no filters are given.

mute_alert(alert_type)  → boolean

Mutes alerts for the given alert category.

Mutes alerts for the given alert category.

unmute_alert(alert_type)  → boolean

Unmutes alerts for the given alert category.

Unmutes alerts for the given alert category.

is_alert_muted(alert_type)  → boolean

If the given alert type is currently muted.

If the given alert type is currently muted.

enable_alert(alert_type)  → boolean

Enables alerts for the given alert category.

Enables alerts for the given alert category.

disable_alert(alert_type)  → boolean

Disables alerts for the given alert category.

Disables alerts for the given alert category.

is_alert_enabled(alert_type)  → boolean

If the given alert type is currently enabled.

If the given alert type is currently enabled.

pipette_entity(entity)  → boolean

Invokes the "smart pipette" action on the player as if the user pressed it.

Invokes the "smart pipette" action on the player as if the user pressed it.

can_place_entity{name=…, position=…, direction?=…}  → boolean

Checks if this player can build the given entity at the given location on the surface the player is on.

Checks if this player can build the given entity at the given location on the surface the player is on.

can_build_from_cursor{position=…, direction?=…, alt?=…, terrain_building_size?=…, skip_fog_of_war?=…}  → boolean

Checks if this player can build what ever is in the cursor on the surface the player is on.

Checks if this player can build what ever is in the cursor on the surface the player is on.

build_from_cursor{position=…, direction?=…, alt?=…, terrain_building_size?=…, skip_fog_of_war?=…}

Builds whatever is in the cursor on the surface the player is on.

Builds whatever is in the cursor on the surface the player is on.

use_from_cursor(position)

Uses the current item in the cursor if it's a capsule or does nothing if not.

Uses the current item in the cursor if it's a capsule or does nothing if not.

play_sound{path=…, position?=…, volume_modifier?=…, override_sound_type?=…}

Play a sound for this player.

Play a sound for this player.

get_associated_characters()  → array[LuaEntity]

The characters associated with this player.

The characters associated with this player.

associate_character(character)

Associates a character with this player.

Associates a character with this player.

disassociate_character(character)

Disassociates a character from this player.

Disassociates a character from this player.

create_local_flying_text{text=…, position?=…, create_at_cursor?=…, color?=…, time_to_live?=…, speed?=…}

Spawn flying text that is only visible to this player.

Spawn flying text that is only visible to this player.

get_quick_bar_slot(index)  → LuaItemPrototype?

Gets the quick bar filter for the given slot or nil.

Gets the quick bar filter for the given slot or nil.

set_quick_bar_slot(index, filter)

Sets the quick bar filter for the given slot.

Sets the quick bar filter for the given slot.

get_active_quick_bar_page(index)  → uint8?

Gets which quick bar page is being used for the given screen page or nil if not known.

Gets which quick bar page is being used for the given screen page or nil if not known.

set_active_quick_bar_page(screen_index, page_index)

Sets which quick bar page is being used for the given screen page.

Sets which quick bar page is being used for the given screen page.

jump_to_cutscene_waypoint(waypoint_index)

Jump to the specified cutscene waypoint.

Jump to the specified cutscene waypoint.

exit_cutscene()

Exit the current cutscene.

Exit the current cutscene.

open_map(position, scale?, entity?)

Queues a request to open the map at the specified position.

Queues a request to open the map at the specified position.

zoom_to_world(position, scale?, entity?)

Queues a request to zoom to world at the specified position.

Queues a request to zoom to world at the specified position.

close_map()

Queues request to switch to the normal game view from the map or zoom to world view.

Queues request to switch to the normal game view from the map or zoom to world view.

is_shortcut_toggled(prototype_name)  → boolean

Is a custom Lua shortcut currently toggled?

Is a custom Lua shortcut currently toggled?

is_shortcut_available(prototype_name)  → boolean

Is a custom Lua shortcut currently available?

Is a custom Lua shortcut currently available?

set_shortcut_toggled(prototype_name, toggled)

Toggle or untoggle a custom Lua shortcut

Toggle or untoggle a custom Lua shortcut

set_shortcut_available(prototype_name, available)

Make a custom Lua shortcut available or unavailable.

Make a custom Lua shortcut available or unavailable.

connect_to_server{address=…, name?=…, description?=…, password?=…}

Asks the player if they would like to connect to the given server.

Asks the player if they would like to connect to the given server.

toggle_map_editor()

Toggles this player into or out of the map editor.

Toggles this player into or out of the map editor.

request_translation(localised_string)  → uint?

Requests a translation for the given localised string.

Requests a translation for the given localised string.

request_translations(localised_strings)  → array[uint]?

Requests translation for the given set of localised strings.

Requests translation for the given set of localised strings.

get_infinity_inventory_filter(index)  → InfinityInventoryFilter?

Gets the filter for this map editor infinity filters at the given index or nil if the filter index doesn't exist or is empty.

Gets the filter for this map editor infinity filters at the given index or nil if the filter index doesn't exist or is empty.

set_infinity_inventory_filter(index, filter)

Sets the filter for this map editor infinity filters at the given index.

Sets the filter for this map editor infinity filters at the given index.

clear_recipe_notifications()

Clears all recipe notifications for this player.

Clears all recipe notifications for this player.

add_recipe_notification(recipe)

Adds the given recipe to the list of recipe notifications for this player.

Adds the given recipe to the list of recipe notifications for this player.

add_to_clipboard(blueprint)

Adds the given blueprint to this player's clipboard queue.

Adds the given blueprint to this player's clipboard queue.

activate_paste()

Gets a copy of the currently selected blueprint in the clipboard queue into the player's cursor, as if the player activated Paste.

Gets a copy of the currently selected blueprint in the clipboard queue into the player's cursor, as if the player activated Paste.

start_selection(position, selection_mode)

Starts selection with selection tool from the specified position.

Starts selection with selection tool from the specified position.

clear_selection()

Clears the players selection tool selection position.

Clears the players selection tool selection position.

help()  → string

All methods and properties that this object supports.

All methods and properties that this object supports.

character [RW] :: LuaEntity?

The character attached to this player, if any.

The character attached to this player, if any.

cutscene_character [R] :: LuaEntity?

When in a cutscene; the character this player would be using once the cutscene is over, if any.

When in a cutscene; the character this player would be using once the cutscene is over, if any.

index [R] :: uint

This player's unique index in LuaGameScript::players.

This player's unique index in LuaGameScript::players.

gui [R] :: LuaGui
opened_self [R] :: boolean

true if the player opened itself.

true if the player opened itself.

controller_type [R] :: defines.controllers
stashed_controller_type [R] :: defines.controllers?

The stashed controller type, if any.

The stashed controller type, if any.

game_view_settings [RW] :: GameViewSettings

The player's game view settings.

The player's game view settings.

minimap_enabled [RW] :: boolean

true if the minimap is visible.

true if the minimap is visible.

color [RW] :: Color

The color associated with the player.

The color associated with the player.

chat_color [RW] :: Color

The color used when this player talks in game.

The color used when this player talks in game.

name [R] :: string

The player's username.

The player's username.

tag [RW] :: string

The tag that is shown after the player in chat and on the map.

The tag that is shown after the player in chat and on the map.

connected [R] :: boolean

true if the player is currently connected to the game.

true if the player is currently connected to the game.

admin [RW] :: boolean

true if the player is an admin.

true if the player is an admin.

entity_copy_source [R] :: LuaEntity?

The source entity used during entity settings copy-paste, if any.

The source entity used during entity settings copy-paste, if any.

afk_time [R] :: uint

How many ticks since the last action of this player

How many ticks since the last action of this player

online_time [R] :: uint

How many ticks did this player spend playing this save (all sessions combined)

How many ticks did this player spend playing this save (all sessions combined)

last_online [R] :: uint

At what tick this player was last online.

At what tick this player was last online.

permission_group [RW] :: LuaPermissionGroup?

The permission group this player is part of, if any.

The permission group this player is part of, if any.

mod_settings [R] :: LuaCustomTable[string → ModSetting]

The current per-player settings for the this player, indexed by prototype name.

The current per-player settings for the this player, indexed by prototype name.

ticks_to_respawn [RW] :: uint?

The number of ticks until this player will respawn.

The number of ticks until this player will respawn.

display_resolution [R] :: DisplayResolution

The display resolution for this player.

The display resolution for this player.

display_scale [R] :: double

The display scale for this player.

The display scale for this player.

blueprint_to_setup [R] :: LuaItemStack

The item stack containing a blueprint to be setup.

The item stack containing a blueprint to be setup.

render_mode [R] :: defines.render_mode

The render mode of the player, like map or zoom to world.

The render mode of the player, like map or zoom to world.

spectator [RW] :: boolean

If true, zoom-to-world noise effect will be disabled and environmental sounds will be based on zoom-to-world view instead of position of player's character.

If true, zoom-to-world noise effect will be disabled and environmental sounds will be based on zoom-to-world view instead of position of player's character.

show_on_map [RW] :: boolean

If true, circle and name of given player is rendered on the map/chart.

If true, circle and name of given player is rendered on the map/chart.

remove_unfiltered_items [RW] :: boolean

If items not included in this map editor infinity inventory filters should be removed.

If items not included in this map editor infinity inventory filters should be removed.

infinity_inventory_filters [RW] :: array[InfinityInventoryFilter]

The filters for this map editor infinity inventory settings.

The filters for this map editor infinity inventory settings.

auto_sort_main_inventory [R] :: boolean

If the main inventory will be auto sorted.

If the main inventory will be auto sorted.

hand_location [RW] :: ItemStackLocation?

The original location of the item in the cursor, marked with a hand.

The original location of the item in the cursor, marked with a hand.

cursor_stack_temporary [RW] :: boolean

Returns true if the current item stack in cursor will be destroyed after clearing the cursor.

Returns true if the current item stack in cursor will be destroyed after clearing the cursor.

drag_target [R] :: DragTarget?

The wire drag target for this player, if any.

The wire drag target for this player, if any.

zoom [W] :: double

The player's zoom-level.

The player's zoom-level.

map_view_settings [W] :: MapViewSettings

The player's map view settings.

The player's map view settings.

valid [R] :: boolean

Is this object valid?

Is this object valid?

object_name [R] :: string

The class name of this object.

The class name of this object.

Inherited from LuaControl: surface, surface_index, position, vehicle, force, force_index, selected, opened, crafting_queue_size, crafting_queue_progress, walking_state, riding_state, mining_state, shooting_state, picking_state, repair_state, cursor_stack, cursor_ghost, driving, crafting_queue, following_robots, cheat_mode, character_crafting_speed_modifier, character_mining_speed_modifier, character_additional_mining_categories, character_running_speed_modifier, character_build_distance_bonus, character_item_drop_distance_bonus, character_reach_distance_bonus, character_resource_reach_distance_bonus, character_item_pickup_distance_bonus, character_loot_pickup_distance_bonus, character_inventory_slots_bonus, character_trash_slot_count_bonus, character_maximum_following_robot_count_bonus, character_health_bonus, character_personal_logistic_requests_enabled, vehicle_logistic_requests_enabled, opened_gui_type, build_distance, drop_item_distance, reach_distance, item_pickup_distance, loot_pickup_distance, resource_reach_distance, in_combat, character_running_speed, character_mining_progress, get_inventory, get_max_inventory_index, get_main_inventory, can_insert, insert, set_gui_arrow, clear_gui_arrow, get_item_count, has_items_inside, can_reach_entity, clear_items_inside, remove_item, teleport, update_selected_entity, clear_selected_entity, disable_flashlight, enable_flashlight, is_flashlight_enabled, get_craftable_count, begin_crafting, cancel_crafting, mine_entity, mine_tile, is_player, open_technology_gui, set_personal_logistic_slot, set_vehicle_logistic_slot, get_personal_logistic_slot, get_vehicle_logistic_slot, clear_personal_logistic_slot, clear_vehicle_logistic_slot, is_cursor_blueprint, get_blueprint_entities, is_cursor_empty

Methods

set_ending_screen_data(message, file?)

Setup the screen to be shown when the game is finished.

Parameters

message :: LocalisedString

Message to be shown.

Message to be shown.

file :: string?

Path to image to be shown.

Path to image to be shown.


print(message, color?)

Print text to the chat console.

Parameters

message :: LocalisedString
color :: Color?

Note

Messages that are identical to a message sent in the last 60 ticks are not printed again.


clear_console()

Clear the chat console.


get_goal_description()  → LocalisedString

Get the current goal description, as a localised string.


set_goal_description(text?, only_update?)

Set the text in the goal window (top left).

Parameters

text :: LocalisedString?

The text to display. Lines can be delimited with \n. Passing an empty string or omitting this parameter entirely will make the goal window disappear.

The text to display. Lines can be delimited with \n. Passing an empty string or omitting this parameter entirely will make the goal window disappear.

only_update :: boolean?

When true, won't play the "goal updated" sound.

When true, won't play the "goal updated" sound.


set_controller{type=…, character?=…, waypoints?=…, start_position?=…, start_zoom?=…, final_transition_time?=…, chart_mode_cutoff?=…}

Set the controller type of the player.

Parameters

Table with the following fields:
type :: defines.controllers

Which controller to use.

Which controller to use.

character :: LuaEntity?

Entity to control. Mandatory when type is defines.controllers.character, ignored otherwise.

Entity to control. Mandatory when type is defines.controllers.character, ignored otherwise.

waypoints :: CutsceneWaypoint?

List of waypoints for the cutscene controller. This parameter is mandatory when type is defines.controllers.cutscene.

List of waypoints for the cutscene controller. This parameter is mandatory when type is defines.controllers.cutscene.

start_position :: MapPosition?

If specified and type is defines.controllers.cutscene, the cutscene will start at this position. If not given the start position will be the player position.

If specified and type is defines.controllers.cutscene, the cutscene will start at this position. If not given the start position will be the player position.

start_zoom :: double?

If specified and type is defines.controllers.cutscene, the cutscene will start at this zoom level. If not given the start zoom will be the players zoom.

If specified and type is defines.controllers.cutscene, the cutscene will start at this zoom level. If not given the start zoom will be the players zoom.

final_transition_time :: uint?

If specified and type is defines.controllers.cutscene, it is the time in ticks it will take for the camera to pan from the final waypoint back to the starting position. If not given the camera will not pan back to the start position/zoom.

If specified and type is defines.controllers.cutscene, it is the time in ticks it will take for the camera to pan from the final waypoint back to the starting position. If not given the camera will not pan back to the start position/zoom.

chart_mode_cutoff :: double?

If specified and type is defines.controllers.cutscene, the game will switch to chart-mode (map zoomed out) rendering when the zoom level is less than this value.

If specified and type is defines.controllers.cutscene, the game will switch to chart-mode (map zoomed out) rendering when the zoom level is less than this value.

Notes

Setting a player to defines.controllers.editor auto promotes the player to admin and enables cheat mode.

Setting a player to defines.controllers.editor also requires the calling player be an admin.


drag_wire{position=…}  → boolean

Start/end wire dragging at the specified location, wire type is based on the cursor contents

Parameters

Table with the following fields:
position :: MapPosition

Position at which cursor was clicked. Used only to decide which side of arithmetic combinator, decider combinator or power switch is to be connected. Entity itself to be connected is based on the player's selected entity.

Position at which cursor was clicked. Used only to decide which side of arithmetic combinator, decider combinator or power switch is to be connected. Entity itself to be connected is based on the player's selected entity.

Return values

→ boolean

true if the action did something


disable_recipe_groups()

Disable recipe groups.


enable_recipe_groups()

Enable recipe groups.


disable_recipe_subgroups()

Disable recipe subgroups.


enable_recipe_subgroups()

Enable recipe subgroups.


print_entity_statistics(entities?)

Print entity statistics to the player's console.

Parameters

entities :: array[string]?

Entity prototypes to get statistics for. If not specified or empty, display statistics for all entities.

Entity prototypes to get statistics for. If not specified or empty, display statistics for all entities.


print_robot_jobs()

Print construction robot job counts to the players console.


print_lua_object_statistics()

Print LuaObject counts per mod.


log_active_entity_chunk_counts()

Logs a dictionary of chunks -> active entities for the surface this player is on.


log_active_entity_counts()

Logs a dictionary of active entities -> count for the surface this player is on.


unlock_achievement(name)

Unlock the achievements of the given player. This has any effect only when this is the local player, the achievement isn't unlocked so far and the achievement is of the type "achievement".

Parameters

name :: string

name of the achievement to unlock

name of the achievement to unlock


clear_cursor()  → boolean

Invokes the "clear cursor" action on the player as if the user pressed it.

Return values

→ boolean

Whether the cursor is now empty.

Raised events

on_player_cursor_stack_changed? current_tick

Raised when the cursor was successfully cleared.


create_character(character?)  → boolean

Creates and attaches a character entity to this player.

Parameters

character :: string?

The character to create else the default is used.

The character to create else the default is used.

Return values

→ boolean

Whether the character was created.

Note

The player must not have a character already connected and must be online (see LuaPlayer::connected).


add_alert(entity, type)

Adds an alert to this player for the given entity of the given alert type.

Parameters

entity :: LuaEntity
type :: defines.alert_type

add_custom_alert(entity, icon, message, show_on_map)

Adds a custom alert to this player.

Parameters

entity :: LuaEntity

If the alert is clicked, the map will open at the position of this entity.

If the alert is clicked, the map will open at the position of this entity.

icon :: SignalID
message :: LocalisedString
show_on_map :: boolean

remove_alert{entity?=…, prototype?=…, position?=…, type?=…, surface?=…, icon?=…, message?=…}

Removes all alerts matching the given filters or if an empty filters table is given all alerts are removed.

Parameters

Table with the following fields:
entity :: LuaEntity?
prototype :: LuaEntityPrototype or string?
position :: MapPosition?
type :: defines.alert_type?
surface :: SurfaceIdentification?
icon :: SignalID?
message :: LocalisedString?

get_alerts{entity?=…, prototype?=…, position?=…, type?=…, surface?=…}  → dictionary[uint → dictionary[defines.alert_type → array[Alert]]]

Get all alerts matching the given filters, or all alerts if no filters are given.

Parameters

Table with the following fields:
entity :: LuaEntity?
prototype :: LuaEntityPrototype?
position :: MapPosition?
type :: defines.alert_type?
surface :: SurfaceIdentification?

Return values

→ dictionary[uint → dictionary[defines.alert_type → array[Alert]]]

A mapping of surface index to an array of arrays of alerts indexed by the alert type.


mute_alert(alert_type)  → boolean

Mutes alerts for the given alert category.

Parameters

alert_type :: defines.alert_type

Return values

→ boolean

Whether the alert type was muted (false if it was already muted).


unmute_alert(alert_type)  → boolean

Unmutes alerts for the given alert category.

Parameters

alert_type :: defines.alert_type

Return values

→ boolean

Whether the alert type was unmuted (false if it was wasn't muted).


is_alert_muted(alert_type)  → boolean

If the given alert type is currently muted.

Parameters

alert_type :: defines.alert_type

enable_alert(alert_type)  → boolean

Enables alerts for the given alert category.

Parameters

alert_type :: defines.alert_type

Return values

→ boolean

Whether the alert type was enabled (false if it was already enabled).


disable_alert(alert_type)  → boolean

Disables alerts for the given alert category.

Parameters

alert_type :: defines.alert_type

Return values

→ boolean

Whether the alert type was disabled (false if it was already disabled).


is_alert_enabled(alert_type)  → boolean

If the given alert type is currently enabled.

Parameters

alert_type :: defines.alert_type

pipette_entity(entity)  → boolean

Invokes the "smart pipette" action on the player as if the user pressed it.

Parameters

entity :: string or LuaEntity or LuaEntityPrototype

Return values

→ boolean

Whether the smart pipette found something to place.

Raised events

on_player_pipette? instantly

Raised if the entity was successfully pipetted.


can_place_entity{name=…, position=…, direction?=…}  → boolean

Checks if this player can build the given entity at the given location on the surface the player is on.

Parameters

Table with the following fields:
name :: string

Name of the entity to check.

Name of the entity to check.

position :: MapPosition

Where the entity would be placed.

Where the entity would be placed.

direction :: defines.direction?

Direction the entity would be placed. Defaults to north.

Direction the entity would be placed. Defaults to north.


can_build_from_cursor{position=…, direction?=…, alt?=…, terrain_building_size?=…, skip_fog_of_war?=…}  → boolean

Checks if this player can build what ever is in the cursor on the surface the player is on.

Parameters

Table with the following fields:
position :: MapPosition

Where the entity would be placed

Where the entity would be placed

direction :: defines.direction?

Direction the entity would be placed

Direction the entity would be placed

alt :: boolean?

If alt build should be used instead of normal build. Defaults to normal.

If alt build should be used instead of normal build. Defaults to normal.

terrain_building_size :: uint?

The size for building terrain if building terrain. Defaults to 2.

The size for building terrain if building terrain. Defaults to 2.

skip_fog_of_war :: boolean?

If chunks covered by fog-of-war are skipped.

If chunks covered by fog-of-war are skipped.


build_from_cursor{position=…, direction?=…, alt?=…, terrain_building_size?=…, skip_fog_of_war?=…}

Builds whatever is in the cursor on the surface the player is on. The cursor stack will automatically be reduced as if the player built normally.

Parameters

Table with the following fields:
position :: MapPosition

Where the entity would be placed

Where the entity would be placed

direction :: defines.direction?

Direction the entity would be placed

Direction the entity would be placed

alt :: boolean?

If alt build should be used instead of normal build. Defaults to normal.

If alt build should be used instead of normal build. Defaults to normal.

terrain_building_size :: uint?

The size for building terrain if building terrain. Defaults to 2.

The size for building terrain if building terrain. Defaults to 2.

skip_fog_of_war :: boolean?

If chunks covered by fog-of-war are skipped.

If chunks covered by fog-of-war are skipped.

Raised events

on_pre_build? instantly

Raised if the cursor was successfully built.

on_built_entity? instantly

Raised if the cursor was successfully built.


use_from_cursor(position)

Uses the current item in the cursor if it's a capsule or does nothing if not.

Parameters

position :: MapPosition

Where the item would be used.

Where the item would be used.


play_sound{path=…, position?=…, volume_modifier?=…, override_sound_type?=…}

Play a sound for this player.

Parameters

Table with the following fields:
path :: SoundPath

The sound to play.

The sound to play.

position :: MapPosition?

Where the sound should be played. If not given, it's played at the current position of the player.

Where the sound should be played. If not given, it's played at the current position of the player.

volume_modifier :: double?

The volume of the sound to play. Must be between 0 and 1 inclusive.

The volume of the sound to play. Must be between 0 and 1 inclusive.

override_sound_type :: SoundType?

The volume mixer to play the sound through. Defaults to the default mixer for the given sound type.

The volume mixer to play the sound through. Defaults to the default mixer for the given sound type.


get_associated_characters()  → array[LuaEntity]

The characters associated with this player.

Notes

The array will always be empty when the player is disconnected (see LuaPlayer::connected) regardless of there being associated characters.

Characters associated with this player will be logged off when this player disconnects but are not controlled by any player.


associate_character(character)

Associates a character with this player.

Parameters

character :: LuaEntity

The character entity.

The character entity.

Notes

The character must not be connected to any controller.

If this player is currently disconnected (see LuaPlayer::connected) the character will be immediately "logged off".

See LuaPlayer::get_associated_characters for more information.


disassociate_character(character)

Disassociates a character from this player. This is functionally the same as setting LuaEntity::associated_player to nil.

Parameters

character :: LuaEntity

The character entity

The character entity

Note

See LuaPlayer::get_associated_characters for more information.


create_local_flying_text{text=…, position?=…, create_at_cursor?=…, color?=…, time_to_live?=…, speed?=…}

Spawn flying text that is only visible to this player. Either position or create_at_cursor are required. When create_at_cursor is true, all parameters other than text are ignored.

Parameters

Table with the following fields:
text :: LocalisedString

The flying text to show.

The flying text to show.

position :: MapPosition?

The location on the map at which to show the flying text.

The location on the map at which to show the flying text.

create_at_cursor :: boolean?

If true, the flying text is created at the player's cursor. Defaults to false.

If true, the flying text is created at the player's cursor. Defaults to false.

color :: Color?

The color of the flying text. Defaults to white text.

The color of the flying text. Defaults to white text.

time_to_live :: uint?

The amount of ticks that the flying text will be shown for. Defaults to 80.

The amount of ticks that the flying text will be shown for. Defaults to 80.

speed :: double?

The speed at which the text rises upwards in tiles/second. Can't be a negative value.

The speed at which the text rises upwards in tiles/second. Can't be a negative value.

Notes

If no custom speed is set and the text is longer than 25 characters, its time_to_live and speed are dynamically adjusted to give players more time to read it.

Local flying text is not saved, which means it will disappear after a save/load-cycle.


get_quick_bar_slot(index)  → LuaItemPrototype?

Gets the quick bar filter for the given slot or nil.

Parameters

index :: uint

The slot index. 1 for the first slot of page one, 2 for slot two of page one, 11 for the first slot of page 2, etc.

The slot index. 1 for the first slot of page one, 2 for slot two of page one, 11 for the first slot of page 2, etc.


set_quick_bar_slot(index, filter)

Sets the quick bar filter for the given slot.

Parameters

index :: uint

The slot index. 1 for the first slot of page one, 2 for slot two of page one, 11 for the first slot of page 2, etc.

The slot index. 1 for the first slot of page one, 2 for slot two of page one, 11 for the first slot of page 2, etc.

filter :: string or LuaItemPrototype or LuaItemStack

The filter or nil.

The filter or nil.


get_active_quick_bar_page(index)  → uint8?

Gets which quick bar page is being used for the given screen page or nil if not known.

Parameters

index :: uint

The screen page. Index 1 is the top row in the gui. Index can go beyond the visible number of bars on the screen to account for the interface config setting change.

The screen page. Index 1 is the top row in the gui. Index can go beyond the visible number of bars on the screen to account for the interface config setting change.


set_active_quick_bar_page(screen_index, page_index)

Sets which quick bar page is being used for the given screen page.

Parameters

screen_index :: uint

The screen page. Index 1 is the top row in the gui. Index can go beyond the visible number of bars on the screen to account for the interface config setting change.

The screen page. Index 1 is the top row in the gui. Index can go beyond the visible number of bars on the screen to account for the interface config setting change.

page_index :: uint

The new quick bar page.

The new quick bar page.


jump_to_cutscene_waypoint(waypoint_index)

Jump to the specified cutscene waypoint. Only works when the player is viewing a cutscene.

Parameters

waypoint_index :: uint

exit_cutscene()

Exit the current cutscene. Errors if not in a cutscene.


open_map(position, scale?, entity?)

Queues a request to open the map at the specified position. If the map is already opened, the request will simply set the position, scale, and entity to follow. Render mode change requests are processed before rendering of the next frame.

Parameters

position :: MapPosition
scale :: double?
entity :: LuaEntity?

The entity to follow. If not given the current entity being followed will be cleared.

The entity to follow. If not given the current entity being followed will be cleared.


zoom_to_world(position, scale?, entity?)

Queues a request to zoom to world at the specified position. If the player is already zooming to world, the request will simply set the position, scale, and entity to follow. Render mode change requests are processed before rendering of the next frame.

Parameters

position :: MapPosition
scale :: double?
entity :: LuaEntity?

The entity to follow. If not given the current entity being followed will be cleared.

The entity to follow. If not given the current entity being followed will be cleared.


close_map()

Queues request to switch to the normal game view from the map or zoom to world view. Render mode change requests are processed before rendering of the next frame.


is_shortcut_toggled(prototype_name)  → boolean

Is a custom Lua shortcut currently toggled?

Parameters

prototype_name :: string

Prototype name of the custom shortcut.

Prototype name of the custom shortcut.


is_shortcut_available(prototype_name)  → boolean

Is a custom Lua shortcut currently available?

Parameters

prototype_name :: string

Prototype name of the custom shortcut.

Prototype name of the custom shortcut.


set_shortcut_toggled(prototype_name, toggled)

Toggle or untoggle a custom Lua shortcut

Parameters

prototype_name :: string

Prototype name of the custom shortcut.

Prototype name of the custom shortcut.

toggled :: boolean

set_shortcut_available(prototype_name, available)

Make a custom Lua shortcut available or unavailable.

Parameters

prototype_name :: string

Prototype name of the custom shortcut.

Prototype name of the custom shortcut.

available :: boolean

connect_to_server{address=…, name?=…, description?=…, password?=…}

Asks the player if they would like to connect to the given server.

Parameters

Table with the following fields:
address :: string

The server (address:port) if port is not given the default Factorio port is used.

The server (address:port) if port is not given the default Factorio port is used.

name :: LocalisedString?

The name of the server.

The name of the server.

description :: LocalisedString?
password :: string?

The password if different from the one used to join this game. Note, if the current password is not empty but the one required to join the new server is an empty string should be given for this field.

The password if different from the one used to join this game. Note, if the current password is not empty but the one required to join the new server is an empty string should be given for this field.

Note

This only does anything when used on a multiplayer peer. Single player and server hosts will ignore the prompt.


toggle_map_editor()

Toggles this player into or out of the map editor. Does nothing if this player isn't an admin or if the player doesn't have permission to use the map editor.

Raised events

on_pre_player_toggled_map_editor? instantly

Raised if the map editor was successfully toggled.

on_player_toggled_map_editor? instantly

Raised if the map editor was successfully toggled.


request_translation(localised_string)  → uint?

Requests a translation for the given localised string. If the request is successful, the on_string_translated event will be fired with the results.

Parameters

localised_string :: LocalisedString

Return values

→ uint?

The unique ID for the requested translation.

Raised events

on_string_translated? future_tick

Raised if the request was successfully sent.

Note

Does nothing if this player is not connected (see LuaPlayer::connected).


request_translations(localised_strings)  → array[uint]?

Requests translation for the given set of localised strings. If the request is successful, a on_string_translated event will be fired for each string with the results.

Parameters

localised_strings :: array[LocalisedString]

Return values

→ array[uint]?

The unique IDs for the requested translations.

Raised events

on_string_translated? future_tick

Raised if the request was successfully sent.

Note

Does nothing if this player is not connected (see LuaPlayer::connected).


get_infinity_inventory_filter(index)  → InfinityInventoryFilter?

Gets the filter for this map editor infinity filters at the given index or nil if the filter index doesn't exist or is empty.

Parameters

index :: uint

The index to get.

The index to get.


set_infinity_inventory_filter(index, filter)

Sets the filter for this map editor infinity filters at the given index.

Parameters

index :: uint

The index to set.

The index to set.

filter :: InfinityInventoryFilter or nil

The new filter or nil to clear the filter.

The new filter or nil to clear the filter.


clear_recipe_notifications()

Clears all recipe notifications for this player.


add_recipe_notification(recipe)

Adds the given recipe to the list of recipe notifications for this player.

Parameters

recipe :: string

Name of the recipe prototype to add.

Name of the recipe prototype to add.


add_to_clipboard(blueprint)

Adds the given blueprint to this player's clipboard queue.

Parameters

blueprint :: LuaItemStack

The blueprint to add.

The blueprint to add.


activate_paste()

Gets a copy of the currently selected blueprint in the clipboard queue into the player's cursor, as if the player activated Paste.


start_selection(position, selection_mode)

Starts selection with selection tool from the specified position. Does nothing if the players cursor is not a selection tool.

Parameters

position :: MapPosition

The position to start selection from.

The position to start selection from.

selection_mode :: string

The type of selection to start. Can be select, alternative-select, reverse-select.

The type of selection to start. Can be select, alternative-select, reverse-select.


clear_selection()

Clears the players selection tool selection position.


help()  → string

All methods and properties that this object supports.

Attributes

character :: LuaEntity? Read/Write

The character attached to this player, if any. Returns nil when the player is disconnected (see LuaPlayer::connected).


cutscene_character :: LuaEntity? Read

When in a cutscene; the character this player would be using once the cutscene is over, if any. Returns nil when the player is disconnected (see LuaPlayer::connected).


index :: uint Read

This player's unique index in LuaGameScript::players. It is given to them when they are created and remains assigned to them until they are removed.


gui :: LuaGui Read


opened_self :: boolean Read

true if the player opened itself. I.e. if they opened the character or god-controller GUI.


controller_type :: defines.controllers Read


stashed_controller_type :: defines.controllers? Read

The stashed controller type, if any.

Note

This is mainly useful when a player is in the map editor.


game_view_settings :: GameViewSettings Read/Write

The player's game view settings.


minimap_enabled :: boolean Read/Write

true if the minimap is visible.


color :: Color Read/Write

The color associated with the player. This will be used to tint the player's character as well as their buildings and vehicles.


chat_color :: Color Read/Write

The color used when this player talks in game.


name :: string Read

The player's username.


tag :: string Read/Write

The tag that is shown after the player in chat and on the map.


connected :: boolean Read

true if the player is currently connected to the game.


admin :: boolean Read/Write

true if the player is an admin.

Note

Trying to change player admin status from the console when you aren't an admin does nothing.


entity_copy_source :: LuaEntity? Read

The source entity used during entity settings copy-paste, if any.


afk_time :: uint Read

How many ticks since the last action of this player


online_time :: uint Read

How many ticks did this player spend playing this save (all sessions combined)


last_online :: uint Read

At what tick this player was last online.


permission_group :: LuaPermissionGroup? Read/Write

The permission group this player is part of, if any.


mod_settings :: LuaCustomTable[string → ModSetting] Read

The current per-player settings for the this player, indexed by prototype name. Returns the same structure as LuaSettings::get_player_settings.

Note

This table will become invalid if its associated player does.


ticks_to_respawn :: uint? Read/Write

The number of ticks until this player will respawn. nil if this player is not waiting to respawn.

Set to nil to immediately respawn the player.

Note

Set to any positive value to trigger the respawn state for this player.


display_resolution :: DisplayResolution Read

The display resolution for this player.

Note

During on_player_created, this attribute will always return a resolution of {width=1920, height=1080}. To get the actual resolution, listen to the on_player_display_resolution_changed event raised shortly afterwards.


display_scale :: double Read

The display scale for this player.

Note

During on_player_created, this attribute will always return a scale of 1. To get the actual scale, listen to the on_player_display_scale_changed event raised shortly afterwards.


blueprint_to_setup :: LuaItemStack Read

The item stack containing a blueprint to be setup.


render_mode :: defines.render_mode Read

The render mode of the player, like map or zoom to world. The render mode can be set using LuaPlayer::open_map, LuaPlayer::zoom_to_world and LuaPlayer::close_map.


spectator :: boolean Read/Write

If true, zoom-to-world noise effect will be disabled and environmental sounds will be based on zoom-to-world view instead of position of player's character.


show_on_map :: boolean Read/Write

If true, circle and name of given player is rendered on the map/chart.


remove_unfiltered_items :: boolean Read/Write

If items not included in this map editor infinity inventory filters should be removed.


infinity_inventory_filters :: array[InfinityInventoryFilter] Read/Write

The filters for this map editor infinity inventory settings.


auto_sort_main_inventory :: boolean Read

If the main inventory will be auto sorted.


hand_location :: ItemStackLocation? Read/Write

The original location of the item in the cursor, marked with a hand. nil if the cursor stack is empty. When writing, the specified inventory slot must be empty and the cursor stack must not be empty.


cursor_stack_temporary :: boolean Read/Write

Returns true if the current item stack in cursor will be destroyed after clearing the cursor. Manually putting it into inventory still preserves the item. If the cursor stack is not one of the supported types (blueprint, blueprint-book, deconstruction-planner, upgrade-planner), write operation will be silently ignored.


drag_target :: DragTarget? Read

The wire drag target for this player, if any.


zoom :: double Write

The player's zoom-level.


map_view_settings :: MapViewSettings Write

The player's map view settings. To write to this, use a table containing the fields that should be changed.


valid :: boolean Read

Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.


object_name :: string Read

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.

Classes

Events

Concepts

Defines

Builtin types

>|