Home

LuaPlayer

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.

Parent

Attributes

physical_surface

The surface this player's physical controller is on.

physical_surface_index

Unique ID associated with the surface this player's physical controller is currently on.

physical_position

The current position of this player's physical controller.

physical_vehicle

The current vehicle of this player's physical controller.

character

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

cutscene_character

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

This player's index in LuaGameScript::players (unique ID). It is assigned when a player is created, and remains so (even when the player is not connected) until the player is irreversibly removed. Indexes of removed players can be reused.

gui

opened_self

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

controller_type

physical_controller_type

The player's "physical" controller. When a player is in the remote controller, this specifies the controller they will return to. When the player is not in the remote controller, this is equivalent to LuaPlayer::controller_type.

stashed_controller_type

The stashed controller type, if any. This is mainly useful when a player is in the map editor.

spidertron_remote_selection

All SpiderVehicles currently selected by the player, if they are holding a spidertron remote.

zoom

The current player controller's zoom level. Must be positive. The baseline zoom level is 1. Values greater than 1 will zoom in closer to the world and values between 0 and 1 will zoom out away from the world.

Writing values outside the current zoom limits is always valid, but read values will always be clamped to the range defined by LuaPlayer::zoom_limits.

zoom_limits

The player's current controller's zoom limits.

Reading this field creates a copy, so modifying the returned table's fields directly will not alter the player's zoom limits. To change the zoom limits for the player's current controller, set the entire field to the desired ZoomLimits table.

Zoom limits are defined and remembered per controller type. If you set the zoom limits of the character controller, then every time the player uses the character controller, it will remember and use the zoom limits previously set. However, other controller types will not use the character controller zoom limits; each controller type must have its zoom limits defined separately.

To set the zoom limits of ANY controller type, not just the currently active one, use LuaPlayer::set_zoom_limits.

centered_on

The entity being centered on in remote view.

When writing, the player will be switched to remote view (if not already in it) and centered on the given entity.

game_view_settings

The player's game view settings.

minimap_enabled

true if the minimap is visible.

color

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

The color used when this player talks in game.

name

The player's username.

tag

The tag that is shown after the player in chat, on the map and above multiplayer selection rectangles.

connected

true if the player is currently connected to the game.

admin

true if the player is an admin.

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

entity_copy_source

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

afk_time

How many ticks since the last action of this player.

online_time

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

last_online

At what tick this player was last online.

permission_group

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

mod_settings

The current per-player settings for the this player, indexed by prototype name. Returns the same structure as LuaSettings::get_player_settings. This table becomes invalid if its associated player does.

Even though this attribute is marked as read-only, individual settings can be changed by overwriting their ModSetting table. Mods can only change their own settings. Using the in-game console, all player settings can be changed.

ticks_to_respawn

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.

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

display_resolution

The display resolution for this player.

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

The display scale for this player.

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.

display_density_scale

The display density scale for this player. The display density scale is the factor of LuaPlayer::display_scale that is determined by the physical DPI of the screen that Factorio is running on. In most cases, the default value is 1. If the player is playing on a high-density display, this value may be 2 or greater.

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

locale

The active locale for this player.

During on_player_created, this attribute will be en. To get the actual value, listen to the on_player_locale_changed event raised shortly afterwards.

blueprint_to_setup

The item stack containing a blueprint to be setup.

blueprints

Records contained in the player's blueprint library.

render_mode

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

input_method

The input method of the player, mouse and keyboard or game controller

spectator

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

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

remove_unfiltered_items

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

infinity_inventory_filters

The filters for this map editor infinity inventory settings.

auto_sort_main_inventory

If the main inventory will be auto sorted.

hand_location

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

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.

undo_redo_stack

The undo and redo stack for this player.

drag_target

The wire drag target for this player, if any.

map_view_settings

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

valid

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

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.

Methods

set_ending_screen_data

LuaPlayer.set_ending_screen_data(message: LocalisedString, file?: string)

Call As

player.set_ending_screen_data(message, file)

Call Convention

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

Parameters

print

LuaPlayer.print(message: LocalisedString, print_settings?: PrintSettings)

Call As

player.print(message, print_settings)

Call Convention

Print text to the chat console.

By default, messages that are identical to a message sent in the last 60 ticks are not printed again.

Parameters

clear_console

LuaPlayer.clear_console()

Call As

player.clear_console()

Call Convention

Clear the chat console.

get_goal_description

LuaPlayer.get_goal_description() -> LocalisedString

Call As

player.get_goal_description()

Call Convention

Get the current goal description, as a localised string.

Returns

set_goal_description

LuaPlayer.set_goal_description(text?: LocalisedString, only_update?: boolean)

Call As

player.set_goal_description()

Call Convention

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

Parameters

set_controller

LuaPlayer.set_controller{ type: defines.controllers, character?: LuaEntity, waypoints?: Array<CutsceneWaypoint>, start_position?: MapPosition, start_zoom?: double, final_transition_time?: uint32, chart_mode_cutoff?: double, position?: MapPosition, surface?: SurfaceIdentification }

Call As

player.set_controller{ type=type }

Call Convention

Set the controller type of the player.

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.

Parameters

drag_wire

LuaPlayer.drag_wire{ position: MapPosition } -> boolean

Call As

player.drag_wire{ position=position }

Call Convention

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

Parameters

Returns

disable_recipe_groups

LuaPlayer.disable_recipe_groups()

Call As

player.disable_recipe_groups()

Call Convention

Disable recipe groups.

enable_recipe_groups

LuaPlayer.enable_recipe_groups()

Call As

player.enable_recipe_groups()

Call Convention

Enable recipe groups.

disable_recipe_subgroups

LuaPlayer.disable_recipe_subgroups()

Call As

player.disable_recipe_subgroups()

Call Convention

Disable recipe subgroups.

enable_recipe_subgroups

LuaPlayer.enable_recipe_subgroups()

Call As

player.enable_recipe_subgroups()

Call Convention

Enable recipe subgroups.

print_entity_statistics

LuaPlayer.print_entity_statistics(entities?: Array<EntityWithQualityID>)

Call As

player.print_entity_statistics()

Call Convention

Print entity statistics to the player's console.

Parameters

print_robot_jobs

LuaPlayer.print_robot_jobs()

Call As

player.print_robot_jobs()

Call Convention

Print construction robot job counts to the player's console.

print_lua_object_statistics

LuaPlayer.print_lua_object_statistics()

Call As

player.print_lua_object_statistics()

Call Convention

Print LuaObject counts per mod.

unlock_achievement

LuaPlayer.unlock_achievement(name: string)

Call As

player.unlock_achievement(name)

Call Convention

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

clear_cursor

LuaPlayer.clear_cursor() -> boolean

Call As

player.clear_cursor()

Call Convention

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

Returns

create_character

LuaPlayer.create_character(character?: EntityWithQualityID) -> boolean

Call As

player.create_character()

Call Convention

Creates and attaches a character entity to this player.

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

Parameters

Returns

add_alert

LuaPlayer.add_alert(entity: LuaEntity, type: defines.alert_type)

Call As

player.add_alert(entity, type)

Call Convention

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

Parameters

add_custom_alert

LuaPlayer.add_custom_alert(entity: LuaEntity, icon: SignalID, message: LocalisedString, show_on_map: boolean)

Call As

player.add_custom_alert(entity, icon, message, true)

Call Convention

Adds a custom alert to this player.

Parameters

remove_alert

LuaPlayer.remove_alert{ entity?: LuaEntity, prototype?: EntityID, position?: MapPosition, type?: defines.alert_type, surface?: SurfaceIdentification, icon?: SignalID, message?: LocalisedString }

Call As

player.remove_alert{ entity=entity }

Call Convention

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

Parameters

get_alerts

LuaPlayer.get_alerts{ entity?: LuaEntity, prototype?: LuaEntityPrototype, position?: MapPosition, type?: defines.alert_type, surface?: SurfaceIdentification } -> Dict<uint32, Dict<defines.alert_type, Array<Alert>>>

Call As

player.get_alerts{ entity=entity }

Call Convention

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

Parameters

Returns

mute_alert

LuaPlayer.mute_alert(alert_type: defines.alert_type) -> boolean

Call As

player.mute_alert(alert_type)

Call Convention

Mutes alerts for the given alert category.

Parameters

Returns

unmute_alert

LuaPlayer.unmute_alert(alert_type: defines.alert_type) -> boolean

Call As

player.unmute_alert(alert_type)

Call Convention

Unmutes alerts for the given alert category.

Parameters

Returns

is_alert_muted

LuaPlayer.is_alert_muted(alert_type: defines.alert_type) -> boolean

Call As

player.is_alert_muted(alert_type)

Call Convention

If the given alert type is currently muted.

Parameters

Returns

enable_alert

LuaPlayer.enable_alert(alert_type: defines.alert_type) -> boolean

Call As

player.enable_alert(alert_type)

Call Convention

Enables alerts for the given alert category.

Parameters

Returns

disable_alert

LuaPlayer.disable_alert(alert_type: defines.alert_type) -> boolean

Call As

player.disable_alert(alert_type)

Call Convention

Disables alerts for the given alert category.

Parameters

Returns

is_alert_enabled

LuaPlayer.is_alert_enabled(alert_type: defines.alert_type) -> boolean

Call As

player.is_alert_enabled(alert_type)

Call Convention

If the given alert type is currently enabled.

Parameters

Returns

add_pin

LuaPlayer.add_pin{ label?: string, preview_distance?: uint16, always_visible?: boolean, entity?: LuaEntity, player?: PlayerIdentification, surface?: SurfaceIdentification, position?: MapPosition }

Call As

player.add_pin{ label=label }

Call Convention

Adds a pin to this player for the given pin specification. Either entity, player, or surface and position must be defined.

Parameters

pipette_entity

LuaPlayer.pipette_entity(entity: EntityWithQualityID, allow_ghost?: boolean) -> boolean

Call As

player.pipette_entity(entity, true)

Call Convention

Invokes the "smart pipette" action on the player as if the user pressed it. This method is deprecated in favor of LuaPlayer::pipette and should not be used.

Parameters

Returns

pipette

LuaPlayer.pipette(id: PipetteID, quality?: QualityID, allow_ghost?: boolean) -> boolean

Call As

player.pipette(id, quality)

Call Convention

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

Parameters

Returns

can_build_from_cursor

LuaPlayer.can_build_from_cursor{ position: MapPosition, direction?: defines.direction, flip_horizontal?: boolean, flip_vertical?: boolean, build_mode?: defines.build_mode, terrain_building_size?: uint32, skip_fog_of_war?: boolean } -> boolean

Call As

player.can_build_from_cursor{ position=position }

Call Convention

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

Parameters

Returns

build_from_cursor

LuaPlayer.build_from_cursor{ position: MapPosition, direction?: defines.direction, mirror?: boolean, flip_horizontal?: boolean, flip_vertical?: boolean, build_mode?: defines.build_mode, terrain_building_size?: uint32, skip_fog_of_war?: boolean }

Call As

player.build_from_cursor{ position=position }

Call Convention

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

clear_inventory_highlights

LuaPlayer.clear_inventory_highlights()

Call As

player.clear_inventory_highlights()

Call Convention

Clears the blinking of the inventory based on insertion of items

use_from_cursor

LuaPlayer.use_from_cursor(position: MapPosition)

Call As

player.use_from_cursor(position)

Call Convention

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

Parameters

play_sound

LuaPlayer.play_sound(sound_specification: PlaySoundSpecification)

Call As

player.play_sound(sound_specification)

Call Convention

Play a sound for this player.

The sound is not played if its location is not charted for this player.

Parameters

get_associated_characters

LuaPlayer.get_associated_characters() -> Array<LuaEntity>

Call As

player.get_associated_characters()

Call Convention

The characters associated with this player.

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.

Returns

associate_character

LuaPlayer.associate_character(character: LuaEntity)

Call As

player.associate_character(character)

Call Convention

Associates a character with this player.

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.

Parameters

disassociate_character

LuaPlayer.disassociate_character(character: LuaEntity)

Call As

player.disassociate_character(character)

Call Convention

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

See LuaPlayer::get_associated_characters for more information.

Parameters

swap_characters

LuaPlayer.swap_characters(player: PlayerIdentification) -> boolean

Call As

player.swap_characters(player)

Call Convention

Swaps this player's character with another player's character.

Parameters

Returns

create_local_flying_text

LuaPlayer.create_local_flying_text{ text: LocalisedString, position?: MapPosition, surface?: SurfaceIdentification, create_at_cursor?: boolean, color?: Color, time_to_live?: uint32, speed?: double }

Call As

player.create_local_flying_text{ text=text }

Call Convention

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.

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 the player more time to read it.

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

Parameters

clear_local_flying_texts

LuaPlayer.clear_local_flying_texts()

Call As

player.clear_local_flying_texts()

Call Convention

Clear any active flying texts for this player.

get_quick_bar_slot

LuaPlayer.get_quick_bar_slot(index: uint32) -> ItemFilter?

Call As

player.get_quick_bar_slot(index)

Call Convention

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

Parameters

Returns

set_quick_bar_slot

LuaPlayer.set_quick_bar_slot(index: uint32, filter: LuaItemStack | ItemWithQualityID | nil)

Call As

player.set_quick_bar_slot(index, filter)

Call Convention

Sets the quick bar filter for the given slot. If a LuaItemStack is provided, the slot will be set to that particular item instance if it has extra data, for example a specific blueprint or spidertron remote. Otherwise, it will be set to all items of that prototype, for example iron plates.

Parameters

get_active_quick_bar_page

LuaPlayer.get_active_quick_bar_page(index: uint32) -> uint8?

Call As

player.get_active_quick_bar_page(index)

Call Convention

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

Parameters

Returns

set_active_quick_bar_page

LuaPlayer.set_active_quick_bar_page(screen_index: uint32, page_index: uint32)

Call As

player.set_active_quick_bar_page(screen_index, page_index)

Call Convention

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

Parameters

jump_to_cutscene_waypoint

LuaPlayer.jump_to_cutscene_waypoint(waypoint_index: uint32)

Call As

player.jump_to_cutscene_waypoint(waypoint_index)

Call Convention

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

Parameters

exit_cutscene

LuaPlayer.exit_cutscene()

Call As

player.exit_cutscene()

Call Convention

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

exit_remote_view

LuaPlayer.exit_remote_view()

Call As

player.exit_remote_view()

Call Convention

Exit remote view if possible. Exiting will fail if the player is in a rocket or in a platform.

is_shortcut_toggled

LuaPlayer.is_shortcut_toggled(prototype_name: string) -> boolean

Call As

player.is_shortcut_toggled(prototype_name)

Call Convention

Is a custom Lua shortcut currently toggled?

Parameters

Returns

is_shortcut_available

LuaPlayer.is_shortcut_available(prototype_name: string) -> boolean

Call As

player.is_shortcut_available(prototype_name)

Call Convention

Is a custom Lua shortcut currently available?

Parameters

Returns

set_shortcut_toggled

LuaPlayer.set_shortcut_toggled(prototype_name: string, toggled: boolean)

Call As

player.set_shortcut_toggled(prototype_name, true)

Call Convention

Toggle or untoggle a custom Lua shortcut

Parameters

set_shortcut_available

LuaPlayer.set_shortcut_available(prototype_name: string, available: boolean)

Call As

player.set_shortcut_available(prototype_name, true)

Call Convention

Make a custom Lua shortcut available or unavailable.

Parameters

connect_to_server

LuaPlayer.connect_to_server{ address: string, name?: LocalisedString, description?: LocalisedString, password?: string }

Call As

player.connect_to_server{ address=address }

Call Convention

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

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

Parameters

toggle_map_editor

LuaPlayer.toggle_map_editor()

Call As

player.toggle_map_editor()

Call Convention

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.

request_translation

LuaPlayer.request_translation(localised_string: LocalisedString) -> uint32?

Call As

player.request_translation(localised_string)

Call Convention

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

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

Parameters

Returns

request_translations

LuaPlayer.request_translations(localised_strings: Array<LocalisedString>) -> Array<uint32>?

Call As

player.request_translations(localised_strings)

Call Convention

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.

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

Parameters

Returns

get_infinity_inventory_filter

LuaPlayer.get_infinity_inventory_filter(index: uint32) -> InfinityInventoryFilter?

Call As

player.get_infinity_inventory_filter(index)

Call Convention

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

Returns

set_infinity_inventory_filter

LuaPlayer.set_infinity_inventory_filter(index: uint32, filter: InfinityInventoryFilter | nil)

Call As

player.set_infinity_inventory_filter(index, filter)

Call Convention

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

Parameters

clear_recipe_notifications

LuaPlayer.clear_recipe_notifications()

Call As

player.clear_recipe_notifications()

Call Convention

Clears all recipe notifications for this player.

add_recipe_notification

LuaPlayer.add_recipe_notification(recipe: RecipeID)

Call As

player.add_recipe_notification(recipe)

Call Convention

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

Parameters

clear_recipe_notification

LuaPlayer.clear_recipe_notification(recipe: RecipeID)

Call As

player.clear_recipe_notification(recipe)

Call Convention

Clears the given recipe from the list of recipe notifications for this player.

Parameters

get_recipe_notifications

LuaPlayer.get_recipe_notifications() -> Array<LuaRecipePrototype>

Call As

player.get_recipe_notifications()

Call Convention

Get all recipes that currently have recipe notifications for this player.

Returns

add_to_clipboard

LuaPlayer.add_to_clipboard(blueprint: LuaItemStack)

Call As

player.add_to_clipboard(blueprint)

Call Convention

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

Parameters

activate_paste

LuaPlayer.activate_paste()

Call As

player.activate_paste()

Call Convention

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

LuaPlayer.start_selection(position: MapPosition, selection_mode: defines.selection_mode)

Call As

player.start_selection(position, selection_mode)

Call Convention

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

Parameters

clear_selection

LuaPlayer.clear_selection()

Call As

player.clear_selection()

Call Convention

Clears the player's selection tool selection position.

enter_space_platform

LuaPlayer.enter_space_platform(space_platform: LuaSpacePlatform) -> boolean

Call As

player.enter_space_platform(space_platform)

Call Convention

Enters the given space platform if possible.

Parameters

Returns

leave_space_platform

LuaPlayer.leave_space_platform()

Call As

player.leave_space_platform()

Call Convention

Ejects this player from the current space platform if in a platform. The player is left on the platform at the position of the hub.

land_on_planet

LuaPlayer.land_on_planet() -> boolean

Call As

player.land_on_planet()

Call Convention

Ejects this player from the current space platform and lands on the current planet.

Returns

set_zoom_limits

LuaPlayer.set_zoom_limits(controller_type: defines.controllers, zoom_limits: ZoomLimits)

Call As

player.set_zoom_limits(controller_type, zoom_limits)

Call Convention

Sets the zoom limits for a specific controller type. To reset a controller's zoom limits to default, pass an empty table for zoom_limits.

Parameters