Home   Help Search Login Register  

Author Topic: Obtaining units from an array  (Read 471 times)

0 Members and 1 Guest are viewing this topic.

Ace Productions

  • Guest
Obtaining units from an array
« on: 23 Jun 2004, 08:14:27 »
Hello everybody,

My problem has to do with arrays and how to extract the names of the units they include. If via a trigger activated by the enemy I obtain the array of enemies using the ‘list' command, how can I obtain the names of the units so I can assign commands to them?

I've tried the following but without success:

_enemies = List _range
_strength = Count _enemies

?(_strength==2):GoTo "2"

#2
_soldier1 = _enemies select 0
_soldier2 = _enemies select 1
 ~0

Exit


Can someone be of any assistance?

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:Obtaining units from an array
« Reply #1 on: 23 Jun 2004, 09:17:06 »
You want to give them orders individually?  :o

;reset bookmark
#reset

;list of enemy inside a named trigger, activated by enemy
;the number of enemy units in the list
;set a counter to zero
_enemylist = list triggername
_max = count _enemylist
_counter = 0

;loop bookmark
#loop
~1
;select a unit from enemylist using counter, which changes on every loop to the next unit
_unit = _enemylist select _counter

;you can give your commands to one individual unit here

;values are reseted when all the units in the array have gone through the loop
;counter is added with one, to select the next unit in array
?_counter == _max: goto "reset"
_counter = _counter +1
goto "loop"
Not all is lost.

Ace Productions

  • Guest
Re:Obtaining units from an array
« Reply #2 on: 23 Jun 2004, 11:21:24 »
Whenever I see the smiling guy with the white beard in a reply I know something good is going to happen!

Thanks a million once again Artak.

Now the quest continuous...

At the point where I can issue an order to the unit, is there any way to assign to this unit a name for later on reference, i.e. order one of my units to shoot this guy at a later stage.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Obtaining units from an array
« Reply #3 on: 23 Jun 2004, 18:44:27 »
Once you've isolated the unit

_unit

you can do anything you like.   To give him a name

nameOfLoon = _unit

Of course you have to make sure that the script does not try to give the same name to a different loon next time the script comes round the loop.    You could have an array of names and extract them one at a time using the same method.
Plenty of reviewed ArmA missions for you to play

Offline Jezuro

  • Members
  • *
  • Hookah 4 lyfe!
    • Jezuro's ArmA Workshop
Re:Obtaining units from an array
« Reply #4 on: 23 Jun 2004, 19:39:14 »
The important has been already said, but there is a little unpleasantness that could really make you mad (as me  :)):

It's good to know that if you use a "list" commad, it is still updated. That means that you can never precisely check something in it... These lists are also updated even when they were loaded into some variable (eg. _mylist = (list MyTrigger)). Most times this updating is a good thing, but it can also destroy your perfectly written code (trust me, I know what am I talking about...).

So, if you want to create a copy of the array, which won't be automatically updated anymore, use "+":

_mylist = +(list MyTrigger)

Too much stramash around nothing, maybe, but it could help in some very stressful situation  ;)
"We are Her salvation, and through Her command we shall live forever. I will not die. Not here. Not now. Never!!!"

Ace Productions

  • Guest
Re:Obtaining units from an array
« Reply #5 on: 23 Jun 2004, 23:10:38 »
Guys a big thanks to all of you.


I used your suggestions to write a  script that will detect all enemy units in the radius of 200m and the player will be able to order his men to target them. Automatically each man targets a different enemy and when you issue the command fire they shoot all enemies at once.


I'm updating for a while now my ancient "Hand Signals" script, which is now called "Stealth Mode v1.0" cause I added a new section called "silent orders".

II'm about to release it in a couple of days.

Thanks again.