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 6 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;
50 changes: 50 additions & 0 deletions addons/common/fnc_randomizeFacewear.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_randomizeFacewear

Description:
Add config defined weighted random facewear to unit.

CBA_facewearList[] = {}; // default: ignore and use facewear from BIS_fnc_unitHeadgear instead
CBA_facewearList[] = {"", 1}; // no facewear, delete and overwrite facewear from BIS_fnc_unitHeadgear

// 40% no facewear, 30% balaclava, 30% bandana. Weighted randomization: Sum of propabilites must not necessarily equal 1.
CBA_facewearList[] = {"", 0.4, "G_Balaclava_blk", 0.3, "G_Bandanna_blk", 0.3};

Parameters:
_unit - unit <OBJECT>

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

Examples:
(begin example)
[unit] call CBA_fnc_randomizeFacewear;
(end)

Author:
commy2
---------------------------------------------------------------------------- */

params [["_unit", objNull, [objNull]]];

if (isNull _unit) exitWith {
WARNING_1("Unit [%1] is null",_unit);
false
};

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

private _facewearList = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_facewearList");

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

private _facewear = selectRandomWeighted _facewearList;

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

true