// special action for engineers to erect a farp
//adding array for support trucks (see init) EGG_EVO_repairtruck

if (player in list AirportIn) exitWith {hint localize "STR_M04t74"};

//EGG_EVO_CHITEMS = ["ToolKit","Medikit"];
if !((EGG_EVO_CHITEMS select 0) in (items player)) exitWith {hint "You need a TOOLKIT to build a FARP"};

_trk=[];
_tpresent =0;
_trk = (nearestObjects [player, ["Car","Truck"], 50]);
sleep 0.5;
_tcount = (count _trk);

if (_tcount < 1) exitWith {hint localize "STR_M04t73"};

_tk = 0;
while {_tk < _tcount} do 
{
	_ntk = (_trk select (_tk));
	_trktype = typeOf (vehicle _ntk);
	if (_trktype in EGG_EVO_repairtruck) then 
	{
		_tpresent =1;
		_tk=_tcount;
	};
	_tk = _tk+1;
	sleep 1;
};

if (_tpresent <1) exitWith {hint localize "STR_M04t73"};

if (!isNil "etent") then { deletevehicle etent; };
if (!isNil "epad") then { deletevehicle epad; };
if (!isNil "ebox") then { deletevehicle ebox; };

_mark = format["%1FARP",(name player)];
deleteMarker _mark;

player playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 3.0;
WaitUntil {animationState player != "AinvPknlMstpSlayWrflDnon_medic"};

epad = (EGG_EVO_FARP select 1) createVehicle (position player);
//epad = "Land_HelipadSquare_F" createVehicle (position player);
_pos = position epad;
_pos2 = [_pos select 0,(_pos select 1) - 18,_pos select 2];

etent = (EGG_EVO_FARP select 2) createVehicle _pos2;
//etent = "Land_MetalBarrel_F" createVehicle _pos2;
_pos3 = [(_pos2 select 0)+3,(_pos2 select 1)+3,_pos2 select 2];

ebox = (EGG_EVO_FARP select 0) createVehicle _pos3;
//ebox = "Box_NATO_Ammo_F" createVehicle _pos3;
clearWeaponCargoGlobal ebox;

EGG_EVO_EngZone setpos _pos;	

_mssg = format["%1's FARP",(name player)];
_engmark = createMarker [_mark, _pos];
_engmark setMarkerShape "ICON";
_engmark setMarkerType "b_hq";
_engmark setMarkerColor "ColorBlack";
_engmark setMarkerText _mssg;
_engmark setMarkerSize [0.5, 0.5];

etent addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];
ebox addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];
