Commands/Lua

Reference for console commands, Lua hooks and Lua commands in CS2D.

CS2D Command CS2D Console Commands

Lua Hook Lua Hooks

Lua Command Lua Commands

Lua Command closeobjects

Categories

Parameters

  • x
  • y
  • radius
  • [type] (optional)

Info

Returns a list of objects which are within the specified radius (in pixels) around the specified position (X|Y) in pixels. Use type to limit the search to objects with a certain type only.

Object types are:
CS2D Dynamic Objects

Sample 1: Get the IDs of objects which are close (300 pixel radius) around the top left corner (0|0) of the map:
local objectlist=closeobjects(0,0,300)
for _,id in pairs(objectlist) do
   print(id)
end


Sample 2: Get the IDs of turrets (object type 8) which are close (100 pixel radius) to player with ID 1 (note the 16 pixel offset which is required for buildings):
local objectlist=closeobjects(player(1, "x") - 16, player(1, "y") - 16, 100, 8)
for _,id in pairs(objectlist) do
   print(id)
end


Note: The position (X|Y) and the radius are specified in PIXELS!

Attention: Some objects (most buildings) do not have their pivot/center point in the middle but at the top left corner. Therefore you might have to use an offset of half a tile (16 pixels) to make distance checks work as intended. See sample 2.