Skip to content

Commit

Permalink
Adds a parameter changedelay to change in-game wait time #20
Browse files Browse the repository at this point in the history
  • Loading branch information
jetelain committed May 20, 2022
1 parent 8363350 commit 8391a92
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 83 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class XtdGearModels
label = "Option A label";
values[] = {"value1", "value2"};
changeingame = 0; // 1 if value can be changed in game via ACE menu
// changedelay = 2; If can changeingame, wait delay before change is effective (can be 0, 0.1, or more)
// icon = "xxx"; If can changeingame, action group icon in ACE menu
class value1
{
Expand All @@ -73,6 +74,7 @@ class XtdGearModels
// icon = "xxx"; If can changeingame, action icon in ACE menu
// actionlabel = "xxx"; If can changeingame, action label in ACE menu
// itemingame = "xxx"; If can changeingame, requires this item to be present in inventory. Item will be removed from inventory (added back if an other value is choosen)
// changedelay = (inherited by default); If can changeingame, wait delay before change is effective
};
class value2
{
Expand Down
6 changes: 4 additions & 2 deletions addons/gearinfo/functions/fnc_getModelOptions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ READ(Number)
private _optionLabel = [_optionDef1, _optionDef2, "label", _optionName] call _readText;
private _optionIcon = [_optionDef1, _optionDef2, "icon", ""] call _readText;
private _optionInGame = [_optionDef1, _optionDef2, "changeingame", 0] call _readNumber;
private _optionDelay = [_optionDef1, _optionDef2, "changedelay", 2] call _readNumber;
private _values = [];
private _optionCenterImage = getNumber (_optionDef1 >> "centerImage");
private _optionValues = getArray (_optionDef1 >> "values");
Expand All @@ -57,9 +58,10 @@ READ(Number)
private _valueDesc = [_valueDef1, _valueDef2, "description", ""] call _readText;
private _valueAction = [_valueDef1, _valueDef2, "actionLabel", format ["%1 %2", _optionLabel, _valueLabel]] call _readText;
private _valueInGame = [_valueDef1, _valueDef2, "changeingame", _optionInGame] call _readNumber;
private _itemInGame = [_valueDef1, _valueDef2, "itemingame", ""] call _readText;
private _valueDelay = [_valueDef1, _valueDef2, "changedelay", _optionDelay] call _readNumber;
private _itemInGame = [_valueDef1, _valueDef2, "itemingame", ""] call _readText;

_values pushBack [_valueName, _valueLabel, _valueImage, _valueIcon, _valueDesc, _valueAction, _valueInGame, _itemInGame];
_values pushBack [_valueName, _valueLabel, _valueImage, _valueIcon, _valueDesc, _valueAction, _valueInGame, _itemInGame, _valueDelay];

} forEach _optionValues;

Expand Down
4 changes: 2 additions & 2 deletions addons/ingame/functions/fnc_aceSelfActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private _loadout = getUnitLoadout _player;
private _itemBack = "";
{
private _valueIndex = _foreachIndex;
_x params ["_valueName", "", "", "_valueIcon", "", "_valueAction", "_valueInGame", "_itemInGame"];
_x params ["_valueName", "", "", "_valueIcon", "", "_valueAction", "_valueInGame", "_itemInGame", "_valueDelay"];

if ( _valueInGame > 0 ) then {

Expand All @@ -47,7 +47,7 @@ private _loadout = getUnitLoadout _player;
_previewOptions set [_optionIndex, _valueName];
private _previewConfig = [_classRoot, _model, _previewOptions] call EFUNC(gearinfo,findConfigName);
if ( _previewConfig != "") then {
_optionActions pushBack [_valueAction, _valueIcon, _previewConfig, _itemInGame];
_optionActions pushBack [_valueAction, _valueIcon, _previewConfig, _itemInGame, _valueDelay];
};
} else {
_itemBack = _itemInGame;
Expand Down
160 changes: 83 additions & 77 deletions addons/ingame/functions/fnc_changeGear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,118 @@
#include "script_component.hpp"

params ["", "", "_params"];
_params params ["_player", "_layout", "_actionLabel", "_config"];
_params params ["_player", "_layout", "_actionLabel", "_config", "", "", ["_delay", 2]];

private _callback = {
params ["_args"];
_args params ["_player", "_layout", "", "_config", "_giveBack", "_consume"];
params ["_args"];
_args params ["_player", "_layout", "", "_config", "_giveBack", "_consume"];

private _insignia = [_player] call BIS_fnc_getUnitInsignia;
// setUnitLoadout will clear insignia, but BIS_fnc_setUnitInsignia does
// not known about this and would ignore the next call
[_player, ""] call BIS_fnc_setUnitInsignia;
private _insignia = [_player] call BIS_fnc_getUnitInsignia;
// setUnitLoadout will clear insignia, but BIS_fnc_setUnitInsignia does
// not known about this and would ignore the next call
[_player, ""] call BIS_fnc_setUnitInsignia;

private _loadout = getUnitLoadout _player;
private _loadout = getUnitLoadout _player;

_layout params ["", "_loadoutIndex", "_loadoutSecondary"];
_layout params ["", "_loadoutIndex", "_loadoutSecondary"];

if ( _loadoutSecondary == -1 ) then {
_loadout set [_loadoutIndex, _config];
} else {
(_loadout select _loadoutIndex) set [_loadoutSecondary, _config];
};
if ( _loadoutSecondary == -1 ) then {
_loadout set [_loadoutIndex, _config];
} else {
(_loadout select _loadoutIndex) set [_loadoutSecondary, _config];
};

// setUnitLoadout causes NVGs to turn off.
// Let's figure out if the player was using NVGs and set the
// state again after setting the loadout.
private _nvgState = currentVisionMode _player;

// setUnitLoadout causes TFAR backpacks to lose settings.
// Before setting the player's loadout, let's grab their TFAR radio
// settings so we can copy the settings to the "new" radio bag.
// TFAR code snippets were adapted from TFAR_fnc_CopySettings.
private _playerBag = (_loadout select 5) select 0;
private _tfarSource = [];
private _lrSettingsSource = [];

// Check if TFAR is active
private _tfarIsActive = isClass (configFile >> "CfgPatches" >> "tfar_core");
if (_tfarIsActive) then
// setUnitLoadout causes NVGs to turn off.
// Let's figure out if the player was using NVGs and set the
// state again after setting the loadout.
private _nvgState = currentVisionMode _player;

// setUnitLoadout causes TFAR backpacks to lose settings.
// Before setting the player's loadout, let's grab their TFAR radio
// settings so we can copy the settings to the "new" radio bag.
// TFAR code snippets were adapted from TFAR_fnc_CopySettings.
private _playerBag = (_loadout select 5) select 0;
private _tfarSource = [];
private _lrSettingsSource = [];

// Check if TFAR is active
private _tfarIsActive = isClass (configFile >> "CfgPatches" >> "tfar_core");
if (_tfarIsActive) then
{
// Check if player has backpack and backpack is TFAR radio
if ([_playerBag] call TFAR_fnc_isLRRadio) then
{
// Check if player has backpack and backpack is TFAR radio
if ([_playerBag] call TFAR_fnc_isLRRadio) then
{
// Get player backpack radio and settigns
_tfarSource = _player call TFAR_fnc_backpackLr;
_lrSettingsSource = _tfarSource call TFAR_fnc_getLrSettings;
};
// Get player backpack radio and settigns
_tfarSource = _player call TFAR_fnc_backpackLr;
_lrSettingsSource = _tfarSource call TFAR_fnc_getLrSettings;
};
};

_player setUnitLoadout _loadout;
_player setUnitLoadout _loadout;

[_player] call EFUNC(gearinfo,applyTextureOptions);
[_player] call EFUNC(gearinfo,applyTextureOptions);

[_player, _insignia] call BIS_fnc_setUnitInsignia;
[_player, _insignia] call BIS_fnc_setUnitInsignia;

// Why would we make someone stand up?
// What if they are laying down to avoid fire?
/*
if ( currentWeapon _player != "" ) then {
_player playMoveNow "amovpercmstpslowwrfldnon";
};
*/
// Why would we make someone stand up?
// What if they are laying down to avoid fire?
/*
if ( currentWeapon _player != "" ) then {
_player playMoveNow "amovpercmstpslowwrfldnon";
};
*/

if ( _consume != "" ) then {
_player removeItem _consume;
};
if ( _giveBack != "" ) then {
_player addItem _giveBack;
};
if ( _consume != "" ) then {
_player removeItem _consume;
};
if ( _giveBack != "" ) then {
_player addItem _giveBack;
};

// Check if TFAR is active
if (_tfarIsActive) then
{
// Check if player has backpack and backpack is TFAR radio
private _newLoadout = getUnitLoadout _player;
_playerBag = (_newLoadout select 5) select 0;

if ([_playerBag] call TFAR_fnc_isLRRadio) then
{
// Get player backpack radio and set settings
private _tfarDestination = _player call TFAR_fnc_backpackLr;
[_tfarDestination,[]+_lrSettingsSource] call TFAR_fnc_setLRSettings;
};
};
// Check if TFAR is active
if (_tfarIsActive) then
{
// Check if player has backpack and backpack is TFAR radio
private _newLoadout = getUnitLoadout _player;
_playerBag = (_newLoadout select 5) select 0;

// Check if player has NVGs. If they do and they were using them, turn back on.
// We also need to make sure that whatever is in the NVG slot has NVG capabilities.
private _nvgItem = hmd _player;
private _hasNVGs = (_nvgItem != "");
private _canNVG = "NVG" in (getArray (configFile >> "CfgWeapons" >> _nvgItem >> "visionMode"));
if (_hasNVGs && {_canNVG && {_nvgState > 0}}) then
if ([_playerBag] call TFAR_fnc_isLRRadio) then
{
_player action ["nvGoggles", _player];
// Get player backpack radio and set settings
private _tfarDestination = _player call TFAR_fnc_backpackLr;
[_tfarDestination,[]+_lrSettingsSource] call TFAR_fnc_setLRSettings;
};
};

// Check if player has NVGs. If they do and they were using them, turn back on.
// We also need to make sure that whatever is in the NVG slot has NVG capabilities.
private _nvgItem = hmd _player;
private _hasNVGs = (_nvgItem != "");
private _canNVG = "NVG" in (getArray (configFile >> "CfgWeapons" >> _nvgItem >> "visionMode"));
if (_hasNVGs && {_canNVG && {_nvgState > 0}}) then
{
_player action ["nvGoggles", _player];
};

};

if ( _delay == 0 ) then {
// Instant
[_params] call _callback;
}
else {
// ace_common_fnc_progressBar does not function while a player is in a vehicle.
// To get around this, we will execute the progress bar only while on foot.
// While in a vehicle, we will simply wait 2 seconds before swapping player items.
private _isOnFoot = isNull objectParent _player;
if (_isOnFoot) then
{
[2, _params, _callback, {}, _actionLabel + "..."] call ace_common_fnc_progressBar;
[_delay, _params, _callback, {}, _actionLabel + "..."] call ace_common_fnc_progressBar;
} else {
[_params,_callback] spawn {
params ["_params","_callback"];
sleep 2;
sleep _delay;
[_params] call _callback;
};
};
};
};
2 changes: 1 addition & 1 deletion addons/ingame/functions/fnc_generateActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private _actions = [];
FUNC(changeGear),
{true},
{},
[_player, _layout, _x select 0, _x select 2, _giveBack, _consume]
[_player, _layout, _x select 0, _x select 2, _giveBack, _consume, _x select 4]
] call ace_interact_menu_fnc_createAction, [], _target];
};
} forEach _optionActions;
Expand Down
2 changes: 1 addition & 1 deletion addons/main/script_version.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define MAJOR 0
#define MINOR 6
#define MINOR 7
#define PATCH 0
#define BUILD 0

0 comments on commit 8391a92

Please sign in to comment.