Skip to content

Instantly share code, notes, and snippets.

@senevoldsen
Last active December 11, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senevoldsen/3dd0f7171fc1080cf674a29569d1c5ee to your computer and use it in GitHub Desktop.
Save senevoldsen/3dd0f7171fc1080cf674a29569d1c5ee to your computer and use it in GitHub Desktop.
Mission compatible insignias
class CfgUnitInsignia
{
#include "Insignia\New_Khazikstan.hpp"
};
class CfgFunctions
{
#include "MF_Insignia\CfgFunctions.hpp"
};
/*** You can use CBA for instance to mass initialize on AI units using the local command (to avoid network traffic).
class Extended_Init_EventHandlers
{
class CAManBase
{
class Enemy_Insignia_Init {
init = "params ['_unit']; if (side group _unit == east) then {[_unit, 'New_Khazikstan'] call MF_fnc_setUnitInsignia;};";
};
};
};
***/
class New_Khazikstan {
displayName = "New Khazikstan";
author = "Rather not say";
texture = "Insignia\New_Khazikstan.paa"; // File not included in gist
textureVehicle = "Insignia\New_Khazikstan.paa"; // File not included in gist.
};
class MF_Insignia
{
tag = "MF";
class Insignia
{
file = "MF_Insignia";
class setUnitInsignia {};
class UnitInsignia_PostInit {
postInit = 1;
};
class setUnitInsigniaGlobal {};
};
};
/*
Argument: Global
Effect: Local
Description:
Sets unit insignia (e.g., shoulder insignia on soldiers)
Parameter(s):
0: OBJECT - unit
1: STRING - CfgUnitInsignia class. Use an empty string to remove current insignia.
Returns:
BOOL - true if insignia was set
*/
#define DEFAULT_MATERIAL "\a3\data_f\default.rvmat"
#define DEFAULT_TEXTURE "#(rgb,8,8,3)color(0,0,0,0)"
params ["_unit", "_class", ["_forceLoad", false]];
private _isRefresh = _class isEqualTo "REFRESH";
if (_isRefresh) then {
_class = _unit getVariable ["MF_fnc_setUnitInsignia_class", ""];
};
// --- load texture from config.cpp or description.ext
private _cfgInsignia = [["CfgUnitInsignia", _class], configNull] call BIS_fnc_loadClass;
// --- check if insignia exists
if (configName _cfgInsignia != _class) exitWith {
[
"'%1' is not found in CfgUnitInsignia. Available classes: %2",
_class,
("true" configClasses (configFile >> "CfgUnitInsignia") apply {configName _x})
+
("true" configClasses (missionConfigFile >> "CfgUnitInsignia") apply {configName _x})
+
("true" configClasses (campaignConfigFile >> "CfgUnitInsignia") apply {configName _x})
]
call BIS_fnc_error;
false
};
private _set = false;
// --- find insignia index in hidden textures
{
if (_x == "insignia") exitWith {
// --- make it safe in scheduled
isNil {
// --- set insignia if not set
if (_isRefresh or {_forceLoad} or {(_unit getVariable ["MF_fnc_setUnitInsignia_class", ""]) != _class}) then {
_unit setVariable ["MF_fnc_setUnitInsignia_class", [_class, nil] select (_class isEqualTo ""), false];
_unit setObjectMaterial [_forEachIndex, getText (_cfgInsignia >> "material") call {[_this, DEFAULT_MATERIAL] select (_this isEqualTo "")}];
_unit setObjectTexture [_forEachIndex, getText (_cfgInsignia >> "texture") call {[_this, DEFAULT_TEXTURE] select (_this isEqualTo "")}];
_set = true;
};
};
};
} forEach getArray (configFile >> "CfgVehicles" >> getText (configFile >> "CfgWeapons" >> uniform _unit >> "ItemInfo" >> "uniformClass") >> "hiddenSelections");
_set
/*
Argument: Global
Effect: Global
Description:
Sets unit insignia (e.g., shoulder insignia on soldiers)
Parameter(s):
0: OBJECT - unit
1: STRING - CfgUnitInsignia class. Use an empty string to remove current insignia.
Returns:
BOOL - true if insignia was set
*/
params ["_unit", "_class", ["_force", true]];
if (_class isEqualTo "REFRESH") then {
_class = _unit getVariable ["MF_fnc_setUnitInsignia_class", ""];
};
// For remotes
[_unit, _class, _force] remoteExecCall ["MF_fnc_SetUnitInsignia", -clientOwner];
// For JIPs
_unit setVariable ["MF_fnc_setUnitInsignia_class", _class, true];
// We run it locally manually to get return value.
// using REFRESH here after setVariable to ensure _force is respected.
[_unit, "REFRESH", _force] call MF_fnc_SetUnitInsignia;
// Updates client insignias from publicVariable data
{
private _insignia = _x getVariable ["MF_fnc_setUnitInsignia_class", ""];
if (not (_insignia isEqualTo "")) then {
[_x, _insignia, true] call MF_fnc_setUnitInsignia;
};
} forEach allUnits;
// For simplicity only handle local player changing loadouts. E.g. not AI's that has later been changed by scripting.
if (hasInterface) then {
[] spawn {
waitUntil {sleep 0.1; local player};
MF_fnc_setUnitInsignia_lastUniform = uniformContainer player;
player addEventHandler ["InventoryClosed", {
params ["_unit", "_targetContainer"];
private _curUniform = uniformContainer _unit;
if (_curUniform != MF_fnc_setUnitInsignia_lastUniform) then {
MF_fnc_setUnitInsignia_lastUniform = _curUniform;
if (not (isNull _curUniform)) then {
[_unit, "REFRESH", true] call MF_fnc_setUnitInsigniaGlobal;
};
};
}];
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment