Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Facewear Randomization #1201

Merged
merged 9 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CfgFunctions {
PATHTO_FNC(binocularMagazine);
PATHTO_FNC(addBinocularMagazine);
PATHTO_FNC(removeBinocularMagazine);
PATHTO_FNC(randomizeFacewear);
};

class Cargo {
Expand Down
3 changes: 3 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ activateAddons GVAR(addons);
}];
}] call CBA_fnc_addClassEventHandler;

// Facewear randomization
["CAManBase", "InitPost", CBA_fnc_randomizeFacewear] call CBA_fnc_addClassEventHandler;

ADDON = true;
44 changes: 44 additions & 0 deletions addons/common/fnc_randomizeFacewear.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_randomizeFacewear

Description:
Add config defined weighted random facewear to unit.
Uses same config as headgearList[].
jonpas marked this conversation as resolved.
Show resolved Hide resolved

Parameters:
_unit - unit <OBJECT>

Returns:
true on success, false on error <BOOLEAN>

Examples:
(begin example)
[unit] call CBA_fnc_randomizeFacewear
jonpas marked this conversation as resolved.
Show resolved Hide resolved
(end)

Author:
commy2
---------------------------------------------------------------------------- */
SCRIPT(randomizeFacewear);
jonpas marked this conversation as resolved.
Show resolved Hide resolved

params [["_unit", objNull]];
jonpas marked this conversation as resolved.
Show resolved Hide resolved

if (isNull _unit) exitWith {
TRACE_1("unit is null",_unit);
commy2 marked this conversation as resolved.
Show resolved Hide resolved
false
};

if (!local _unit || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true};
jonpas marked this conversation as resolved.
Show resolved Hide resolved

private _allowedFacewear = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_allowedFacewear");
jonpas marked this conversation as resolved.
Show resolved Hide resolved

if (_allowedFacewear isEqualTo []) exitWith {true};

private _facewear = selectRandomWeighted _allowedFacewear;

if (_facewear == "") then {
jonpas marked this conversation as resolved.
Show resolved Hide resolved
removeGoggles _unit;
} else {
_unit addGoggles _facewear;
};
jonpas marked this conversation as resolved.
Show resolved Hide resolved