// Nur Server       ArmA         [GNC]Lord-MDB 13.01.2007
//Aufruf in der Init.sqs:, temp =[[TruckW1,TruckW2,TruckW3,TruckW4,TruckW5],MHQWEST] execVM "MHQcheck.sqf"

exit;

private ["_i","_currentMHQ","_MHQs","_numMHQs","_Basispos","_healActionOn"];

_MHQs=_this select 0;
_Basispos=_this select 1;

//_healActionOn=0;
sleep 1;

_currentMHQ=0;
_numMHQs=count _MHQs;

if  ( (_numMHQs-1) == _currentMHQ) then //last MHQ
{
	(_MHQs select _currentMHQ) addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\resurrect.sqf"}];
};

while {true} do
{
	//add heal action to MHQ
	//	if (_healActionOn==0) then 
	//	{
	//		(_MHQs select _currentMHQ) addAction [("<t color='#d5e9ed'>" + "#Heal at MHQ Ambulance" + "</t>"), "actions\healme.sqf",[],6,false,true];
	//		_healActionOn=1;
	//	};

	//check if MHQ is in water
	if ( (getposASL (_MHQs select _currentMHQ ) select 2) < -1) then 
	{
		(_MHQs select _currentMHQ ) setDamage 1; 
		sleep 1;
	};

	//replace dead MHQ
	if (not Alive (_MHQs select _currentMHQ )) then
	{						
		if ( (_numMHQs-1) > _currentMHQ) then
		{			
			_currentMHQ=_currentMHQ + 1 ;
			
			(_MHQs select _currentMHQ ) setpos getpos _Basispos;
			(_MHQs select _currentMHQ ) setdir getdir _Basispos;

			if  ( (_numMHQs-1) == _currentMHQ) then //last MHQ
			{
				(_MHQs select _currentMHQ) addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\resurrect.sqf"}];
			};
		};
		
		//_healActionOn=0;
	};
		
	sleep 5;
	
	if (not Alive (_MHQs select _currentMHQ )) then	
	{
		hint format["MHQ %1/%2 Dead", _currentMHQ, _numMHQs ];
	}
	else
	{
		hint format["MHQ %1/%2 Alive", _currentMHQ, _numMHQs ];
	};
};




