Jump to content
Sign in to follow this  
Chemnitzer

Trigger identifying a triggering unit

Recommended Posts

Helo,

I need help with a silly problem, I cannot resolve myself.

How can I pass identity of an unit activating a trigger to a script executed by this trigger on activation?

For example - I want to place a trigger set to, let's say, civilian/repeatedly. I want this trigger - when activated by any civilian unit (unit, not group) - to launch a script ordering this unit to do something, to go somewhere etc.

E.g. I want any civilian unit activating the trigger to go to a marker named "destinationmarker".

And so I place something like this in the trigger's on activation field:

[???] exec "myscript.sqs"

And then in myscript.sqs...

??? = _unit

_unit domove position destinationmarker

exit

What should I place instead of ???s to have this script working?

Kind regards

Chemnitzer

Share this post


Link to post
Share on other sites

Thank you!

But how should I define this unit inside the script then?

Would it be _unit = this select 0?

Regards

Chemnitzer

Share this post


Link to post
Share on other sites

Yes, but with an underscore before 'this', like this:

_unit = _this select 0

Share this post


Link to post
Share on other sites

OK, thank you very much!

EDIT

My script is generally working, almost perfect.

Just one more question and a problem.

What should I add to the {[_x] exec "myscript.sqs"} forEach thisList line to pass trigger's name to the script too?

And my problem is, that even if the units are commanded to go with these lines:

_unit SetBehaviour "CARELESS"

_unit SetSpeedMode "LIMITED"

_unit domove position _destination

...some of them are still running, as if they were in the "normal" speed mode. Let's say some 80 per cent of units are walking, but the rest are running. I use standard OFP civilians and some Farmland ones - but this running issue appears in both cases. What's wrong here?

Kind regards

Chemnitzer

Edited by Chemnitzer

Share this post


Link to post
Share on other sites

How large is the trigger area? Trigger doesn't activate again until it deactivates, so units staying inside could prevent units coming later from having the trigger activate on them.

Share this post


Link to post
Share on other sites

Hi all.

My first post here.

And my problem is, that even if the units are commanded to go with these lines:

_unit SetBehaviour "CARELESS"

_unit SetSpeedMode "LIMITED"

_unit domove position _destination

...some of them are still running, [..]. What's wrong here?

As correctly suggested by Pulverizer, you must consider another way to catch the units inside (and still entering) the trigger.

Forget the method {[_x] exec "myscript.sqs"} forEach thisList.

Why?

I'll simulate a typical chain of events in which the above approach fails to satisfy your expectations:

a- mission starts: the trigger status is OFF (no units present by design);

b- some units enter, at the same time, the area of the trigger: the trigger meets the condition and the event "On Activation" is called, so your script too (since the use of "ForEach", you'll have multiple calls);

c- each istance of your script will contain an unit as parameter;

d- one unit is still inside the trigger area: the trigger status is still ACTIVATED;

e- a new unit enter the trigger area: nothing happens;

f- both unit of "d" and "e" points leave the trigger area: the trigger status is now OFF, the condition is no more met and the event "On Deactivation" is called.

Go to "b" point.

The good way for you.

In the field "On Activation" put: trigger_name Exec "myscript.sqs".

Your script will be called once (one istance) and will parse continuosly (loop) the array "List _THIS", where "_THIS" is the reference to the object trigger named "trigger_name".

As soon the array "List _THIS" is empty, the script exits.

A debug sample of the script "myscript.sqs":

_list_old=[]

#LoopTrig
_list_now=(List _THIS)

@((Count _list_now)!=(Count _list_old))

Player GlobalChat Format ["§ %1",_list_now]

;Parses the array.
_t=(Count _list_now)

;Did all units leave the trigger area?
?_t<1:Player GlobalChat "§ Bye!";Exit

_i=0
#LoopNewUns
_un=(_list_now Select _i)

;Look for new units.
?(_un In _list_old):GoTo "NextNewUns"

;Here your code to apply to the unit "_un".
Player GlobalChat Format ["§ _un=%1 entered",_un]

#NextNewUns
_i=_i+1
?_i<_t:GoTo "LoopNewUns"

;Note the "=+": duplicates the array in memory.
_list_old=+_list_now
GoTo "LoopTrig"

Try it and the report us if the units are seen as you expect.

Regards,

j0e

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×