Home   Help Search Login Register  

Author Topic: Non-Existant Units Activating triggers?  (Read 582 times)

0 Members and 3 Guests are viewing this topic.

bored_onion

  • Guest
Non-Existant Units Activating triggers?
« 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?

Offline Mud_Spike

  • Contributing Member
  • **
Re:Non-Existant Units Activating triggers?
« Reply #1 on: 13 Aug 2004, 16:21:53 »
'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:
Code: [Select]
("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:
Code: [Select]
tanks = tanks + [this](You might want to initialize 'tanks' before that with 'tanks = []')

Then in the trigger:
Code: [Select]
("(GetDammage _x) >= 1" count tanks) == count tanks

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Non-Existant Units Activating triggers?
« Reply #2 on: 13 Aug 2004, 16:27:57 »
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"...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

bored_onion

  • Guest
Re:Non-Existant Units Activating triggers?
« Reply #3 on: 13 Aug 2004, 18:03:16 »
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

Offline Mud_Spike

  • Contributing Member
  • **
Re:Non-Existant Units Activating triggers?
« Reply #4 on: 13 Aug 2004, 19:00:38 »
_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:
Code: [Select]
"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.;
Code: [Select]
"_x SetCaptive true" foreach [unit0,unit1,unit2]Is exactly the same as:
Code: [Select]
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:
Code: [Select]
"Captive _x" count [unit0,unit1,unit2]Is the same as
Code: [Select]
_i = 0
? (captive unit0): _i = _i + 1
? (captive unit1): _i = _i + 1
? (captive unit2): _i = _i + 1


bored_onion

  • Guest
Re:Non-Existant Units Activating triggers?
« Reply #5 on: 13 Aug 2004, 19:41:34 »
gee,
a very comprehensive explanation. thanks, that has explained things and i'll get back with the results of using it.

bored_onion

  • Guest
Re:Non-Existant Units Activating triggers?
« Reply #6 on: 13 Aug 2004, 20:38:33 »
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

Offline Mud_Spike

  • Contributing Member
  • **
Re:Non-Existant Units Activating triggers?
« Reply #7 on: 13 Aug 2004, 20:52:02 »
Print the contents of 'tanks':
hint format ["%1 = %2", tanks, "GetDammage _x >= 1.0" count tanks]


Offline Mud_Spike

  • Contributing Member
  • **
Re:Non-Existant Units Activating triggers?
« Reply #8 on: 13 Aug 2004, 21:03:55 »
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:
Code: [Select]
tanks = +thislist

bored_onion

  • Guest
Re:Non-Existant Units Activating triggers?
« Reply #9 on: 13 Aug 2004, 21:16:00 »
i finally got the thing working

thanks a lot guys