OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Ace Productions 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?
-
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"
-
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.
-
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.
-
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 ;)
-
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.