LuaPlayer

class LuaPlayer extends LuaControl - sort
set_ending_screen_data(message, file) Setup the screen to be shown when the game is finished.
print(message, color) Print text to the chat console.
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).
set_controller{type=…, character=…, waypoints=…, final_transition_time=…} Set the controller type of the player.
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.
print_robot_jobs() Print construction robot job counts to the players console.
print_lua_object_statistics() Print LuaObject counts per mod.
unlock_achievement(name) Unlock the achievements of the given player.
clean_cursor() → boolean Invokes the "clean cursor" action on the player as if the user pressed it.
create_character(character) → boolean 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.
add_custom_alert(entity, icon, message, show_on_map) 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.
get_alerts{entity=…, prototype=…, position=…, type=…, surface=…} → dictionary uintdictionary defines.alert_typearray of alert Gets all alerts matching the given filters or if no filters are given all alerts are returned.
mute_alert(alert_type) → boolean Mutes alerts for the given alert category.
unmute_alert(alert_type) → boolean Unmutes alerts for the given alert category.
is_alert_muted(alert_type) → boolean If the given alert type is currently muted.
enable_alert(alert_type) → boolean Enables alerts for the given alert category.
disable_alert(alert_type) → boolean Disables alerts for the given alert category.
is_alert_enabled(alert_type) → boolean 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.
can_place_entity{name=…, position=…, direction=…} → boolean Checks if this player can build the give 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.
build_from_cursor{position=…, direction=…, alt=…, terrain_building_size=…, skip_fog_of_war=…} Builds what ever 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.
play_sound{path=…, position=…, volume_modifier=…} → boolean Plays a sound for this player
get_associated_characters() → array of LuaEntity The characters associated with this player.
associate_character(character) Associates a character with this player.
disassociate_character(character) Disassociates a character from this player.
create_local_flying_text{text=…, position=…, color=…, time_to_live=…, speed=…} Spawn a 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.
set_quick_bar_slot(index, filter) 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.
set_active_quick_bar_page(screen_index, page_index) 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.
exit_cutscene() Exit the current cutscene.
open_map(position, scale) Queues a request to open the map at the specified position.
zoom_to_world(position, scale) 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.
is_shortcut_toggled(prototype_name) → boolean Is a custom shortcut currently toggled?
is_shortcut_available(prototype_name) → boolean Is a custom shortcut currently available?
set_shortcut_toggled(prototype_name, toggled) Toggle or untoggle a custom shortcut
set_shortcut_available(prototype_name, available) Make a custom shortcut available or unavailable.
connect_to_server{address=…, name=…, description=…, password=…} Asks the player if they would like to connect to the given server.
character :: LuaEntity [RW] The character attached to this player, or nil if no character.
index :: uint [R] This player's index in LuaGameScript::players.
gui :: LuaGui [R]
opened_self :: boolean [R] true if the player opened itself.
controller_type :: defines.controllers [R]
game_view_settings :: GameViewSettings [RW] The player's game view settings.
minimap_enabled :: boolean [RW] true if the minimap is visible.
color :: Color [RW] The color associated with the player.
chat_color :: Color [RW] The color used when this player talks in game.
name :: string [RW] The player's username.
tag :: string [RW] The tag that is shown after the player in chat and on the map.
connected :: boolean [R] true if the player is currently connected to the game.
admin :: boolean [RW] true if the player is an admin.
entity_copy_source :: LuaEntity [R] The source entity used during entity settings copy-paste if any.
afk_time :: uint [R] How many ticks since the last action of this player
online_time :: uint [R] How many ticks did this player spend playing this save (all sessions combined)
last_online :: uint [R] At what tick this player was last online.
permission_group :: LuaPermissionGroup [RW] The permission group this player is part of or nil if not part of any group.
mod_settings [R]
ticks_to_respawn :: uint [RW] The number of ticks until this player will respawn or nil if not waiting to respawn.
display_resolution :: DisplayResolution [R] The display resolution for this player.
display_scale :: double [R] The display scale for this player.
blueprint_to_setup :: LuaItemStack [R] The item stack containing a blueprint to be setup.
render_mode :: defines.render_mode [R] The render mode of the player, like map or zoom to world.
spectator :: boolean [RW] 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.
zoom :: double [W] The player's zoom-level.
map_view_settings :: MapViewSettings [W] The player's map view settings.
valid :: boolean [R] Is this object valid?
help() → string All methods, and properties that this object supports.

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.

set_ending_screen_data(message, file)

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

Parameters
message :: LocalisedString: Message to be shown.
file :: string (optional): Path to image to be shown.
print(message, color)

Print text to the chat console.

Parameters
message :: LocalisedString
color :: Color (optional)
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 (optional): The text to display. \n can be used to delimit lines. Passing empty string or omitting this parameter entirely will make the goal window disappear.
only_update :: boolean (optional): When true, won't play the "goal updated" sound.
set_controller{type=…, character=…, waypoints=…, final_transition_time=…}

Set the controller type of the player.

Parameters
Table with the following fields:
  • type :: defines.controllers: Which controller to use
  • character :: LuaEntity (optional): Entity to control. Mandatory when type is defines.controllers.character, ignored otherwise.
  • waypoints (optional): List of waypoints for the cutscene controller. This parameter is mandatory when type is defines.controllers.cutscene. Each waypoint is a table:
    • position :: Position (optional): Position to pan the camera to.
    • target :: LuaEntity or LuaUnitGroup (optional): Entity or unit group to pan the camera to.
    • transition_time :: uint: How many ticks it will take to reach this waypoint from the previous one.
    • time_to_wait :: uint: Time in ticks to wait before moving to the next waypoint.
    • zoom :: double (optional): Zoom level to be set when the waypoint is reached. When not specified, the previous waypoint's zoom is used.
    • chart_mode_cutoff :: double (optional): If specified, the game will switch to chart-mode (map zoomed out) rendering when the zoom level is less than this value.
  • final_transition_time :: uint (optional): Mandatory when 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.
Note: Setting a player to defines.controllers.editor auto promotes the player to admin and enables cheat mode.
Note: Setting a player to defines.controllers.editor also requires the calling player be an admin.
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 of string (optional): 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.

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
clean_cursor() → boolean

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

Return value
If the cursor is now empty.
create_character(character) → boolean

Creates and attaches a character entity to this player.

Parameters
character :: string (optional): The character to create else the default is used.
Return value
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
add_custom_alert(entity, icon, message, show_on_map)

Adds a custom alert to this player.

Parameters
entity :: LuaEntity
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:
get_alerts{entity=…, prototype=…, position=…, type=…, surface=…} → dictionary uintdictionary defines.alert_typearray of alert

Gets all alerts matching the given filters or if no filters are given all alerts are returned.

A mapping of surface index to an array of arrays of alerts indexed by the alert type. An alert is a table:

  • target :: LuaEntity (optional)
  • prototype :: LuaEntityPrototype (optional)
  • position :: Position (optional)
  • tick :: uint: The tick this alert was created
  • icon :: SignalID (optional): The SignalID used for a custom alert. Only present for custom alerts.
  • message :: LocalisedString (optional): The message for a custom alert. Only present for custom alerts.

Parameters
Table with the following fields:
mute_alert(alert_type) → boolean

Mutes alerts for the given alert category.

Parameters
alert_type :: defines.alert_type
Return value
If 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 value
If 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 value
If 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 value
If 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
Return value
If the smart pipette found something to place
can_place_entity{name=…, position=…, direction=…} → boolean

Checks if this player can build the give 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
  • position :: Position: Where the entity would be placed
  • direction :: defines.direction (optional): Direction the entity would be placed
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 :: Position: Where the entity would be placed
  • direction :: defines.direction (optional): Direction the entity would be placed
  • alt :: boolean (optional): If alt build should be used instead of normal build. Defaults to normal.
  • terrain_building_size :: uint (optional): The size for building terrain if building terrain. Defaults to 2.
  • skip_fog_of_war :: boolean (optional): If chunks covered by fog-of-war are skipped.
build_from_cursor{position=…, direction=…, alt=…, terrain_building_size=…, skip_fog_of_war=…}

Builds what ever is in the cursor on the surface the player is on.

Parameters
Table with the following fields:
  • position :: Position: Where the entity would be placed
  • direction :: defines.direction (optional): Direction the entity would be placed
  • alt :: boolean (optional): If alt build should be used instead of normal build. Defaults to normal.
  • terrain_building_size :: uint (optional): The size for building terrain if building terrain. Defaults to 2.
  • skip_fog_of_war :: boolean (optional): If chunks covered by fog-of-war are skipped.
Note: Anything built will fire normal player-built events.
Note: The cursor stack will automatically be reduced as if the player built normally.
use_from_cursor(position)

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

Parameters
position :: Position: Where the item would be used.
play_sound{path=…, position=…, volume_modifier=…} → boolean

Plays a sound for this player

Parameters
Table with the following fields:
  • path :: SoundPath: The sound to play
  • position :: Position (optional): Where the sound should be played. If not given it's played 'everywhere'.
  • volume_modifier :: double (optional): Must be between 0 and 1 inclusive.
get_associated_characters() → array of LuaEntity

The characters associated with this player.

Note: The array will always be empty when the player is disconnected (see LuaPlayer::connected) regardless of there being associated characters.
Note: 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.
Note: The character must not be connected to any controller.
Note: If this player is currently disconnected (see LuaPlayer::connected) the character will be immediately "logged off".
Note: 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
Note: See LuaPlayer::get_associated_characters for more information.
create_local_flying_text{text=…, position=…, color=…, time_to_live=…, speed=…}

Spawn a flying text that is only visible to this player.

Parameters
Table with the following fields:
Note: Local flying text is not saved, this means it will disappear after save/load.
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.
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.
filter :: string or LuaItemPrototype or LuaItemStack: 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.
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.
page_index :: uint: 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)

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

Parameters
position :: Position
scale :: double (optional)
zoom_to_world(position, scale)

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 (and scale). Render mode change requests are processed before rendering of the next frame.

Parameters
position :: Position
scale :: double (optional)
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 shortcut currently toggled?

Parameters
prototype_name :: string: Prototype name of the custom shortcut.
is_shortcut_available(prototype_name) → boolean

Is a custom shortcut currently available?

Parameters
prototype_name :: string: Prototype name of the custom shortcut.
set_shortcut_toggled(prototype_name, toggled)

Toggle or untoggle a custom shortcut

Parameters
prototype_name :: string: Prototype name of the custom shortcut.
toggled :: boolean
set_shortcut_available(prototype_name, available)

Make a custom shortcut available or unavailable.

Parameters
prototype_name :: string: 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.
  • name :: LocalisedString (optional): The name of the server.
  • description :: LocalisedString (optional)
  • password :: string (optional): 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.
character :: LuaEntity [Read-Write]

The character attached to this player, or nil if no character.

Note: Will also return nil when the player is disconnected (see LuaPlayer::connected).
index :: uint [Read-only]

This player's index in LuaGameScript::players.

gui :: LuaGui [Read-only]

opened_self :: boolean [Read-only]

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

controller_type :: defines.controllers [Read-only]

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-Write]

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-only]

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-only]

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

nil if there isn't currently a source entity.

afk_time :: uint [Read-only]

How many ticks since the last action of this player

online_time :: uint [Read-only]

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

last_online :: uint [Read-only]

At what tick this player was last online.

permission_group :: LuaPermissionGroup [Read-Write]

The permission group this player is part of or nil if not part of any group.

mod_settings [Read-only]

Note: This can become invalid if during operation this player becomes invalid.
ticks_to_respawn :: uint [Read-Write]

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

Note: 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-only]

The display resolution for this player.

display_scale :: double [Read-only]

The display scale for this player.

blueprint_to_setup :: LuaItemStack [Read-only]

The item stack containing a blueprint to be setup.

render_mode :: defines.render_mode [Read-only]

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.

zoom :: double [Write-only]

The player's zoom-level.

map_view_settings :: MapViewSettings [Write-only]

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