
if (isServer) then {
	_spawntype = _this select 0;
	_pos = getPos ASpad;
	_dir = getDir ASpad;
	_airtype = "C130J";
	_type = "GUE_Soldier_Pilot";
	mygroup = creategroup side player;
	


// Config
_mapMarkText = "Click on the map to designate the supply drop LZ";
_closeMapMessage = "Close the map to initiate drop procedure";
_droppoint = "SD_DropMarker";
_dropMarkerType = "SupplyVehicle";
_incomingMessage = "This is eagle one, we are inbound with supply drop, please stand by...";
_triggerDistance = 200;

// Map click to determine where the supplies will be dropped.
SD_dropmarked = true;
hint _mapMarkText;
_mapString = format["SD_DropMarker = createMarker [""%1"", _pos]; ""%1"" setMarkerType ""%2"";;SD_dropmarked=false",_droppoint, _dropMarkerType];
onMapSingleClick _mapString;
waitUntil{!SD_dropmarked};
onMapSingleClick "";

// Wait till they close the map to continue.
hint _closeMapMessage;
waitUntil{!visibleMap};
hintSilent "";

// Have the player toss smoke to mark the spot.
player playAction "ThrowGrenade";
sleep 2;
SD_smokePot = "SmokeShellGreen" createVehicle (getMarkerPos _droppoint);
[SD_smokePot, [0.4,0.8,0.4]] spawn {
	_sh=_this select 0;
	_col=_this select 1;
	_c1=_col select 0;
	_c2=_col select 1;
	_c3=_col select 2;
	
	sleep (3+random 1);
	
	_source = "#particlesource" createVehicleLocal getpos _sh;
	_source setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 7, 48], "", "Billboard", 1, 20, [0, 0, 0], [0.2, 0.1, 0.1], 0, 1.277, 1, 0.025, [0.1, 2, 6], [[_c1, _c2, _c3, 0.2], [_c1, _c2, _c3, 0.05], [_c1, _c2, _c3, 0]], [1.5,0.5], 1, 0.04, "", "", _sh];
	_source setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.1], 0, 0, 10];
	_source setDropInterval 0.03;
	_source2 = "#particlesource" createVehicleLocal getpos _sh;
	_source2 setParticleParams [["\Ca\Data\ParticleEffects\Universal\Universal", 16, 12, 8, 0], "", "Billboard", 1, 20, [0, 0, 0], [0.2, 0.1, 0.1], 0, 1.277, 1, 0.025, [0.1, 2, 6], [[_c1, _c2, _c3, 1], [_c1, _c2, _c3, 0.5], [_c1, _c2, _c3, 0]], [0.2], 1, 0.04, "", "", _sh];
	_source2 setParticleRandom [2, [0, 0, 0], [0.25, 0.25, 0.25], 0, 0.5, [0, 0, 0, 0.2], 0, 0, 360];
	_source2 setDropInterval 0.03;
};


// Spawn.

	_target = createVehicle  ["testsphere2",[_pos select 0,_pos select 1,-10], [], 0, "FLY"];
	deleteCollection _target;
	_target setpos [_pos select 0,_pos select 1,200];
	_target setDir _dir;
	_vdir = vectorDir _target;
	_target setpos [(_pos select 0) + (_vdir select 0) * 26, (_pos select 1) + (_vdir select 1) * 26,200];
	_apos = getposasl _target;
	
	
	_npos = [(_pos select 0) + (_vdir select 0) * -1500, (_pos select 1) + (_vdir select 1) * -1500, 300];
	
	_vehicle = createVehicle  [_airtype,_npos, [], 0, "FLY"];
	_vehicle setpos _npos;
	_vehicle setDir _dir;
	
	
	_vehicle setvelocity [(_vdir select 0)*50,(_vdir select 1)*50, 5];
	
	_type createUnit [_npos, mygroup,"pilot=this;"];
	_pilot = pilot;
	_pilot moveindriver _vehicle;
	_pilot reveal _target;
	_pilot doMove _npos;
	_pilot dotarget _target;
	_pilot dowatch _target;
	_pilot FlyInHeight 400;
	_vehicle FlyInHeight 400;
	
	
	while {_vehicle distance _target > 40} do {
	    sleep 0.5;
	    if(_vehicle distance _target < 600) then {
	        _pilot FlyInHeight 400;
	        _pilot doMove _npos;
	    };
	};


// Drop.	
	    _bpos = _vehicle ModelToWorld [0,-12,-5.5];
	    _bomb = _spawntype createVehicle _bpos;
	    _bomb setpos _bpos;
	    _bomb setDir direction _vehicle;
	    _chute = "ParachuteMediumWest" createVehicle getpos _bomb;
	    _chute setpos (_bomb ModelToWorld [0,0,3]);
	    _bomb attachTo [_chute,[0,0,0]];
	    deletevehicle _target;
	    sleep 0.05;
	
	_plane FlyInHeight 250;
	
	
	sleep 1;
	_plane FlyInHeight 450;
	_pilot doMove [(_pos select 0) + (_vdir select 0) * 800, (_pos select 1) + (_vdir select 1) * 800, 500];
	
	sleep 15;
	
	deletevehicle _vehicle;
	deletevehicle _pilot;
};
