; exit script 05 Scrap


; Saving player's status
aa = aP saveStatus "05Player";
; Player will be saved


; -------- Vehicles ---------

_veh = [Tank1, Tank2, Tank3, Tank4, BMP];
_j = 0;
_i = count _veh;

#LOOPVehicles
? _j >= _i : goto "ENDVehicles"

_who = _veh select _j;
_do = false
? (alive _who) and (_who distance aP < 400) and  ((side (driver _who) == resistance) or ((driver _who != driver _who))) : _do = true;

? not (_do) : goto "LOOPVehIn"

? _who == Tank1 : GLB_05_T80 = true; saveVar "GLB_05_T80"; goto "LOOPVehIn"
? _who == Tank2 : GLB_05_T72a = true; saveVar "GLB_05_T72a"; goto "LOOPVehIn"
? _who == Tank3 : GLB_05_T72b = true; saveVar "GLB_05_T72b"; goto "LOOPVehIn"
? _who == Tank4 : GLB_05_T72c = true; saveVar "GLB_05_T72c"; goto "LOOPVehIn"
? _who == BMP : GLB_05_BMP = true; saveVar "GLB_05_BMP"; goto "LOOPVehIn"

#LOOPVehIn
_j = _j + 1;
goto "LOOPVehicles"

#ENDVehicles


goto "SOLD"


; Now not using - doing it manually for this mission...
_j = 0;
_k = 0;
_veh = [Tank1, GLB_05_T80, "GLB_05_T80", "05T80", Tank2, GLB_05_T72a, "GLB_05_T72a", "05T72a", Tank3, GLB_05_T72b, "GLB_05_T72b", "05T72b", Tank4, GLB_05_T72c, "GLB_05_T72c", "05T72c", BMP, GLB_05_BMP, "GLB_05_BMP", "05BMP"];

_i = count _veh;
_what = (vehicle aP);

#LOOPVEH
? _j >= _i : goto "AfterVeh"

? (alive (_veh select _j)) and ((_veh select _j) distance _what < 300) : (_veh set [(_j+1), true]); saveVar (_veh select (_j+2)); xx = (_veh select _j) saveStatus (_veh select (_j+3)); _k = _k +1

_j = _j + 4;
goto "LOOPVEH"

#AfterVeh
GLB_05_VEHICLES = _k; saveVar "GLB_05_VEHICLES";


xx = deleteStatus "04Truck";
GLB_04_TRUCK = false;
? canmove Truck : GLB_04_TRUCK = true; xx = Truck saveStatus "04Truck";
SaveVar "GLB_04_TRUCK";


; Saving soldiers - player's group
#SOLD

GLB_05_HOWMANY = 8 - (count units group aP);
? GLB_05_HOWMANY < 0 : GLB_05_HOWMANY = 0;
saveVar "GLB_05_HOWMANY";

; Special soldiers
? alive aMed : GLB_05_MED = true; saveVar "GLB_05_MED"; xx = aMed saveStatus "05Medic";
? alive aMed2 : GLB_05_MED2 = true; saveVar "GLB_05_MED2"; xx = aMed2 saveStatus "05Medic2";

; ------- Player's group ---------

_i = count units group aP;
_j = 0;
_k = 0;
_Mis = "05";
_Out = [aMed, aMed2, aP];

#LOOP
? _j >= _i : goto "Next"

? ((units group aP) select _j) in _Out : goto "SKIP"
? alive ((units group aP) select _j) : xx = ((units group aP) select _j) saveStatus _Mis + (format ["Sold%1", _k]); _k = _k+1;

#SKIP
_j = _j + 1;
goto "LOOP"

#Next
GLB_05_NUMBER = _k; saveVar "GLB_05_NUMBER";


; ================== BEGIN: WEAPON POOL ====================

#POOL

; Added by mission designer



; Alway adding basic weapons
? (queryWeaponPool "AK47CZ") < 10 : addWeaponPool ["AK47CZ", 10]
? (queryMagazinePool "AK47") < 100 : addMagazinePool ["AK47", 30]


; Weapon holders stolen?

GLB_TR = 0;
; just working variable - remove!!!

_vehs = [BMP, Tr1, Tr2, Tr3, Tank1, Tank2, Tank3, Tank4];
; These vehicles will add their weapons to pool if they are close enough

_a = 0;
_b = count units group aP;

; Add all group vehicles to _vehs
#LOOPGroupVeh

? _b >= _a : goto "ENDGroupVeh"

_who = (units group aP) select _a;
? (vehicle _who != _who) and not ((vehicle _who) in _vehs) : _vehs = _vehs + [vehicle _who];

_a = _a + 1;
goto "LOOPGroupVeh";

#ENDGroupVeh

_a = 0;
_b = count _vehs;

#LOOPHolders
? _a >= _b : goto "ENDHolders"

_work = false;
_u = _vehs select _a
? side (driver _u) == resistance : _work = true;
? alive _u and (driver _u != driver _u) and ((_u distance aP) < 300) : _work = true;

? _work : pickWeaponPool (vehicle _u); clearWeaponCargo (vehicle _u); clearMagazineCargo (vehicle _u); GLB_TR = GLB_TR + 1

_a = _a + 1;
goto "LOOPHolders"

#ENDHolders
saveVar "GLB_TR";

; ================== END: WEAPON POOL ====================






; ------------- END -------------
