OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bored_onion on 13 Aug 2004, 16:06:46
-
i have a mission where you have to blow up some parked tanks (empty) - nothing special - as a black op. however, i wanted to make it so that there is a different number of tanks each time so the mission can be vaguely replayable. But to complete the objective the tanks have to have been destroyed but see it as some never exist in the first place you can never complete the objective
i used the probability of presence feature in the unit dialogue box and i used the !alive command for the condition in the trigger
are there anyways to make the trigger only refer to the units that are present?
-
'not alive myUnit' will be false if myUnit has not been initialized (iirc),
so you probably want to do it the other way around with something like:
("alive _x" count [tank0, tank1, tank2, tank3]) == 0
However, alive on empty vehicles might not work correctly 100% of the time (think I read that somewhere),
so you would probably want to use GetDammage instead.
But, to tidy things up alittle, create an array at the beginning of the mission containing the tanks that are actually created.
Put this in each tank's init-field:
tanks = tanks + [this](You might want to initialize 'tanks' before that with 'tanks = []')
Then in the trigger:
("(GetDammage _x) >= 1" count tanks) == count tanks
-
Empty vehicles in OFP are classed on side civilian, so a trigger activated by civilian could work much easier...
That is if the tanks remain empty for the whole mission...
So if the trigger is set to activated by civilian and not present it should work regardless of the amount of tanks...
And as the catchphrase goes, "No guarantees on the syntax :P"...
-
i think i'll try both and see what works best
before i use the code could you tell me what the "_x" refers to. i understand the rest.
thanks
-
_x is a special variable used in the 'foreach' and 'count' commands (and maybe some others too), representing each element in the array.
The 'foreach' command has the following syntax:
"commands.." foreach array
It will execute "commands.." for each array element, and that element will be assigned to the special variable _x in the commandstring.
I.e.;
"_x SetCaptive true" foreach [unit0,unit1,unit2]Is exactly the same as:
unit0 SetCaptive true
unit1 SetCaptive true
unit2 SetCaptive true
But with foreach we can do that in just one line, and we also dont have to know the contents of the array.
The 'count' command counts the number of elements in an array,
and it has an optional left-side argument which is an expression which must be true for that element to be added to the count result.
Example:
"Captive _x" count [unit0,unit1,unit2]Is the same as _i = 0
? (captive unit0): _i = _i + 1
? (captive unit1): _i = _i + 1
? (captive unit2): _i = _i + 1
-
gee,
a very comprehensive explanation. thanks, that has explained things and i'll get back with the results of using it.
-
ok i tried it and the trigger just activated itself straight away
condition in trigger
("(GetDammage _x) >= 1" count tanks) == count tanks
tanks = [] is made at the start
and in the init field of each tank i put:
tanks = tanks + [this]
anything else to do or any sytax probs anyone can see?
thx
-
Print the contents of 'tanks':
hint format ["%1 = %2", tanks, "GetDammage _x >= 1.0" count tanks]
-
Whats probably happening is that 'tanks = []' is being executed after the tanks-array additions.
Two things comes to mind on how solve this quickly:
1) Prepend tanks=[] ; in one of the tanks' init-fields, you'll have to play around to see which one is initialized first, that one should have it.
2) Check if tanks has been initialized (Check the isVar function) before adding the tank to it, if not, initialize it first.
Or you could use what Hater_Kint said for this.
Create a trigger, Civilian Present, Once, in the OnActivation field type:
tanks = +thislist
-
i finally got the thing working
thanks a lot guys