//Начало скрипта//

//Часть I

//Объявление переменных
MenuState = 0;
_ar = _this;
if (count _ar == 0) exitwith {hint "Массив пуст!"};
_a_car = [];
_a_arm = [];
_a_air = [];
_a_stc = [];
_ind = 350;
_car = 0;
_dial = createdialog "SupportHelp";

(findDisplay 10001) displayAddEventHandler ["keyDown", "if (_this select 1 == 0x01) then {null = [] execVM 'ACS\menu\esc.sqf';};"];
//Заполнение массивов

{
_obj = _ar select _car;
if (_obj isKindof "Car") then
    {
        _a_car = _a_car + [_obj];
    };
if (_obj isKindof "tank") then
    {
        _a_arm = _a_arm + [_obj];
    };
if (_obj isKindof "Air") then
    {
        _a_air = _a_air + [_obj];
    };
if (_obj isKindof "StaticWeapon") then
    {
        _a_stc = _a_stc + [_obj];
    };
_car = _car + 1;

} foreach _ar;

//Добавление классов в comboBox1(Тип)

//Машины
if (count _a_car != 0) then {
    lbAdd[10003,"Машины"];
};
//Танки
if (count _a_arm != 0) then {
    lbAdd[10003,"Танки"];
};
//Воздушные средства
if (count _a_air != 0) then {
    lbAdd[10003,"Воздух"];
};
//Статики
if (count _a_stc != 0) then {
    lbAdd[10003,"Орудия"];
};

//Создание маркера сброса

_dz = createMarker ["dzMenu", [(getpos player select 0)-75,(getpos player select 1)-75]];
_dz setMarkerShape "icon";
_dz setmarkercolor "ColorBlue";
_dz setmarkertype "hd_pickup";
_dz setmarkertext "Место сброса";

//Перемещение маркера сброса
onmapSingleClick "
    _x = _pos select 0;    
    _y = _pos select 1;
    'dzMenu' setmarkerpos [_x,_y];
    true;
";

//Заполнение comboBox2(Средство)
scopename "while-do";
while {MenuState == 0} do {
    _lb = lbcursel 10003;
    waitUntil {(lbcursel 10003 != _lb) || (MenuState == 1)};
    if (MenuState == 1) then 
    {
        if (lbcursel 10003 != -1) then {breakTo "while-do"} else {MenuState = 0};
    };
    lbclear 10004;
    switch (lbtext [10003, lbcursel 10003]) do
    {   
        case "Машины": 
        {
            _a = 0;
            {
                _ob = _a_car select _a;
                lbAdd[10004,getText(configFile >> "CfgVehicles" >> (_ob) >> "displayName")];
                _a = _a + 1;
            } foreach _a_car;
            lbsetcursel [10004,0];
        };
        case "Танки": 
        {
            _a = 0;
            {
                _ob = _a_arm select _a;
                lbAdd[10004,getText(configFile >> "CfgVehicles" >> (_ob) >> "displayName")];
                _a = _a + 1;
            } foreach _a_arm;
            lbsetcursel [10004,0];
        };
        case "Воздух": 
        {
            _a = 0;
            {
                _ob = _a_air select _a;
                lbAdd[10004,getText(configFile >> "CfgVehicles" >> (_ob) >> "displayName")];
                _a = _a + 1;
            } foreach _a_air;
            lbsetcursel [10004,0];
        };
        case "Орудия": 
        {
            _a = 0;
            {
                _ob = _a_stc select _a;
                lbAdd[10004,getText(configFile >> "CfgVehicles" >> (_ob) >> "displayName")];
                _a = _a + 1;
            } foreach _a_stc;
            lbsetcursel [10004,0];
        };
        default  {};
    };
    
};

//Часть II

//Объявление новых переменных
_a_veh = [];
switch (lbtext [10003, lbcursel 10003]) do 
{
    case "Машины" : {_a_veh = _a_veh + _a_car;};
    case "Танки" : {_a_veh = _a_veh + _a_arm;};
    case "Воздух" : {_a_veh = _a_veh + _a_air;};
    case "Орудия" : {_a_veh = _a_stc + _a_stc;};
    default {hint "Defs"};
};
_veh = lbcursel 10004;

//Вызов самолета
closedialog 0;
_g_p = creategroup west;
_s = createVehicle ["C130J_US_EP1", [(getmarkerpos "dzmenu" select 0),(getmarkerpos "dzMenu" select 1)+2000,500], [], 0,"none"];
_s setdir 180;
_p = _g_p createUnit ["US_Soldier_Crew_EP1", [0,0,0], [],0,"none"];
_p setcaptive true;
_s flyinheight 500;
_s setvelocity [0,-100,0];
_p moveindriver _s;
addSwitchableUnit _p;
_dwp = _g_p addwaypoint [getmarkerpos "dzmenu",0];
_ewp = _g_p addwaypoint [[getmarkerpos "dzmenu" select 0, (getmarkerpos "dzMenu" select 1)-2000,0],0];
_ewp setwaypointStatements ["true","deleteVehicle (vehicle this); deletevehicle This"];
waitUntil {_s distance getmarkerpos "dzMenu" < 550};

//Сброс контейнера

_cr = "Land_Misc_Cargo1E_EP1" createVehicle [0, 0, 0];
_cr setpos [getpos _s select 0, getPos _s select 1, (getPos _s select 2) - 10];
_c = "ParachuteBigWest_EP1" createVehicle [0, 0, 0]; 
_c setPos [getpos _cr select 0, getPos _cr select 1, getPos _cr select 2];
_cr attachto [_c, [0, 0, 0]];
sleep 0.1;
_c setvelocity [velocity _s select 0,velocity _s select 1,-50];
_flar1 = "F_40mm_Green" createVehicle [getpos _cr select 0, getPos _cr select 1, (getPos _cr select 2) - 10];
waituntil {(getpos _cr select 2  < 0.001)};
"dzMenu" setmarkerpos (getpos _cr);
_smoke = createVehicle ["SmokeShellGreen", position _cr, [], 0, "None"];
detach _cr;
_c setvelocity [2,2,0];
_cr setpos [getpos _cr select 0, getpos _cr select 1, 0];

while {player distance _cr >= 10} do {

    _flar2 = "F_40mm_Red" createVehicle [getPos _cr select 0,getPos _cr select 1,+200];
    waitUntil {(getpos _flar2 select 2 <= 5) || ((player distance _cr) < 10)};
    if (getpos _flar2 select 2 <= 5) then {deletevehicle _flar2;};
};

while {!isNull _cr} do {
    waituntil {player distance _cr < 10};
    _ida = player addAction ["Развернуть подарок", "ACS\menu\menu2.sqf", [_cr, _veh, _a_veh], 3, true, true, "","true"];
    waituntil {player distance _cr >= 10};
    player removeaction _ida;
};
if (true) exitWith {};