Jump to content
Ex3B

Making the AI wait to open their chute

Recommended Posts

Basically I want to have a paradrop from high altitude (low altitude thread from MANPADS), and I find plenty of scripts to get the AI to eject, but I'd like them to wait to open their chute, instead of having them float around for a long, long time at the start of the mission.

How can I script it so that the AI will wait to open their chute?

My only idea so far is to not give them any chutes, and add a chute to them by script when they get below a certain altitude.

Share this post


Link to post
Share on other sites

Good idea. Do it like you said.

 

HALOdrop = [] spawn {

  waitUntil {
    sleep 0.5; 
    (getPos player) select 2 > 150 
    }; 
player addItem "Steerable_Parachute_F";
};


**untested

Share this post


Link to post
Share on other sites
51 minutes ago, wogz187 said:

Good idea. Do it like you said.

 

HALOdrop = [] spawn {

  waitUntil {
    sleep 0.5; 
    (getPos player) select 2 > 150 
    }; 
player addItem "Steerable_Parachute_F";
};


**untested

wrong!

 

1. AI is not a player

2. condition is wrong. it should wait until  (getPos _unit) select 2 < 150 

Share this post


Link to post
Share on other sites

@sarogahtyp

Better?
 

HALOdrop = [] spawn {

  waitUntil {
    (getPos _unit) select 2 < 150 
    }; 
_unit addItem "Steerable_Parachte_F";
};

** UNTESTED
Will the AI open the parachute?

Share this post


Link to post
Share on other sites
2 hours ago, wogz187 said:

Will the AI open the parachute?

Very simple for you to test yourself.  Name an AI unit Bob, run in the editor.  setPos bob 1000M high, and run the mini-script on him.

Share this post


Link to post
Share on other sites

@johnnyboy
 

Quote

Very simple for you to test yourself.  Name an AI unit Bob, run in the editor.  setPos bob 1000M high, and run the mini-script on him.

@Ex3B

Share this post


Link to post
Share on other sites

*sigh* I hate arma scripting...

So I've placed a file named HALOdrop.sqf (can't seem to put it in an init field).

that file has this:

Quote

HALOdrop = [] spawn {

 

  waitUntil {
    (getPos _unit) select 2 < 150
    }; 
_unit addItem "Steerable_Parachute_F";
};

*note the parahcute typo has been corrected.

Then I have a trigger with this in on activation:

Quote

Bob setPosASL [getPosASL Bob select 0, getPosASL Bob select 1, 900]; _handle = Bob execVM "HALOdrop.sqf";

 

It keeps telling me that there's an error because _unit is not defined. I tried with "this" instead of "_unit", but then it calls this an "undefined" variable.

I changed "this"/"_unit" to "Bob", and it gave no error messages.

It also doesn't seem to spawn a parachute, poor Bob falls to his death every time, with no parachute on him. I changed addItem to addBackpack, still poor Bob never gets a parachute.

 

Don't know what to do, would like a script that can run once for every member of a squad, like the eject script I'm using:

Spoiler

_group = _this select 0;
_vehicle = _this select 1;

if ( (typename _group != "GROUP") or (typename _vehicle != "OBJECT") ) exitwith {
hintSilent "Invalid Parameters parsed";
};

sleep 1;

{
       _x allowDamage false;
unassignvehicle _x;
_x action ["EJECT", _vehicle];
sleep 0.015;
       _X allowDamage true;
} foreach units _group;

 

Share this post


Link to post
Share on other sites

Thanks for the script.

In the meantime, I found that this simple code works in the init, but I would like to generalize it so that I don't have to change the name every time

 

Quote

_spl = [] spawn { waitUntil { 
    (getPos Bob) select 2 < 120 
    };  
Bob addBackpack "B_Parachute"; };  
 

 

  • Like 1

Share this post


Link to post
Share on other sites
51 minutes ago, Ex3B said:

I would like to generalize it so that I don't have to change the name every time

in which way? are you spawning the AI? is it placed in editor? do u have an array of the units objects? is it a group and you have the object of the leader? give details and u ll get those as well.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Ex3B said:

*sigh* I hate arma scripting...

So I've placed a file named HALOdrop.sqf (can't seem to put it in an init field).

that file has this:

*note the parahcute typo has been corrected.

Then I have a trigger with this in on activation:

 

It keeps telling me that there's an error because _unit is not defined. I tried with "this" instead of "_unit", but then it calls this an "undefined" variable.

I changed "this"/"_unit" to "Bob", and it gave no error messages.

It also doesn't seem to spawn a parachute, poor Bob falls to his death every time, with no parachute on him. I changed addItem to addBackpack, still poor Bob never gets a parachute.

 

Don't know what to do, would like a script that can run once for every member of a squad, like the eject script I'm using:

  Reveal hidden contents

_group = _this select 0;
_vehicle = _this select 1;

if ( (typename _group != "GROUP") or (typename _vehicle != "OBJECT") ) exitwith {
hintSilent "Invalid Parameters parsed";
};

sleep 1;

{
       _x allowDamage false;
unassignvehicle _x;
_x action ["EJECT", _vehicle];
sleep 0.015;
       _X allowDamage true;
} foreach units _group;

 

_unit is not defined inside the scope of the spawned script, hence the error.

"this" also doesn't exist inside the scope of the spawned script, it's a magic variable that only works in a few places.

 

Pretty basic stuff, I suggest reading one of the various guides/tutorials for sqf scripting or go through Mr. Murrays guide.

Easily doable without prior knowledge in a weekend or two (4-5 hours total).

 

The waitUntil will complete everytime the checked unit is below 150m AGLS, if the chopper takes off from ground level the unit receives a backpack as soon as the mission starts.

You might want to check this using a getOut eventHandler, depending if you spawn those units mid mission, upon mission start inside chopper etc.

 

Cheers

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
2 hours ago, Grumpy Old Man said:

-Snip-

 

 

My post is not a helpful contribution to this forum at all - I just wanted to point out that your responses are not living up to your username, and this makes me a little sad.

  • Haha 1

Share this post


Link to post
Share on other sites
3 minutes ago, genesis92x said:

 

My post is not a helpful contribution to this forum at all - I just wanted to point out that your responses are not living up to your username, and this makes me a little sad.

Well if it helps to put your mind at ease

Spoiler

 

I was looking grumpy while typing

 

 

Cheers

  • Like 2
  • Haha 2

Share this post


Link to post
Share on other sites

@Ex3B,
 

Quote

Bob addBackpack "B_Parachute"

My bad.

Share this post


Link to post
Share on other sites
2 hours ago, wogz187 said:

@Ex3B,
 

My bad.

No problem, I was able to make it work for a single unit with some changes. How would I get the "_unit" part working?

 

5 hours ago, sarogahtyp said:

in which way? are you spawning the AI? is it placed in editor? do u have an array of the units objects? is it a group and you have the object of the leader? give details and u ll get those as well.

I am placing the AI in the editor. I would like to either a) have the script apply it to all units within a specific group or (b) just be able to copy and paste the same thing into each unit's init field without having to name the unit and make a corresponding change in the init field.

 

Actually, I'd rather have all units start with backpacks, and just not have them open it.

Maybe if I do disableAI "ALL" they won't open the chute, and the script can instead enableAI on the units and have them open their chutes then?

*edit* nope, they still open the chute with disableAI "ALL";

 

4 hours ago, Grumpy Old Man said:

_unit is not defined inside the scope of the spawned script, hence the error.

"this" also doesn't exist inside the scope of the spawned script, it's a magic variable that only works in a few places.

 

Pretty basic stuff, I suggest reading one of the various guides/tutorials for sqf scripting or go through Mr. Murrays guide.

I just downloaded the guide, will try to read it soon. I notice that _x and _unit do not work, yet in the eject script that I was using (copied from somewhere on these forums, I forget):

Spoiler

_group = _this select 0;
_vehicle = _this select 1;

if ( (typename _group != "GROUP") or (typename _vehicle != "OBJECT") ) exitwith {
hintSilent "Invalid Parameters parsed";
};

sleep 1;

{
       _x allowDamage false;
unassignvehicle _x;
_x action ["EJECT", _vehicle];
sleep 0.015;
       _X allowDamage true;
} foreach units _group;

I don't see anywhere that _x would be defined, yet it works... so I don't understand

Share this post


Link to post
Share on other sites
22 minutes ago, Ex3B said:

How would I get the "_unit" part working?

Depends on how you execute the function,

from an objects init field using your example above could look like this:

_spl = [this] spawn {
	params ["_unit"];//declares the first passed parameter as _unit
	waitUntil { 
    	(getPos _unit) select 2 < 120 
    };  
	_unit addBackpack "B_Parachute";
};  

This way you could copypaste the snippet to other units and it will still work.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Ok, so I've got *something working*, I would still prefer a solution having parachutes on units. Having it affect a player (or playble unit that could be AI or player controlled) is not ideal... since a player will start with no chute and be confused with limited time...

Anyway....

In the trigger for ejecting them, I've also put:

 _xhandle2 = [Spartan] execvm "HALOdrop.sqf";  // where "Spartan" is the name of the group

 

Then my HALOdrop.sqf script is:

 

_group = _this select 0;
if ( (typename _group != "GROUP") ) exitwith {
hintSilent "Invalid Parameters parsed";
};
sleep 1;
{
  waitUntil {
    sleep 0.25; 
    (getPos _x) select 2 < 125 
    }; 
_x addBackpack "B_Parachute"; hint "Deploy your parachute!";
} foreach units _group;

You really need to be on the ball to deploy your chute in time, the AI do it immediately after they get it

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, Ex3B said:

Ok, so I've got *something working*, I would still prefer a solution having parachutes on units.

If you want parachutes on units so it looks better to a watching player or in a movie, add a backpack to the unit (choose a backpack that looks most like the parachute pack).  Then modify your script to first remove that backpack before adding parachute.

  • Like 1

Share this post


Link to post
Share on other sites

Well, I'd like the player to be able to open the parachute earlier, but not AIs, because they open at the earliest opportunity.

When placing units that are playble (could be AI or player controlled) this is a problem.

To the player, when the backpack spawns, they need to realize it and then select the action and press enter. The AI will pop the chute the first time step that they can... so I don't like this solution so well.

My only alternative is to allow players to take parachutes one their own before getting ejected.

Share this post


Link to post
Share on other sites
11 hours ago, Ex3B said:

Well, I'd like the player to be able to open the parachute earlier, but not AIs, because they open at the earliest opportunity.

When placing units that are playble (could be AI or player controlled) this is a problem.

To the player, when the backpack spawns, they need to realize it and then select the action and press enter. The AI will pop the chute the first time step that they can... so I don't like this solution so well.

My only alternative is to allow players to take parachutes one their own before getting ejected.

 

your code modified to get backpack on players instantly but wait until height reached for AIs:

 

_group = _this # 0;

 if ( (typename _group != "GROUP") ) exitwith { hintSilent "Invalid Parameters parsed";};

 sleep 1;

 _d= {
  _d = [_x] spawn
  {
   if !(isPlayer _x) then
   {
    waitUntil 
    {
     sleep 0.25; 
     (getPos _x) select 2 < 125 
    };
   };
   _this # 0 addBackpack "B_Parachute"; hint "Deploy your parachute!";
  };
 } count units _group; 

 

Share this post


Link to post
Share on other sites

You don’t want to run your script in scheduled and waituntil. Something time critical as opening of parachute at correct altitude has to run where it is guaranteed to happen as soon as condition is true. The guarantee you can get like that is from EachFrame event.

  • Like 1

Share this post


Link to post
Share on other sites
36 minutes ago, killzone_kid said:

You don’t want to run your script in scheduled and waituntil. Something time critical as opening of parachute at correct altitude has to run where it is guaranteed to happen as soon as condition is true. The guarantee you can get like that is from EachFrame event.

 

just a try, not tested:

_group = _this # 0;


if ( (typename _group != "GROUP") ) exitwith { hintSilent "Invalid Parameters parsed";};

Ex3BParaUnits = [];

sleep 1;

_d= 
{
 if !(isPlayer _x) then
 {
 
  _d = Ex3BParaUnits pushBack _x;

 }
 else
 {
  _x addBackpack "B_Parachute"; hint "Deploy your parachute!";
 };
} count units _group; 


_d = addMissionEventHandler["EachFrame", 
{
 if (Ex3BParaUnits isEqualTo [] ) exitWith { removeMissionEventHandler ["EachFrame", _thisEventHandler]; };

 _readyUnits = Ex3BParaUnits select { (getPos _x) # 2 < 125 };


 if ( _readyUnits isEqualTo [] ) exitWith {};

  
 Ex3BParaUnits = Ex3BParaUnits - _readyUnits;


 {
  _x addBackpack "B_Parachute";   
 } count _readyUnits;
}];

 

Share this post


Link to post
Share on other sites
Just now, sarogahtyp said:

typename _group != "GROUP")

Prefer isEqualType over typeName

 

Just now, sarogahtyp said:

_d =

Why are you assigning _d variable twice and never using it?

 

1 minute ago, sarogahtyp said:

Ex3BParaUnits = [];

You are clearing all units everytime a new group is pushed, what if there are two groups in the air at the same time?

 

2 minutes ago, sarogahtyp said:

_d = Ex3BParaUnits pushBack _x;

Why store in a variable? doesn't make any sense?

 

3 minutes ago, sarogahtyp said:

_readyUnits = Ex3BParaUnits select { (getPos _x) # 2 < 125 };

https://community.bistudio.com/wiki/unitsBelowHeight

  • Like 2

Share this post


Link to post
Share on other sites
13 minutes ago, Dedmen said:

Why are you assigning _d variable twice and never using it?

a habit to avoid return values. _d is just a dummy.

 

13 minutes ago, Dedmen said:

You are clearing all units everytime a new group is pushed, what if there are two groups in the air at the same time?

true but not requested by op so far. also the first group would get a nice touchdown :D

 

13 minutes ago, Dedmen said:

Why store in a variable? doesn't make any sense?

avoiding the return value to conflict with count

 

13 minutes ago, Dedmen said:

thx, didn't know bout that command.

Share this post


Link to post
Share on other sites

I haven't read the entire thread, so I may be misunderstanding what the OP wants, but an easy way to get this to work would be...

 

Place a trigger on the LZ with the trigger size, A 250, B 250, C 125

 

Name your group, group1

 

In the trigger, activation type, Bluefor present, 

 

On activation 

 

{_x addBackpack "B_Parachute"; 
} foreach units group1; 0 = player spawn {waitUntil {getPosATL _this select 2 < 122}; player action ["openParachute"];};

 

This does everything automatically, no need for the player to have to try to open his cute as the last second.

 

You can give the player a parachute from the start, it doesn't matter.

 

This may not be exactly what the OP wants, but it's the simplest way to do this. 

  • 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

×