Jump to content
Sign in to follow this  
vrakpant

!alive trigger on spawned units using a spawned trigger

Recommended Posts

Hi! I'm working on a small script to respawn a group of units upon death, mostly as an exercise, so inb4 links to respawn scripts on armaholic.

My script is:
 

_myGroup = createGroup West;
_Soldier = _myGroup createUnit ["B_Soldier_F", getmarkerpos "start",[],0.8,"Sergeant"];
_Soldier2 = _myGroup createUnit ["B_Soldier_F", getmarkerpos "start",[],0.8,"private"];
_trg = createTrigger ["EmptyDetector", getPos _soldier];
_trg setTriggerActivation ["NONE", "PRESENT", false];
_trg setTriggerStatements ["((!alive _soldier) and (!alive _soldier2))", "hint 'test'",""];

And it passes without any error-messages in the editor, but when I kill _soldier and _soldier2, the hint at the end does not show up. Where did I go wrong, is it the names?

Share this post


Link to post
Share on other sites

Make the soldier names global, such as Soldier and Soldier2 without the underscore.

Share this post


Link to post
Share on other sites

You cant use local variables in trigger code. Local variables are local for script after script done your local variables becomes undefined.

You need to storage objects variable on the trigger using setvariable command like this:

_myGroup = createGroup West;
_Soldier = _myGroup createUnit ["B_Soldier_F", getmarkerpos "start",[],0.8,"Sergeant"];
_Soldier2 = _myGroup createUnit ["B_Soldier_F", getmarkerpos "start",[],0.8,"private"];
_trg = createTrigger ["EmptyDetector", getPos _soldier];
_trg setTriggerActivation ["NONE", "PRESENT", false];
_trg setVariable ["soldier", _Soldier];
_trg setVariable ["soldier2", _Soldier2];
_trg setTriggerStatements ["
private ['_soldier', '_soldier2'];
_soldier = thisTrigger getVariable 'soldier';
_soldier2 = thisTrigger getVariable 'soldier2';
!alive _soldier && !alive _soldier2",
"
hint 'test';
",""
];

The difference between AZCoder proposition  is that there will be no global variables "Soldier" and "Soldier2"  on machine where the script was executed.

  • Like 1

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  

×