Skip to content

Commit

Permalink
added executeForPlayersInRange wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
y0014984 committed Aug 22, 2023
1 parent 05e8d31 commit ff81ef4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 41 deletions.
7 changes: 1 addition & 6 deletions addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/* ---------------------------------------- */
7 changes: 2 additions & 5 deletions addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/* ---------------------------------------- */
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions addons/armaos/functions/fnc_terminal_updateBatteryStatus.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/* ---------------------------------------- */
Expand Down
7 changes: 1 addition & 6 deletions addons/armaos/functions/fnc_terminal_updateOutput.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/* ---------------------------------------- */
1 change: 1 addition & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PREP(3den_checkConnection);

/* Misc */
PREP(getPlayersInRange);
PREP(executeForPlayersInRange);

/* Terminate */
PREP(terminateDevice);
Expand Down
31 changes: 31 additions & 0 deletions addons/main/functions/fnc_executeForPlayersInRange.sqf
Original file line number Diff line number Diff line change
@@ -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 <NUMBER>
* 1: Object <OBJECT>
* 2: Function <STRING> or <CODE>
* 3: Arguments <ANY>
*
* 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];
};

0 comments on commit ff81ef4

Please sign in to comment.