Home   Help Search Login Register  

Author Topic: How do I stop a helicopter from taking off before I want it to?  (Read 2190 times)

0 Members and 1 Guest are viewing this topic.

Offline Griff

  • Members
  • *
(I realize I posted a topic only few hours ago, but this is completely unrelated, so I hope it's OK)

I have a Mi-17 loaded with troops (placed in the heli with the moveInCargo init script). The helicopter is set to do this:
1. "MOVE" about two feet north. This is synchronized with a trigger activated by BLUFOR.
2. "UNLOAD TRANSPORT" in the town next to the trigger. Since waypoint 1. is synchronized with the trigger, it won't do this until the trigger is activated (basic knowledge for you experienced guys, but just saying).
3. "MOVE" far away, meaning it will leave the area after unloading the troops.

The troops are set to do this:
1. "SEEK AND DESTROY" in the town. Since the helicopter is set to move, they won't do this until the helicopter has landed.

Now, the problem is that if the players use a long time to get to the trigger area, the helicopter might just run out of fuel. It needs to take off in the first place because of waypoint 1. (and the sequence won't work if I remove that waypoint), and changing wapoint 1. to "HOLD", for example, does nothing.

So I can't figure out how to keep the helicopters grounded. And will the troops exit the helicopter before it reaches the landing site if I do?

The whole sequence works like occasionally skippy clockwork if the players reach the trigger in time (some times the helicopter will fly straight into the mountainside, or bail out for some inexplicable reason, but it works most of the time), the helicopter will fly to the objective, land, the troops will get out and the helicopter will fly away.

But it ain't that impressive if it never happens, you know?
« Last Edit: 10 Feb 2009, 20:32:49 by Griff »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
You may refuel it in a constant loop:
Code: [Select]
while {alive mychopper} do
{
   mychopper setFuel 1.0;
   Sleep 20;
};

Make sure you execute this there where the chopper is local, if full of AI, then the server, in case of doubt, everywhere.

Offline Griff

  • Members
  • *
Yikes, scripting. :-s

I've tried reading some sections of this tutorial here: http://www.ofpec.com/forum/index.php?topic=28702.0
But I'm completely lost, it's like French to me (and I'm NOT good at French). I haven't done any scripting at all, so if you could explain super-quick how to implement it in my mission I would ever grateful.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Create a text file named init.sqf
inside that file (which is a script that will be executed always and automatically as soon as your mission starts), put:

Code: [Select]
Sleep 1;
while {alive mychopper} do
{
   mychopper setFuel 1.0;
   Sleep 20;
};

Forgot to say, that init.sqf should be in your mission folder (there where your mission.sqm is).

Change mychopper by the name of your chopper.

Offline Griff

  • Members
  • *
And it works like a charm. You're a wonderful man, man. :)

So if I want to do it for the rest of my vehicles, I just copy/paste it like this in the same file?
Code: [Select]
Sleep 1;
while {alive mychopper} do
{
   mychopper setFuel 1.0;
   Sleep 20;
};
Sleep 1;
while {alive mystardestroyer} do
{
   mystardestroyer setFuel 1.0;
   Sleep 20;
};

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Nope, because the firt while condition will not allow the execution of the second one as long as mychopper is alive.
What you can do is the following:
Code: [Select]
{
   [_x] spawn
   {
      _vehicle = _this select 0;
      while {alive _vehicle} do
      {
         _vehicle setFuel 1.0;
         Sleep 20;
      };
   };
} forEach [mychopper, mystardestroyer];

For each vehicle in the array, a new block of code is executed in paralel (spawn) to refuel it while it is alive.