add isNull check to load vehicle

This commit is contained in:
vbawol 2016-06-15 10:47:25 -05:00
parent 7c8e645169
commit 072ef02e77

View File

@ -65,180 +65,186 @@ for "_i" from 1 to _maxVehicleLimit do {
}; };
_vehicle = createVehicle [_class, _location, [], 0, "CAN_COLLIDE"]; _vehicle = createVehicle [_class, _location, [], 0, "CAN_COLLIDE"];
_allVehicles pushBack _vehicle; if !(isNull _vehicle) then {
_vehicle call EPOCH_server_setVToken;
_vehicle call EPOCH_server_vehicleInit;
_vehicle setVectorDirAndUp _worldspace; _allVehicles pushBack _vehicle;
_vehicle setposATL _location; _vehicle call EPOCH_server_setVToken;
_vehicle setDamage _damage; _vehicle call EPOCH_server_vehicleInit;
_allHitpoints = getAllHitPointsDamage _vehicle; _vehicle setVectorDirAndUp _worldspace;
if !(_allHitpoints isEqualTo []) then{ _vehicle setposATL _location;
_actualHitpoints = _allHitpoints select 0; _vehicle setDamage _damage;
_hitpoints = _arr select 3;
if ((count _actualHitpoints) == (count _hitpoints)) then{
{
_dmg = _hitpoints param [_forEachIndex,0];
if (_x in ["HitFuel", "HitEngine"]) then {
_dmg = _dmg min 0.9;
};
_vehicle setHitIndex [_forEachIndex, _dmg];
} forEach _actualHitpoints;
};
};
if (_immuneVehicleSpawn) then{ _allHitpoints = getAllHitPointsDamage _vehicle;
_vehicle allowDamage false; if !(_allHitpoints isEqualTo []) then{
}; _actualHitpoints = _allHitpoints select 0;
_hitpoints = _arr select 3;
_vehicle setFuel (_arr select 4); if ((count _actualHitpoints) == (count _hitpoints)) then{
{
_cfgEpochVehicles = 'CfgEpochVehicles' call EPOCH_returnConfig; _dmg = _hitpoints param [_forEachIndex,0];
_availableColorsConfig = (_cfgEpochVehicles >> _class >> "availableColors"); if (_x in ["HitFuel", "HitEngine"]) then {
if (isArray(_availableColorsConfig)) then { _dmg = _dmg min 0.9;
_color = _arr select 7; };
_colors = getArray(_availableColorsConfig); _vehicle setHitIndex [_forEachIndex, _dmg];
_textureSelectionIndex = (_cfgEpochVehicles >> _class >> "textureSelectionIndex"); } forEach _actualHitpoints;
_selections = if (isArray(_textureSelectionIndex)) then { getArray(_textureSelectionIndex) } else { [0] };
_count = (count _colors) - 1;
{
_textures = _colors select 0;
if (_count >= _forEachIndex) then {
_textures = _colors select _forEachIndex;
}; };
_vehicle setObjectTextureGlobal [_x, _textures select _color];
} forEach _selections;
_vehicle setVariable ["VEHICLE_TEXTURE", _color];
};
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
_vehicle disableTIEquipment true;
_vehicle lock true;
_vehicle setVariable ["VEHICLE_SLOT", str(_i), true];
//diag_log format ["FILLING: _vehicle %1 pos: %2", _vehicle, (getPosATL _vehicle)];
{
_objType = _forEachIndex;
_objTypes = _x;
_objQty = [];
if (_objType in [1, 2, 3]) then {
_objTypes = _x select 0;
_objQty = _x select 1;
}; };
if (_immuneVehicleSpawn) then{
_vehicle allowDamage false;
};
_vehicle setFuel (_arr select 4);
_cfgEpochVehicles = 'CfgEpochVehicles' call EPOCH_returnConfig;
_availableColorsConfig = (_cfgEpochVehicles >> _class >> "availableColors");
if (isArray(_availableColorsConfig)) then {
_color = _arr select 7;
_colors = getArray(_availableColorsConfig);
_textureSelectionIndex = (_cfgEpochVehicles >> _class >> "textureSelectionIndex");
_selections = if (isArray(_textureSelectionIndex)) then { getArray(_textureSelectionIndex) } else { [0] };
_count = (count _colors) - 1;
{
_textures = _colors select 0;
if (_count >= _forEachIndex) then {
_textures = _colors select _forEachIndex;
};
_vehicle setObjectTextureGlobal [_x, _textures select _color];
} forEach _selections;
_vehicle setVariable ["VEHICLE_TEXTURE", _color];
};
clearWeaponCargoGlobal _vehicle;
clearMagazineCargoGlobal _vehicle;
clearBackpackCargoGlobal _vehicle;
clearItemCargoGlobal _vehicle;
_vehicle disableTIEquipment true;
_vehicle lock true;
_vehicle setVariable ["VEHICLE_SLOT", str(_i), true];
//diag_log format ["FILLING: _vehicle %1 pos: %2", _vehicle, (getPosATL _vehicle)];
{ {
switch _objType do { _objType = _forEachIndex;
// Weapon cargo
case 0: {
if (_x isEqualType []) then {
if ((count _x) >= 4) then {
_vehicle addWeaponCargoGlobal[_x deleteAt 0, 1]; _objTypes = _x;
_objQty = [];
_attachments = []; if (_objType in [1, 2, 3]) then {
_wMags = false; _objTypes = _x select 0;
_wMagsArray = []; _objQty = _x select 1;
// suppressor, laser, optics, magazines(array), bipods };
{
// magazines {
if (_x isEqualType []) then{ switch _objType do {
_wMags = true; // Weapon cargo
_wMagsArray = _x; case 0: {
} if (_x isEqualType []) then {
else { if ((count _x) >= 4) then {
// attachments
if (_x != "") then{ _vehicle addWeaponCargoGlobal[_x deleteAt 0, 1];
_attachments pushBack _x;
_attachments = [];
_wMags = false;
_wMagsArray = [];
// suppressor, laser, optics, magazines(array), bipods
{
// magazines
if (_x isEqualType []) then{
_wMags = true;
_wMagsArray = _x;
}
else {
// attachments
if (_x != "") then{
_attachments pushBack _x;
};
};
} forEach _x;
// add all attachments to vehicle
// TODO replace with adding attachments directly to gun (Arma feature dependant)
{
_vehicle addItemCargoGlobal[_x, 1];
} forEach _attachments;
if (_wMags) then{
if (_wMagsArray isEqualType [] && (count _wMagsArray) >= 2) then{
_vehicle addMagazineAmmoCargo[_wMagsArray select 0, 1, _wMagsArray select 1];
}; };
}; };
} forEach _x;
// add all attachments to vehicle
// TODO replace with adding attachments directly to gun (Arma feature dependant)
{
_vehicle addItemCargoGlobal[_x, 1];
} forEach _attachments;
if (_wMags) then{
if (_wMagsArray isEqualType [] && (count _wMagsArray) >= 2) then{
_vehicle addMagazineAmmoCargo[_wMagsArray select 0, 1, _wMagsArray select 1];
};
}; };
};
};
// Magazine cargo
case 1: {
_magazineName = _x;
_magazineSize = _objQty select _forEachIndex;
if ((_magazineName isEqualType "STRING") && (_magazineSize isEqualType 0)) then {
_magazineSizeMax = getNumber (configFile >> "CfgMagazines" >> _magazineName >> "count");
// Add full magazines cargo
_vehicle addMagazineAmmoCargo [_magazineName, floor (_magazineSize / _magazineSizeMax), _magazineSizeMax];
// Add last non full magazine
if ((_magazineSize % _magazineSizeMax) > 0) then {
_vehicle addMagazineAmmoCargo [_magazineName, 1, floor (_magazineSize % _magazineSizeMax)];
};
};
};
// Backpack cargo
case 2: {
if (_x isEqualType "STRING") then {
_qty = _objQty select _forEachIndex;
_vehicle addBackpackCargoGlobal [_x, _qty];
};
};
// Item cargo
case 3: {
if (_x isEqualType "STRING") then {
_qty = _objQty select _forEachIndex;
_vehicle addItemCargoGlobal [_x, _qty];
}; };
}; };
}; };
// Magazine cargo } forEach _objTypes;
case 1: { } forEach (_arr select 5);
_magazineName = _x;
_magazineSize = _objQty select _forEachIndex;
if ((_magazineName isEqualType "STRING") && (_magazineSize isEqualType 0)) then { // remove and add back magazines works for armed trucks but not helis ATM
_magazineSizeMax = getNumber (configFile >> "CfgMagazines" >> _magazineName >> "count"); {_vehicle removeMagazineGlobal _x}count (magazines _vehicle);
{_vehicle addMagazine _x}count (_arr select 6);
// Add full magazines cargo // turrets
_vehicle addMagazineAmmoCargo [_magazineName, floor (_magazineSize / _magazineSizeMax), _magazineSizeMax]; /*
_mags = _vehicle magazinesTurret [0];
{
_object removeMagazinesTurret [_x, [0]];
} forEach _mags;
// Add last non full magazine _mags = _vehicle magazinesTurret [-1];
if ((_magazineSize % _magazineSizeMax) > 0) then { {
_vehicle addMagazineAmmoCargo [_magazineName, 1, floor (_magazineSize % _magazineSizeMax)]; _object removeMagazinesTurret [_x, [-1]];
}; } forEach _mags;
}; */
};
// Backpack cargo
case 2: {
if (_x isEqualType "STRING") then {
_qty = _objQty select _forEachIndex;
_vehicle addBackpackCargoGlobal [_x, _qty];
};
};
// Item cargo
case 3: {
if (_x isEqualType "STRING") then {
_qty = _objQty select _forEachIndex;
_vehicle addItemCargoGlobal [_x, _qty];
};
};
};
} forEach _objTypes;
} forEach (_arr select 5);
// remove and add back magazines works for armed trucks but not helis ATM if (EPOCH_DEBUG_VEH) then {
{_vehicle removeMagazineGlobal _x}count (magazines _vehicle); _marker = createMarker [str(_location) , _location];
{_vehicle addMagazine _x}count (_arr select 6); _marker setMarkerShape "ICON";
_marker setMarkerType "mil_dot";
_marker setMarkerText _class;
_marker setMarkerColor "ColorGreen";
};
// turrets if (_simulationHandler) then{
/* _vehicle enableSimulationGlobal false;
_mags = _vehicle magazinesTurret [0]; };
{
_object removeMagazinesTurret [_x, [0]];
} forEach _mags;
_mags = _vehicle magazinesTurret [-1]; } else {
{ diag_log format["DEBUG: vehicle object Null: class: %1, loc: %2, slot: %3",_class, _location,str(_i)];
_object removeMagazinesTurret [_x, [-1]];
} forEach _mags;
*/
if (EPOCH_DEBUG_VEH) then {
_marker = createMarker [str(_location) , _location];
_marker setMarkerShape "ICON";
_marker setMarkerType "mil_dot";
_marker setMarkerText _class;
_marker setMarkerColor "ColorGreen";
};
if (_simulationHandler) then{
_vehicle enableSimulationGlobal false;
}; };
} else { } else {