Jump to content
Sign in to follow this  
rosentorf

Is atrigger necessary for BIS_fnc_spawnVehicle?

Recommended Posts

Hello,

I am making my first steps in mission editing. My first scenario is a dynamically created "rescue pilots after helicopter crash" mission. For this I want to spawn a helicopter with crew in flight to then crash so I have something to rescue surviving pilots from.

Now, I have found a solution but I am wondering why it is necessary to set it up this way:

_trg = createTrigger["EmptyDetector",getMarkerPos "spawnpos"];

_trg setTriggerArea[5,5,0,false];

_trg setTriggerActivation["NONE","PRESENT",false];

_trg setTriggerStatements["1==1", "_chopper = ([getMarkerPos 'spawnpos', 0, 'UH1Y', west] call BIS_fnc_spawnVehicle) select 0","hint 'test trigger'"];

In the above script I create a trigger that is activated right after creation by itself to then spawn a UH1Y in flight with complete crew. It works but I would like to know why it is not enough to simply put this in the script to achive the same result:

_chopper = ([getMarkerPos "spawnpos", 0, "UH1Y", west] call BIS_fnc_spawnVehicle) select 0;

Do I need the trigger to initialize something? The script is in an external file which is called from within the initialization of the player unit using:

_null = [] execVM "CreateRescueMission.sqf";

I'd really like to understand this as I feel that this trigger is unnecessary and many examples in the forum here show only the function call without any trigger.

Thanks for any help!

rosentorf

Share this post


Link to post
Share on other sites

If the function has to be executed directly when the main script is called, then a trigger is indeed unnecessary. A trigger should be used when something should happen at certain defined conditions which aren't fixed on the timeline (at a more or less random point during a mission).

So indeed you guessed completely right and the whole trigger stuff can be left out in your case.

Just as example: with trigger it would make sense if there would be a Tunguska in the area which the player would have to destroy first before the chopper is (can be) spawned. In this case, the trigger should be linked with the Tunguskas alive status.

As said, just an example.

Share this post


Link to post
Share on other sites

That's what I thought, but if I omit the trigger stuff the Chopper won't be spawned.

Edit: I assume the trigger does something so that the function call works.

Share this post


Link to post
Share on other sites

Hmmm...i don't see any reason why it wouldn't work.

_myArray = [getMarkerPos "spawnpos", 0, "UH1Y", west] call BIS_fnc_spawnVehicle;
waituntil {!isnil ("_myArray")};
_chopper = _myArray select 0;

Untested but try this. Quick shot from the hips.

Share this post


Link to post
Share on other sites

Thanks for your help...unfortunately that does not work either. Maybe I have a fundamental error in my setup?

I created a mission in the editor with a player unit, the function module and a marker called spawnpos. Then I wrote the CreateRescueMission.sqf and call it from within the initialization field of the player unit. The script-file only holds the lines mentioned above. Do I need to make the script wait for something?

EDIT: The lines that you gave me work. I tried them in a Trigger I manually created in the editor. They just won't work in the script file.

Edited by rosentorf

Share this post


Link to post
Share on other sites

These are the contends of CreateRescueMission.sqf:

// spawn chopper

_chopper = ([getMarkerPos "spawnpos", 0, "UH1Y", west] call BIS_fnc_spawnVehicle) select 0;

I have found out just now that if use a trigger to start the "CreateRescueMission.sqf"; the chopper will spawn too. So it seems I should not use the player initialization field to call the script. But what else do you use to start the script in a mission when there is only one unit on the map?

Share this post


Link to post
Share on other sites

A quick test: put this line directly into the players initline:

[getMarkerPos "spawnpos", 0, "UH1Y", west] call BIS_fnc_spawnVehicle

To be honest, i have no clue what happens or doesn't happen. So i try to track it down.

Share this post


Link to post
Share on other sites

Ok, found it out: the functions module isn't initialized at that point where the script is called. You have to wait until initialization is done.

nul = this spawn {
 waituntil {!isnil "bis_fnc_init"};
 [getMarkerPos "spawnpos", 0, "UH1Y", west] call BIS_fnc_spawnVehicle;
};

This code is now tested and works if called directly from the players init line.

The waituntil is the key as it makes sure the functions module is done with initializing.

I assume that in the initial version where it created a trigger, those commands delayed it long enough for the functions module.

Hope you get it working now. Maybe a got idea to have the waituntil by default when working with the functions module.

Share this post


Link to post
Share on other sites

All right!!! :D Thanks a lot!! Finally I can move on with making the mission. I have gotten really frustrated with this. I was assuming every thing gets initialized before the player is created.

This knowledge will help me lots in the future I am sure.

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  

×