Jump to content
Sign in to follow this  
Abrahamsen

Trigger based on passengers in helicopter.

Recommended Posts

I have a question. (Multiplayer, it has to work, localitywise)

I want a setup to trigger one of 4 different outcomes.

  1. If one of the units is a passenger in the helicopter, trigger someting
  2. If two of the units are passengers in the helicopter, trigger something else
  3. if three of the units are passengers in the helicopter, trigger something else
  4. if none of the units are passengers, hint something.

The units are civilians that you have to extract. If you get all of them you should get one ending and the task about saving that unit should be set to SUCCESS.

How do I go and do that?

Share this post


Link to post
Share on other sites

Multiple ways to count how many are on a chopper, here one for a specific (named) chopper:

{vehicle _x == myChopper} count myUnitList

More generic, checking any chopper:

{(vehicle _x) iskindof "Helicopter"} count myUnitList

Those will return how many are onboard. That number can be then used for your checks, like:

({vehicle _x == myChopper} count myUnitList) > 1

That would mean there are at least 2 units on the chopper.

If you are going to place 4 trigger with just different number in them, remember that even if your plan is to check for 3 passengers, the 1 and 2 triggers will activate as well, since units will get in one by one.

Checking if all the units are in the chopper:

({vehicle _x == myChopper} count myUnitList) == count myUnitList

Then you can just put on Act: yourRescueTask settaskstate "succeeded"

or to end the mission, change the trigger type to one of the END#s.

Share this post


Link to post
Share on other sites

But wouldn't that count ALL passengers in the helicopter?

I need it to only count specific units.

---------- Post added at 01:04 PM ---------- Previous post was at 01:02 PM ----------

And I need it to tell which unit is in and which is not. When the pilot trigger the trigger I want to know if unit A is in, if B is in and if C is in.

A, B and C each have a task. If A is in then task tskA is triggered. if A and C is in then tskA and tskC is triggered.

Share this post


Link to post
Share on other sites
But wouldn't that count ALL passengers in the helicopter?

I need it to only count specific units.

No, myUnitList is the list of the units you want to check, it can be "[p1,p2,p3]" or "units myWhateverGroup" etc.

And I need it to tell which unit is in and which is not. When the pilot trigger the trigger I want to know if unit A is in, if B is in and if C is in.

A, B and C each have a task. If A is in then task tskA is triggered. if A and C is in then tskA and tskC is triggered.

This works if you have units named unitA, unitB, unitC and tasks named tskA, tskB, tskC

{if (vehicle (call compile format ["unit%1",_x]) == theChopperName) then {
call compile format ["tsk%1 setTaskState ""SUCCEEDED""",_x];
};} foreach ["A","B","C"];

Edit: and replace the chopper name as well, of course

Share this post


Link to post
Share on other sites

Thank you, I will try that out!

I don't have any prior programming skills so I have to teach myself every aspect of coding. Would you mind explaining what exactly happens and for what reason in each step of the code? I know how it works by stuff like why you call compile format something and how %x is used (tsk%1) and how _x works.

Also, if you have the time to explain the execVM command (Script = argument execVM filename).

It's hard building your own working scripts when these basic concepts aren't sticking.

Thank you for the solution to the problem, as said, I'll go try it now :)

---------- Post added at 01:47 PM ---------- Previous post was at 01:45 PM ----------

and actually my tasks are named tskObj0, tskObj1, tskObj2 and soforth. the units are called obj_zar1, obj_zar2, obj_zar3.

Share this post


Link to post
Share on other sites

Also, if you have the time to explain the execVM command (Script = argument execVM filename).

Script = Handle, a variable which refers to the whole script thread (like a process). Rarely needed, but you can check if the whole script is done etc.

argument(s) = Data you want to use inside the script. Examples:

Let's call a script:

"David" execvm "namehint.sqf";

The script itself:

hint _this;

That will display a hint that says "David";

In that we passed only one argument (a string with value "David") to the script. Let's pass multiple values, for that we need to use an array:

["David",25] execvm "nameandagehint.sqf";

The script:

_name = _this select 0;

_age = _this select 1;

hint format ["Name: %1, Age: %2",_name,_age];

That will display a hint with "Name: David, Age: 25". What we did inside the script was to take values from the passed array with command "select". Format is a command to, well, format strings. :) It seems weird at first, but all it does is, it replaces the %1, %2 etc with the values at the end. In this case, %1 is replaced with the value inside _name variable, which is string "David". %2 is replaced with value of _age.

and actually my tasks are named tskObj0, tskObj1, tskObj2 and soforth. the units are called obj_zar1, obj_zar2, obj_zar3.

{if (vehicle (call compile format ["obj_zar%1",_x]) == theChopperName) then {
call compile format ["tskObj%1 setTaskState ""SUCCEEDED""",_x];
};} foreach [1,2,3];

Would you mind explaining what exactly happens and for what reason in each step of the code? I know how it works by stuff like why you call compile format something and how %x is used (tsk%1) and how _x works.

We go through an array with values that are common with in the name of both tasks and units. It can be A, B, C or 1, 2, 3, or whatever. What's common between there?

tsk1

tsk2

unit1

unit2

Yep, 1 and 2.

This time we use command "foreach". As the name suggests, it executes given code for each value inside the array. The value is passed to the code in variable "_x", one by one.

{

the code goes here

} foreach [1,2,3];

Inside the foreach, we check if the vehicle of the unit is the chopper unit.

if (vehicle (call compile format ["obj_zar%1",_x]) == theChopperName) then {

};

That basically does this: vehicle unit == chopper unit. We use here the same format command we saw earlier. It takes the given variable _x (1, 2, 3) and changes string "obj_zar%1" to "obj_zar1", "obj_zar2" and "obj_zar3". But, since that is in a string format and not an object (unit) we could use for the vehicle command, we make it in one with commands call and compile. Compile takes a string and makes it into code that the game engine can execute. Call command just runs that code.

This uses the same idea, but just runs code that updates the task state:

call compile format ["tskObj%1 setTaskState ""SUCCEEDED""",_x];

Edited by Shuko

Share this post


Link to post
Share on other sites

I have never had it explained like that before, that's pure gold! I really get most that now.

THANK YOU SHK. I'll read that through a couple of times now :)

edit:

Hmm. Still can't get it to work. It's not updating the task.

---------- Post added at 03:24 PM ---------- Previous post was at 02:47 PM ----------

I could get this to work:

if (vehicle obj_zar1 == heli1) then {

tskObj0 setTaskState "SUCCEEDED";

};

though, what am I missing?

---------- Post added at 03:28 PM ---------- Previous post was at 03:24 PM ----------

I got this in a trigger now:

if (vehicle obj_zar1 == heli1) then { tskObj0 setTaskState "SUCCEEDED"; } else { tskObj0 setTaskState "FAILED"; };

If you have the guy with you in the helicopter, it's a success, if you don't it's failed.

It works. I can't figur out why I can't get your much cleaner script to work.

---------- Post added at 03:32 PM ---------- Previous post was at 03:28 PM ----------

another thing: It should be the opposite for east side.

If west completes a task, east should fail it and vica versa.

---------- Post added at 03:41 PM ---------- Previous post was at 03:32 PM ----------

I'm just gonna ham-hand something together that works, then ask for expert help on trimming it down to something clean :)

Edited by Abrahamsen

Share this post


Link to post
Share on other sites

Your task name is 0 and unit is 1, they don't match. The code expects that task1 is for unit1, task2 is for unit2 etc.

Share this post


Link to post
Share on other sites
Your task name is 0 and unit is 1, they don't match. The code expects that task1 is for unit1, task2 is for unit2 etc.

yep, that was it. I thought about it, but I didn't think it would stop the whole script from working if it could not find the task.

Share this post


Link to post
Share on other sites

Now how about a script that checks if obj_zar1, obj_zar2 and obj_zar3 dies and if obj_zar1 dies, it sets east sides 1st task as SUCCEEDED and west side as FAILED? (same goes for obj_zar2 and obj_zar3 to tskObj2 and tskObj3).

And if they all die or are rescued the mission ends (with a different END# for each outcome)

How do I setup that?

:D

Share this post


Link to post
Share on other sites

I'd make the following tasks:

tskE1 (kill obj_zar1)

tskE2 (kill obj_zar2)

tskE3 (kill obj_zar3)

tskW1 (rescue obj_zar1)

tskW2 (rescue obj_zar2)

tskW3 (rescue obj_zar3)

Rescue trigger for the chopper:

{
if (vehicle (call compile format ["obj_zar%1",_x]) == heli1) then {
call compile format ["tskW%1 setTaskState ""SUCCEEDED""",_x];
call compile format ["tskE%1 setTaskState ""FAILED""",_x];
};
} foreach [1,2,3];

A trigger for each guy.

Cond:

!alive obj_zar1

on Act:

tskE1 setTaskState "SUCCEEDED";tskW1 setTaskState "FAILED";

End trigger:

({alive _x} count [obj_zar1,obj_zar2,obj_zar3]) < 1

The rescue end trigger can probably done in the chopper trigger, if you tell me how exactly the missions works. Is the chopper trigger checked only once, meaning you have only one chance/rescue trip?

Share this post


Link to post
Share on other sites

I have an extraction that is in a hot LZ, as the ai board the extraction helo I need to count them, when the count reaches 4 units, I need to say a radio message "go go go" so the pilot knows all units are on board and ready to go.

I am thinking it will be a while statement in a trigger something like :

while vehicle (thisList select 0) units count < 4 razor2 sidechat "wait"; sleep 1; else Razor2 sidechat "go go go";

Hmmm but this is flawed, because if one member of the fireteam gets killed the extraction is a failure .

I am just not sure exactly how to syntax it and whether I can put this in a trigger or if it needs to be in a script?

Edited by Pappy60

Share this post


Link to post
Share on other sites

okay, I got passed this by having a separate trigger that has a condition of :

count crew Jolly61 == 5 or count crew Jolly62 == 5; 

tells me if all passengers have boarded on either of the possible helos

Edited by Pappy60

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  

×