Home

LuaControl

This is an abstract base class containing the common functionality between LuaPlayer and entities (see LuaEntity). When accessing player-related functions through a LuaEntity, it must refer to a character entity.

Attributes

surface

The surface this entity is currently on.

surface_index

Unique index (ID) associated with the surface this entity is currently on.

position

The current position of the entity.

render_position

The current render position of the entity.

is_flying

If this player or character entity is flying.

When called on an entity, only valid if this entity is a character.

flight_height

The current flight height for this player or character entity.

When called on an entity, only valid if this entity is a character.

vehicle

The vehicle the player is currently sitting in.

cargo_pod

The cargo pod the player is currently sitting in or the cargo pod attached to this rocket silo.

hub

The space platform hub the player is currently sitting in.

force

The force of this entity. Reading will always give a LuaForce, but it is possible to assign either string, uint8 or LuaForce to this attribute to change the force.

force_index

Unique index (ID) associated with the force of this entity.

selected

The currently selected entity. Assigning an entity will select it if is selectable, otherwise the selection is cleared.

opened

The GUI the player currently has open.

This is the GUI that will asked to close (by firing the on_gui_closed event) when the Esc or E keys are pressed. If this attribute is non-nil, then writing nil or a new GUI to it will ask the existing GUI to close.

Write supports any of the types. Read will return the entity, equipment, equipment-grid, player, element, inventory, item or nil.

crafting_queue_size

Size of the crafting queue.

crafting_queue_progress

The crafting queue progress in the range [0-1]. 0 when no recipe is being crafted.

walking_state

Current walking state of the player, or the spider-vehicle the character is driving.

riding_state

Current riding state of this car, or of the car this player is riding in.

mining_state

Current mining state.

When the player isn't mining tiles the player will mine whatever entity is currently selected. See LuaControl::selected and LuaControl::update_selected_entity.

shooting_state

Current shooting state.

picking_state

Current item-picking state.

repair_state

Current repair state.

cursor_stack

The player's cursor stack. nil if the player controller is a spectator.

cursor_ghost

The ghost prototype in the player's cursor.

Items in the cursor stack will take priority over the cursor ghost.

cursor_record

The blueprint record in the player's cursor.

driving

true if the player is in a vehicle. Writing to this attribute puts the player in or out of a vehicle.

crafting_queue

The current crafting queue items.

following_robots

The current combat robots following the character.

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

cheat_mode

When true hand crafting is free and instant.

character_crafting_speed_modifier

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_mining_speed_modifier

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_additional_mining_categories

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_running_speed_modifier

Modifies the running speed of this character by the given value as a percentage. Setting the running modifier to 0.5 makes the character run 50% faster. The minimum value of -1 reduces the movement speed by 100%, resulting in a speed of 0.

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_build_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_item_drop_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_reach_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_resource_reach_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_item_pickup_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_loot_pickup_distance_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_inventory_slots_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_trash_slot_count_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_maximum_following_robot_count_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

character_health_bonus

When called on a LuaPlayer, it must be associated with a character (see LuaPlayer::character).

opened_gui_type

build_distance

The build distance of this character or max uint when not a character or player connected to a character.

drop_item_distance

The item drop distance of this character or max uint when not a character or player connected to a character.

reach_distance

The reach distance of this character or max uint when not a character or player connected to a character.

item_pickup_distance

The item pickup distance of this character or max double when not a character or player connected to a character.

loot_pickup_distance

The loot pickup distance of this character or max double when not a character or player connected to a character.

resource_reach_distance

The resource reach distance of this character or max double when not a character or player connected to a character.

in_combat

Whether this character entity is in combat.

character_running_speed

The current movement speed of this character, including effects from exoskeletons, tiles, stickers and shooting.

character_mining_progress

The current mining progress between 0 and 1 of this character, or 0 if they aren't mining.

Methods

get_inventory

LuaControl.get_inventory(inventory: defines.inventory) -> LuaInventory?

Call As

player.get_inventory(inventory)

Call Convention

Get an inventory belonging to this entity. This can be either the "main" inventory or some auxiliary one, like the module slots or logistic trash slots.

A given defines.inventory is only meaningful for the corresponding LuaObject type. EG: get_inventory(defines.inventory.character_main) is only meaningful if 'this' is a player character. You may get a value back but if the type of 'this' isn't the type referred to by the defines.inventory it's almost guaranteed to not be the inventory asked for.

Parameters

Returns

get_inventory_name

LuaControl.get_inventory_name(inventory: defines.inventory) -> string?

Call As

player.get_inventory_name(inventory)

Call Convention

Get name of inventory. Names match keys of defines.inventory.

Parameters

Returns

get_max_inventory_index

LuaControl.get_max_inventory_index() -> defines.inventory

Call As

player.get_max_inventory_index()

Call Convention

The highest index of all inventories this entity can use. Allows iteration over all of them if desired.

Returns

get_main_inventory

LuaControl.get_main_inventory() -> LuaInventory?

Call As

player.get_main_inventory()

Call Convention

Gets the main inventory for this character or player if this is a character or player.

Returns

can_insert

LuaControl.can_insert(items: ItemStackIdentification) -> boolean

Call As

player.can_insert(items)

Call Convention

Can at least some items be inserted?

Parameters

Returns

insert

LuaControl.insert(items: ItemStackIdentification) -> uint32

Call As

player.insert(items)

Call Convention

Insert items into this entity. This works the same way as inserters or shift-clicking: the "best" inventory is chosen automatically.

Parameters

Returns

set_gui_arrow

LuaControl.set_gui_arrow{ margin: uint32, type: GuiArrowType }

Call As

player.set_gui_arrow{ margin=margin, type=type }

Call Convention

Create an arrow which points at this entity. This is used in the tutorial. For examples, see control.lua in the campaign missions.

Parameters

clear_gui_arrow

LuaControl.clear_gui_arrow()

Call As

player.clear_gui_arrow()

Call Convention

Removes the arrow created by set_gui_arrow.

get_item_count

LuaControl.get_item_count(item?: ItemFilter) -> uint32

Call As

player.get_item_count()

Call Convention

Get the number of all or some items in this entity.

Parameters

Returns

has_items_inside

LuaControl.has_items_inside() -> boolean

Call As

player.has_items_inside()

Call Convention

Does this entity have any item inside it?

Returns

can_reach_entity

LuaControl.can_reach_entity(entity: LuaEntity) -> boolean

Call As

player.can_reach_entity(entity)

Call Convention

Can a given entity be opened or accessed?

Parameters

Returns

clear_items_inside

LuaControl.clear_items_inside()

Call As

player.clear_items_inside()

Call Convention

Remove all items from this entity.

remove_item

LuaControl.remove_item(items: ItemStackIdentification) -> uint32

Call As

player.remove_item(items)

Call Convention

Remove items from this entity.

Parameters

Returns

teleport

LuaControl.teleport(position: MapPosition, surface?: SurfaceIdentification, raise_teleported?: boolean, snap_to_grid?: boolean, build_check_type?: defines.build_check_type) -> boolean

Call As

player.teleport(position, surface)

Call Convention

Teleport the entity to a given position, possibly on another surface.

Some entities may not be teleported. For instance, transport belts won't allow teleportation and this method will always return false when used on any such entity.

You can also pass 1 or 2 numbers as the parameters and they will be used as relative teleport coordinates 'teleport(0, 1)' to move the entity 1 tile positive y. 'teleport(4)' to move the entity 4 tiles to the positive x.

script_raised_teleported will not be raised if teleporting a player with no character.

Parameters

Returns

update_selected_entity

LuaControl.update_selected_entity(position: MapPosition)

Call As

player.update_selected_entity(position)

Call Convention

Select an entity, as if by hovering the mouse above it.

Parameters

clear_selected_entity

LuaControl.clear_selected_entity()

Call As

player.clear_selected_entity()

Call Convention

Unselect any selected entity.

disable_flashlight

LuaControl.disable_flashlight()

Call As

player.disable_flashlight()

Call Convention

Disable the flashlight.

Applied per controller. Only supported by defines.controllers.character and defines.controllers.remote.

enable_flashlight

LuaControl.enable_flashlight()

Call As

player.enable_flashlight()

Call Convention

Enable the flashlight.

Applied per controller. Only supported by defines.controllers.character and defines.controllers.remote.

is_flashlight_enabled

LuaControl.is_flashlight_enabled() -> boolean

Call As

player.is_flashlight_enabled()

Call Convention

Is the flashlight enabled for the current controller. Only supported by defines.controllers.character and defines.controllers.remote.

Returns

get_craftable_count

LuaControl.get_craftable_count(recipe: RecipeID) -> uint32

Call As

player.get_craftable_count(recipe)

Call Convention

Gets the count of the given recipe that can be crafted.

Parameters

Returns

begin_crafting

LuaControl.begin_crafting{ count: uint32, recipe: RecipeID, silent?: boolean } -> uint32

Call As

player.begin_crafting{ count=count, recipe=recipe }

Call Convention

Begins crafting the given count of the given recipe.

Parameters

Returns

cancel_crafting

LuaControl.cancel_crafting{ index: uint32, count: uint32 }

Call As

player.cancel_crafting{ index=index, count=count }

Call Convention

Cancels the given amount of crafts at the given crafting queue position. If this causes any later crafts that depend on the cancelled one to have insufficient ingredients, those crafts will also be cancelled.

Parameters

mine_entity

LuaControl.mine_entity(entity: LuaEntity, force?: boolean) -> boolean

Call As

player.mine_entity(entity, true)

Call Convention

Mines the given entity as if this player (or character) mined it.

Parameters

Returns

mine_tile

LuaControl.mine_tile(tile: LuaTile) -> boolean

Call As

player.mine_tile(tile)

Call Convention

Mines the given tile as if this player (or character) mined it.

Parameters

Returns

is_player

LuaControl.is_player() -> boolean

Call As

player.is_player()

Call Convention

When true control adapter is a LuaPlayer object, false for entities including characters with players.

Returns

open_technology_gui

LuaControl.open_technology_gui(technology?: TechnologyID)

Call As

player.open_technology_gui()

Call Convention

Open the technology GUI and select a given technology.

Parameters

open_factoriopedia_gui

LuaControl.open_factoriopedia_gui(prototype?: FactoriopediaID)

Call As

player.open_factoriopedia_gui()

Call Convention

Open the Factoriopedia GUI and select a given entry, if any valid ID is given.

Parameters

close_factoriopedia_gui

LuaControl.close_factoriopedia_gui()

Call As

player.close_factoriopedia_gui()

Call Convention

Closes the Factoriopedia GUI if it's open.

is_cursor_blueprint

LuaControl.is_cursor_blueprint() -> boolean

Call As

player.is_cursor_blueprint()

Call Convention

Returns whether the player is holding a blueprint. This takes both blueprint items as well as blueprint records from the blueprint library into account.

Note that both this method refers to the currently selected blueprint, which means that a blueprint book with a selected blueprint will return the information as well.

Returns

is_cursor_empty

LuaControl.is_cursor_empty() -> boolean

Call As

player.is_cursor_empty()

Call Convention

Returns whether the player is holding something in the cursor. Takes into account items from the blueprint library, as well as items and ghost cursor.

Returns

get_requester_point

LuaControl.get_requester_point() -> LuaLogisticPoint?

Call As

player.get_requester_point()

Call Convention

Gets the requester logistic point for this entity if it has one.

Returns

set_driving

LuaControl.set_driving(driving: boolean, force?: boolean)

Call As

player.set_driving(true, true)

Call Convention

Sets if this character or player is driving. Returns if the player or character is still driving.

Parameters

can_place_entity

LuaControl.can_place_entity{ name: EntityID, position: MapPosition, direction?: defines.direction } -> boolean

Call As

player.can_place_entity{ name="name", position=position }

Call Convention

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

Parameters

Returns