Skip to content

Commit

Permalink
fix civ loadout setting (#75)
Browse files Browse the repository at this point in the history
* do not completely reset civ layout if uniform & headgear are set
* but remove watch in 50%, map in 95% and compass in 99% of all cases
* uniform and headgear are now settable independently
* fix loadout setter functions

NOTE: had to add a delay when setting face. no idea why.
  • Loading branch information
Fusselwurm authored Jul 4, 2020
1 parent d16d261 commit 9674f73
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 40 deletions.
2 changes: 1 addition & 1 deletion addons/cars/functions/fnc_setVehicles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

params [["_value",[]]];

[QGVAR(vehicles), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(vehicles), _value, 1, "mission"] call CBA_settings_fnc_set;
1 change: 1 addition & 0 deletions addons/loadout/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(applyRandomConfigArrayValue);
PREP(civAddLoadout);
PREP(initConfig);
PREP(setBackpacks);
Expand Down
10 changes: 9 additions & 1 deletion addons/loadout/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ if (!([QEGVAR(main,enabled)] call CBA_settings_fnc_get)) exitWith {
INFO("GRAD civs is disabled. Good bye!");
};


[QEGVAR(legacy,civ_added), {
params [["_civ", objNull, [objNull]]];
assert(!isNull _civ);
if (local _civ) then {
[_civ] call FUNC(civAddLoadout);
};
}] call CBA_fnc_addEventHandler;

[QGVAR(broadcastFace), {
params [
["_unit", objNull, [objNull]],
["_face", "", [""]]
];
if (isNull _unit) exitWith {};
_unit setFace _face;
}] call CBA_fnc_addEventHandler;
30 changes: 30 additions & 0 deletions addons/loadout/functions/fnc_applyRandomConfigArrayValue.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "..\script_component.hpp"

params [
["_configVarname", "", [""]],
["_args", objNull, [objNull, [], 0, "", false]],
["_callback", {}, [{}]]
];

scopeName "main";
private _rawValue = [_configVarname] call cba_settings_fnc_get;
private _arrValue = [];
switch (typeName _rawValue) do {
case ("STRING"): {
if (_rawValue == "") then {
breakOut "main";
};
_arrValue = parseSimpleArray _rawValue;
};
case ("ARRAY"): {
_arrValue = _rawValue;
};
default {
ERROR_2("unexpected type %1 for config %2", typeName _rawValue, _configVarname);
breakOut "main";
};
};

if (count _arrValue == 0) exitWith {};

[_args, (selectRandom _arrValue)] call _callback
89 changes: 57 additions & 32 deletions addons/loadout/functions/fnc_civAddLoadout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,68 @@ params [
];

assert(!isNull _unit);
assert(local _unit);


private _reclotheHim = {
params ["_unit", "_loadout"];

_unit setUnitLoadout _loadout;
private _faces = parseSimpleArray ([QGVAR(faces)] call cba_settings_fnc_get);
if (count _faces > 0) then {
[_unit, selectRandom _faces] remoteExec ["setFace", 0, _unit];
};
if (random 1 > 0.5) then {
_unit unlinkItem "ItemWatch";
};

private _addBeard = {
params ["_unit"];
private _goggles = parseSimpleArray ([QGVAR(goggles)] call cba_settings_fnc_get);
if (count _goggles > 0) then {
_unit addGoggles selectRandom _goggles;
};
if (random 1 > 0.05) then {
_unit unlinkItem "ItemMap";
};
if (random 1 > 0.01) then {
_unit unlinkItem "ItemCompass";
};

private _addBackpack = {
params ["_unit"];
[
QGVAR(clothes),
_unit,
{
params ["_unit", "_value"];
_unit addUniform _value;
}
] call FUNC(applyRandomConfigArrayValue);

private _backpacks = parseSimpleArray ([QGVAR(backpacks)] call cba_settings_fnc_get);
private _backpackProbability = [QGVAR(backpackProbability)] call cba_settings_fnc_get;
if ((_backpackProbability > (random 1)) && {count _backpacks > 0}) then {
_unit addBackpackGlobal selectRandom _backpacks;
};
};
[
QGVAR(headgear),
_unit,
{
params ["_unit", "_value"];
_unit addHeadgear _value;
}
] call FUNC(applyRandomConfigArrayValue);

private _clothes = parseSimpleArray ([QGVAR(clothes)] call cba_settings_fnc_get);
private _headgear = parseSimpleArray ([QGVAR(headgear)] call cba_settings_fnc_get);
if ((count _clothes > 0) && (count _headgear > 0)) then {
private _unitLoadout = [[],[],[],[selectRandom _clothes,[]],[],[],selectRandom _headgear,"""",[],["""","""","""","""","""",""""]];
[_unit, _unitLoadout] call _reclotheHim;
};
[
QGVAR(faces),
_unit,
{
[
{
[QGVAR(broadcastFace), _this] call CBA_fnc_globalEventJIP;
},
_this,
2
] call CBA_fnc_waitAndExecute;
}
] call FUNC(applyRandomConfigArrayValue);


[_unit] call _addBeard;
[_unit] call _addBackpack;
[
QGVAR(goggles),
_unit,
{
params ["_unit", "_value"];
_unit addGoggles _value;
}
] call FUNC(applyRandomConfigArrayValue);

private _backpackProbability = [QGVAR(backpackProbability)] call cba_settings_fnc_get;
if (_backpackProbability > (random 1)) then {
[
QGVAR(backpacks),
_unit,
{
params ["_unit", "_value"];
_unit addBackpackGlobal _value;
}
] call FUNC(applyRandomConfigArrayValue);
};
4 changes: 2 additions & 2 deletions addons/loadout/functions/fnc_setBackpacks.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

params [["_value",[]],["_probability",0.5]];

[QGVAR(backpacks), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(backpackProbability), _probability, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(backpacks), str _value, 1, "mission"] call CBA_settings_fnc_set;
[QGVAR(backpackProbability), _probability, 1, "mission"] call CBA_settings_fnc_set;
2 changes: 1 addition & 1 deletion addons/loadout/functions/fnc_setClothes.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

params [["_value",[]]];

[QGVAR(clothes), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(clothes), str _value, 1, "mission"] call CBA_settings_fnc_set;
2 changes: 1 addition & 1 deletion addons/loadout/functions/fnc_setFaces.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

params [["_value",[]]];

[QGVAR(faces), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(faces), str _value, 1, "mission"] call CBA_settings_fnc_set;
2 changes: 1 addition & 1 deletion addons/loadout/functions/fnc_setGoggles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

params [["_value",[]]];

[QGVAR(goggles), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(goggles), str _value, 1, "mission"] call CBA_settings_fnc_set;
2 changes: 1 addition & 1 deletion addons/loadout/functions/fnc_setHeadgear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

params [["_value",[]]];

[QGVAR(headgear), _value, 0, "mission"] call CBA_settings_fnc_set;
[QGVAR(headgear), str _value, 1, "mission"] call CBA_settings_fnc_set;

0 comments on commit 9674f73

Please sign in to comment.