This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
4rpl:commands:findunitenemy [2021/01/08 16:01] – created - external edit 127.0.0.1 | 4rpl:commands:findunitenemy [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 13: | Line 13: | ||
firePriority is interpreted differently in each case. For deepest (the mortar) firepriority chooses between targeting creeper or mesh (it picks one and ignores the other). | firePriority is interpreted differently in each case. For deepest (the mortar) firepriority chooses between targeting creeper or mesh (it picks one and ignores the other). | ||
For nearest (the cannon) firePriority will find either if the other (creeper or mesh) is not present. | For nearest (the cannon) firePriority will find either if the other (creeper or mesh) is not present. | ||
+ | |||
+ | If the unit can move, you'll want to use [[4rpl: | ||
+ | ===== Performance ===== | ||
+ | This API is performance expensive when many custom units call it. There for, it would be utmost wise to not call FindUnitEnemy more than absolutely necessary within a unit's script.\\ | ||
+ | As to be expected, the larger the range of the unit, the more expensive this API becomes.\\ | ||
+ | A performance efficient example is provided. Units with longer range should have a higher upper and lower bound in [[4rpl: | ||
===== Examples ===== | ===== Examples ===== | ||
<code 4rpl> | <code 4rpl> | ||
FindUnitEnemy(self true 0) ->cellZ ->cellX | FindUnitEnemy(self true 0) ->cellZ ->cellX | ||
+ | </ | ||
+ | <code 4rpl> | ||
+ | if(GetTimer0 eq0) #We are aloud to find a target. | ||
+ | FindUnitEnemy(self true 0) ->tCellZ ->tCellX | ||
+ | if(< | ||
+ | RandInt(30 60) SetTimer0 | ||
+ | #The randInt ensures multiple of this unit don't all call FindUnitEnemy at the same time, | ||
+ | #(which would cause the game to stutter every time they all used FindUnitEnemy). | ||
+ | else | ||
+ | @aimAndShoot | ||
+ | endif | ||
+ | endif | ||
</ | </ | ||
< | < | ||