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

Extended Loadout Framework #1503

Merged
merged 12 commits into from
May 17, 2022
Merged

Conversation

BrettMayson
Copy link
Contributor

@BrettMayson BrettMayson commented Sep 20, 2021

When merged this pull request will:

  • Enable mods to store extended info about a player's loadout
  • Superceed Filtered Loadouts #1270, this system can also be used to filter the loadouts, to remove radio IDs as an example
ACE Earplugs Example
["CBA_loadoutSet", {
    params ["_unit", "_loadout", "_extradata"];
    private _hasEarplugs = _extradata getOrDefault ["ace_earplugs", false];
    _unit setVariable ["ACE_hasEarPlugsIn", _hasEarplugs, true];
    [[true]] remoteExec ["ace_hearing_fnc_updateVolume", _unit];
}] call CBA_fnc_addEventHandler;

["CBA_loadoutGet", {
    params ["_unit", "_loadout", "_extradata"];
    if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
        _extradata set ["ace_earplugs", true]
    };
}] call CBA_fnc_addEventHandler;
ACRE Flagged Radio example
["CBA_loadoutGet", {
    params ["", "_loadout", ""];
    if ((_loadout select 9) select 2 == "ItemRadioAcreFlagged") then {
        (_loadout select 9) set [2, ""];
    };
    
    // Set ACRE base classes
    private _replaceRadioAcre = {
        params ["_item"];
        // Replace only if string (array can be eg. weapon inside container) and an ACRE radio
        if (!(_item isEqualType []) && {[_item] call acre_api_fnc_isRadio}) then {
            _this set [0, [_item] call acre_api_fnc_getBaseRadio];
        };
    };
    if !((_loadout select 3) isEqualTo []) then {
        {_x call _replaceRadioAcre} forEach ((_loadout select 3) select 1); // Uniform items
    };
    if !((_loadout select 4) isEqualTo []) then {
        {_x call _replaceRadioAcre} forEach ((_loadout select 4) select 1); // Vest items
    };
    if !((_loadout select 5) isEqualTo []) then {
        {_x call _replaceRadioAcre} forEach ((_loadout select 5) select 1); // Backpack items
    };
}] call CBA_fnc_addEventHandler;

Usage is very similar to the vanilla getUnitLoadout when applied to units

private _loadout = [player] call CBA_fnc_getLoadout;
[player, _loadout, true] call CBA_fnc_setLoadout

@BrettMayson BrettMayson changed the title extended loadout Extended Loadout Framework Sep 20, 2021
@commy2
Copy link
Contributor

commy2 commented Sep 22, 2021

Very clean code.

Why do we need the whole LoadoutSet framework though? Couldn't we just raise and listen to "vanilla" CBA events?

@BrettMayson
Copy link
Contributor Author

BrettMayson commented Sep 23, 2021

We'd still need to store the defaults for those somewhere, and I don't see any advantage of events over a dedicated function

@commy2
Copy link
Contributor

commy2 commented Sep 24, 2021

We'd still need to store the defaults for those somewhere, and I don't see any advantage of events over a dedicated function

Maybe make it a wrapper that uses CBA events?

I would really like to avoid duplicating the events logic yet again.

addons/loadout/fnc_setLoadout.sqf Outdated Show resolved Hide resolved
addons/loadout/fnc_setLoadout.sqf Outdated Show resolved Hide resolved
addons/loadout/fnc_setLoadout.sqf Outdated Show resolved Hide resolved
@BrettMayson BrettMayson requested a review from commy2 October 4, 2021 00:26
@commy2 commy2 self-assigned this Nov 8, 2021
@BrettMayson BrettMayson mentioned this pull request Nov 9, 2021
@BrettMayson
Copy link
Contributor Author

Any updates on this?

@BrettMayson
Copy link
Contributor Author

Anyone want to take on modifying this to commy's requirements? I do not have the time.

@BrettMayson
Copy link
Contributor Author

@commy2 Updated as discussed on Slack

@PabstMirror PabstMirror added this to the 3.15.7 milestone May 13, 2022
BrettMayson and others added 2 commits May 13, 2022 17:57
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
@BrettMayson BrettMayson requested a review from PabstMirror May 13, 2022 23:58
@PabstMirror PabstMirror merged commit 33eef5c into CBATeam:master May 17, 2022
@BrettMayson BrettMayson deleted the extended_loadout branch May 18, 2022 16:07
@jonpas jonpas mentioned this pull request Sep 7, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants