Home   Help Search Login Register  

Author Topic: Detecting the nearest unit (not object) of a certain type  (Read 1098 times)

0 Members and 1 Guest are viewing this topic.

BOPMatt

  • Guest
Well, first of all some background information:
I am using version 1.46 since most of the people I know don't have RES (maybe I'll port that mission to 1.75 later). One of the mission's goals will be to arrest/capture a certain enemy officer. So I'll have to define and check conditions which will make the officer surrender and those should be:

1) None of his own guards/troops alive or within let's say a range of 300m
2) At least one member of the player's squad within 25m distance


Ok, I could put all guards into one array and check the distance for all array elements e.g. every 10 seconds (there will be more looping scripts so I don't want to make an interval shorter than neccessary) and do the same thing about the player's squad.
But I think that would be a very unflexible and static solution so I was wondering if I could handle the problem with a more dynamic script.

As far as I have tested it nearestObject does only take real objects as second parameter and does not work with unittypes (e.g. "SoldierWB") or vehicles (? actually I don't remember if I tested that though I would not help me in this case) accordingly. Is there any kind of workaround for that problem except for such things as attaching objects (e.g. gamelogic) to the desired units enabling the use of nearestObject (apparently that method would not really be more flexible than the unit-array)? And please don't tell me about that 1.75-bug with nearestObject since that does not concern me right now ;)

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Detecting the nearest unit (not object) of a certain type
« Reply #1 on: 11 Sep 2002, 18:15:15 »
Use lists on triggers.

Every five seconds or so, move two triggers: one called "enemyprox" set to EAST(or whatever the general's side is) present anybody repeatedly, witha  radius of 300, the other "FriendlyProx" set to West present anybody repeatedly radius 25.

#top
~5
FriendlyProx setpos getpos evilgeneral
EnemyProx setpos getpos evilgeneral
~1
?"man" counttype list enemyprox > 0:goto "top"
?["leader _x == leader player" count list friendlyprox == 0:goto "top"

#surrender
evilgeneral globalchat "I surrender. Don't shoot.  I'm putting my gun down and removing my pants!"
exit
 
Dinger/Cfit

BOPMatt

  • Guest
Re:Detecting the nearest unit (not object) of a certain type
« Reply #2 on: 11 Sep 2002, 18:41:46 »
D'oh! ... I really forgot that you could also move triggers with SetPos ... so thanks for the reminder and that should do the job :)