Jump to content
Sign in to follow this  
ArtVandelay

Checking height of all units in a group

Recommended Posts

Hi,

Firstly sorry if this has already been asked somewhere else, but I've been searching (and learning!) for the past few days on how to tackle my problem and I've dug up bits and pieces but nothing directly related.

Back story:

I'm creating an Aircraft Carrier mission using the LHD addon. The idea is that a small team of players infiltrate the carrier using various methods (helicopter, boat, Vodnik etc.). I've created a makeshift base including defences (.50cal MGs and M240 nests) and jerry-rigged some ladders together for players to climb up to the lower walkway below deck (if they decide to approach via sea). There are a group of 15 AI on deck.

Now my problem is that when the AI start getting shot at they decide to 'abandon ship' so to speak (rather they run off the edge). What I'm attempting to achieve is when they decide to go for a swim is to teleport them back on deck.

My attempt:

private ["_group","_unitsAlive","_unit","_units","_unitHeight","_pos","_preferredHeight"];

_group = _this select 0;
_pos = _this select 1;

_unitsAlive = ({alive _x} count units _group);
_preferredHeight = 15.5; //Height of the LHD deck for units


while {_unitsAlive > 0} do
{
sleep 1;
_unitsAlive = ({alive _x} count units _group);
_units = units _group;
for "_i" from 0 to (count _units - 1);
	_unit = _units select _i;
	if (isNil _unit) OR (!alive _unit) then
	{
		_units set [_forEachIndex, - 1];
	}
	else
	{
		_unitHeight = getPos _unit select 2;
		if (_unitHeight < _preferredHeight) then
		{
			_unit setPos [(_pos select 0) - 10, (_pos select 1), 16]; //Get on deck!
		};
	_unitsAlive = ({alive _x} count units _group);
};

I'll explain my logic of the script above I created. You may need to hold my hand here a bit - I'm relatively new to Arma scripting.

> While the units are alive

> Count the amount of alive units

> Loop through all units in the group until you last is reached

> Check if there is a unit in the array index OR if the unit is dead (if so subtract from array)

> Otherwise check the unit's height

> If the unit's height is less than the height of the LHD deck (15.5 in this case) move the unit back to starting position

> Check if the units of the group are still alive

That is my full understanding of what I wrote above. I'm not really sure what I'm doing wrong or where it's going wrong so any help or insight would be very much appreciated. Again, I aplogise if this has been asked before (I did a quick check of the FAQ thread before thread creation). I have tried using various prevention methods (Kronzky's UPS for example) but they continue to bail after being fired at.

Art Vandelay

Share this post


Link to post
Share on other sites

It's not answering your question at all, but there's an 'invisible wall' you could put around the edge of the deck to stop the AI jumping off. Not sure how it would look or how they'd react to such a wall.

Share this post


Link to post
Share on other sites

Inv wall only works for Player sad to say.

where is _forEachIndex defined

This sort of works ,Rather than remove the unit from an array I just remove him from the group.

private ["_group","_unitsAlive","_unit","_units","_unitHeight","_pos","_preferredHeight"];

_group = _this select 0;
_pos = _this select 1;

_unitsAlive = ({alive _x} count units _group);
_preferredHeight = 15.5; //Height of the LHD deck for units


while {_unitsAlive > 0} do
{
   sleep 1;
   _unitsAlive = ({alive _x} count units _group);
  {
 if (!alive _x) then {[_x] joinsilent grpnull};
_unitHeight = getposasl _x select 2;
  if (_unitHeight < _preferredHeight) then {_x setPosASL [(_pos select 0) - 10, ( _pos select 1), 16.2];}  } foreach units _group;

};   

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Inv wall only works for Player sad to say.

where is _forEachIndex defined

This sort of works ,Rather than remove the unit from an array I just remove him from the group.

private ["_group","_unitsAlive","_unit","_units","_unitHeight","_pos","_preferredHeight"];

_group = _this select 0;
_pos = _this select 1;

_unitsAlive = ({alive _x} count units _group);
_preferredHeight = 15.5; //Height of the LHD deck for units


while {_unitsAlive > 0} do
{
   sleep 1;
   _unitsAlive = ({alive _x} count units _group);
  {
 if (!alive _x) then {[_x] joinsilent grpnull};
_unitHeight = getposasl _x select 2;
  if (_unitHeight < _preferredHeight) then {_x setPosASL [(_pos select 0) - 10, ( _pos select 1), 16.2];}  } foreach units _group;

};   

This works perfectly! Thank you very much, you have no idea the amount of pain and rage you have spared me. Also thanks to everyone who posted! I had no idea invisible walls existed, your advice is invaluable.

Regards,

Art Vandelay

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  

×