Jump to content
Sign in to follow this  
Melmarkian

Trigger created per script should activate if group is dead

Recommended Posts

Hi,

I am testing now for hours to get a script created trigger to work. I create a group with a function which includes a trigger to check if the unit is still alive. Here are the important parts:

_group = _this select 0;

_deathtrigger = createtrigger ["EmptyDetector", getpos player];
_deathtrigger setTriggerArea [0,0,0,false];
_deathtrigger setTriggerActivation ["BLUFOR", "EAST D", false];
   if (debugshow) then {hintc "deathtrigger!";};
   _deathtrigger setTriggerStatements ["({alive _x} count units _group) < 1","patrolactive = false; hintc 'Dead!'",""];

I always get the debug hint "deathtrigger!" but the trigger never activates. Could it be that _group is not the same variable in the trigger?

I also checked the condition seperate with the name of the actually spawned group and the unit counting works.

Edit:

Maybe this could work:

call compile format ["_deathtrigger setTriggerStatements ['({alive _x} count units '%1') < 1','patrolactive = false;',''];", _group];

but I don´t get the syntax right with all this strings.

Edited by Melmarkian

Share this post


Link to post
Share on other sites

you cant use a local variable ( _group) in the statement of the trigger, workaround for placing local variables using format:

_triggerStatement = format["({alive _x} count units %1) < 1","patrolactive = false; hintc 'Dead!'",_group];
_deathtrigger setTriggerStatements [_triggerStatement,""];

Edited by Demonized
edited info

Share this post


Link to post
Share on other sites

Thank you again! :)

Edit:

Still the same problem with the syntax. rpt says:

Error in expression <({alive _x} count units O 1-1-D) < 1>
 Error position: <1-1-D) < 1>
 Error Missing )

Seems to be a problem with how the content of _group is written in the text.

And had to write the format a bit different because it doesn´t work with two strings:

_triggerStatement = format["({alive _x} count units %1) < 1",_group];
   _deathtrigger setTriggerStatements [_triggerStatement,"patrolactive = false; hintc 'Dead!'", ""];

Edited by Melmarkian

Share this post


Link to post
Share on other sites

ops was a bit quick when i posted, i combined cond and on act in same line,

i asume you got it working now.

Share this post


Link to post
Share on other sites

Yes, the statements are working, but the rpt wasn´t related to it.

When I use format to get the content of _group into the statement the check is messed up because the actual groupname is something like 0 1-1-D and it takes it as two arguments

Share this post


Link to post
Share on other sites
Yes, the statements are working, but the rpt wasn´t related to it.

When I use format to get the content of _group into the statement the check is messed up because the actual groupname is something like 0 1-1-D and it takes it as two arguments

yes your right, this works as ive tested it myself this time.

using (units grpname) instead of group:

deathtrigger = createtrigger ["EmptyDetector", getpos player];
deathtrigger setTriggerArea [0,0,0,false];
deathtrigger setTriggerActivation ["BLUFOR", "PRESENT", false];
inittext = format["({alive _x} count %1) < 2",(units grp1)];
deathtrigger setTriggerStatements [inittext,"hintc 'Dead!'",""];

edit: this may count only the units in the group at the time the trigger was created, and not when trigger is activating, not sure.

Edited by Demonized

Share this post


Link to post
Share on other sites

The triggerstatement looks like this:

["({alive _x} count [b 1-1-D:1,B 1-1-D:2]) < 2","hintc 'Dead!'",""]

I think this should work because it doesn´t need to change the units inside the count [array]. It just checks if they are alive.

But i still get the errors:

Error in expression <({alive _x} count [b 1-1-D:1,B 1-1-D:2]) < 2>
 Error position: <1-1-D:1,B 1-1-D:2]) < 2>
 Error Missing ]
Error in expression <({alive _x} count [b 1-1-D:1,B 1-1-D:2]) < 2>
 Error position: <B 1-1-D:1,B 1-1-D:2]) < 2>

seems like the engine doesn´t understand the unit names.

B 1-1-D:1 

Edit:

Tested a bit:

call compile format ["count [%1, %2]", josh1, operator1];

works because it actually writes josh1 and operator1 inside the array.

call compile format ["count %1", (units group player)];

is the same error as always. It writes the B 1-1-1D:1 type unitnames for the unnamed units. So it would work if all units in the group had set variablenames.

Edited by Melmarkian

Share this post


Link to post
Share on other sites

You doing:

_group = _this select 0;

indicates that you start a separate script with execvm.

Thus, all you need is:

_group = _this select 0;
waituntil {{alive _x} count units _group < 1};
patrolactive = false;
hintc "Dead!";

Share this post


Link to post
Share on other sites

Thanks! Never actually thought about it because I put it into a function. But I can spawn instead of call.

But I think it´s a bit weird that the original unitnames aren´t working.

Edited by Melmarkian

Share this post


Link to post
Share on other sites

Well, that's just the game engine. :)

B 1-1-D:1 doesn't refer to an object. It's just it's "name" or ID.

Another option, if you need to use triggers is to use global variables.

Share this post


Link to post
Share on other sites

I actually used a global variable. Because there is only 1 group + a chance of a second reinforcementgroup I return the group created in the function.I created a trigger in the editor which counts the units of the group and a variable which is true as long as the spawn is active.

patrolactive AND ({alive _x} count units activegroup) < 1

&

reinforcementsactive AND ({alive _x} count units reinforcementsgroup) < 1

works pretty good and if I want more groups it's not too complicated to expand. I am working at the moment on a threat system with enemy patrols from different bases and guessed positions of the player depending on his actions.

btw: thanks for your SHK_pos. It helped me a lot to create random patrol points around the guessed positions.

Share this post


Link to post
Share on other sites

Sometimes that old adage "keep it simple" can be effective. If you have a mission that you want to end if all the units in a certain group are killed, a rescue mission maybe. You can just name all the units in that group say p1 to p4 then make a lose end trigger & put !

!alive p1 AND !alive p2 AND !alive p3 AND !alive p4

in the condition

When the last named unit of that group is killed the mission will end.

Simple but it works.:yay:

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  

×