Skip to content

Instantly share code, notes, and snippets.

@Seb105
Last active October 29, 2021 10:45
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 Seb105/4e3b653b83a2f723884e73b92310bf2e to your computer and use it in GitHub Desktop.
Save Seb105/4e3b653b83a2f723884e73b92310bf2e to your computer and use it in GitHub Desktop.
Fix, add loading screen
EZFaction_fnc_buildPrettyName = {
params [
"_thing",
["_config", "CfgWeapons"]
];
[
getText (configFile >> _config >> _thing >> "displayName"),
_thing,
getText (configFile >> _config >> _thing >> "picture")
]
};
EZFACTION_BOXHEIGHT = 16;
private _fnc_introBox = {
[
"EZ Faction Intro",
[
[
"EDIT:MULTI",
"The EZ Faction allows swapping of gear guaranteeing no item or attribute loss.",
[" ", {}, 0],
true
],
[
"EDIT:MULTI",
"Hit backspace to hide the Eden UI and view the full EZ faction UI.",
[" ", {}, 0],
true
],
[
"CHECKBOX",
["Preserve weapon attachments", "You may get more weapon variety by not preserving attachments, however you may lose scopes, grips, and flashlights or lasers"],
true,
false
]
],
{
params ["_dialog_data","_args"];
_dialog_data params ["_useless", "_useless2", "_preserveAttachments"];
EZFaction_preserveAttachments = _preserveAttachments;
[] spawn EZFaction_main;
},
{
EZFaction_preserveAttachments = true;
},
[]
] call zen_dialog_fnc_create;
};
EZFaction_main = {
private _fnc_swapWeapons = {
private _allWeapons = _this;
// Build list of all unique guns, and all used accessories for each gun.
private _uniquePrimaryWeapons = createHashMap;
{
private _unit = _x;
private _unitPrimary = primaryWeapon _unit;
private _unitPrimaryMags = primaryWeaponMagazine _unit;
private _unitPrimaryAccessories = (primaryWeaponItems _unit) select {_x != ""};
if (_unitPrimary == "") then {continue};
if (_unitPrimary in _uniquePrimaryWeapons) then {
private _array = _uniquePrimaryWeapons get _unitPrimary;
{
_array#0 pushBackUnique _x;
} forEach _unitPrimaryMags;
{
_array#1 pushBackUnique _x;
} forEach _unitPrimaryAccessories;
} else {
_uniquePrimaryWeapons set [
_unitPrimary,
[
_unitPrimaryMags,
_unitPrimaryAccessories
]
]
}
} forEach playableUnits;
// Build zen_dialog "COMBO" for each unique weapon.
private _uiArray = [];
{
private _baseWeapon = _x;
_y params ["_baseMags", "_baseAccessories"];
private _compatibleWeapons = [];
{
_x params ["_weapon", "_compatibleMagazines", "_compatibleAccessories"];
// If this weapon can fit all magazines and accessories for the original gun then it is suitable.
_attachmentsCompatible = if (EZFaction_preserveAttachments) then {
{_compatibleAccessories find _x != -1} count _baseAccessories == count _baseAccessories
} else {
true
};
if (
{_compatibleMagazines find _x != -1} count _baseMags == count _baseMags
&& _attachmentsCompatible
) then {
_compatibleWeapons pushBackUnique _weapon;
}
} forEach _allWeapons;
private _toolTip = format [
"Weapon %1 will become",
getText (configFile >> "CfgWeapons" >> _baseWeapon >> "displayName")
];
private _index = _compatibleWeapons find _baseWeapon;
private _prettyNames = _compatibleWeapons apply {
_x call EZFaction_fnc_buildPrettyName
};
// Used to build zen dialog
_uiArray pushBack [
"LIST",
_toolTip,
[_compatibleWeapons, _prettyNames, _index, EZFACTION_BOXHEIGHT min (count _compatibleWeapons)],
true
];
} forEach _uniquePrimaryWeapons;
// Create zen dialog
[
"Weapon Swapper",
_uiArray,
{
params ["_dialog_data","_uniquePrimaryWeapons"];
private _replacements = [];
{
private _oldWeapon = _x;
private _newWeapon = (_dialog_data#_forEachIndex);
_replacements pushBack _newWeapon;
} forEach _uniquePrimaryWeapons;
{
private _unit = _x;
private _loadout = getUnitLoadout _unit;
private _currentWeapon = primaryWeapon _unit;
if (_currentWeapon == "") then {continue};
private _newWeapon = _replacements#((keys _uniquePrimaryWeapons) find _currentWeapon);
_loadout#0 set [0, _newWeapon];
_unit setUnitLoadout _loadout;
} forEach playableUnits;
save3DENInventory playableUnits;
EZ_FACTION_DIALOG = true;
},
{},
_uniquePrimaryWeapons
] call zen_dialog_fnc_create;
};
private _fnc_swapHeadgear = {
private _allHelmets = _this;
private _uniqueHelmets = [];
{
private _helmet = headgear _x;
if (_helmet == "") then {continue};
_uniqueHelmets pushBackUnique _helmet;
} forEach playableUnits;
private _uiArray = [];
private _prettyNames = _allHelmets apply {_x call EZFaction_fnc_buildPrettyName};
{
private _helmet = _x;
private _index = _allHelmets find _helmet;
private _toolTip = format [
"%1 will become",
getText (configFile >> "CfgWeapons" >> _helmet >> "displayName")
];
_uiArray pushBack [
"LIST",
_toolTip,
[_allHelmets, _prettyNames, _index, EZFACTION_BOXHEIGHT min (count _allHelmets)],
true
];
} forEach _uniqueHelmets;
[
"Helmet Swapper",
_uiArray,
{
params ["_dialog_data","_uniqueHelmets"];
private _replacements = [];
{
private _old = _x;
private _new = (_dialog_data#_forEachIndex);
_replacements pushback _new;
} forEach _uniqueHelmets;
{
private _unit = _x;
private _loadout = getUnitLoadout _unit;
private _current = headgear _unit;
if (_current == "") then {continue};
private _new = _replacements#(_uniqueHelmets find _current);
_loadout set [6,_new];
_unit setUnitLoadout _loadout;
} forEach playableUnits;
save3DENInventory playableUnits;
EZ_FACTION_DIALOG = true;
},
{},
_uniqueHelmets
] call zen_dialog_fnc_create;
};
private _fnc_swapVestUniformBackpack = {
params ["_allItems", "_where"];
private _inventoryIndex = switch _where do {
case "Uniform": {
3
};
case "Vest": {
4
};
case "Backpack": {
5
};
};
private _config = if (_where == "Backpack") then {"CfgVehicles"} else {"CfgWeapons"};
private _uniqueItems = [];
{
private _unit = _x;
private _loadout = getUnitLoadout _unit;
private _item = _loadout#_inventoryIndex#0;
if (isNil "_item") then {continue};
if (_item == "") then {continue};
_uniqueitems pushBackUnique _item;
} forEach playableUnits;
private _uiArray = [];
{
private _item = _x;
private _minLoad = getContainerMaxLoad _item;
private _compatibleItems = _allItems select {
getContainerMaxLoad _x >= _minLoad
};
private _prettyNames = _compatibleItems apply {[_x, _config] call EZFaction_fnc_buildPrettyName};
private _index = _compatibleItems find _item;
private _toolTip = format [
"%1 will become",
getText (configFile >> _config >> _item >> "displayName")
];
_uiArray pushBack [
"LIST",
_toolTip,
[_compatibleItems, _prettyNames, _index, EZFACTION_BOXHEIGHT min (count _compatibleItems)],
true
];
} forEach _uniqueItems;
[
_where + " Swapper",
_uiArray,
{
params ["_dialog_data","_dialogParams"];
_dialogParams params ["_uniqueItems", "_inventoryIndex"];
private _replacements = [];
{
private _old = _x;
private _new = (_dialog_data#_forEachIndex);
_replacements pushBack _new;
} forEach _uniqueItems;
{
private _unit = _x;
private _loadout = getUnitLoadout _unit;
private _current = _loadout#_inventoryIndex#0;
if (_current == "") then {continue};
private _new = _replacements#(_uniqueItems find _current);
_loadout#_inventoryIndex set [0,_new];
_unit setUnitLoadout _loadout;
} forEach playableUnits;
save3DENInventory playableUnits;
EZ_FACTION_DIALOG = true;
},
{},
[_uniqueItems, _inventoryIndex]
] call zen_dialog_fnc_create;
};
startLoadingScreen ["Loading EZ Faction"];
private _cfgWeapons = ([configFile >> "CfgWeapons", 0] call BIS_fnc_returnChildren) select {
getNumber (_x >> "scope") == 2
&& ([_x, "scopeArsenal", 2] call BIS_fnc_returnConfigEntry) == 2
};
progressLoadingScreen 0.25;
private _allWeapons = [];
private _allHelmets = [];
private _allUniforms = [];
private _allVests = [];
private _allBackpacks = (([configFile >> "CfgVehicles", 0] call BIS_fnc_returnChildren) select {
getNumber (_x >> "scope") == 2
&& ([_x, "scopeArsenal", 2] call BIS_fnc_returnConfigEntry) == 2
&& (configName _x) isKindOf "Bag_Base"
}) apply {
configName _x
};
progressLoadingScreen 0.5;
{
private _cfgEntry = _x;
private _configName = configName _cfgEntry;
private _parents = [_cfgEntry >> "ItemInfo", true] call BIS_fnc_returnParents;
if (_configName isKindOf ["RifleCore", configFile >> "CfgWeapons"]
&& ([_cfgEntry, "baseWeapon", _configName] call BIS_fnc_returnConfigEntry) isEqualTo _configName) then {
_allWeapons pushBack [
_configName,
[_configName, true] call CBA_fnc_compatibleMagazines,
_configName call CBA_fnc_compatibleItems
];
continue
};
if ("HeadgearItem" in _parents) then {
_allHelmets pushBack _configName;
continue
};
if ("UniformItem" in _parents) then {
_allUniforms pushBack _configName;
continue
};
if ("VestItem" in _parents) then {
_allVests pushBack _configName;
continue
};
} forEach _cfgWeapons;
progressLoadingScreen 0.75;
_allWeapons = [_allWeapons, [], {getText (configFile >> "CfgWeapons" >> _x#0 >> "displayName")}, "ASCEND"] call BIS_fnc_sortBy;
_allHelmets = [_allHelmets, [], {getText (configFile >> "CfgWeapons" >> _x >> "displayName")}, "ASCEND"] call BIS_fnc_sortBy;
_allUniforms = [_allUniforms, [], {getText (configFile >> "CfgWeapons" >> _x >> "displayName")}, "ASCEND"] call BIS_fnc_sortBy;
_allVests = [_allVests, [], {getText (configFile >> "CfgWeapons" >> _x >> "displayName")}, "ASCEND"] call BIS_fnc_sortBy;
_allBackpacks = [_allBackpacks, [], {getText (configFile >> "CfgVehicles" >> _x >> "displayName")}, "ASCEND"] call BIS_fnc_sortBy;
endLoadingScreen;
EZ_FACTION_DIALOG = false;
{
_x params ["_functionArgs", "_function"];
startLoadingScreen ["Loading EZ Faction"];
_functionArgs call _function;
endLoadingScreen;
waitUntil {EZ_FACTION_DIALOG};
EZ_FACTION_DIALOG = false;
} forEach [
[_allWeapons, _fnc_swapWeapons],
[_allHelmets, _fnc_swapHeadgear],
[[_allUniforms, "Uniform"], _fnc_swapVestUniformBackpack],
[[_allVests, "Vest"], _fnc_swapVestUniformBackpack],
[[_allBackpacks, "Backpack"], _fnc_swapVestUniformBackpack]
];
};
call _fnc_introBox;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment