OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: tai mai shu on 02 Sep 2002, 07:01:47

Title: how do i use "foreach" in a trigger?
Post by: tai mai shu on 02 Sep 2002, 07:01:47
hi.

i was wondering , how do i (without using scripts) use the "foreach thislist" command inside of the condition field of triggers???

for example:  how do i make a trigger go off when any person in a group (an array of units) is in a vehicle?  and then if this is true, single out THAT guy and pass it to a script (or make that person perform an action or command)?

so basically what im thinking is this:

condition :  ? ("_x in vehicle1" foreach group1)
activation : (guy who is in the vehicle) action ["eject"]

any help will be appreciated, as this is an important command for use in scripting and other stuff.
Title: Re:how do i use "foreach" in a trigger?
Post by: Chris Death on 02 Sep 2002, 07:44:46
You can use "foreach" as a command, but not as a
condition.

In condition you need to use the count command.

"_x in vehicle1" count (units group1) == count (units group1)

: this condition expects all units of group1 to be inside vehicle1

"_x in vehicle1" count (units group1) > 0

: this condition expects at least one of the group to be inside

For your activation field, you might need a little trickier thingy.
You can pass the cargo of that vehicle into an array, and
execute the eject command foreach your_array.

invehiclearray=crew vehicle1 - driver vehicle1
followed by your eject action foreach invehiclearray

~S~ CD
Title: Re:how do i use "foreach" in a trigger?
Post by: tai mai shu on 02 Sep 2002, 09:08:50
damn.  i wish i knew C++, that most likely explains how to handle arrays like this.   ???  :-\  >:(
Title: Re:how do i use "foreach" in a trigger?
Post by: Chris Death on 02 Sep 2002, 09:18:05
Quote
d**n.  i wish i knew C++, that most likely explains how to handle arrays like this

 :D nope - that's generally the basics of any programmer's
language in combination with some mathematics

~S~ CD
Title: Re:how do i use "foreach" in a trigger?
Post by: tai mai shu on 02 Sep 2002, 09:46:51
exactly.  it has a LOT to do with arrays and such.
Title: Re:how do i use "foreach" in a trigger?
Post by: tai mai shu on 02 Sep 2002, 21:23:05
erm, can anyone help?
Title: Re:how do i use "foreach" in a trigger?
Post by: toadlife on 02 Sep 2002, 22:07:19
If you have a vehicle named "vehcle1" and you want to eject everyone inside, the code would be as follows:

"_x action [""EJECT"", (vehicle _x)]" foreach crew vehicle1