Jump to content
scottb613

Simple test to see if asset exists ?

Recommended Posts

Hi Folks,

 

How do you test to see if the asset exits - in my case a helicopter named "slick1" ? The end result I need an array with only those helicopters that exist...

 

I started with checking the distance from 0-0-0 - a kludge I know...

 

{

//@@@//
hint format["slick = %1",_x];
sleep _debugTime;
//@@@//

	_slkhold = getpos _x;
	_slkdist = _slkhold distance _slkzero;
	if ( _slkdist != 0 ) then
	{
	switch (_x) do {
		case slick1: { _slkGrp = slick1 };
		case slick2: { _slkGrp = slick2 };
		case slick3: { _slkGrp = slick3 };
		case slick4: { _slkGrp = slick4 };
	};
	[_slkarr,_slkGrp] call BIS_fnc_arrayPush;
	};
} foreach _slkname;

 

Then I tried isNull - which is not working at all:

 

if (isNull slick4) then {hint "true"};
sleep 10;

 

The problem is if I try to call an asset that doesn't exist - the script throws an error on the screen...

 

So how do I get an array with only those helicopters that exist out of a given list ???

 

Thanks...

 

Regards,
Scott

Share this post


Link to post
Share on other sites
{
	//@@@//
	hint format["slick = %1",_x];
	sleep _debugTime;
	//@@@//
	if (!isNull _x) then
	{
		_slkhold = getpos _x;
		_slkdist = _slkhold distance _slkzero;
		if ( _slkdist != 0 ) then
		{
			_slkarr pushBack _x;
		};
	};
} foreach _slkname;

Firstly, I recommend the pushBack command, used above, instead of the BIS function. Secondly, I think you switch statement was redundant. Thirdly, the !isNull at the top checks if each object exists before running any code on it.

  • Like 2

Share this post


Link to post
Share on other sites

If you know it's a finite amount of assets and you also know the name of all possible assets this will do:

_existingSlicks = [slick1,slick2,slick3,slick4] select {!isNil "_x"};

Cheers

  • Like 2

Share this post


Link to post
Share on other sites
{//@@@//hint format["slick = %1",_x];sleep _debugTime;//@@@//if (!isNull _x) then{	_slkhold = getpos _x;	_slkdist = _slkhold distance _slkzero;	if ( _slkdist != 0 ) then	{		_slkarr pushBack _x;	};};} foreach _slkname;

Firstly, I recommend the pushBack command, used above, instead of the BIS function. Secondly, I think you switch statement was redundant. Thirdly, the !isNull at the top checks if each object exists before running any code on it.

 

 

Hi...

 

Hah - "redundant" - so it is - yeah - it's a WIP - I had found commands I used later on required the group name instead of the asset name - so I was pulling the group name initially - I must have changed it - the distance check seemed to be working even though it was throwing the error when the asset didn't exist... I'll look at the command you suggested and take it on board... Half the battle is just finding the proper command to use on the wiki...

 

Thank you !!!

 

Regards,

Scott

 

 

 

Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites
If you know it's a finite amount of assets and you also know the name of all possible assets this will do:

_existingSlicks = [slick1,slick2,slick3,slick4] select {!isNil "_x"};

Cheers

 

 

Hi...

 

I do... It seems so simple now - I'll give this a try as well... I've spent hours on this...

 

Thank you...

 

Regards,

Scott

 

 

Sent from my iPad using Tapatalk

Share this post


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

If you know it's a finite amount of assets and you also know the name of all possible assets this will do:


_existingSlicks = [slick1,slick2,slick3,slick4] select {!isNil "_x"};

Cheers

 

Hi,

 

Re:

  • slick1 and slick2 exist;
  • slick 3 and slick 4 do not exist.

 

I tried this - and like my earlier attempts - it works - but the script throws an error when it hits slick3; = "undefined variable" ???

 

Complete Script:

Spoiler


//============================//
// SLICKS - SCO Launch Script //
//============================//

// Note: Only tested in Single Player

// Given: 1 to 4 helicopters preloaded with crew and infantry squads - units named in assets.
// Given: Helicopters will assault LZ with defined helipads - drop troops - RTB to home helipads.
// Given: User can define manual path with up to four inbound markers "inb1-inb4" if desired - else direct to LZ pad.
// Given: User can define manual path with up to four outbound markers "out1-out4" if desired - else direct to BS pad.
// Given: Example Flight Path - [BsPad1 -> inb1 -> inb2 -> inb3 -> inb4 -> LzPad1 -> out1 -> out2 -> BsPad1].
// Given: In order to have outbound waypoints work - you need at least one inbound waypoint specified.
// Given: Even though helicopters are individual units - they will maintain a diamond formation along flight path.

// Named Asset: [OPTIONAL] ("s1" - player unit)
// Named Asset: ("slick1" - slick helo) ("slick2" - slick helo) ("slick3" - slick helo) ("slick4" - slick helo)
// Named Asset: ("chalk1" - inf squad) ("chalk2" - inf squad) ("chalk3" - inf squad) ("chalk4" - inf squad)
// Named Marker: ("lz1" - lz pad marker) ("lz2" - lz pad marker) ("lz3" - lz pad marker) ("lz4" - lz pad marker)
// Named Marker: [OPTIONAL] ("inb1" - inbound marker) ("inb2" - inbound marker) ("inb3" - inbound marker) ("inb4" - inbound marker) 
// Named Marker: [OPTIONAL] ("out1" - outbound marker) ("out2" - outbound marker) ("out3" - outbound marker) ("out4" - outbound marker)

// Classname: ("Land_HelipadEmpty_F" - invisible helipad)

//@@@//
hint "Slicks GO";
sleep 2;
//@@@//

private ["_slkUnt","_slkGrp","_LzPad1","_LzPad2","_LzPad3","_LzPad4","_BsPad1","_BsPad2","_BsPad3","_BsPad4","_wpcnt","_wpplus","_wpslklz","_wpslkip","_wpchkul","_wpchkmv","_wpslkbs","_arrX","_arrY","_arrZ","_arrXn","_arrYn","_wpslkun","_chkgrp","_chkGp1","_chkGp2","_chkGp3","_chkGp4","_strlnd","_strhgt","_formdis","_formoff","_slkFrmWp","_dist","_offs","_strp","_endp","_head","_mkrzero","_mkrhold","_inbcnt","_inbarr","_inb0","_inb1","_inb2","_inb3","_inb4","_out0","_out1","_out2","_out3","_out4","_inbname","_outcnt","_outarr","_outname","_slkname","_slkhold","_slkzero","_slkdist","_slkarr","_debugTime"];

_debugTime = 15;
_counter = 0;

// var - waypoints //
_wpslklz = nil;
_wpslkip = nil;
_wpchkul = nil;
_wpchkmv = nil;
_wpslkbs = nil;
_wpslkun = nil;

// var - position array //
_arrX = nil;
_arrY = nil;
_arrZ = nil;
_arrXn = nil;
_arrYn = nil;

//var - position calculations //
_head = nil;
_dist = nil;
_offs = nil;
_strp = nil;
_endp = nil;

// var - manual marker positions //
_mkrzero = [0,0,0];
_inbcnt = 0;
_inbarr = [];
_inb0 = [];
_inbname = ["inb1","inb2","inb3","inb4"];
_inb1 = getMarkerPos "inb1";
_inb2 = getMarkerPos "inb2";
_inb3 = getMarkerPos "inb3";
_inb4 = getMarkerPos "inb4";

_outcnt = 0;
_outarr = [];
_outname = ["out1","out2","out3","out4"];
_out0 = [];
_out1 = getMarkerPos "out1";
_out2 = getMarkerPos "out2";
_out3 = getMarkerPos "out3";
_out4 = getMarkerPos "out4";

// function - calulate slick formation positions per leg flown - args [distance, angle offset, start point, end point] //
_slkFrmWp = {
	_dist = _this select 0;
	_offs = _this select 1;
	_strp = _this select 2;
	_endp = _this select 3;
	
	_arrX = _endp select 0;
	_arrY = _endp select 1;
	_arrZ = _endp select 2;
	
	_head = [_endp, _strp] call BIS_fnc_dirTo;
	_head = _head + _offs;
	if (_head > 360) then {_head = _head - 360};
	if (_head < 0) then {_head = _head + 360};
	_arrXn = ((sin _head) * _dist) + _arrX;
	_arrYn = ((cos _head) * _dist) + _arrY;
	[_arrXn,_arrYn,_arrZ];
	};

// test for the existance of "slicks" - slick1,slick2,slick3,slick4 //

_slkarr = [slick1,slick2,slick3,slick4] select {!isNil "_x"};

//@@@//
hint format["slick array = %1",_slkarr];
sleep _debugTime;
//@@@//
	
// test for the existance of "inbound" waypoints - inb1,inb2,inb3,inb4 //
{
	_mkrhold = getMarkerPos _x;
	_mkrdist = _mkrhold distance _mkrzero;
	if ( _mkrdist != 0 ) then
	{
	[_inbarr,_x] call BIS_fnc_arrayPush;
	};
} foreach _inbname;


// test for the existance of "outbound" waypoints - out1,out2,out3,out4 //
{
	_mkrhold = getMarkerPos _x;
	_mkrdist = _mkrhold distance _mkrzero;
	if ( _mkrdist != 0 ) then
	{
	[_outarr,_x] call BIS_fnc_arrayPush;
	};
} foreach _outname;

// get marker counts //
_inbcnt = count _inbarr;
_outcnt = count _outarr;

//@@@//
hint format ["inbound=%1 outbound=%2",_inbarr,_outarr];
sleep _debugTime;
//@@@//

// add inb0 (slick starting posit) to array //
if (_inbcnt < 0) then 
{
	_mkrhold = _inbarr;
	_inbarr = ["inb0"];
	[_inbarr,_mkrhold] call BIS_fnc_arrayPushStack;
	_inbcnt = count _inbarr;
};

// add e0 (slick lz posit) to array // e0
if (_outcnt < 0) then 
{
	_mkrhold = _outarr;
	_outarr = ["out0"];
	[_outarr,_mkrhold] call BIS_fnc_arrayPushStack;
	_outcnt = count _outarr;
	_out0 = getPos _x;
};

// slick delete all waypoints //
while {(count (waypoints _x)) > 0} do
{
	deleteWaypoint ((waypoints _x) select 0);
};
	
// troop delete all waypoints //
while {(count (waypoints _chkgrp)) > 0} do
{
	deleteWaypoint ((waypoints _chkgrp) select 0);
};

// for each slick loop ///
{
	// get slick LZ and Base waypoint - get respective troop var //
	switch (_x) do {
        case slick1: {
						_BsPad1 = "Land_HelipadCircle_F" createVehicle position slick1,[],0,"CAN_COLLIDE";
						_BsPad1 = getPos _BsPad1;
						_LzPad1 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz1";
						_LzPad1 = getPos _LzPad1;
						_slkUnt = "slick1";
						_slkGrp = group slick1;
						_wpslklz = _LzPad1;
						_wpslkbs = _BsPad1;
						_chkgrp = chalk1;
						_strlnd = "slick1 land 'LAND'";
						_strhgt = "slick1 flyInHeight 20";
						_formdis = 100;
						_formoff = 180;
						_inb0 = getPos slick1;
						_out0 = _LzPad1;
					};
        case slick2: {
						_BsPad2 = "Land_HelipadCircle_F" createVehicle position slick2,[],0,"CAN_COLLIDE";
						_BsPad2 = getPos _BsPad2;
						_LzPad2 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz2";
						_LzPad2 = getPos _LzPad2;						
						_slkUnt = "slick2";
						_slkGrp = group slick2;
						_wpslklz = _LzPad2;
						_wpslkbs = _BsPad2;
						_chkgrp = chalk2;
						_strlnd = "slick2 land 'LAND'";
						_strhgt = "slick2 flyInHeight 22";
						_formdis = 100;
						_formoff = 45;
						_inb0 = getPos slick2;
						_out0 = _LzPad2;

					};
		case slick3: { 	
						_BsPad3 = "Land_HelipadCircle_F" createVehicle position slick3,[],0,"CAN_COLLIDE";
						_BsPad3 = getPos _BsPad3;
						_LzPad3 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz3";
						_LzPad3 = getPos _LzPad3;
						_slkUnt = "slick3";
						_slkGrp = group slick3;
						_wpslklz = _LzPad3;
						_wpslkbs = _BsPad3;
						_chkgrp = chalk3;
						_strlnd = "slick3 land 'LAND'";
						_strhgt = "slick3 flyInHeight 19";
						_formdis = 100;
						_formoff = -45;
						_inb0 = getPos slick3;
						_out0 = _LzPad3;
					};
		case slick4: { 
						_BsPad4 = "Land_HelipadCircle_F" createVehicle position slick4,[],0,"CAN_COLLIDE";
						_BsPad4 = getPos _BsPad4;
						_LzPad4 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz4";
						_LzPad4 = getPos _LzPad4;
						_slkUnt = "slick4";
						_slkGrp = group slick4;
						_wpslklz = _LzPad4;
						_wpslkbs = _BsPad4;
						_chkgrp = chalk4;
						_strlnd = "slick4 land 'LAND'";
						_strhgt = "slick4 flyInHeight 21";
						_formdis = 100;
						_formoff = 0;
						_inb0 = getPos slick4;
						_out0 = _LzPad4;
					};
    };

	// if manual waypoint exist - else auto waypoint //
	_wpcnt = 0;
	if (_inbcnt > 0) then
	{
		// add "inbound" waypoint for manual marker - with offsets //
		{
			_formstr = call compile format ["_inb%1",_wpcnt];
			_wpplus = _wpcnt + 1;
			_formend = call compile format ["_inb%1",_wpplus];
			
//@@@//
hint format ["pos1 dis=%1 off=%2 str=%3 end=%4",_formdis,_formoff,_formstr,_formend];
sleep _debugTime;
//@@@//

			_wpform = [_formdis,_formoff,_formstr,_formend] call _slkFrmWp;
			_wpslik = _slkGrp addWaypoint [_wpform,0];
			_wpslik setWaypointType "MOVE";
			_wpslik setWaypointBehaviour "CARELESS";
			_wpcnt = _wpcnt + 1;
		} foreach _inbarr;
		
		// add waypoint to lz //
		_wpslkun = _slkGrp addWaypoint [_wpslklz,0];
		_wpslkun setWaypointType "TR UNLOAD";
		
		// add "outbound" waypoint for manual marker - with offsets //
		if (_outcnt > 0) then
		{	
			_wpcnt = 0;
			{
				_formstr = call compile format ["_out%1",_wpcnt];
				_wpplus = _wpcnt + 1;
				_formend = call compile format ["_out%1",_wpplus];	

//@@@//				
hint format ["pos2 dis=%1 off=%2 str=%3 end=%4",_formdis,_formoff,_formstr,_formend];
sleep _debugTime;
//@@@//

				_wpform = [_formdis,_formoff,_formstr,_formend] call _slkFrmWp;
				_wpslik = _slkGrp addWaypoint [_wpform,0];
				_wpslik setWaypointType "MOVE";
				_wpslik setWaypointBehaviour "CARELESS";
				_wpcnt = _wpcnt + 1;
			} foreach _outarr;
		};
		
		// add final waypoint to base //
		_wpslkbs = _slkGrp addWaypoint [_wpslkbs,0];
		_wpslkbs setWaypointType "MOVE";
		_wpslkbs setWaypointStatements ["true", _strlnd];
	}
	else 
	{
		// get slick IP waypoint - bearing relative to start posit - COS and SIN reversed for BIS //
		_formdis = 0;
		_formoff = 0;

//@@@//
hint format ["pos3 dis=%1 off=%2 str=%3 end=%4",_formdis,_formoff,_wpslkbs,_wpslklz];
sleep _debugTime;
//@@@//
		_wpslkip = [_formdis,_formoff,_wpslkbs,_wpslklz] call _slkFrmWp;
	
		// create slick waypoints //
		_wpslkip = _x addWaypoint [_wpslkip,0];
		_wpslkun = _x addWaypoint [_wpslklz,0];
		_wpslkbs = _x addWaypoint [_wpslkbs,0];
		
		_wpslkip setWaypointType "MOVE";
		_wpslkun setWaypointType "TR UNLOAD";
		_wpslkun setWaypointSpeed "LIMITED";
		_wpslkbs setWaypointType "MOVE";
		_wpslkbs setWaypointSpeed "NORMAL";
		_wpslkbs setWaypointBehaviour "CARELESS";
		_wpslkbs setWaypointCompletionRadius 50;
		_wpslkbs setWaypointStatements ["true", _strlnd];	
	};
	
	// get LZ position and break down array //
	_arrX = _wpslklz select 0;
	_arrY = _wpslklz select 1;
	_arrZ = _wpslklz select 2;
	
	// get chalk UNLOAD waypoint //
	_arrXn = _arrX + 5;
	_wpchkul = [_arrXn,_arrY,_arrZ];
	
	// get chalk MOVE waypoint //
	_arrXn = _arrX - 50;
	_arrYn = _arrY + 50;
	_wpchkmv = [_arrXn,_arrYn,_arrZ];
	
	// create chalk waypoints //
	_wpchkul = _chkgrp addWaypoint [_wpchkul,0];
	_wpchkmv = _chkgrp addWaypoint [_wpchkmv,0];

	_wpchkul setWaypointType "GETOUT";
	_wpchkmv setWaypointType "MOVE";
	_wpchkmv setWaypointBehaviour "COMBAT";
	//_wpchkmv setWaypointSpeed "LIMITED";
	_wpchkmv setWaypointFormation "WEDGE";
	_wpchkmv	setWaypointCombatMode "RED";
	
	// sync unload waypoints - slick and chalk //
	_wpslkun synchronizeWaypoint _wpchkul;
	
	// sleep for spacing of slicks //
	sleep 5;

} foreach _slkarr;

 

 

Regards,

Scott

Share this post


Link to post
Share on other sites

Hi...

 

#99 which equates to the !isNil statement...

 

The script still has issues further on - adapting it from one I had in Arma 2 - but this is the first error it throws...

 

Regards,

Scott

Share this post


Link to post
Share on other sites
4 minutes ago, scottb613 said:

Hi...

 

#99 which equates to the !isNil statement...

 

The script still has issues further on - adapting it from one I had in Arma 2 - but this is the first error it throws...

 

Regards,

Scott

That's weird, I just double checked if my -showScriptErrors wasn't set for some reason, but it's showing errors when doing naughty stuff like dividing through zero.

I'm not getting any error and the select command properly returns all currently existing assets.

Placed all 8 markers, copied your snippet all up to the point of the _slkarr with slick1 and slick2 present on the map, it returns both of them inside the array with no error.

Try putting systemchat str _slkarr and see what it returns.

 

Cheers

 

  • Like 1

Share this post


Link to post
Share on other sites
That's weird, I just double checked if my -showScriptErrors wasn't set for some reason, but it's showing errors when doing naughty stuff like dividing through zero.
I'm not getting any error and the select command properly returns all currently existing assets.
Placed all 8 markers, copied your snippet all up to the point of the _slkarr with slick1 and slick2 present on the map, it returns both of them inside the array with no error.
Try putting systemchat str _slkarr and see what it returns.
 
Cheers
 


Hi,

Thanks - I really don't want to take too much of your time - really appreciate the extra mile - I'll try that system chat thing - never thought of that before - I always debug with hints which seem less than ideal... The hint I had does show the proper values for _slkarr = "slick1,slick2" and the helicopters will launch - strange you're not seeing the error...

LOL - this is what happens when I try to improve the code...

Regards,
Scott




Sent from my iPad using Tapatalk

Share this post


Link to post
Share on other sites

Hi Folks,

One other thought - I guess I can't redirect the output of a command to something like /dev/null - so even though it errors - no output is splashed on the screen ?

In UNIX: 2>/dev/null

Regards,
Scott


Sent from my iPad using Tapatalk

Share this post


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

if (!isNil "_x") then {hint format["slick = %1",_x]};

 

Thanks Pierre - I'll give that a shot...

 

I didn't have a chance to test - but looking at the WIKI - it seems that isNil  is looking specifically for a variable - - - while @jshock's - - - isNull is looking for an object - perhaps that's the cause of my error ??? "slick1" is a named asset in the editor so I would assume that's an object... I won't have a chance to try it until next weekend - but that's on the list now too...

 

Regards,
Scott

Share this post


Link to post
Share on other sites

Slick1 is a variable that you have assigned to reference the vehicle. It is not explicitly the vehicle.

 

For example:

slick1 = theVehicleIWantItToBe; // <=== yes, it is the vehicle
slick1 = 666; // <=== now slick1 is equal to 666.  The vehicle (theVehicleIWantItToBe) still exists, but is not referred to as slick1 anymore

 

A variable is nil if either:

 

1) It has never been created.  Ex:

 

systemChat format ["is it nil: %1",isNil "_someVariableNameIJustMadeUp"];  // returns true as it has not been defined previously

 

2) It has been previously defined then intentionally nilled.  Ex:

 

_myVar = 10;
systemChat format ["is it nil: %1",isNil "_myVar"];  // returns false
_myVar = nil;
systemChat format ["is it nil: %1",isNil "_myVar"]; // returns true

 

A variable (an object for example) can be nil or null or neither.

It's nil if you test for it before you have defined it.
It's neither when you have defined and created it
It's null (but not nil) once you have then deleted it.
You can then nil it if you so choose (but I would not bother).

 

Run this script in the debug window to see what's happening.

 

0 = 0 spawn {
	player sideChat format ["is it nil: %1",isNil "_myVehicle"];
	sleep 2;
	_myVehicle = "C_Offroad_01_F" createVehicle position player;
	player setDir (player getDir _myVehicle);
	sleep 1;
	player groupChat "created vehicle";
	player sideChat format ["is it nil: %1",isNil "_myVehicle"];
	player sideChat format ["is it null: %1",isNull _myVehicle];
	sleep 3;
	deleteVehicle _myVehicle;
	sleep 1;
	player groupChat "deleted vehicle";
	player sideChat format ["is it nil: %1",isNil "_myVehicle"];
	player sideChat format ["is it null: %1",isNull _myVehicle];
	sleep 3;
	_myVehicle = nil;
	player groupChat "nilled variable";
	player sideChat format ["is it nil: %1",isNil "_myVehicle"];
	player sideChat format ["is it null: %1",isNull _myVehicle];
};

 

You'll notice the last isNull check throws an error  and returns (BOOL) because you have not established that the variable exists before testing to see if it is null.  We know it did, but we nilled it - Arma does not know that however and throws a hissy.

 

So in your case, I would run the following check for your slicks:

_slicks = [slick1,slick2,slick3,slick4,slick5] select {not isNil "_x" and {not isNull _x}};
diag_log _slicks;

Do some reading on data types to get a better grasp of what is going on and what you are dealing with.

 

https://community.bistudio.com/wiki/Category:Data_Types

 

It can be confusing, but once you crack it, it's easy (like anything really).

  • Like 2

Share this post


Link to post
Share on other sites

Hi Das (oddball - great movie),

 

Thanks so much for taking the time writing this all up - big help I think - I'm getting a grasp on all this and I have more things to try when I get home... I wish my laptop could handle enough ArmA just to some basic testing while I travel - but it can't... I just came across that "diag_log" command and included it in my diag routine - so I can start writing to the log file - seems far better than trying to catch the hint windows... I'll probably add GOM's system chat messages as well... I'll be sure to read your reference... 

 

I've got most of the other errors in my script cleared except one towards the end - a simple WP sync - that seemed to work fine in A2... The WP's look valid to me - I'll have to play with this some more as well... 

 

  • _wpSlkUn synchronizeWaypoint _wpChkUn;

 

Appreciate the help...

 

Regards,
Scott

 

Updated Script:

Spoiler


//============================//
// SLICKS - SCO Launch Script //
//============================//

// Note: Only tested in Single Player

// Given: 1 to 4 helicopters preloaded with crew - units named in assets.
// Given: Infantry squads (chalkx) will be loaded as cargo into helicopter (slickx) with respect to number when _loadChk = 1. 
// Given: Helicopters will assault LZ with defined helipads - drop troops - RTB to home helipads.
// Given: User can define manual path with up to four inbound markers "inb1-inb4" if desired - else direct to LZ pad.
// Given: User can define manual path with up to four outbound markers "out1-out4" if desired - else direct to BS pad.
// Given: Example Flight Path - [BsPad1 -> inb1 -> inb2 -> inb3 -> inb4 -> LzPad1 -> out1 -> out2 -> BsPad1].
// Given: In order to have outbound waypoints work - you need at least one inbound waypoint specified.
// Given: Even though helicopters are individual units - they will maintain a diamond formation along flight path.

// Named Asset: [OPTIONAL] ("s1" - player unit)
// Named Asset: ("slick1" - slick helo) ("slick2" - slick helo) ("slick3" - slick helo) ("slick4" - slick helo)
// Named Asset: ("chalk1" - inf squad) ("chalk2" - inf squad) ("chalk3" - inf squad) ("chalk4" - inf squad)
// Named Marker: ("lz1" - lz pad marker) ("lz2" - lz pad marker) ("lz3" - lz pad marker) ("lz4" - lz pad marker)
// Named Marker: [OPTIONAL] ("inb1" - inbound marker) ("inb2" - inbound marker) ("inb3" - inbound marker) ("inb4" - inbound marker) 
// Named Marker: [OPTIONAL] ("out1" - outbound marker) ("out2" - outbound marker) ("out3" - outbound marker) ("out4" - outbound marker)

// Classname: ("Land_HelipadEmpty_F" - invisible helipad)
// Classname: ("Land_HelipadCircle_F" - visible helipad)

hint "Slicks GO GO GO";
sleep 2;

private ["_slkUnt","_slkGrp","_LzPad1","_LzPad2","_LzPad3","_LzPad4","_BsPad1","_BsPad2","_BsPad3","_BsPad4","_wpCnt","_wpPlus","_wpSlkLz","_wpSlkIp","_wpChkUn","_wpChkMv","_wpSlkBs","_arrX","_arrY","_arrZ","_arrXn","_arrYn","_wpSlkUn","_chkGrp","_chkGp1","_chkGp2","_chkGp3","_chkGp4","_strLnd","_strHgt","_formDis","_formOff","_fcFormWp","_fcDist","_fcOffs","_fcStrP","_fcEndP","_fcHead","_mkrZero","_mkrHold","_inbCnt","_inbArr","_inb0","_inb1","_inb2","_inb3","_inb4","_out0","_out1","_out2","_out3","_out4","_inbName","_outCnt","_outArr","_outName","_slkname","_slkhold","_slkzero","_slkdist","_slkArr","_debug","_debugTime","_spaceTime","_loadChk"];

// var - misc controls //
_debug = 1;
_debugTime = 10;
_spaceTime = 5;
_loadChk = 1;

// var - waypoints //
_wpSlkLz = nil;
_wpSlkIp = nil;
_wpChkUn = nil;
_wpChkMv = nil;
_wpSlkBs = nil;
_wpSlkUn = nil;

// var - position array //
_arrX = nil;
_arrY = nil;
_arrZ = nil;
_arrXn = nil;
_arrYn = nil;

//var - position calculations //
_fcHead = nil;
_fcDist = nil;
_fcOffs = nil;
_fcStrP = nil;
_fcEndP = nil;

// var - inbound manual marker positions //
_inbName = ["inb1","inb2","inb3","inb4"];
_mkrZero = [0,0,0];
_inbCnt = 0;
_inbArr = [];
_inb0 = [];
_inb1 = getMarkerPos "inb1";
_inb2 = getMarkerPos "inb2";
_inb3 = getMarkerPos "inb3";
_inb4 = getMarkerPos "inb4";

// var - outbound manual marker positions //
_outName = ["out1","out2","out3","out4"];
_outCnt = 0;
_outArr = [];
_out0 = [];
_out1 = getMarkerPos "out1";
_out2 = getMarkerPos "out2";
_out3 = getMarkerPos "out3";
_out4 = getMarkerPos "out4";

// function - calulate formation positions per leg flown - args [distance, angle offset, start point, end point] //
_fcFormWp = {
	_fcDist = _this select 0;
	_fcOffs = _this select 1;
	_fcStrP = _this select 2;
	_fcEndP = _this select 3;
	
	_arrX = _fcEndP select 0;
	_arrY = _fcEndP select 1;
	_arrZ = _fcEndP select 2;

	_fcHead = [_fcEndP, _fcStrP] call BIS_fnc_dirTo;
	_fcHead = _fcHead + _fcOffs;
	if (_fcHead > 360) then {_fcHead = _fcHead - 360};
	if (_fcHead < 0) then {_fcHead = _fcHead + 360};
	_arrXn = ((sin _fcHead) * _fcDist) + _arrX;
	_arrYn = ((cos _fcHead) * _fcDist) + _arrY;
	[_arrXn,_arrYn,_arrZ];
	};

// test for the existance of "slicks" - slick1,slick2,slick3,slick4 //
_slkArr = [slick1,slick2,slick3,slick4] select {!isNull "_x"};

//@@@@@//
if  (_debug = 1) then 
{
hint format["Slick Array = %1",_slkArr];
diag_log format ["SCO: Slick Array = %1",_slkArr];
sleep _debugTime;
};
//@@@@@//

// test for the existance of "inbound" waypoints - inb1,inb2,inb3,inb4 //
{
	_mkrHold = getMarkerPos _x;
	_mkrDist = _mkrHold distance _mkrZero;
	if ( _mkrDist != 0 ) then
	{
	[_inbArr,_x] call BIS_fnc_arrayPush;
	};
} foreach _inbName;

// test for the existance of "outbound" waypoints - out1,out2,out3,out4 //
{
	_mkrHold = getMarkerPos _x;
	_mkrDist = _mkrHold distance _mkrZero;
	if ( _mkrDist != 0 ) then
	{
	[_outArr,_x] call BIS_fnc_arrayPush;
	};
} foreach _outName;

// get marker counts //
_inbCnt = count _inbArr;
_outCnt = count _outArr;

//@@@@@//
if  (_debug = 1) then 
{
hint format ["Inbound=%1 Outbound=%2",_inbArr,_outArr];
diag_log format ["SCO: Inbound=%1 Outbound=%2",_inbArr,_outArr];
sleep _debugTime;
};
//@@@@@//

// add inb0 (slick starting posit) to array //
if (_inbCnt < 0) then 
{
	_mkrHold = _inbArr;
	_inbArr = ["inb0"];
	[_inbArr,_mkrHold] call BIS_fnc_arrayPushStack;
	_inbCnt = count _inbArr;
};

// add out0 (slick lz posit) to array //
if (_outCnt < 0) then 
{
	_mkrHold = _outArr;
	_outArr = ["out0"];
	[_outArr,_mkrHold] call BIS_fnc_arrayPushStack;
	_outCnt = count _outArr;
	_out0 = getPos _x;
};

// for each slick loop ///
{
	// get slick LZ and Base waypoint - get respective troop var //
	switch (_x) do {
        case slick1: {
						// create base helipad //
						_BsPad1 = "Land_HelipadCircle_F" createVehicle position slick1,[],0,"CAN_COLLIDE";
						_BsPad1 = getPos _BsPad1;
						// create lz helipad //
						_LzPad1 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz1";
						_LzPad1 = getPos _LzPad1;
						_slkUnt = slick1;
						_slkGrp = group slick1;
						_wpSlkLz = _LzPad1;
						_wpSlkBs = _BsPad1;
						_chkGrp = chalk1;
						_strLnd = "slick1 land 'LAND'";
						_strHgt = "slick1 flyInHeight 20";
						_formDis = 100;
						_formOff = 180;
						_inb0 = _BsPad1;
						_out0 = _LzPad1;
						// troop delete all waypoints //
						while {(count (waypoints _chkGrp)) > 0} do
						{		
							deleteWaypoint ((waypoints _chkGrp) select 0);
						};
						// slick delete all waypoints //
						while {(count (waypoints _slkGrp)) > 0} do
						{
							deleteWaypoint ((waypoints _slkGrp) select 0);
						};						
					};
        case slick2: {
						// create base helipad //		
						_BsPad2 = "Land_HelipadCircle_F" createVehicle position slick2,[],0,"CAN_COLLIDE";
						_BsPad2 = getPos _BsPad2;
						// create lz helipad //
						_LzPad2 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz2";
						_LzPad2 = getPos _LzPad2;
						// set vars //
						_slkUnt = slick2;
						_slkGrp = group slick2;
						_wpSlkLz = _LzPad2;
						_wpSlkBs = _BsPad2;
						_chkGrp = chalk2;
						_strLnd = "slick2 land 'LAND'";
						_strHgt = "slick2 flyInHeight 22";
						_formDis = 100;
						_formOff = 45;
						_inb0 = _BsPad2;
						_out0 = _LzPad2;
						// troop delete all waypoints //
						while {(count (waypoints _chkGrp)) > 0} do
						{		
							deleteWaypoint ((waypoints _chkGrp) select 0);
						};
						// slick delete all waypoints //
						while {(count (waypoints _slkGrp)) > 0} do
						{
							deleteWaypoint ((waypoints _slkGrp) select 0);
						};
					};
		case slick3: { 	
						// create base helipad //
						_BsPad3 = "Land_HelipadCircle_F" createVehicle position slick3,[],0,"CAN_COLLIDE";
						_BsPad3 = getPos _BsPad3;
						// create lz helipad //
						_LzPad3 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz3";
						_LzPad3 = getPos _LzPad3;
						// set vars //
						_slkUnt = slick3;
						_slkGrp = group slick3;
						_wpSlkLz = _LzPad3;
						_wpSlkBs = _BsPad3;
						_chkGrp = chalk3;
						_strLnd = "slick3 land 'LAND'";
						_strHgt = "slick3 flyInHeight 19";
						_formDis = 100;
						_formOff = -45;
						_inb0 = _BsPad3;
						_out0 = _LzPad3;
						// troop delete all waypoints //
						while {(count (waypoints _chkGrp)) > 0} do
						{		
							deleteWaypoint ((waypoints _chkGrp) select 0);
						};
						// slick delete all waypoints //
						while {(count (waypoints _slkGrp)) > 0} do
						{
							deleteWaypoint ((waypoints _slkGrp) select 0);
						};
					};
		case slick4: { 
						// create base helipad //
						_BsPad4 = "Land_HelipadCircle_F" createVehicle position slick4,[],0,"CAN_COLLIDE";
						_BsPad4 = getPos _BsPad4;
						// create lz helipad //
						_LzPad4 = "Land_HelipadCircle_F" createVehicle getMarkerPos "lz4";
						_LzPad4 = getPos _LzPad4;
						// set vars //
						_slkUnt = slick4;
						_slkGrp = group slick4;
						_wpSlkLz = _LzPad4;
						_wpSlkBs = _BsPad4;
						_chkGrp = chalk4;
						_strLnd = "slick4 land 'LAND'";
						_strHgt = "slick4 flyInHeight 21";
						_formDis = 100;
						_formOff = 0;
						_inb0 = _BsPad4;
						_out0 = _LzPad4;
						// troop delete all waypoints //
						while {(count (waypoints _chkGrp)) > 0} do
						{		
							deleteWaypoint ((waypoints _chkGrp) select 0);
						};
						// slick delete all waypoints //
						while {(count (waypoints _slkGrp)) > 0} do
						{
							deleteWaypoint ((waypoints _slkGrp) select 0);
						};
					};
    };
	
	// load chalk into slick //
	if (_loadFlg = 1) then
	{
		{_x moveInCargo _slkUnt} foreach units _chkGrp;
	};
	
	// if manual waypoint exist - else auto waypoint //
	_wpCnt = 0;
	if (_inbCnt > 0) then
	{
		// add "inbound" waypoint for manual marker - with offsets //
		{
			_formStr = call compile format ["_inb%1",_wpCnt];
			_wpPlus = _wpCnt + 1;
			_formEnd = call compile format ["_inb%1",_wpPlus];

//@@@@@//
if  (_debug = 1) then 
{
hint format ["FunCall-1 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_formStr,_formEnd];
diag_log format ["SCO: FunCall-1 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_formStr,_formEnd];
sleep _debugTime;
};
//@@@@@//

			_wpForm = [_formDis,_formOff,_formStr,_formEnd] call _fcFormWp;
			_wpSlkMv = _slkGrp addWaypoint [_wpForm,0];
			_wpSlkMv setWaypointType "MOVE";
			_wpSlkMv setWaypointBehaviour "CARELESS";
			_wpCnt = _wpCnt + 1;
		} foreach _inbArr;
		
		// add waypoint to lz //
		_wpSlkUn = _slkGrp addWaypoint [_wpSlkLz,0];
		_wpSlkUn setWaypointType "TR UNLOAD";
		
		// add "outbound" waypoint for manual marker - with offsets //
		if (_outCnt > 0) then
		{	
			_wpCnt = 0;
			{
				_formStr = call compile format ["_out%1",_wpCnt];
				_wpPlus = _wpCnt + 1;
				_formEnd = call compile format ["_out%1",_wpPlus];	

//@@@@@//
if  (_debug = 1) then 
{				
hint format ["FunCall-2 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_formStr,_formEnd];
diag_log format ["SCO: FunCall-2 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_formStr,_formEnd];
sleep _debugTime;
};
//@@@@@//

				_wpForm = [_formDis,_formOff,_formStr,_formEnd] call _fcFormWp;
				_wpSlkMv = _slkGrp addWaypoint [_wpForm,0];
				_wpSlkMv setWaypointType "MOVE";
				_wpSlkMv setWaypointBehaviour "CARELESS";
				_wpCnt = _wpCnt + 1;
			} foreach _outArr;
		};
		
		// add final waypoint to base //
		_wpSlkBs = _slkGrp addWaypoint [_wpSlkBs,0];
		_wpSlkBs setWaypointType "MOVE";
		_wpSlkBs setWaypointStatements ["true", _strLnd];
	}
	else 
	{
		// get slick IP waypoint - bearing relative to start posit - COS and SIN reversed for BIS //
		_formDis = 0;
		_formOff = 0;

//@@@@@//
if  (_debug = 1) then 
{
hint format ["FunCall-3 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_wpSlkBs,_wpSlkLz];
diag_log format ["SCO: FunCall-3 dis=%1 off=%2 str=%3 end=%4",_formDis,_formOff,_wpSlkBs,_wpSlkLz];
sleep _debugTime;
};
//@@@@@//

		_wpSlkIp = [_formDis,_formOff,_wpSlkBs,_wpSlkLz] call _fcFormWp;
		
		// create slick waypoints //
		_wpSlkIp = _x addWaypoint [_wpSlkIp,0];
		_wpSlkUn = _x addWaypoint [_wpSlkLz,0];
		_wpSlkBs = _x addWaypoint [_wpSlkBs,0];
		
		_wpSlkIp setWaypointType "MOVE";
		_wpSlkUn setWaypointType "TR UNLOAD";
		_wpSlkUn setWaypointSpeed "LIMITED";
		_wpSlkBs setWaypointType "MOVE";
		_wpSlkBs setWaypointSpeed "NORMAL";
		_wpSlkBs setWaypointBehaviour "CARELESS";
		_wpSlkBs setWaypointCompletionRadius 50;
		_wpSlkBs setWaypointStatements ["true", _strLnd];	
	};
	
	// get LZ position and break down array //
	_arrX = _wpSlkLz select 0;
	_arrY = _wpSlkLz select 1;
	_arrZ = _wpSlkLz select 2;
	
	// get chalk UNLOAD waypoint //
	_arrXn = _arrX + 5;
	_wpChkUn = [_arrXn,_arrY,_arrZ];
	
	// get chalk MOVE waypoint //
	_arrXn = _arrX - 50;
	_arrYn = _arrY + 50;
	_wpChkMv = [_arrXn,_arrYn,_arrZ];
	
	// create chalk waypoints //
	_wpChkUn = _chkGrp addWaypoint [_wpChkUn,0];
	_wpChkMv = _chkGrp addWaypoint [_wpChkMv,0];

	_wpChkUn setWaypointType "GETOUT";
	_wpChkMv setWaypointType "MOVE";
	_wpChkMv setWaypointBehaviour "COMBAT";
	//_wpChkMv setWaypointSpeed "LIMITED";
	_wpChkMv setWaypointFormation "WEDGE";
	_wpChkMv	setWaypointCombatMode "RED";
	
	// sync unload waypoints - slick and chalk //

//@@@@@//
if  (_debug = 1) then 
{	
hint format ["_wpSlkUn=%1 _wpChkUn=%2",_wpSlkUn,_wpChkUn];
diag_log format ["SCO: WP Sync _wpSlkUn=%1 _wpChkUn=%2",_wpSlkUn,_wpChkUn];
sleep _debugTime;
};
//@@@@@//
	
	_wpSlkUn synchronizeWaypoint _wpChkUn;
	
	// sleep for spacing of slicks //
	sleep _spaceTime;

} foreach _slkArr;

 

 

 

Share this post


Link to post
Share on other sites

Thanks for looking Pierre - yeah - with the "hint" I have it appears to have valid data being fed to it - but it throws an error - I'll take some screenshots of the actual error messages when I get a chance to work this... I'm still getting that "Undefined Variable" error on Slick3 that GOM did not - which is odd in and of itself - but I haven't been able to try the new information posted here yet...

 

This all started with ALiVE - as I'm a huge fan of their work but I got tired of losing assets while flying directly over known hostile enemy emplacements - wanted the ability to fly a designated path with multiple helicopters for an air cav assault... I have a similar script I'm working on for the supporting gunships in the CAS role... I'm getting there - line by line... It's still kind of amazing to me when your script runs and does what it's supposed to do - in the sim...

 

Again - a big thank you for everyone's help and input... Very much appreciated - one and all...

 

Regards,
Scott

Share this post


Link to post
Share on other sites
14 minutes ago, scottb613 said:

Thanks for looking Pierre - yeah - with the "hint" I have it appears to have valid data being fed to it - but it throws an error - I'll take some screenshots of the actual error messages when I get a chance to work this... I'm still getting that "Undefined Variable" error on Slick3 that GOM did not - which is odd in and of itself - but I haven't been able to try the new information posted here yet...

 

Upload it somewhere and I'll have a look for you

Share this post


Link to post
Share on other sites
14 minutes ago, das attorney said:

 

Upload it somewhere and I'll have a look for you

 

Hi @das attorney

 

Will do - all I have is the SQF with me - when I get in this weekend - I'll swap all the assets for vanilla - takes 2 minutes - and I'll package it up and post it...

 

Much obliged - sir...

 

Regards,

Scott

Share this post


Link to post
Share on other sites

It seems to me weird to check existence for slick1, slick2... then switch with cases of these variables, even if not defined....

 

btw:

_slkArr = [slick1,slick2,slick3,slick4] select {!isNull "_x"}; // has no sense  _x can be null object and "_x" can be a nil variable, do you see the difference?

 

_slkArr = [slick1,slick2,slick3,slick4] select {!isNil "_x"}; seems to me a good filter. (isNull _x can be also. Check for returned error but I guess it's fine)

 

But most of all, work with the returned array! (disregard the whole cases with undefined variables)

 

{ switch (_x) do { case slick1: <code>; ..... } } forEach _slkArr; // seems to me an error if slick1 is not defined.

 

{ if (isnil "slick1" && {_x == slick1}) exitwith {<code>}; .... } foreach _sllArr; // should work

 

 

Share this post


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

@pierremgi If you read up you can see that's already been suggested.

But not applied in the last script!... and not see a line about the replacement of the "switch do cases".

Share this post


Link to post
Share on other sites

Hi Folks,

 

It's all good and appreciated - some of the changes like the isNull I added this week before I had some new information - never tested - now that I think I've got a better grasp on it and have some new things to try - thanks to all the help I've been getting here...

 

LOL - god knows I'm a hack and my code is far from elegant... Pierre - I'm not sure I follow with the case stuff yet - I'm short of time but I'll read it over more carefully tonight... The bottom line is we can have a random number of helicopters assigned to the mission - that's up to the mission creator - I just need the option to handle any number though 4... Each one has it's own unique set of variables that need to be set - so I'm not exactly sure what you're saying to get around it - again - I'll read more closely tonight and see if I can figure it out... 

 

Again - if you see something I'm doing badly - - - your wisdom, insights, and experience is most welcome... This is my first Arma script...

 

Regards,
Scott

Share this post


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

and not see a line about the replacement of the "switch do cases".

 

That's because I didn't write one.

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

×