move to cfg, update createbox, create /defines
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Author: Hizumi & IndigoFox
|
||||
*
|
||||
* Create Mortar resupply box for the 17th Battalion
|
||||
* Create Mortar resupply box for the 17th Battalion. Primarily called from milsim_fnc_addZenModules
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Vehicle - <OBJECT>
|
||||
* 1: Position - <ARRAY>
|
||||
* 1: Type - <STRING>
|
||||
* 2: Position - <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* Function executed <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* [box] call milsim_fnc_createBox; // create mortar ammo box via init line of editor object
|
||||
* [objNull, pos] call milsim_fnc_createBox; // create mortar ammo box via zeus module
|
||||
* [box, "AmmoSquad"] call milsim_fnc_createBox; // create mortar ammo box via init line of editor object
|
||||
* [objNull, "AmmoHeavy", pos] call milsim_fnc_createBox; // create mortar ammo box via zeus module
|
||||
*
|
||||
* Public: Yes
|
||||
*
|
||||
@@ -34,68 +35,133 @@ params [
|
||||
["_pos", [0,0,0], [[]], 3]
|
||||
];
|
||||
|
||||
if (isNil "milsim_resupply_crateDefinitions") exitWith {
|
||||
format["Resupply Boxes: milsim_resupply_crateDefinitions is not defined, possibly a bad edit?"] remoteExec ["systemChat", 0];
|
||||
false;
|
||||
// get defs class
|
||||
private _supplyCratesCfg = call milsim_resupply_fnc_getSupplyCratesCfg;
|
||||
if (!isClass _supplyCratesCfg) exitWith {
|
||||
["Resupply Boxes: Failed to load crate definitions, possibly a bad edit?"] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
// get the subclass names
|
||||
private _boxTypesAvailable = _supplyCratesCfg call BIS_fnc_getCfgSubClasses;
|
||||
|
||||
// if no type is provided, show the available types
|
||||
if (_type isEqualTo "") exitWith {
|
||||
format["Resupply Boxes: [_boxObject, _type, _pos] call milsim_fnc_createBox"] remoteExec ["systemChat", 0];
|
||||
format["Please use one of the following types for _type:"] remoteExec ["systemChat", 0];
|
||||
format["%1", (keys milsim_resupply_crateDefinitions)] remoteExec ["systemChat", 0];
|
||||
false;
|
||||
[
|
||||
"%1 | %2 %3",
|
||||
"Resupply Boxes: [_boxObject, _type, _pos] call milsim_fnc_createBox",
|
||||
"No type provided. Please use one of the following types for _type:",
|
||||
_boxTypesAvailable joinString ", "
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
private _boxData = milsim_resupply_crateDefinitions getOrDefault [_type, createHashMap];
|
||||
if (count _boxData isEqualTo 0) exitWith {
|
||||
format["Resupply Boxes: [_boxObject, _type, _pos] call milsim_fnc_createBox"] remoteExec ["systemChat", 0];
|
||||
format["%1 is not a valid type for _type", _type] remoteExec ["systemChat", 0];
|
||||
format["Please use one of the following types for _type:"] remoteExec ["systemChat", 0];
|
||||
format["%1", (keys milsim_resupply_crateDefinitions)] remoteExec ["systemChat", 0];
|
||||
false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// get the box definition class
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
private _boxDef = (_supplyCratesCfg >> _type);
|
||||
// validate it exists
|
||||
if (!isClass _boxDef) exitWith {
|
||||
[
|
||||
"%1 | %2 %3",
|
||||
"Resupply Boxes: [_boxObject, _type, _pos] call milsim_fnc_createBox",
|
||||
"Invalid type provided. Please use one of the following types for _type:",
|
||||
_boxTypesAvailable joinString ", "
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
private _boxItems = _boxData getOrDefault ["items", createHashMap];
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Create box if one wasn't provided in parameters
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
if (isNull _box) then {
|
||||
_box = (_boxData get "className") createVehicle _pos;
|
||||
private _neededBoxType = getText(_boxDef >> "boxClass");
|
||||
if (_neededBoxType isEqualTo "") exitWith {
|
||||
[
|
||||
"Resupply Boxes: Failed to create box. No boxClass defined in the box definition."
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
_box = _neededBoxType createVehicle _pos;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Clear box
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
clearBackpackCargoGlobal _box;
|
||||
clearItemCargoGlobal _box;
|
||||
clearMagazineCargoGlobal _box;
|
||||
clearWeaponCargoGlobal _box;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Get [item, quantity] arrays from definition
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
private _backpacks = ([_boxDef >> "backpacks"] call BIS_fnc_getCfgDataArray);
|
||||
if (isNil "_backpacks") exitWith {
|
||||
[
|
||||
"Resupply Boxes: Failed to create box. No backpacks defined in the box definition."
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
private _weapons = ([_boxDef >> "weapons"] call BIS_fnc_getCfgDataArray);
|
||||
if (isNil "_weapons") exitWith {
|
||||
[
|
||||
"Resupply Boxes: Failed to create box. No weapons defined in the box definition."
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
private _magazines = ([_boxDef >> "magazines"] call BIS_fnc_getCfgDataArray);
|
||||
if (isNil "_magazines") exitWith {
|
||||
[
|
||||
"Resupply Boxes: Failed to create box. No magazines defined in the box definition."
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
private _items = ([_boxDef >> "items"] call BIS_fnc_getCfgDataArray);
|
||||
if (isNil "_items") exitWith {
|
||||
[
|
||||
"Resupply Boxes: Failed to create box. No items defined in the box definition."
|
||||
] call BIS_fnc_error;
|
||||
objNull;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Add stuff to box
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
_x params ["_class", "_qty"];
|
||||
|
||||
_box addBackpackCargoGlobal [_class, _qty]
|
||||
|
||||
} foreach (_boxItems getOrDefault ["backpacks", []]);
|
||||
} foreach _backpacks;
|
||||
|
||||
{
|
||||
_x params ["_class", "_qty"];
|
||||
|
||||
_box addItemCargoGlobal [_class, _qty]
|
||||
|
||||
} foreach (_boxItems getOrDefault ["items", []]);
|
||||
} foreach _items;
|
||||
|
||||
{
|
||||
_x params ["_class", "_qty"];
|
||||
|
||||
_box addMagazineCargoGlobal [_class, _qty]
|
||||
|
||||
} foreach (_boxItems getOrDefault ["magazines", []]);
|
||||
} foreach _magazines;
|
||||
|
||||
{
|
||||
_x params ["_class", "_qty"];
|
||||
|
||||
_box addWeaponCargoGlobal [_class, _qty]
|
||||
|
||||
} foreach (_boxItems getOrDefault ["weapons", []]);
|
||||
} foreach _weapons;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Adjust ACE settings
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// set box size
|
||||
[_box,1] call ace_cargo_fnc_setSize;
|
||||
|
||||
// ignore weight restrictions for carry/drag
|
||||
_box setVariable ["ace_ignoreWeightCarry", true, true];
|
||||
|
||||
// Return the box
|
||||
_box;
|
||||
Reference in New Issue
Block a user