Home   Help Search Login Register  

Author Topic: Create explosion on nearest enemy unit  (Read 890 times)

0 Members and 1 Guest are viewing this topic.

PsyWarrior

  • Guest
Create explosion on nearest enemy unit
« on: 22 Oct 2002, 16:38:56 »
Oooookay...
so, I need to create a tank/missile/whatever explosion at the pos of the nearest enemy unit (for instance Shell103 or maybe even a mortar). There is one problem. I need to detect the nearest enemy (i.e. east) unit (infantry, tank, building anything) to the player and create the explosion there - getpos of predefined unit? easy. getpos of nearest unit on a certain side?
 ???  ???  ???
I have tried using NearestObject but to no avail. Anyone have a suggesion?

---------------------------
PsyWarrior
=====================
Transmission Terminated
 :help:

Bremmer

  • Guest
Re:Create explosion on nearest enemy unit
« Reply #1 on: 23 Oct 2002, 10:54:26 »
I'm currently debugging an AI script that uses similar logic (except I target the most known about enemy). The way I do it is using a small loop to check all enemy units, like this:

Set up an east present trigger over all units you want to check. In the condition line put eastunits = thislist.

In your script insert the following loop:


_distance = 9999
_target = objnull
_i = (count eastlist) - 1
#loop
_unit = eastlist select _i
? not alive _unit : goto "next"
? player distance _unit < _distance  : _distance = player distance _unit; _target = _unit
#next
_i = _i - 1
? _i >= 0 : goto "loop"


At the end of this loop your nearest unit will be called _target, unless it is further than 9999m away, in which case there will be no target.

Hope that helps.

 :)

PsyWarrior

  • Guest
Re:Create explosion on nearest enemy unit
« Reply #2 on: 23 Oct 2002, 12:53:47 »
Aha! I hadn't considered using triggers.
I'll test that immediately. Thanks Bremmer

===============
PsyWarrior
-------------------
End  8)
===============