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

Radio - Replace inventory PFH with CBA loadout handler #1015

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/sys_core/fnc_arsenalClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ private _weapons = [acre_player] call EFUNC(sys_core,getGear);
ACRE_ARSENAL_RADIOS = [];
GVAR(arsenalRadios) = [];
GVAR(arsenalOpen) = false;

[] call EFUNC(sys_radio,monitorRadiosHandler);
Freddo3000 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion addons/sys_radio/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PREP(monitorRadios);
PREP(monitorRadiosPFH);
PREP(monitorRadiosHandler);
PREP(setActiveRadio);

PREP(openRadio);
Expand Down
2 changes: 2 additions & 0 deletions addons/sys_radio/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

#include "initSettings.sqf"

Freddo3000 marked this conversation as resolved.
Show resolved Hide resolved
// Define caches to save repetitive config lookups.
GVAR(radioUniqueCache) = HASH_CREATE;
GVAR(radioBaseClassCache) = HASH_CREATE;
Expand Down
8 changes: 6 additions & 2 deletions addons/sys_radio/fnc_monitorRadios.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: ACRE2Team
* Sets up the per frame event handler for monitoring the local player inventory for changes.
* Sets up the CBA loadout event handler for monitoring the local player inventory for changes.
*
* Arguments:
* None
Expand All @@ -22,5 +22,9 @@ GVAR(requestingNewId) = false;
LOG("Monitor Inventory Starting");

[{ACRE_DATA_SYNCED && {(!isNil "ACRE_SERVER_INIT")} && {time >= 1}},{
[DFUNC(monitorRadiosPFH), 0.25, []] call CBA_fnc_addPerFrameHandler;
[
"loadout",
DFUNC(monitorRadiosHandler),
true
] call CBA_fnc_addPlayerEventHandler;
},[]] call CBA_fnc_waitUntilAndExecute;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* None
*
* Example:
* [] call acre_sys_radio_fnc_monitorRadiosPFH
* [] call acre_sys_radio_fnc_monitorRadiosHandler
*
* Public: No
*/
Expand Down Expand Up @@ -46,19 +46,28 @@ private _currentUniqueItems = [];
if (GVAR(requestingNewId)) exitWith { };
private _radio = _x;
private _hasUnique = _radio call EFUNC(sys_radio,isBaseClassRadio);
if (_hasUnique || {_radio == "ItemRadio"}) then {

GVAR(requestingNewId) = true;
if (_radio == "ItemRadio") then {
if (_radio == "ItemRadio") then {
if (GVAR(defaultItemRadioType) != "") then {
// Replace vanilla radio item
_radio = GVAR(defaultItemRadioType);
GVAR(requestingNewId) = true;
[acre_player, "ItemRadio", _radio] call EFUNC(sys_core,replaceGear);
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for", _radio);
} else {
// Vanilla radio item replacement disabled, simply remove it.
[acre_player, "ItemRadio"] call EFUNC(sys_core,removeGear);
};
} else {
if (_hasUnique) then {
GVAR(requestingNewId) = true;
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for", _radio);
};
TRACE_1("Getting ID for", _radio);

["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
};
private _isUnique = _radio call EFUNC(sys_radio,isUniqueRadio);
if (_isUnique) then {

if (_radio call EFUNC(sys_radio,isUniqueRadio)) then {
if !([_radio] call EFUNC(sys_data,isRadioInitialized)) then {
WARNING_1("%1 was found in personal inventory but is uninitialized! Trying to collect new ID.",_radio);
private _baseRadio = BASECLASS(_radio);
Expand Down
19 changes: 19 additions & 0 deletions addons/sys_radio/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private _allRadios = [] call EFUNC(api,getAllRadios);
Freddo3000 marked this conversation as resolved.
Show resolved Hide resolved
private _radioClasses = [""] + _allRadios # 0;
private _radioNames = ["None"] + _allRadios # 1;
Freddo3000 marked this conversation as resolved.
Show resolved Hide resolved

[
QGVAR(defaultItemRadioType),
"LIST",
[
LLSTRING(DefaultItemRadioType_DisplayName),
LLSTRING(DefaultItemRadioType_Description)
],
"ACRE2",
[
_radioClasses,
_radioNames,
(_radioClasses find "ACRE_PRC343") max 0
],
true
] call CBA_fnc_addSetting;
6 changes: 6 additions & 0 deletions addons/sys_radio/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,11 @@
<Chinesesimp>设定无线电为1%</Chinesesimp>
<Portuguese>Rádio configurado a %1</Portuguese>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultItemRadioType_DisplayName">
<English>Vanilla radio item replacement</English>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultItemRadioType_Description">
<English>ItemRadio inventory items will be replaced with this type of radio.</English>
</Key>
</Package>
</Project>