Module Player

LuaPlayer methods.

Module Status: Work in progress. Compatibility: Factorio Runtime.

Usage:

    local Player = require('__eradicators-library__/erlib/factorio/Player')()
    

Methods

try_reach_entity(p, entity, text) Calls LuaControl.can_reach_entity and automatically creates a local flying text at the entity position if not.
notify(p, text[, position=at the cursor position]) Creates a plain localized flying text for a player.
get_player(player) Gets a LuaPlayer object.
get_event_player(e) Gets a LuaPlayer object.
get_valid_for_read_cursor_stack([p[, e]]) Gets the item in the players cursor.
toggle_shortcut(p, name) Sets a shortcut to the opposite state it is in now.

Draft

get_selected_entity(p, position) Gets the currently selected entity.
try_swap_character(p, prototype_name) Attaches a new character to a player if possible.


Methods

try_reach_entity(p, entity, text)
Calls LuaControl.can_reach_entity and automatically creates a local flying text at the entity position if not.

Parameters:

Returns:

    boolean
notify(p, text[, position=at the cursor position])
Creates a plain localized flying text for a player.

Syntactic Sugar for LuaPlayer create_local_flying_text

Parameters:

get_player(player)
Gets a LuaPlayer object.

Functionally equivalent to LuaGameScript.get_player, but faster because the player object is cached on the lua side.

Parameters:

Returns:

    LuaPlayer
get_event_player(e)
Gets a LuaPlayer object.

Shortcut for Player.get_player(e.player_index).

Parameters:

  • e table Any event table that contains player_index.

Returns:

    LuaPlayer

Usage:

    -- Maximum speed access to lua player objects.
    local getp = Player.get_event_player
    script.on_event(defines.events.on_something_happend, function(e)
      local p = getp(e)
      game.print(p.name .. ' did something!')
      end)
    
get_valid_for_read_cursor_stack([p[, e]])
Gets the item in the players cursor.

Parameters:

  • p LuaPlayer (optional)
  • e table If you don't have a LuaPlayer object you can instead pass an event table containing player_index. (optional)

Returns:

  1. nil or LuaItemStack Returns nil if the cursor was not LuaItemStack.valid_for_read.
  2. LuaPlayer
toggle_shortcut(p, name)
Sets a shortcut to the opposite state it is in now.

Parameters:

Returns:

    boolean The new state.

Draft

get_selected_entity(p, position)
Gets the currently selected entity.

While holding a blueprint entity selection is not updated naturally and LuaControl.update_selected_entity does not work. In that case a best-guess result using LuaSurface.find_entities_filtered is returned.

Note: Emulation does not check for entity visibility (force_visibility, render_to_forces, etc). Emulation is based on collision_box instead of selection_box.

Related MIR: Method to get "selected" entity while player is holding a blueprint.

Parameters:

Returns:

    nil or LuaEntity
try_swap_character(p, prototype_name)
Attaches a new character to a player if possible.

If the player has no character then a new one will be attached. If the player has a character then all inventories, logistic requests, etc. will be copied to the new character before the old one is destroyed.

If the target prototype does not have enough inventory slots, logistic slots, etcpp, or the swapping fails for some other reason the original character will be kept as is.

Parameters:

Returns:

    boolean If the swap was successful.
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19