From ff81ef46f6884793ed3236ea29aa4a2d2c89dfa8 Mon Sep 17 00:00:00 2001 From: y0014984 Date: Tue, 22 Aug 2023 10:31:32 +0200 Subject: [PATCH] added executeForPlayersInRange wrapper function --- .../fnc_terminal_setKeyboardLayout.sqf | 7 +--- .../fnc_terminal_setTerminalDesign.sqf | 7 +--- ...minal_uiOnTex_addUpdateAllEventHandler.sqf | 39 +++++++++---------- .../fnc_terminal_updateBatteryStatus.sqf | 4 +- .../functions/fnc_terminal_updateOutput.sqf | 7 +--- addons/main/XEH_PREP.hpp | 1 + .../fnc_executeForPlayersInRange.sqf | 31 +++++++++++++++ 7 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 addons/main/functions/fnc_executeForPlayersInRange.sqf diff --git a/addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf b/addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf index 9da56908..649b7aba 100644 --- a/addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf +++ b/addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf @@ -32,12 +32,7 @@ _computer setVariable ["AE3_terminal", _terminal]; if (AE3_UiOnTexture) then { - private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange; - - if ((count _playersInRange) > 0) then - { - [_computer, _terminalKeyboardLayout] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_setKeyboardLayout", _playersInRange]; - }; + [3, _computer, "AE3_armaos_fnc_terminal_uiOnTex_setKeyboardLayout", [_computer, _terminalKeyboardLayout]] call AE3_main_fnc_executeForPlayersInRange; }; /* ---------------------------------------- */ \ No newline at end of file diff --git a/addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf b/addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf index fc4ed47b..8050907e 100644 --- a/addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf +++ b/addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf @@ -49,12 +49,9 @@ if (AE3_UiOnTexture) then { private _computer = _consoleOutput getVariable "AE3_computer"; - private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange; + private _args = [_computer, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole]; - if ((count _playersInRange) > 0) then - { - [_computer, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_setTerminalDesign", _playersInRange]; - }; + [3, _computer, "AE3_armaos_fnc_terminal_uiOnTex_setTerminalDesign", _args] call AE3_main_fnc_executeForPlayersInRange; }; /* ---------------------------------------- */ \ No newline at end of file diff --git a/addons/armaos/functions/fnc_terminal_uiOnTex_addUpdateAllEventHandler.sqf b/addons/armaos/functions/fnc_terminal_uiOnTex_addUpdateAllEventHandler.sqf index 73d0c372..4fa99a52 100644 --- a/addons/armaos/functions/fnc_terminal_uiOnTex_addUpdateAllEventHandler.sqf +++ b/addons/armaos/functions/fnc_terminal_uiOnTex_addUpdateAllEventHandler.sqf @@ -27,32 +27,29 @@ _handle = if (AE3_UiOnTexture) then { - private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange; + private _languageButtonCtrl = _consoleDialog displayCtrl 1310; + private _batteryButtonCtrl = _consoleDialog displayCtrl 1050; + private _headerBackgroundCtrl = _consoleDialog displayCtrl 900; + private _consoleBackgroundCtrl = _consoleDialog displayCtrl 910; + private _headerCtrl = _consoleDialog displayCtrl 1000; + private _consoleCtrl = _consoleDialog displayCtrl 1100; - if ((count _playersInRange) > 0) then - { - private _languageButtonCtrl = _consoleDialog displayCtrl 1310; - private _batteryButtonCtrl = _consoleDialog displayCtrl 1050; - private _headerBackgroundCtrl = _consoleDialog displayCtrl 900; - private _consoleBackgroundCtrl = _consoleDialog displayCtrl 910; - private _headerCtrl = _consoleDialog displayCtrl 1000; - private _consoleCtrl = _consoleDialog displayCtrl 1100; + private _output = ctrlText _consoleCtrl; + private _terminalKeyboardLayout = ctrlText _languageButtonCtrl; + private _value = ctrlText _batteryButtonCtrl; + private _bgColorHeader = ctrlBackgroundColor _headerBackgroundCtrl; + private _bgColorConsole = ctrlBackgroundColor _consoleBackgroundCtrl; + private _fontColorHeader = ctrlTextColor _headerCtrl; + private _fontColorConsole = ctrlTextColor _consoleCtrl; - private _output = ctrlText _consoleCtrl; - private _terminalKeyboardLayout = ctrlText _languageButtonCtrl; - private _value = ctrlText _batteryButtonCtrl; - private _bgColorHeader = ctrlBackgroundColor _headerBackgroundCtrl; - private _bgColorConsole = ctrlBackgroundColor _consoleBackgroundCtrl; - private _fontColorHeader = ctrlTextColor _headerCtrl; - private _fontColorConsole = ctrlTextColor _consoleCtrl; + private _terminal = _computer getVariable "AE3_terminal"; - private _terminal = _computer getVariable "AE3_terminal"; + private _terminalBufferVisible = _terminal get "AE3_terminalBufferVisible"; + private _size = _terminal get "AE3_terminalSize"; - private _terminalBufferVisible = _terminal get "AE3_terminalBufferVisible"; - private _size = _terminal get "AE3_terminalSize"; + private _args = [_computer, _terminalBufferVisible, _size, _terminalKeyboardLayout, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole, _value]; - [_computer, _terminalBufferVisible, _size, _terminalKeyboardLayout, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole, _value] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_updateAll", _playersInRange]; - }; + [3, _computer, "AE3_armaos_fnc_terminal_uiOnTex_updateAll", _args] call AE3_main_fnc_executeForPlayersInRange; } else { diff --git a/addons/armaos/functions/fnc_terminal_updateBatteryStatus.sqf b/addons/armaos/functions/fnc_terminal_updateBatteryStatus.sqf index c8fb2be9..d23436ae 100644 --- a/addons/armaos/functions/fnc_terminal_updateBatteryStatus.sqf +++ b/addons/armaos/functions/fnc_terminal_updateBatteryStatus.sqf @@ -56,9 +56,7 @@ _handle = if ((AE3_UiOnTexture) && !(_oldValue isEqualTo _newValue)) then { - private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange; - - [_computer, _value] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_updateBatteryStatus", _playersInRange]; + [3, _computer, "AE3_armaos_fnc_terminal_uiOnTex_updateBatteryStatus", [_computer, _value]] call AE3_main_fnc_executeForPlayersInRange; }; /* ---------------------------------------- */ diff --git a/addons/armaos/functions/fnc_terminal_updateOutput.sqf b/addons/armaos/functions/fnc_terminal_updateOutput.sqf index 73828f16..09391ff0 100644 --- a/addons/armaos/functions/fnc_terminal_updateOutput.sqf +++ b/addons/armaos/functions/fnc_terminal_updateOutput.sqf @@ -35,12 +35,7 @@ _computer setVariable ["AE3_terminal", _terminal]; if (AE3_UiOnTexture) then { - private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange; - - if ((count _playersInRange) > 0) then - { - [_computer, _output] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_updateOutput", _playersInRange]; - }; + [3, _computer, "AE3_armaos_fnc_terminal_uiOnTex_updateOutput", [_computer, _output]] call AE3_main_fnc_executeForPlayersInRange; }; /* ---------------------------------------- */ \ No newline at end of file diff --git a/addons/main/XEH_PREP.hpp b/addons/main/XEH_PREP.hpp index ab20949a..0318a815 100644 --- a/addons/main/XEH_PREP.hpp +++ b/addons/main/XEH_PREP.hpp @@ -16,6 +16,7 @@ PREP(3den_checkConnection); /* Misc */ PREP(getPlayersInRange); +PREP(executeForPlayersInRange); /* Terminate */ PREP(terminateDevice); diff --git a/addons/main/functions/fnc_executeForPlayersInRange.sqf b/addons/main/functions/fnc_executeForPlayersInRange.sqf new file mode 100644 index 00000000..c55ed28d --- /dev/null +++ b/addons/main/functions/fnc_executeForPlayersInRange.sqf @@ -0,0 +1,31 @@ +/** + * Gets all players within a radius around the given object and executes a given function, command or script with arguments on these clients. + * + * Arguments: + * 0: Range + * 1: Object + * 2: Function or + * 3: Arguments + * + * Return: + * Nothing + */ + + params ["_range", "_object", "_fnc", "_args"]; + +private _playersInRange = [_range, _object] call AE3_main_fnc_getPlayersInRange; + +// using remoteExec on a zero sized array leads to RPT spam warnings +if ((count _playersInRange) == 0) exitWith {}; + +// use remoteExec if _fnc is type "string" +if ((typeName _fnc) isEqualTo "STRING") then +{ + _args remoteExec [_fnc, _playersInRange]; +}; + +// use a remote executed "call" if _fnc is type "code" +if ((typeName _fnc) isEqualTo "CODE") then +{ + [_args, _fnc] remoteExec ["call", _playersInRange]; +}; \ No newline at end of file