Jump to content
Sign in to follow this  
scottb613

Flow Control ?

Recommended Posts

Hi Folks,

Working on my first attempt at real Arma scripting - wiki in one hand and notepad++ in the other...

I'm trying to script a function to launch an Air Assault and for the most part it's going pretty well... I'm starting to get the hang of controlling helicopters via script...

One question - I have bunch of helicopters approaching an LZ - I don't know who's going to be there first - i don't want anyone hovering over a hot LZ waiting for loops in the script to complete... I posted a simplified version of what I am working with below... The code is already running is a "spawned" sqf called from the editor...

I guess a could just spawn each helicopter in its own shell and execute the code for each helicopter separately ? Is there a better way to do this ? Again - just learning so I'm trying to figure out the correct and efficient way... There are more than two helicopters...

while { ( (alive guns1) && !(unitReady guns1) ) } do
{
       sleep 5;
};
 
while { ( (alive guns2) && !(unitReady guns2) ) } do
{
       sleep 5;
};
               
hint "3";
guns1 land "LAND";
guns2 land "LAND";
Regards,

Scott

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites
waituntil {{alive _x AND unitReady _x} count [guns1,guns2,guns3,whatever] > 0};

This will wait until at least 1 unit inside the array will be ready AND alive.

You could also make a small function and spawn it from within the script that spawns all choppers:

_myLandingFunction = {

params ["_chopper"];
sleep 3; //wait 3 seconds so the chopper can receive a waypoint or move command
waituntil {unitReady _chopper};
if (!alive _chopper) exitWith {false};
_chopper land "LAND";

};

//your spawn code here

_land = [_spawnedChopper] spawn _myLandingFunction;

In this example each chopper spawns his own landing function,

waituntil doesn't check for alive state since it's handled afterwards, so the loop exits if the chopper is destroyed, but makes the chopper land if it's alive.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I guess a could just spawn each helicopter in its own shell and execute the code for each helicopter separately ? Is there a better way to do this ?

 

Well, if you want them to act completely independent of eachother, then this is just the way.

 

 

 

Another option would be to mess around with limitSpeed in order to make sure they arrive at the same time.

 

ps.: notepad++ is great but for sqf I'd really recommend you to give poseidon a try:

https://forums.bistudio.com/topic/155514-poseidon-advanced-text-editor-for-scripts-configs/

  • Like 1

Share this post


Link to post
Share on other sites

Hi Grumpy,

Thanks for the response...

One bit of clarification ? If I understand it correctly - the first helicopter to be "alive" and "ready" will break the loop - thereby - issue land commands to every helicopter all at once - even those not ready ? From testing - it seems I should have each helicopter at its final waypoint location before issuing the land command to the respective helicopter ?

Regards,

Scott

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites

HI Folks,

OK - thanks for the responses - let me play with this and I'll take a gander at that other editor as well...

Much appreciated - gents...

Regards,

Scott

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites

Hi Folks,

So putting it all together - might this seem plausible ? Haven't had a chance to try it - just typed up on my iPad...

//My Launch Script Slicks//
 
hint "Launch Slicks";
FlgGun = 1;                                                                // flags global
FlgIni = 0;
_slkU1 = slick1;                                                     // slick units
_slkU2 = slick2;
_slkU3 = slick3;
_slkU4 = slick4;
_slkG1 = group slick1;                                               // slick groups
_slkG2 = group slick2;
_slkG3 = group slick3;
_slkG4 = group slick4;
_lzPad = _lzPad;                                    // lz landing pads
_lzPad1 = getPos LzPad1;                                       
_lzPad2 = getPos LzPad2;
_lzPad3 = getPos LzPad3;
_lzPad4 = getPos LzPad4;
_hmPad1 = getPos HmPad1;                                        // home landing pads
_hmPad2 = getPos HmPad2;
_hmPad3 = getPos HmPad3;
_hmPad4 = getPos HmPad4;
_count1 = 1;                                                         // counters    
_count2 = 1;                                                   
 
private ["_slkG1","_slkG2","_slkG3","_slkG4","_lzPad1","_lzPad2","_lzPad3","_lzPad4","_count1","_count2"];
 
_myLandSlick = {                                                     // function lz land
params ["_chopper"];
sleep 3;                                                            
waituntil {unitReady _chopper};
if (!alive _chopper) exitWith {false};
_chopper land "GET OUT";
};
 
sleep 10;
 
{
     while {(count (waypoints _x)) > 0} do                // delete all waypoints
     {  
           deleteWaypoint ((waypoints _x) select 0);
           _count1 = _count1 + 1;
     };
     _lzPad = str _lzPad + str _count2;
     _x addWaypoint [_lzPad,0,1];                               // add lz waypoint
     [_x, 1] setWaypointType "MOVE";                            // move to waypoint
     _count2 = _count2 + 1;
     sleep 5;
     _land = [_x] spawn _myLandSlick;                           // spawn landing function
} foreach [_slkG1,_slkG2,_slkG3,_slkG4];
Regards,

Scott

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites

Hi Folks,

I thinks I'm making some pretty good progress on my first attempt at Arma scripting... Much of what I'm trying to accomplish seems to be working - LOL - still working on the guns side if the house and haven't started testing my slicks yet... I have a keg in both Arma 2 for Unsung and Arma 3 for IF and RHS... Some of the commands had to be edited to make them backwards compatable....

For reference:

//=============================//
// GUNSHIPS - My Launch Script //
//=============================//

// Given: Two loaded gunships ready for launch - named as listed in assets.
// Given: Player named s1.

// Assets: (guns1 - gunship helo) (guns2 - gunship helo) (M1 - initial lz target marker) (M2 - initial lz target marker)
// Assets: (s1 - player)

hint "Launch Gunships";

// global var - run flag //
FlgGunRtb = 0;

// var - gun units //
_gunU1 = guns1;
_gunU2 = guns2;

// var - gun groups //
_gunG1 = group guns1;
_gunG2 = group guns2;

// var - array test //
_aray1 = true;
_aray2 = true;

// var - player position //
_posit = getPos s1;

private ["_gunU1","_gunU2","_gunG1","_gunG2","_posit","_targ1","_targ2","_aray1","_aray2"];

sleep 2;

// Get marker positions - M1 M2 //
_mpos1 = getMarkerPos "M1";
_mpos2 = getMarkerPos "M2";

{
	// Test to see if markers exists - M1 //
	_aray1 = _mpos1 select _x;
	if ( _aray1 != 0 ) exitWith {false};
} foreach [0,1];

	hint format["aray1 = %1",_aray1];
	sleep 2;

{
	// Test to see if markers exists - M2 //
	_aray2 = _mpos2 select _x;
	if ( _aray2 != 0 ) exitWith {false};
} foreach [0,1];

	hint format["aray2 = %1",_aray2];
	sleep 2;

// If either M1 or M2 missing - create new positions //
if (_aray1 != 0 && _aray2 != 0) then
{
	_targ1 = getMarkerPos "M1";
	_targ2 = getMarkerPos "M2";
	
	hint "M1 and M2 Markers Exist";
}
else
{
	// Get player position and break down array //
	_posit = getPos s1;
	_arayX = _posit select 0;
	_arayY = _posit select 1;
	_arayZ = _posit select 2;

	// Define new position 1 //
	_arayXn = _arayX - 150;
	_arayYn = _arayY + 150;

	// Create new position array 1 //
	_targ1 = [_arayXn, _arayYn, arayZ];
	
	// Create new marker M1 //
	_mkr1 = createMarker ["M1", _targ1];
	_mkr1 setMarkerShape "ICON";
	_mkr1 setMarkerType "hd_dot";
	_mkr1 setMarkerText "M1-SAD";

	// Define new position 2 //
	_arayXn = _arayX + 150;
	_arayYn = _arayY - 150;

	// Create new position array 2 //
	_targ2 = [_arayXn, _arayYn, arayZ];
	
	// Create new marker M2 //
	_mkr2 = createMarker ["M2", _targ2];
	_mkr2 setMarkerShape "ICON";
	_mkr2 setMarkerType "hd_dot";
	_mkr2 setMarkerText "M2-SAD";

	hint "No Defined Markers";
};

sleep 2;

// Delete all waypoints guns1 //
while {(count (waypoints _gunG1)) > 0} do
{
	deleteWaypoint ((waypoints _gunG1) select 0);
	hint "delete waypoints gunG1";
	sleep 2;
};

// Delete all waypoints guns2 //
while {(count (waypoints _gunG2)) > 0} do
{
	deleteWaypoint ((waypoints _gunG2) select 0);
	hint "delete waypoints gunG2";
	sleep 2;
};

// Create new SAD waypoint and launch guns 1 //
_gunG1 addWaypoint [_targ1,0,1];
[_gunG1, 1] setWaypointType "SAD";
_gunU1 forceSpeed 100;
hint "Launch guns1";
sleep 5;

// Create new SAD waypoint and launch guns 2 //
_gunG2 addWaypoint [_targ2,0,1];
[_gunG2, 1] setWaypointType "SAD";
_gunU2 forceSpeed 100;
hint "Launch guns2";
//==========================//
// GUNSHIPS - My RTB Script //
//==========================//

// Given: Two loaded gunships ready for launch - named as listed in assets.
// Given: Player named s1.

// Assets: (guns1 - gunship helo) (guns2 - gunship helo) (M1 - target marker) (M2 - target marker)
// Assets: (HmPad5 - home helo pad) (HmPad5 - home helo pad)

// global var - run flag //
FlgGunRtb = 1;

// var - gun units //
_gunU1 = guns1;
_gunU2 = guns2;

// var - gun groups //
_gunG1 = group guns1;
_gunG2 = group guns2;

/ var - home helo pad //
_hmPad5 = getPos HmPad5;
_hmPad6 = getPos HmPad6;

private ["_gunU1","_gunU2","_gunG1","_gunG2","_hmPad5","_hmPad6"];

hint "Gunship RTB";
sleep 2;

// Delete any markers //
deleteMarker "M1";
deleteMarker "M2";

// Delete waypoints guns1 //
while {(count (waypoints _gunG1)) > 0} do
{
	deleteWaypoint ((waypoints _gunG1) select 0);
	hint "Delete Waypoints guns1";
	sleep 2;
};

// Delete waypoints guns2 //
while {(count (waypoints _gunG2)) > 0} do
{
	deleteWaypoint ((waypoints _gunG2) select 0);
		hint "Delete Waypoints guns1";
		sleep 2;
};

// FUNCTION - landing //
_myLandGun = {
	hint format ["helo func start = %1", _this];
	// delay - to make sure ready //
	sleep 3;
	waituntil {unitReady _this};
	if (!alive _this) exitWith {false};
	if ( FlgGunRtb == 0 ) exitWith {false};
	_this land "LAND";
	hint format ["helo func end = %1", _this];
	sleep 3;
	};

		hint "Add Waypoints guns1";
		sleep 2;

// Add waypoints guns1 and spawn land //
_gunG1 addWaypoint [_hmPad5,0,1];
[_gunG1, 1] setWaypointType "MOVE";
_gunG1 setBehaviour "CARELESS";
_gunG1 setCombatMode "BLUE";
_land = [_gunU1] spawn _myLandGun;

		hint "Add Waypoints guns2";
		sleep 2;

// Add waypoints guns2 and spawn land //
_gunG2 addWaypoint [_hmPad6,0,1];
[_gunG2, 1] setWaypointType "MOVE";
_gunG2 setBehaviour "CARELESS";
_gunG2 setCombatMode "BLUE";
_land = [_gunU2] spawn _myLandGun;

Regards,
Scott


Sent from my iPad using Tapatalk

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  

×