-
Notifications
You must be signed in to change notification settings - Fork 158
Common - Add more loadout randomization options #1783
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
Open
DartRuffian
wants to merge
19
commits into
CBATeam:master
Choose a base branch
from
DartRuffian:loadout-randomization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ae3ab2c
Add more loadout randomization
DartRuffian 4592eb6
Remove duplicate checks
DartRuffian af678b7
Fix issues from when moving to CBA
DartRuffian 68555a8
Remove (now) unused defines
DartRuffian 971763c
Fix loadout array
DartRuffian e635116
Change to Init, fix when slot is empty
DartRuffian b80ff6e
Slight rework
DartRuffian d1e2cc5
Add function to set unit's identity in Eden
DartRuffian 00f16cb
Update addons/common/XEH_init3DEN.sqf
DartRuffian a0815aa
Fix function names
DartRuffian ba4abb2
Update addons/common/fnc_setIdentity3DEN.sqf
DartRuffian 51def60
Fix zeus spawned units, remove function only called once
DartRuffian 1b76db6
Formatting
DartRuffian 57326c4
Combine ifs
DartRuffian faac7d9
Fix EH
DartRuffian c817e9b
Fix typo
DartRuffian 6dc1536
Delay eden fixAnimation
DartRuffian ecca769
Remove animation workaround
DartRuffian de22cf7
Deleted too much
DartRuffian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #include "script_component.hpp" | ||
| /* ---------------------------------------------------------------------------- | ||
| Function: CBA_fnc_randomizeLoadout | ||
|
|
||
| Description: | ||
| Add config defined weighted random weapons, uniforms, vests, headgear, facewear, etc. to a unit. | ||
|
|
||
| CBA_headgearList[] = {}; // default: Use `linkedItems` property | ||
| CBA_headgearList[] = {"H_HelmetHBK_headset_F", 1, "H_HelmetHBK_chops_F", 1}; // 50% headset, 50% chops | ||
|
|
||
| CBA_primaryList[] = { | ||
| // 50% chance for AK-12, with 2 30Rnd magazines and 2 75Rnd magazines | ||
| // 50% chance for hunter shotgun with 3 12 gauge magazines | ||
| {"arifle_AK12_F", {{"30Rnd_762x39_AK12_Mag_F", 2}, {"75Rnd_762x39_Mag_F", 2}}}, 1, | ||
| {"sgun_HunterShotgun_01_F", {{"2Rnd_12Gauge_Pellets", 3}}}, 1 | ||
| }; | ||
|
|
||
| Parameters: | ||
| _unit - unit <OBJECT> | ||
|
|
||
| Returns: | ||
| true on success, false on error <BOOLEAN> | ||
|
|
||
| Examples: | ||
| (begin example) | ||
| [unit] call CBA_fnc_randomizeLoadout; | ||
| (end) | ||
|
|
||
| Author: | ||
| DartRuffian | ||
| ---------------------------------------------------------------------------- */ | ||
|
|
||
| #define INDEX_PRIMARY 0 | ||
| #define INDEX_LAUNCHER 1 | ||
| #define INDEX_HANDGUN 2 | ||
| #define INDEX_UNIFORM 3 | ||
| #define INDEX_VEST 4 | ||
| #define INDEX_BACKPACK 5 | ||
| #define INDEX_HELMET 6 | ||
| #define INDEX_FACEWEAR 7 | ||
| #define INDEX_LINKEDITEMS 9 | ||
|
|
||
| // Note that this is specifically for a loadout array | ||
| #define INDEX_NVG 5 | ||
|
|
||
| params [["_unit", objNull, [objNull]]]; | ||
|
|
||
| if (isNull _unit) exitWith { | ||
| WARNING_1("Unit [%1] is null",_unit); | ||
| false | ||
| }; | ||
|
|
||
| // Disabled conditions | ||
| if (!local _unit) exitWith {true}; | ||
|
|
||
| private _randomizationDisabled = getArray (missionConfigFile >> "disableRandomization") findIf { | ||
| _unit isKindOf _x || {(vehicleVarName _unit) isEqualTo _x} | ||
| } != -1; | ||
|
|
||
| if (_randomizationDisabled || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; | ||
|
|
||
| if (isNull _unit || !(_unit getVariable ["BIS_enableRandomization", true])) exitWith {}; | ||
DartRuffian marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private ["_headgearList", "_uniformList", "_vestList", "_backpackList", "_nvgList", "_facewearList", "_primaryList", "_secondaryList", "_launcherList"]; | ||
|
|
||
| private _cache = GVAR(randomLoadoutUnits) getOrDefaultCall [typeOf _unit, { | ||
| private _unitConfig = configOf _unit; | ||
| _headgearList = getArray (_unitConfig >> "CBA_headgearList"); | ||
| _uniformList = getArray (_unitConfig >> "CBA_uniformList"); | ||
| _vestList = getArray (_unitConfig >> "CBA_vestList"); | ||
| _backpackList = getArray (_unitConfig >> "CBA_backpackList"); | ||
| _nvgList = getArray (_unitConfig >> "CBA_nvgList"); | ||
| _facewearList = getArray (_unitConfig >> "CBA_facewearList"); | ||
|
|
||
| _primaryList = getArray (_unitConfig >> "CBA_primaryList"); | ||
| _secondaryList = getArray (_unitConfig >> "CBA_secondaryList"); | ||
| _launcherList = getArray (_unitConfig >> "CBA_launcherList"); | ||
|
|
||
| // If all arrays are empty, just cache `[false]` to not save a bunch of empty arrays | ||
| if (_headgearList isEqualTo [] && | ||
| _uniformList isEqualTo [] && | ||
| _vestList isEqualTo [] && | ||
| _backpackList isEqualTo [] && | ||
| _nvgList isEqualTo [] && | ||
| _facewearList isEqualTo [] && | ||
| _primaryList isEqualTo [] && | ||
| _secondaryList isEqualTo [] && | ||
| _launcherList isEqualTo [] | ||
| ) then { [false] } else { | ||
| [true, _headgearList, _uniformList, _vestList, _backpackList, _nvgList, _facewearList, _primaryList, _secondaryList, _launcherList]; | ||
| }; | ||
| }, true]; | ||
|
|
||
| // Exit if unit has no randomization | ||
| if (!(_cache select 0)) exitWith {}; | ||
|
|
||
| (_unit call CBA_fnc_getLoadout) params ["_loadout", "_extendedInfo"]; | ||
|
|
||
| { | ||
| _x params ["_loadoutIndex", "_items"]; | ||
| if (_items isEqualTo []) then { continue }; | ||
|
|
||
| _loadout set [_loadoutIndex, selectRandomWeighted _items]; | ||
| } forEach [ | ||
| [INDEX_HELMET, _headgearList], | ||
| [INDEX_UNIFORM, _uniformList], | ||
| [INDEX_VEST, _vestList], | ||
| [INDEX_BACKPACK, _backpackList], | ||
| [INDEX_FACEWEAR, _facewearList] | ||
| ]; | ||
|
|
||
| if (_nvgList isNotEqualTo []) then { | ||
| _loadout select INDEX_LINKEDITEMS set [INDEX_NVG, selectRandomWeighted _nvgList]; | ||
| }; | ||
|
|
||
| { | ||
| _x params ["_loadoutIndex", "_items"]; | ||
| if (_items isEqualTo []) then { continue }; | ||
|
|
||
| (selectRandomWeighted _items) params ["_weapon", "_magazineCounts"]; | ||
| _loadout set [_loadoutIndex, _weapon]; | ||
|
|
||
| { | ||
| _x params ["_magazine", "_count"]; | ||
| for "_" from 1 to _count do { | ||
| // Exit if magazine can't be added | ||
| if !([_unit, _magazine] call CBA_fnc_addMagazine) exitWith {}; | ||
| }; | ||
| } forEach _magazineCounts; | ||
| } forEach [ | ||
| [INDEX_PRIMARY, _primaryList], | ||
| [INDEX_HANDGUN, _secondaryList], | ||
| [INDEX_LAUNCHER, _launcherList] | ||
| ]; | ||
|
|
||
| [_unit, [_loadout, _extendedInfo]] call CBA_fnc_setLoadout; | ||
| true; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.