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=…, name=…, type=…, force=…} → array of LuaEntity | Find entities of given type or name in a given area. |
count_entities_filtered{area=…, name=…, type=…, force=…} → 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) | 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=…} → 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) | 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. |
find_logistic_network_by_position(position, force) → LuaLogisticNetwork | Find the logistic network that covers a given position. |
valid :: boolean [R] | Is this object valid? |
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. |
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.get_surface(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.get_surface(1).find_entities_filtered{area = {{-10, -10}, {10, 10}}, type= "resource"} -- gets all resources in the rectangle
game.get_surface(1).find_entities_filtered{area = {{-10, -10}, {10, 10}}, name= "iron-ore"} -- gets all iron ores in the rectangle
game.get_surface(1).find_entities_filtered{area = {{-10, -10}, {10, 10}}, force= "player"} -- gets player owned 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.get_surface(1).create_entity{name = "assembling-machine-1", position = {15, 3}, force=game.forces.player, recipe = "iron-stick"}
game.get_surface(1).create_entity{
name = "smart-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.get_surface(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.get_surface(1).create_entity{name = "big-biter", position= {15, 3}, force = game.forces.player} -- Friendly biter
game.get_surface(1).create_entity{name = "medium-biter", position= {15, 3}, force = game.forces.enemy} -- Enemy biter
game.get_surface(1).create_entity{name = "basic-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.
Is a given chunk generated?
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.
The name of this surface. Names are unique among surfaces.
Unique ID associated with this surface.
Gets the generation settings for the surface.