LuaForce
LuaForce
encapsulates data local to each "force" or "faction" of the game. Default forces are player, enemy and neutral. Players and mods can create additional forces (up to 64 total).
Count entities of given type.
Disable research for this force.
Enable research for this force.
Disable all recipes and technologies.
Enables all recipes and technologies.
Load the original version of all recipes from the prototypes.
Unlock all recipes.
Unlock all technologies.
Research all technologies.
Load the original versions of technologies from prototypes.
Reset everything.
Reapplies all possible research effects, including unlocked recipes.
Chart a portion of the map.
Erases chart data for this force.
Force a rechart of the whole chart.
Chart all generated chunks.
Has a chunk been charted?
Is the given chunk currently charted and visible (not covered by fog of war) on the map.
Cancels pending chart requests for the given surface or all surfaces.
Add other
force to this force's cease fire list.
Is other
force in this force's cease fire list?
Add other
force to this force's friends list.
Is other
force in this force's friends list.
Is pathfinder busy?
Kill all units and flush the pathfinder.
Gets the count of a given item launched in rockets.
Sets the count of a given item launched in rockets.
Print text to the chat console of all players on this force.
Adds a custom chart tag to the given surface and returns the new tag or nil
if the given position isn't valid for a chart tag.
Finds all custom chart tags within the given bounding box on the given surface.
Gets the saved progress for the given technology or nil
if there is no saved progress.
Sets the saved progress for the given technology.
Resets evolution for this force to zero.
Play a sound for every player in this force.
Gets train stops matching the given filters.
Gets if the given recipe is explicitly disabled from being hand crafted.
Sets if the given recipe can be hand-crafted.
Add this technology to the back of the research queue if the queue is enabled.
Stop the research currently in progress.
Gets the linked inventory for the given prototype and link ID if it exists or nil
.
Technologies owned by this force, indexed by name
.
Recipes available to this force, indexed by name
.
Multiplier of the manual mining speed.
Multiplier of the manual crafting speed.
The current technology in research, or nil
if no research is currently ongoing.
Progress of current research, as a number in range [0, 1].
The previous research if any.
The inserter stack size bonus for non stack inserters
Number of items that can be transferred by stack inserters.
Number of character trash slots.
Maximum number of follower robots.
Additional lifetime for following robots.
The time, in ticks, before a placed ghost disappears.
Enables some higher-level AI behaviour for this force.
List of logistic networks, grouped by surface.
The item production statistics for this force.
The fluid production statistics for this force.
The kill counter statistics for this force.
The entity build statistics for this force (built and mined)
Modifies the running speed of all characters in this force by the given value as a percentage.
the number of additional inventory slots the character main inventory has.
The time, in ticks, before a deconstruction order is removed.
Ability to use zoom-to-world on map.
Ability to build ghosts through blueprint or direct ghost placement, or "mine" ghosts when using zoom-to-world.
Ability to create new blueprints using empty blueprint item when using zoom-to-world.
Ability to use deconstruction planner when using zoom-to-world.
Ability to use custom selection tools when using zoom-to-world.
true
if character requester logistics is enabled.
The number of rockets launched.
All of the items that have been launched in rockets.
The connected players belonging to this force.
Evolution factor of this force.
If friendly fire is enabled for this force.
If sharing chart data is enabled for this force.
Whether the research queue is available for this force.
The research queue of this force.
Whether research is enabled for this force, see LuaForce::enable_research and LuaForce::disable_research
The class name of this object.
get_entity_count(name)
→
uint
disable_all_prototypes()
Disable all recipes and technologies. Only recipes and technologies enabled explicitly will be useable from this point.
enable_all_prototypes()
Enables all recipes and technologies. The opposite of LuaForce::disable_all_prototypes
research_all_technologies(include_disabled_prototypes)
Research all technologies.
Whether technologies that are explicitly disabled in the prototype should also be researched. Defaults to false
.
reset_technologies()
Load the original versions of technologies from prototypes. Preserves research state of technologies.
reset()
Reset everything. All technologies are set to not researched, all modifiers are set to default values.
reset_technology_effects()
Reapplies all possible research effects, including unlocked recipes. Any custom changes are lost. Preserves research state of technologies.
chart(surface,
area)
Chart a portion of the map. The chart for the given area is refreshed; it creates chart for any parts of the given area that haven't been charted yet.
The area on the given surface to chart.
Charts a 2048x2048 rectangle centered around the origin.
game.player.force.chart(game.player.surface, {{x = -1024, y = -1024}, {x = 1024, y = 1024}})
clear_chart(surface)
Erases chart data for this force.
Which surface to erase chart data for or if not provided all surfaces charts are erased.
chart_all(surface)
Chart all generated chunks.
Which surface to chart or all if not given.
is_chunk_charted(surface,
position)
→
boolean
Has a chunk been charted?
Position of the chunk.
is_chunk_visible(surface,
position)
→
boolean
Is the given chunk currently charted and visible (not covered by fog of war) on the map.
cancel_charting(surface)
Cancels pending chart requests for the given surface or all surfaces.
get_ammo_damage_modifier(ammo)
→
double
get_gun_speed_modifier(ammo)
→
double
get_turret_attack_modifier(turret)
→
double
set_cease_fire(other,
cease_fire)
Add other
force to this force's cease fire list. Forces on the cease fire list won't be targeted for attack.
get_cease_fire(other)
→
boolean
set_friend(other,
friend)
Add other
force to this force's friends list. Friends have unrestricted access to buildings and turrets won't fire at them.
get_friend(other)
→
boolean
is_pathfinder_busy()
→
boolean
Is pathfinder busy? When the pathfinder is busy, it won't accept any more pathfinding requests.
find_logistic_network_by_position(position,
surface)
→
LuaLogisticNetwork?
Position to find a network for
Surface to search on
The found network or nil
.
set_spawn_position(position,
surface)
The new position on the given surface.
Surface to set the spawn position for.
get_spawn_position(surface)
→
MapPosition
unchart_chunk(position,
surface)
The chunk position to unchart.
Surface to unchart on.
get_item_launched(item)
→
uint
print(message,
color)
Print text to the chat console of all players on this force.
Messages that are identical to a message sent in the last 60 ticks are not printed again.
get_trains(surface)
→
array[LuaTrain]
If given only trains on the surface are returned.
add_chart_tag(surface,
tag)
→
LuaCustomChartTag?
Adds a custom chart tag to the given surface and returns the new tag or nil
if the given position isn't valid for a chart tag.
Which surface to add the tag to.
The tag to add.
Raised if the chart tag was successfully added.
The chunk must be charted for a tag to be valid at that location.
get_saved_technology_progress(technology)
→
double?
Gets the saved progress for the given technology or nil
if there is no saved progress.
The technology
The progress as a percent.
set_saved_technology_progress(technology,
progress)
Sets the saved progress for the given technology. The technology must not be in progress, must not be completed, and the new progress must be < 100%.
The technology
Progress as a percent. Set to nil
to remove the saved progress.
play_sound{path,
position,
volume_modifier,
override_sound_type}
Play a sound for every player in this force.
The sound to play.
Where the sound should be played. If not given, it's played at the current position of each player.
The volume of the sound to play. Must be between 0 and 1 inclusive.
The volume mixer to play the sound through. Defaults to the default mixer for the given sound type.
get_train_stops{name,
surface}
→
array[LuaEntity]
Gets train stops matching the given filters.
get_hand_crafting_disabled_for_recipe(recipe)
→
boolean
add_research(technology)
→
boolean
Add this technology to the back of the research queue if the queue is enabled. Otherwise, set this technology to be researched now.
Whether the technology was successfully added.
Raised if the technology was successfully added.
cancel_current_research()
Stop the research currently in progress. This will remove any dependent technologies from the research queue.
get_linked_inventory(prototype,
link_id)
→
LuaInventory?
Gets the linked inventory for the given prototype and link ID if it exists or nil
.
is_friend(other)
→
boolean
Is this force a friend? This differs from get_friend
in that it is always true for neutral force. This is equivalent to checking the friend
ForceCondition.
is_enemy(other)
→
boolean
Is this force an enemy? This differs from get_cease_fire
in that it is always false for neutral force. This is equivalent to checking the enemy
ForceCondition.
name
:: string
[Read]
Name of the force.
Prints "player
"
game.player.print(game.player.force.name)
technologies
:: LuaCustomTable[string → LuaTechnology]
[Read]
Technologies owned by this force, indexed by name
.
Researches the technology for the player's force
game.player.force.technologies["steel-processing"].researched = true
recipes
:: LuaCustomTable[string → LuaRecipe]
[Read]
Recipes available to this force, indexed by name
.
Prints the category of the given recipe
game.player.print(game.player.force.recipes["transport-belt"].category)
manual_mining_speed_modifier
:: double
[Read/Write]
Multiplier of the manual mining speed. Default value is 0
. The actual mining speed will be multiplied by 1 + manual_mining_speed_modifier
.
Double the player's mining speed
game.player.force.manual_mining_speed_modifier = 1
manual_crafting_speed_modifier
:: double
[Read/Write]
Multiplier of the manual crafting speed. Default value is 0
. The actual crafting speed will be multiplied by 1 + manual_crafting_speed_modifier
.
Double the player's crafting speed
game.player.force.manual_crafting_speed_modifier = 1
laboratory_speed_modifier
:: double
[Read/Write]
laboratory_productivity_bonus
:: double
[Read/Write]
worker_robots_speed_modifier
:: double
[Read/Write]
worker_robots_battery_modifier
:: double
[Read/Write]
worker_robots_storage_bonus
:: double
[Read/Write]
current_research
:: LuaTechnology
[Read]
The current technology in research, or nil
if no research is currently ongoing.
research_progress
:: double
[Read/Write]
Progress of current research, as a number in range [0, 1].
previous_research
:: LuaTechnology
[Read/Write]
The previous research if any.
inserter_stack_size_bonus
:: double
[Read/Write]
The inserter stack size bonus for non stack inserters
stack_inserter_capacity_bonus
:: uint
[Read/Write]
Number of items that can be transferred by stack inserters. When writing to this value, it must be >= 0 and <= 254.
character_trash_slot_count
:: double
[Read/Write]
Number of character trash slots.
maximum_following_robot_count
:: uint
[Read/Write]
Maximum number of follower robots.
following_robots_lifetime_modifier
:: double
[Read/Write]
Additional lifetime for following robots.
ghost_time_to_live
:: uint
[Read/Write]
The time, in ticks, before a placed ghost disappears.
players
:: array[LuaPlayer]
[Read]
Players belonging to this force.
ai_controllable
:: boolean
[Read/Write]
Enables some higher-level AI behaviour for this force. When set to true
, biters belonging to this force will automatically expand into new territories, build new spawners, and form unit groups. By default, this value is true
for the enemy force and false
for all others.
Setting this to false
does not turn off biters' AI. They will still move around and attack players who come close.
It is necessary for a force to be AI controllable in order to be able to create unit groups or build bases from scripts.
logistic_networks
:: dictionary[string → array[LuaLogisticNetwork]]
[Read]
List of logistic networks, grouped by surface.
item_production_statistics
:: LuaFlowStatistics
[Read]
The item production statistics for this force.
fluid_production_statistics
:: LuaFlowStatistics
[Read]
The fluid production statistics for this force.
kill_count_statistics
:: LuaFlowStatistics
[Read]
The kill counter statistics for this force.
entity_build_count_statistics
:: LuaFlowStatistics
[Read]
The entity build statistics for this force (built and mined)
character_running_speed_modifier
:: double
[Read/Write]
Modifies the running speed of all characters in this force 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
.
artillery_range_modifier
:: double
[Read/Write]
character_build_distance_bonus
:: uint
[Read/Write]
character_item_drop_distance_bonus
:: uint
[Read/Write]
character_reach_distance_bonus
:: uint
[Read/Write]
character_resource_reach_distance_bonus
:: double
[Read/Write]
character_item_pickup_distance_bonus
:: double
[Read/Write]
character_loot_pickup_distance_bonus
:: double
[Read/Write]
character_inventory_slots_bonus
:: uint
[Read/Write]
the number of additional inventory slots the character main inventory has.
deconstruction_time_to_live
:: uint
[Read/Write]
The time, in ticks, before a deconstruction order is removed.
character_health_bonus
:: double
[Read/Write]
max_successful_attempts_per_tick_per_construction_queue
:: uint
[Read/Write]
max_failed_attempts_per_tick_per_construction_queue
:: uint
[Read/Write]
zoom_to_world_enabled
:: boolean
[Read/Write]
Ability to use zoom-to-world on map.
zoom_to_world_ghost_building_enabled
:: boolean
[Read/Write]
Ability to build ghosts through blueprint or direct ghost placement, or "mine" ghosts when using zoom-to-world.
zoom_to_world_blueprint_enabled
:: boolean
[Read/Write]
Ability to create new blueprints using empty blueprint item when using zoom-to-world.
zoom_to_world_deconstruction_planner_enabled
:: boolean
[Read/Write]
Ability to use deconstruction planner when using zoom-to-world.
zoom_to_world_selection_tool_enabled
:: boolean
[Read/Write]
Ability to use custom selection tools when using zoom-to-world.
character_logistic_requests
:: boolean
[Read/Write]
true
if character requester logistics is enabled.
rockets_launched
:: uint
[Read/Write]
The number of rockets launched.
items_launched
:: dictionary[string → uint]
[Read]
All of the items that have been launched in rockets. The attribute is a dictionary mapping the item prototype names to the launched amounts.
connected_players
:: array[LuaPlayer]
[Read]
The connected players belonging to this force.
This is primarily useful when you want to do some action against all online players of this force.
This does not index using player index. See LuaPlayer::index on each player instance for the player index.
mining_drill_productivity_bonus
:: double
[Read/Write]
train_braking_force_bonus
:: double
[Read/Write]
evolution_factor
:: double
[Read/Write]
Evolution factor of this force.
evolution_factor_by_pollution
:: double
[Read/Write]
evolution_factor_by_time
:: double
[Read/Write]
evolution_factor_by_killing_spawners
:: double
[Read/Write]
friendly_fire
:: boolean
[Read/Write]
If friendly fire is enabled for this force.
research_queue_enabled
:: boolean
[Read/Write]
Whether the research queue is available for this force.
index
:: uint
[Read]
Unique ID associated with this force.
research_queue
:: array[TechnologyIdentification]
[Read/Write]
The research queue of this force. The first technology in the array is the currently active one. Reading this attribute gives an array of LuaTechnology.
To write to this, the entire table must be written. Providing an empty table or nil
will empty the research queue and cancel the current research. Writing to this when the research queue is disabled will simply set the last research in the table as the current research.
This only allows mods to queue research that this force is able to research in the first place. As an example, an already researched technology or one whose prerequisites are not fulfilled will not be queued, but dropped silently instead.
research_enabled
:: boolean
[Read]
Whether research is enabled for this force, see LuaForce::enable_research and LuaForce::disable_research
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.