get_pollution(position) → double | Get the pollution for a given position. |
can_place_entity{name=…, position=…, direction=…, force=…} → boolean | Check for collisions with terrain or other entities. |
find_entity(entity, position) → LuaEntity | Find a specific entity at a specific position. |
find_entities(area) → array of LuaEntity | Find entities in a given area. |
find_entities_filtered{area=…, position=…, name=…, type=…, force=…, limit=…} → array of LuaEntity | Find entities of given type or name in a given area. |
count_entities_filtered{area=…, position=…, name=…, type=…, force=…, limit=…} → uint | Count entities of given type or name in a given area. |
find_non_colliding_position(name, center, radius, precision) → Position | Find a non-colliding possition within a given rectangle. |
spill_item_stack(position, items, enable_looted) | Spill items on the ground centered at a given location. |
find_enemy_units(center, radius, force) → array of LuaEntity | Find units enemy of a given force within an area. |
find_nearest_enemy{position=…, max_distance=…, force=…} → LuaEntity | Find the enemy closest to the given position. |
set_multi_command{command=…, unit_count=…, force=…, unit_search_distance=…} → uint | Give a command to multiple units. |
create_entity{name=…, position=…, direction=…, force=…, target=…, source=…, fast_replace=…, player=…, spill=…} → LuaEntity | Create an entity on this surface. |
create_unit_group{position=…, force=…} → LuaUnitGroup | Create a new unit group at a given position. |
build_enemy_base(position, unit_count, force) | Send a group to build a new base. |
get_tile(x, y) → LuaTile | Get the tile at a given position. |
get_tileproperties(x, y) → TileProperties | Get tile properties. |
set_tiles(tiles, correct_tiles) | Set tiles at specified locations. |
pollute(source, amount) | Spawn pollution at the given position. |
get_chunks() → LuaChunkIterator | Get an iterator going over every chunk on this surface. |
is_chunk_generated(position) → boolean | Is a given chunk generated? |
request_to_generate_chunks(position, radius) | Request that the game's map generator generate chunks at the given position for the given radius on this surface. |
set_chunk_generated_status(position, status) | Set generated status of a chunk. |
find_logistic_network_by_position(position, force) → LuaLogisticNetwork | Find the logistic network that covers a given position. |
freeze_daytime(freeze) | Freeze or unfreeze time of day at the current value. |
deconstruct_area{area=…, force=…} | Place a deconstruction request. |
cancel_deconstruct_area{area=…, force=…} | Cancel a deconstruction order. |
get_hidden_tile(position) | The hidden tile name or nil if there isn't one for the given position. |
get_connected_tiles(position, tiles) → array of Position | Gets all tiles of the given types that are connected horizontally or vertically to the given tile position including the given tile position. |
regenerate_entity(entitites) | Regenerate autoplacement of some entities on this surface. |
print(message) | Print text to the chat console of all players on this surface. |
name :: string [R] | The name of this surface. |
index :: uint [R] | Unique ID associated with this surface. |
map_gen_settings :: MapGenSettings [R] | Gets the generation settings for the surface. |
always_day :: boolean [RW] | When set to true, the sun will always shine. |
daytime :: float [RW] | Current time of day, as a number in range [0, 1). |
darkness :: float [R] | Amount of darkness at the current time. |
wind_speed :: float [RW] | Current wind speed. |
wind_orientation :: float [RW] | Current wind direction. |
wind_orientation_change :: float [RW] | Change in wind orientation per tick. |
peaceful_mode :: boolean [RW] | Is peaceful mode enabled on this surface? |
valid :: boolean [R] | Is this object valid? |
A "domain" of the world. Surfaces can only be created through the API and can not be deleted. However, it is planned to allow deletion of a surface in the future. Surfaces are uniquely identified by their name. Every game contains at least the surface "nauvis".
Get the pollution for a given position.
game.surfaces[1].get_pollution({1,2})
Check for collisions with terrain or other entities.
Find entities in a given area.
game.surfaces["nauvis"].find_entities({{-10, -10}, {10, 10}})
Find entities of given type or name in a given area.
If no filters (name
, type
, or force
) are given, returns all entities in the search area.
If multiple filters are specified, returns only entities matching all given filters.
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, type= "resource"} -- gets all resources in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, name= "iron-ore"} -- gets all iron ores in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, force= "player"} -- gets player owned entities in the rectangle
game.surfaces[1].find_entities_filtered{area = {{-10, -10}, {10, 10}}, limit= 5} -- gets the first 5 entities in the rectangle
Count entities of given type or name in a given area. Works just like LuaSurface::find_entities_filtered, except this only returns the count. As it doesn't construct all the wrapper objects, this is more efficient if one is only interested in the number of entities.
Find a non-colliding possition within a given rectangle.
nil
if no suitable position was found.Spill items on the ground centered at a given location.
Find units enemy of a given force within an area.
local enemies = game.player.surface.find_enemy_units(game.player.character.position, 100)
Find the enemy closest to the given position.
nil
if no enemy could be found within the
given area.Give a command to multiple units. This will automatically select suitable units for the task.
count
if not enough units were
available.Create an entity on this surface.
"output"
or "input"
; default is "input"
.nil
if the creation failed.asm = game.surfaces[1].create_entity{name = "assembling-machine-1", position = {15, 3}, force=game.forces.player, recipe = "iron-stick"}
game.surfaces[1].create_entity{
name = "filter-inserter", position = {20, 15}, force=game.player.force,
conditions={red={name="wood", count=3, operator=">"},
green={name="iron-ore", count=1, operator="<"},
logistics={name="wood", count=3, operator="="}},
filters={ {index=1, name="iron-ore"} }
}
game.surfaces[1].create_entity{
name = "logistic-chest-requester", position = {game.player.position.x+3, game.player.position.y},
force=game.player.force, request_filters={ {index=1, name="iron-plate", count=128} }
}
game.surfaces[1].create_entity{name = "big-biter", position= {15, 3}, force = game.forces.player} -- Friendly biter
game.surfaces[1].create_entity{name = "medium-biter", position= {15, 3}, force = game.forces.enemy} -- Enemy biter
game.surfaces[1].create_entity{name = "inserter", position = game.player.position, direction = defines.direction.north}
Send a group to build a new base.
force.ai_controllable
must be true
.Set tiles at specified locations. Automatically corrects the edges around modified tiles.
Get an iterator going over every chunk on this surface.
Set generated status of a chunk. Useful when copying chunks.
Freeze or unfreeze time of day at the current value.
Place a deconstruction request.
Cancel a deconstruction order.
Gets all tiles of the given types that are connected horizontally or vertically to the given tile position including the given tile position.
The name of this surface. Names are unique among surfaces.
Unique ID associated with this surface.
Gets the generation settings for the surface.
When set to true, the sun will always shine.
Current time of day, as a number in range [0, 1).
Amount of darkness at the current time.
Current wind speed.
Current wind direction.
Change in wind orientation per tick.
Is peaceful mode enabled on this surface?