FindAliens (Harvest)

From OxeyeWiki

(Difference between revisions)
Jump to: navigation, search
(Created page with '{{HarvestMethod | getNumBuildings() | Finds all buildings. | | Returns an array of all buildings. }} {{HarvestMethod | getNumBuildings(type) | Finds all buildings of a certain t...')
 
Line 1: Line 1:
{{HarvestMethod
{{HarvestMethod
|
|
-
getNumBuildings()
+
findAliens()
|
|
-
Finds all buildings.
+
Finds all aliens.
|
|
|
|
-
Returns an array of all buildings.
+
Returns an array of all aliens.
}}
}}
{{HarvestMethod
{{HarvestMethod
|
|
-
getNumBuildings(type)
+
findAliens(type)
|
|
-
Finds all buildings of a certain type, such as "SPARKPRODUCER" (Solar Plants).
+
Finds all aliens of a certain type, such as ALIEN_DEFAULT.
|
|
{{MethodParam|type|String|The building identifier name used for selection.}}
{{MethodParam|type|String|The building identifier name used for selection.}}
|
|
-
Returns an array of all buildings of a cretin identifier name.
+
Returns an array of all aliens of a cretin identifier name.
}}
}}
{{HarvestMethod
{{HarvestMethod
|
|
-
getNumBuildings(x, y, radius)
+
findAliens(x, y, radius)
|
|
-
Finds all buildings in a circle.
+
Finds all aliens in a circle.
|
|
{{MethodParam|x|Number|The x coordinate of a point on the world map.}}
{{MethodParam|x|Number|The x coordinate of a point on the world map.}}
Line 30: Line 30:
{{MethodParam|radius|Number|The radius to be used.}}
{{MethodParam|radius|Number|The radius to be used.}}
|
|
-
Returns an array of all buildings in an certain radius.
+
Returns an array of all aliens in an certain radius.
}}
}}
{{HarvestMethod
{{HarvestMethod
|
|
-
getNumBuildings(x, y, radius, type)
+
findAliens(x, y, radius, type)
|
|
-
Finds all buildings of a certain type in a circle.
+
Finds all aliens of a certain type in a circle.
|
|
{{MethodParam|x|Number|The x coordinate of a point on the world map.}}
{{MethodParam|x|Number|The x coordinate of a point on the world map.}}
Line 44: Line 44:
{{MethodParam|type|String|The building identifier name used for selection.}}
{{MethodParam|type|String|The building identifier name used for selection.}}
|
|
-
Returns an array of all buildings in an certain radius with a certain type.
+
Returns an array of all aliens in an certain radius with a certain type.
}}
}}
{{HarvestMethod
{{HarvestMethod
|
|
-
getNumBuildings(left, top, right, bottom, type)
+
findAliens(left, top, right, bottom, type)
|
|
-
Finds all buildings of a certain type in a rectangle.
+
Finds all aliens of a certain type in a rectangle.
|
|
{{MethodParam|left|Number|The left coordinate of the rectangle.}}
{{MethodParam|left|Number|The left coordinate of the rectangle.}}
Line 59: Line 59:
{{MethodParam|type|String|The building identifier name used for selection.}}
{{MethodParam|type|String|The building identifier name used for selection.}}
|
|
-
Returns an array of all buildings in an certain rectangle with a certain type.
+
Returns an array of all aliens in an certain rectangle with a certain type.
}}
}}
=== Description ===
=== Description ===
-
All of the functions above will return an array (which can be empty) of buildings. The buildings will be of user data lua type, and refer to a CBuildingLuaInfo in Harvest's C++ code. On these objects you can perform getPosition(), getId() and various other functions (see separate thread soon). However, you may not keep a reference to these objects since it's not possible to predict when a building is destroyed. Instead, if you need to keep track of a specific building, you will have to save it's ID number and then locate it each frame with harvest.getBuilding(id).
+
Like with buildings, all of the functions above will return an array (which can be empty). The aliens will be of userdata lua type, and refer to a CAlienLuaInfo in Harvest's C++ code. On these objects you can perform getPosition(), getId() and various other functions (see separate thread soon). However, you may not keep a reference to these objects since it's not possible to predict when an alien has been removed. Instead, if you need to keep track of a specific alien, you will have to save it's ID number and then locate it each frame with harvest.getAlien(id).
=== Example ===
=== Example ===
<pre>
<pre>
-
-- destroy all buildings in the circle!
+
-- randomly displace all aliens
-
buildings = harvest.findBuildings(x, y, 200)
+
aliens = harvest.findAliens()
-
for i=1,#buildings do
+
local left,top,right,bottom = harvest.getWorldBorders()
-
   local x,y = buildings[i]:getPosition()
+
local width, height = right - left, bottom - top
-
  harvest.spawnParticle(buildings[i]:getDeathParticle(), x, y)
+
for i=1,#aliens do
-
  buildings[i]:remove()
+
   aliens[i]:setPosition(left + math.random() * width, top + math.random() * height)
end
end
</pre>
</pre>

Latest revision as of 20:04, 2 December 2009

findAliens()

Finds all aliens.

Parameter Expected Type Description
Returns

Returns an array of all aliens.

Harvest Library


findAliens(type)

Finds all aliens of a certain type, such as ALIEN_DEFAULT.

Parameter Expected Type Description
type String The building identifier name used for selection.
Returns

Returns an array of all aliens of a cretin identifier name.

Harvest Library


findAliens(x, y, radius)

Finds all aliens in a circle.

Parameter Expected Type Description
x Number The x coordinate of a point on the world map.
y Number The y coordinate of a point on the world map.
radius Number The radius to be used.
Returns

Returns an array of all aliens in an certain radius.

Harvest Library


findAliens(x, y, radius, type)

Finds all aliens of a certain type in a circle.

Parameter Expected Type Description
x Number The x coordinate of a point on the world map.
y Number The y coordinate of a point on the world map.
radius Number The radius to be used.
type String The building identifier name used for selection.
Returns

Returns an array of all aliens in an certain radius with a certain type.

Harvest Library


findAliens(left, top, right, bottom, type)

Finds all aliens of a certain type in a rectangle.

Parameter Expected Type Description
left Number The left coordinate of the rectangle.
top Number The top coordinate of the rectangle.
right Number The right coordinate of the rectangle.
bottom Number The bottom coordinate of the rectangle.
type String The building identifier name used for selection.
Returns

Returns an array of all aliens in an certain rectangle with a certain type.

Harvest Library


Description

Like with buildings, all of the functions above will return an array (which can be empty). The aliens will be of userdata lua type, and refer to a CAlienLuaInfo in Harvest's C++ code. On these objects you can perform getPosition(), getId() and various other functions (see separate thread soon). However, you may not keep a reference to these objects since it's not possible to predict when an alien has been removed. Instead, if you need to keep track of a specific alien, you will have to save it's ID number and then locate it each frame with harvest.getAlien(id).

Example

-- randomly displace all aliens
aliens = harvest.findAliens()
local left,top,right,bottom = harvest.getWorldBorders()
local width, height = right - left, bottom - top
for i=1,#aliens do
   aliens[i]:setPosition(left + math.random() * width, top + math.random() * height)
end

Resources

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox