FindAliens (Harvest)
From OxeyeWiki
(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 | ||
| | | | ||
- | + | findAliens() | |
| | | | ||
- | Finds all | + | Finds all aliens. |
| | | | ||
| | | | ||
- | Returns an array of all | + | Returns an array of all aliens. |
}} | }} | ||
{{HarvestMethod | {{HarvestMethod | ||
| | | | ||
- | + | findAliens(type) | |
| | | | ||
- | Finds all | + | 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 | + | Returns an array of all aliens of a cretin identifier name. |
}} | }} | ||
{{HarvestMethod | {{HarvestMethod | ||
| | | | ||
- | + | findAliens(x, y, radius) | |
| | | | ||
- | Finds all | + | 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 | + | Returns an array of all aliens in an certain radius. |
}} | }} | ||
{{HarvestMethod | {{HarvestMethod | ||
| | | | ||
- | + | findAliens(x, y, radius, type) | |
| | | | ||
- | Finds all | + | 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 | + | Returns an array of all aliens in an certain radius with a certain type. |
}} | }} | ||
{{HarvestMethod | {{HarvestMethod | ||
| | | | ||
- | + | findAliens(left, top, right, bottom, type) | |
| | | | ||
- | Finds all | + | 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 | + | Returns an array of all aliens in an certain rectangle with a certain type. |
}} | }} | ||
=== Description === | === 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 === | === Example === | ||
<pre> | <pre> | ||
- | -- | + | -- randomly displace all aliens |
- | + | aliens = harvest.findAliens() | |
- | for i=1,# | + | 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 | 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. |
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. |
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. |
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. |
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. |
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