remoteExec: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[\[[Cc]ategory:[ _]?Arma[ _]3:[ _]?([^|]*)]]" to "{{GameCategory|arma3|$1}}")
No edit summary
 
(79 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3
|version1= 1.50


|1.50|Game version=
|gr1= Multiplayer


|gr1 = Multiplayer |GROUP1=
|descr= Asks the server to execute the given function or script command on the given target machine(s).
* Functions are executed in the [[Scheduler#Scheduled Environment|scheduled environment]]; suspension is allowed.
* Script commands are executed in the [[Scheduler#Unscheduled Environment|unscheduled environment]]; suspension is not allowed (see {{Link|#Example 7}}).


Read [[Arma 3: Remote Execution]] for more information about remote execution, security features and JIP techniques.


____________________________________________________________________________________________
{{Feature|informative|[[remoteExec]]/[[remoteExecCall]] can be used in single player as well, as it is considered as player-hosted multiplayer.}}


| Asks server to execute given scripted function or script command on given target PC. The environment chosen for the execution is as follows:<br><br>
{{Feature|important|The direct execution of [[call]] or [[spawn]] via [[remoteExec]] (or [[remoteExecCall]]) should be avoided to prevent issues in cases where the remote execution of [[call]] or [[spawn]] is blocked by [[Arma 3: CfgRemoteExec|CfgRemoteExec]]. It is instead recommended to create a function to be itself remote-executed.}}
* Scripted function - ''[[Scheduler#Scheduled_Environment|scheduled]]'' environment ([[Scheduler#Suspension|suspension]] is allowed, i.e. [[spawn]], [[execVM]]).
* Script command - ''[[Scheduler#Unscheduled_Environment|unscheduled]]'' environment ([[Scheduler#Suspension|suspension]] is NOT allowed).<br><br>
[[remoteExec]] can also be used in SP (the same restrictions apply both to SP and MP).
For more information about the usage, security features and advanced [[Multiplayer Scripting#Join In Progress|JIP]] techniques check the [[Arma 3 Remote Execution]] dedicated section.
<br><br>
{{Informative|Direct execution of [[call]] or [[spawn]] via [[remoteExec]] or [[remoteExecCall]] should be avoided to prevent issues in cases where remote execution of [[call]] and [[spawn]] is blocked in [[CfgRemoteExec]]. Instead create a function which is then excecuted by [[remoteExec]] or [[remoteExecCall]].}}
|DESCRIPTION=
____________________________________________________________________________________________


| params [[remoteExec]] [functionName, targets, JIP] |SYNTAX=
{{Feature|warning|The order of persistent remote execution for JIP players is not guaranteed, i.e. the order in which multiple calls are added is not necessarily the order they will be executed for joining player.}}


|p1= '''params''': [[Anything]]
|mp= Remote executions are queued and are therefore executed in the same order on remote clients (see {{Link|#Example 8}}).
<br>Example for scripted function:
<code>// &lt;params&gt; [[spawn]] fnc_someScriptedFunction;
&lt;params&gt; [[remoteExec]] ["fnc_someScriptedFunction", targets, JIP];</code>
Examples for script commands of every kind:
<code>// someScriptCommand;
[] [[remoteExec]] ["someScriptCommand", targets, JIP];</code>
<code>// someScriptCommand &lt;params&gt;;
[&lt;params&gt;] [[remoteExec]] ["someScriptCommand", targets, JIP];</code>
<code>// &lt;params1&gt; someScriptCommand &lt;params2&gt;;
[&lt;params1&gt;, &lt;params2&gt;] [[remoteExec]] ["someScriptCommand", targets, JIP];</code>
|Parameter1=
|p2= '''[functionName, targets, JIP]''': [[Array]] |Parameter2=


|p3= '''functionName''': [[String]] - function or command name.<br>
|s1= params [[remoteExec]] [order, targets, JIP]
While any function can be used, only commands and functions defined in [[CfgRemoteExec]] will be executed. |PARAMETER3=


|p4= '''targets''' (Optional): [default: 0 = everyone]
|p1= '''params''': [[Anything]] '''but''' [[Structured Text]] - ''order''<nowiki/>'s parameter {{Feature|important|[[Structured Text]] is '''not''' meant to be sent over network.}}
* [[Number]]
** When 0, the function or command will be executed globally, i.e. on the server and every connected client, including the one where [[remoteExec]] was originated.
** When 2, it will be executed only on the [[isServer|server]].
** When 3, 4, 5... it will be executed on the client where [[clientOwner]] ID matches the given number.
** When number is negative, the effect is inverted. -2 means execute on every client but not the server. -12, for example, means execute on the server and every client, but not on the client where [[clientOwner]] ID is equal to 12.
* [[Object]] - the function will be executed only where unit is local
* [[String]] - the function will be executed only where object or group defined by the variable with passed name is local
* [[Side]] - the function will be executed only on clients where the player is on the specified side
* [[Group]] - the function will be executed only on clients where the player is in the specified group. In order to execute the function where group is [[local]] pass owner of the group as param: <br><tt>_myGroup [[remoteExec]] ["deleteGroup", [[groupOwner]] _myGroup];</tt>
* [[Array]] - array of any of types listed above
|PARAMETER4=


|p5= ''' JIP''' (Optional): [default: false]<br><br>
|p2= '''order''': [[String]] - function or command name; while any function or command can be used here, only those allowed by [[Arma 3: CfgRemoteExec|CfgRemoteExec]] will actually be executed
* [[String]] or [[Boolean]] - If [[true]], function generates a unique ID for the message and the message itself is added to the JIP queue and executed for every JIP. If a non-empty string is given, it is treated a custom ID of the message and the message itself is added to the JIP queue overriding any [[remoteExec]] message with the same ID. Otherwise, no ID is generated and no message is placed into the JIP queue. (see also Example 7 on how to remove previously set function from JIP queue)<br><br>
* [[Object]] or [[Group]] or [[netId]] - The persistent execution of the given [[remoteExec]] statement will be attached to the given [[Object]] or [[Group]], passed directly by reference or by their [[netId]]: <tt>_netId = "this is my car" [[remoteExec]] ["hint", 0, car];</tt> or <tt>_netId = "this is my car" [[remoteExec]] ["hint", 0, [[netId]] car];</tt>Upon success, the command will return [[netId]] of the used [[Object]] or [[Group]] or [[netId]]. When [[Object]] or [[Group]] is deleted and becomes [[objNull]] or [[grpNull]], the persistent [[remoteExec]] statement is automatically removed from JIP queue. Manual removal of the JIP statement could be done by passing either [[Object]], [[Group]] or [[netId]] as usual:<tt>[[remoteExec]] ["", car];</tt> or <tt>[[remoteExec]] ["", [[netId]] car];</tt>When JIP param is [[String]] in format "[[Number]]:[[Number]]", the string will be tested first whether or not it is the valid [[netId]] of an existing [[Object]] or [[Group]], and if not the execution will be aborted, if yes, that [[Object]] or [[Group]] will be used to set persistent execution.|PARAMETER5=


|p6= {{Informative| JIP mostly makes sense for messages doing changes local to client (not directly synchronized over the network). Otherwise, after remoteExec is executed, depending on the contents of the global JIP queue there is a chance a new message could be added to it, unnecessary increasing the number of messages sent to any newly connected client.
|p3= '''targets''' - (Optional, default 0):
E.g. calling "..remoteExec ["setFuel"..]" is fine, however, calling "..remoteExec ["publicVariable",..]" is not.}} |PARAMETER6=
* [[Number]] (See also [[Multiplayer Scripting#Machine network ID|Machine network ID]]):
** '''0:''' the order will be executed globally, i.e. on the server and every connected client, including the machine where [[remoteExec]] originated
** '''2:''' the order will only be executed on the server - is both dedicated and hosted server. See [[Multiplayer_Scripting#Different_machines_and_how_to_target_them|for more info]]
** '''Other number:''' the order will be executed on the machine where [[clientOwner]] matches the given number
** '''Negative number:''' the effect is inverted: '''-2''' means every client but not the server, '''-12''' means the server and every client, except for the client where [[clientOwner]] returns 12
* [[Object]] - the order will be executed where the given object is [[Multiplayer Scripting#Locality|local]]
* [[String]] - interpreted as an [[Identifier]] (variable name); the function / command will be executed where the object or group identified by the variable with the provided name is [[Multiplayer Scripting#Locality|local]]
* [[Side]] - the order will be executed on machines where the player is on the specified side
* [[Group]] - the order will be executed on machines '''where the player is in the specified group''' ('''not''' where said group is local!)
* [[Array]] - array of any combination of the types listed above


|p7= {{Warning| There could be '''only one JIP message with the same JIP ID in the JIP queue'''. This means that if one tries to [[remoteExec]] again with the existing JIP ID, the JIP message which is already in the JIP queue will be overwritten. Passing [[true]] for JIP param autogenerates unique ID, therefore adding new message in the JIP queue each time. All other options have potential to overwrite existing JIP message.}}|PARAMETER7=
|p4= '''JIP''' - (Optional, default [[false]]):
* [[Boolean]] - if [[true]], a unique JIP ID is generated and the [[remoteExec]] statement is added to the JIP queue from which it will be executed for every JIP
* [[String]]:
** if the string is empty, it is interpreted as [[false]]
** if the string is in format "[[Number]]:[[Number]]" (e.g. "0:0"), it is interpreted as a [[netId]] (see below)
** else the string is treated as a custom JIP ID and the [[remoteExec]] statement is added to the JIP queue, replacing statements that have the same JIP ID
* [[Object]], [[Group]] or [[netId]] - the persistent execution of the [[remoteExec]] statement is attached to the given object or group, replacing any previous statement that has the same JIP ID.<br>When the object / group is deleted, the [[remoteExec]] statement is automatically removed from the JIP queue


| [[Anything]] - Nil in case of error. [[String]] otherwise. If JIP is not requested this is an empty string, if JIP is requested, it is the JIP ID. See the topic [[Function#Return_Values|Function]] for more information. |RETURNVALUE=
The '''JIP''' parameter can only be used if the '''targets''' parameter is 0 or a negative number.<br>
See also [[#Example 3|Example 3]] on how to remove statements from the JIP queue.


____________________________________________________________________________________________
|r1=
* [[nil]] - In case of error.
* [[String]] - In case of success (see [[remoteExecutedJIPID]]).
** If the '''JIP''' parameter was [[false]] or an empty string, the return value is "".
** If the '''JIP''' parameter was [[true]] or a custom JIP ID, the JIP ID is returned.
** If the '''JIP''' parameter was an [[Object]], a [[Group]] or a [[netId]], the (corresponding) [[netId]] is returned.


|s2= [[remoteExec]] [functionName, targets, JIP] |SYNTAX2=
|s2= [[remoteExec]] [functionName, targets, JIP]


|p21= '''[functionName, targets, JIP]''': [[Array]] |PARAMETER21=
|p21= '''functionName''': [[String]] - see the main syntax above for more details.


|p22= '''functionName''': [[String]] - function or command name.<br>
|p22= '''targets''': [[Number]], [[Object]], [[String]], [[Side]], [[Group]] or [[Array]] - (Optional, default 0) see the main syntax above for more details.
While any function can be used, only commands and functions defined in [[CfgRemoteExec]] will be executed. |PARAMETER22=


|p23= '''targets''' (Optional): [default: 0 = everyone]
|p23= '''JIP''': [[Boolean]], [[String]], [[Object]], [[Group]] or [[netId]] - (Optional, default [[false]]) see the main syntax above for more details.
* [[Number]]  
** When 0, the function or command will be executed globally, i.e. on the server and every connected client, including the one where [[remoteExec]] was originated.
** When 2, it will be executed only on the [[isServer|server]].
** When 3, 4, 5... it will be executed on the client where [[clientOwner]] ID matches the given number.
** When number is negative, the effect is inverted. -2 means execute on every client but not the server. -12, for example, means execute on the server and every client, but not on the client where [[clientOwner]] ID is equal to 12.
* [[Object]] - the function will be executed only where unit is local
* [[String]] - the function will be executed only where object or group defined by the variable with passed name is local
* [[Side]] - the function will be executed only on clients where the player is on the specified side
* [[Group]] - the function will be executed only on clients where the player is in the specified group. In order to execute the function where group is [[local]] pass owner of the group as param: <br><tt>_myGroup [[remoteExec]] ["deleteGroup", [[groupOwner]] _myGroup];</tt>
* [[Array]] - array of any of types listed above
|PARAMETER23=


|p24= ''' JIP''' (Optional): [default: false]<br><br>
|r2= [[nil]] or [[String]] - see the main syntax above for more details.
* [[String]] or [[Boolean]] - If [[true]], function generates a unique ID for the message and the message itself is added to the JIP queue and executed for every JIP. If a non-empty string is given, it is treated a custom ID of the message and the message itself is added to the JIP queue overriding any [[remoteExec]] message with the same ID. Otherwise, no ID is generated and no message is placed into the JIP queue. (see also Example 7 on how to remove previously set function from JIP queue)<br><br>
* [[Object]] or [[Group]] or [[netId]] - The persistent execution of the given [[remoteExec]] statement will be attached to the given [[Object]] or [[Group]], passed directly by reference or by their [[netId]]: <tt>_netId = "this is my car" [[remoteExec]] ["hint", 0, car];</tt> or <tt>_netId = "this is my car" [[remoteExec]] ["hint", 0, [[netId]] car];</tt>Upon success, the command will return [[netId]] of the used [[Object]] or [[Group]] or [[netId]]. When [[Object]] or [[Group]] is deleted and becomes [[objNull]] or [[grpNull]], the persistent [[remoteExec]] statement is automatically removed from JIP queue. Manual removal of the JIP statement could be done by passing either [[Object]], [[Group]] or [[netId]] as usual:<tt>[[remoteExec]] ["", car];</tt> or <tt>[[remoteExec]] ["", [[netId]] car];</tt>When JIP param is [[String]] in format "[[Number]]:[[Number]]", the string will be tested first whether or not it is the valid [[netId]] of an existing [[Object]] or [[Group]], and if not the execution will be aborted, if yes, that [[Object]] or [[Group]] will be used to set persistent execution.|PARAMETER24=


|p25= {{Informative| JIP mostly makes sense for messages doing changes local to client (not directly synchronized over the network). Otherwise, after remoteExec is executed, depending on the contents of the global JIP queue there is a chance a new message could be added to it, unnecessary increasing the number of messages sent to any newly connected client.
E.g. calling "..remoteExec ["setFuel"..]" is fine, however, calling "..remoteExec ["publicVariable",..]" is not.}}|PARAMETER25=


|p26= {{Warning| There could be '''only one JIP message with the same JIP ID in the JIP queue'''. This means that if one tries to [[remoteExec]] again with the existing JIP ID, the JIP message which is already in the JIP queue will be overwritten. Passing [[true]] for JIP param autogenerates unique ID, therefore adding new message in the JIP queue each time. All other options have potential to overwrite existing JIP message.}}|PARAMETER26=
<!-- Don't place links within strings in these examples. -->


|r2= [[Anything]] - Nil in case of error. [[String]] otherwise. If JIP is not requested this is an empty string, if JIP is requested, it is the JIP ID. See the topic [[Function#Return_Values|Function]] for more information. |RETURNVALUE2=
____________________________________________________________________________________________
 
|x1= <code>// runs hint "hello" on each connected client
"hello" [[remoteExec]] ["[[hint]]"]; </code> |Example1=


|x2= <code>// runs hint "hello" on first connected client
|x1= How to write [[remoteExec]]/[[remoteExecCall]]:
"hello" [[remoteExec]] ["[[hint]]", 3]; </code> |Example2=
<code style="display: block">{{Color|darkorange|hint}} {{Color|teal|"Hello"}};
{{cc|becomes}}
[{{Color|teal|"Hello"}}] remoteExec ["{{Color|darkorange|hint}}"];
{{Color|teal|"Hello"}} remoteExec ["{{Color|darkorange|hint}}"]; {{cc|alternatively}}</code>


|x3= <code>// runs hint "hello" everywhere but server
<code style="display: block">{{Color|green|unit1}} {{Color|darkorange|setFace}} {{Color|teal|"Miller"}};
"hello" [[remoteExec]] ["[[hint]]", -2]; </code> |Example3=
{{cc|becomes}}
[{{Color|green|unit1}}, {{Color|teal|"Miller"}}] remoteExec ["{{Color|darkorange|setFace}}"];</code>


|x4= <code>// runs hint "hello" everywhere but server, JIPs the message
<code style="display: block">{{Color|darkorange|cutRsc}} {{Color|darkred|["", "BLACK OUT"]}};
// and returns e.g. "3_1" as a unique JIP id
{{cc|becomes}}
myJipID = "hello" [[remoteExec]] ["[[hint]]", -2, [[true]]]; </code> |Example4=
[{{Color|darkred|["", "BLACK OUT"]}}] remoteExec ["{{Color|darkorange|cutRsc}}"]; {{cc|double brackets are needed as the unary command takes an array}}</code>


|x5= <code>// runs hint "hello" everywhere but server, JIPs the message under ID "some_JIP_ID"
<code style="display: block">
// replacing any previous message with this ID in the JIP queue.
{{cc|functions, however, do not need double squared brackets}}
"hello" [[remoteExec]] ["[[hint]]", -2, "some_JIP_ID"];</code> |Example5=
{{Color|teal|["line 1", "line 2"]}} spawn {{Color|darkorange|BIS_fnc_infoText}};
{{cc|becomes}}
{{Color|teal|["line 1", "line 2"]}} remoteExec ["{{Color|darkorange|BIS_fnc_infoText}}"];
</code>


|x6= <code>// runs "someFuncWithNoArgs" on each connected client
|x2= send an order to specific machines:
[[remoteExec]] ["someFuncWithNoArgs"]; </code> |Example6=
<sqf>
"message" remoteExec ["hint", 0]; // sends a hint message to everyone, identical to "message" remoteExec ["hint"]
"message" remoteExec ["hint", -2]; // sends a hint message to everybody but the server (also not hosted server)
"message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local
"message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine
</sqf>


|x7= <code>// removes a message identified by "IamUnique" from the JIP queue
|x3= <!-- This example is referenced in the Syntax section. -->
[[remoteExec]] ["", "IamUnique"]; </code> |Example7=
Add statements to the JIP queue:
<sqf>
private _jipId = ["mission state: the car is broken"] remoteExec ["systemChat", 0, true]; // adds the hint to the JIP queue and returns the JIP queue order id
waitUntil { canMove _car };
remoteExec ["", _jipId]; // the systemChat order is removed from the JIP queue
</sqf>


|x8= <code>// all clients will have their ammo set to 1 for their current weapon
<sqf>
{[[player]] [[setAmmo]] [<nowiki/>[[primaryWeapon]] [[player]], 1];} [[remoteExec]] ["[[BIS_fnc_call|bis_fnc_call]]", 0]; </code> |Example8=
["mission state: the car is broken"] remoteExec ["systemChat", 0, _queueObject];
// ...
remoteExec ["", _queueObject]; // the order attached to _queueObject is removed
</sqf>


|x9= <code>// Object obj will have its ammo set to 1 where it is local
<sqf>
[obj,<nowiki>[</nowiki>[[primaryWeapon]] obj, 1]<nowiki>]</nowiki> [[remoteExec]] ["[[setAmmo]]", obj]; </code> |Example9=
private _jipId = ["mission state: the car is broken"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // _jipId is actually "MY_JIP_ID" now
waitUntil { canMove _car };
["mission state: the car is repaired"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // this order replaces the previous one
// ...
remoteExec ["", "MY_JIP_ID"]; // the "MY_JIP_ID" order is removed from the JIP queue
</sqf>


|x10= <code>myJipID = "hello" [[remoteExec]] ["", 0];
|x4= Some more complex examples:
[[if]] ([[isNil]] "myJipID") [[then]] { [[hint]] "empty function name is not allowed"; }; </code> |Example10=
<sqf>
____________________________________________________________________________________________
["Open", true] remoteExec ["BIS_fnc_arsenal", MyTargetPlayer];
[MyCurator, [[MyObject1, MyObject2], false]] remoteExec ["addCuratorEditableObjects", 2];
</sqf>


| [[remoteExecCall]], [[isRemoteExecuted]], [[isRemoteExecutedJIP]], [[remoteExecutedOwner]], [[canSuspend]], [[BIS_fnc_MP]], [[Arma_3_Remote_Execution|Remote Execution]] |SEEALSO=
|x5= A tricky example: executing <sqf inline>player setAmmo [primaryWeapon player, 1];</sqf> (on machines where the player is in MyGroup):
}}
<sqf>
[player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // WRONG: the local player object is used here!
[{ player setAmmo [primaryWeapon player, 1]; }] remoteExec ["call", MyGroup]; // CORRECT: the remote player object is used here
</sqf>
 
|x6= '''[[Multiplayer Scripting]] "performance trick"'''<br>
This <sqf inline>[0, -2] select isDedicated</sqf> check is worth it to avoid '''function''' server-side calculations only. See also {{Link|#Example 9}} for an advanced solution.
<sqf>
["message"] remoteExec ["BIS_fnc_infoText"]; // not ideal - the function will still run on the dedicated server for nothing
["message"] remoteExec ["BIS_fnc_infoText", [0, -2] select isDedicated]; // ideal - the dedicated server will not run the code, a player-hosted server will
 
["message"] remoteExec ["hint", [0, -2] select isDedicated]; // the check is too expensive to be worthy - it becomes worthy if the server logs an RPT warning
["message"] remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface
 
private _allPlayersTarget = [0, -2] select isDedicated; // caching the result for multiple usages makes it worthy - think of {{Link|Arma 3: Headless_Client|headless clients}} as well
["message 1"] remoteExec ["hint", _allPlayersTarget];
["message 2"] remoteExec ["hint", _allPlayersTarget];
</sqf>
{{Feature|informative|See {{Link|#Example 9}} below for an advanced example.}}
 
|x7= <!-- This example is referenced in the Description section. -->
As said in the description: '''commands''' will be executed in an [[Scheduler#Unscheduled Environment|unscheduled environment]]
<sqf>[{ sleep 1 }] remoteExec ["call"]; // will throw an error: it is forbidden to use sleep (or waitUntil, etc) in unscheduled environment</sqf>
 
|x8= <!-- This example is referenced in the Description section. -->
<sqf>
"Message 1" remoteExec ["systemChat"];
"Message 2" remoteExec ["systemChat"];
// will result in
// "Message 1"
// "Message 2"
// in this exact order on clients
</sqf>
 
|x9= <!-- This example is referenced in the Syntax section. -->
It is possible to create a "to all players" remote exec target variable:
<sqf>
if (isServer) then
{
TO_ALL_PLAYERS = [0, -2] select isDedicated;
publicVariable "TO_ALL_PLAYERS";
};
</sqf>
<spoiler text="Show HC-compatible version">
If {{Link|Arma 3: Headless Client|Headless Clients}} are involved:
<sqf>
if (isServer) then
{
TO_ALL_PLAYERS = [0, -2] select isDedicated;
 
private _allNegativeHCs = allPlayers apply { getPlayerID _x } select { _x != "-1" } // all valid playerIDs
apply { getUserInfo _x } select { _x select 7 } // filter by HC
apply { -(_x select 1) }; // get negative network ID
 
if (_allNegativeHCs isNotEqualTo []) then
{
TO_ALL_PLAYERS = [TO_ALL_PLAYERS] + _allNegativeHCs;
};
 
publicVariable "TO_ALL_PLAYERS";


<h3 style='display:none'>Bottom Section</h3>
addMissionEventHandler ["OnUserConnected", {
params ["_networkId"];
private _userInfo = getUserInfo _networkId;
if !(_userInfo select 7) exitWith {}; // not a HC


[[Category:Scripting_Commands_Arma_3]]
if (TO_ALL_PLAYERS isEqualType 0) then // number to array conversion
{{GameCategory|arma3| Remote Execution}}
{
if (TO_ALL_PLAYERS == 0) then // player-hosted
{
TO_ALL_PLAYERS = [-(_userInfo select 1)];
}
else // -2, dedicated server
{
TO_ALL_PLAYERS = [TO_ALL_PLAYERS, -(_userInfo select 1)];
};
}
else // already an array
{
TO_ALL_PLAYERS pushBackUnique -(_userInfo select 1);
};


publicVariable "TO_ALL_PLAYERS";
}];
};
</sqf>
</spoiler>
<sqf>
// client or server will always target the good machines
["Yay!"] remoteExec ["hint", TO_ALL_PLAYERS];
</sqf>


<h3 style='display:none'>Notes</h3>
|seealso= [[Multiplayer Scripting]] [[remoteExecCall]] [[remoteExecutedOwner]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[Arma 3: Remote Execution]] [[canSuspend]] [[BIS_fnc_MP]] [[remoteExecutedJIPID]]
<dl class='command_description'>
}}


<dd class="notedate">Posted on December 29, 2015 - 20:28 (UTC)</dd>
<dt class="note">[[User:AgentRevolution|AgentRev]]</dt>
<dd class="note">
[[remoteExec]] and [[remoteExecCall]] are currently filtered by BattlEye's remoteexec.txt, the string analyzed by BE is formatted the same way as the following example's output:
<code>[[format]] ["%1 %2", functionName, [[str]] params]</code>
If [[CfgRemoteExec]] <tt>class Functions</tt> is set to <tt>mode = 1;</tt>, the following remoteexec.txt exclusion can be used to safely allow all whitelisted *_fnc_* functions taking an array as parameter to go through:
<code>!="\w+?_fnc_\w+? \[[\S\s]*\]"</code>
Any attempt to exploit this exclusion using other RE methods like [[createUnit]] will run into "Error Missing ;" without any malicious code being executed. Mod makers should refrain from remote-executing raw commands from clients, as they require individual exclusions, and instead use *_fnc_* functions taking an array as parameter, which are covered by the above exclusion.
</dd>


<dd class="notedate">Posted on March 24, 2016 - 14:09 (UTC)</dd>
{{GameCategory|arma3|Remote Execution}}
<dt class="note">[[User:R3vo|R3vo]]</dt>
<dd class="note">
The INCORRECT way to call [[reveal]] command on a certain object for every player:
<code><nowiki>[</nowiki>[[player]], _desired_object] [[remoteExec]] ["reveal", 0];</code>
In this case [[player]] object will be the object obtained on the computer where [[remoteExec]] is initiated. If it is dedicated server, player will be [[objNull]], if it is client, player would be [[player]] object on this client. In any case this will not reveal _desired_object for all connected players.
<br><br>
The CORRECT way:
<code>[_desired_object, {[[player]] [[reveal]] _this}] [[remoteExec]] ["call", 0];</code>
The _desired_object will be identical on every client, this is what we want, but [[player]] will refer to individual player on each client, so _desired_object will be revealed to all connected players.
</dd>


<dd class="notedate">Posted on May 25, 2016 - 18:23 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
When adapting mission from dedicated server for SP, if target used in [[remoteExec]] is -2 (execute on every client but not server), in SP this will not execute since client is server in SP. To work around, the target could be set using [[isMultiplayer]] condition like this:
<code>"123" [[remoteExec]] ["hint", [0, -2] [[select]] [[isMultiplayer]]];</code>
This will execute [[hint]] on every client in MP on dedicated server (target -2) and will also execute it in SP (target 0).
</dd>


<dd class="notedate">Posted on May 28, 2016 - 20:51 (UTC)</dd>
{{Note
<dt class="note">[[User:R3vo|R3vo]]</dt>
|user= AgentRev
<dd class="note">
|timestamp= 20151229202800
While KK's solution works fine in sp missions and on dedicated servers, it will not work properly for hosted missions.<br>
|text= [[remoteExec]] and [[remoteExecCall]] are currently filtered by BattlEye's remoteexec.txt, the string analyzed by BE is formatted the same way as the following example's output:
'''Solution:'''
<sqf>format ["%1 %2", functionName, str params]</sqf>
<code>[0,0.5] [[remoteExec]] ['[[fadeRadio]]',[0,-2] [[select]] [[isDedicated]],[[true]]];</code><br>
If [[CfgRemoteExec]] {{hl|class Functions}} is set to {{hl|c= mode = 1;}}, the following remoteexec.txt exclusion can be used to safely allow all whitelisted *_fnc_* functions taking an array as parameter to go through:
Singleplayer: isDedicated returns false -> code is executed everywhere (0)<br>
<sqf>!="\w+?_fnc_\w+? \[[\S\s]*\]"</sqf>
Hosted: isDedicated returns false -> code is executed everywhere '''including host''' (0)<br>
Any attempt to exploit this exclusion using other RE methods like [[createUnit]] will run into "Error Missing ;" without any malicious code being executed. Mod makers should refrain from remote-executing raw commands from clients, as they require individual exclusions, and instead use *_fnc_* functions taking an array as parameter, which are covered by the above exclusion.
Dedicated: isDedicated returns true -> code is executed everywhere '''excluding server'''(-2)
}}
</dd>


<dd class="notedate">Posted on Jan 30, 2017 - 18:35 (UTC)</dd>
{{Note
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
|user= Pierre MGI
<dd class="note">
|timestamp= 20170130183500
<code>[some params] [[remoteExec]] ['some command',2,true];</code>  
|text= <sqf>[someArgs] remoteExec ['someCommand', 2, true];</sqf>  
will fail, as you can't use JIP and remoteExec on server only<br>
will fail, as you can't use JIP and remoteExec on server only
<code>[some params] [[remoteExec]] ['some command',2]; // works</code><br>
<sqf>[someArgs] remoteExec ['someCommand', 2]; // works</sqf>
</dd>
}}


<dd class="notedate">Posted on May 10, 2017 - 20:10 (UTC)</dd>
{{Note
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
|user= 7erra
<dd class="note">
|timestamp= 20210305004800
To [[remoteExec]]:  
|text= The [[remoteExec]]'ed function only has to exist on the target machine. For example:
<code>[[titleText]] ["Test Message", "PLAIN", 1];</code>
<sqf>
Use
// initPlayerLocal.sqf
<code><nowiki>[</nowiki>["Test Message", "PLAIN", 1]] [[remoteExec]] ["titleText"];</code>
TAG_fnc_testRemote = {
</dd>
hint "Remote Exec Received";
};
</sqf>
<sqf>
// executed on a DEDICATED server
remoteExec ["TAG_fnc_testRemote", -2];
</sqf>
Will display a hint for every client. This is especially useful for when the server is running a mod that is not required by clients.
}}


<dd class="notedate">Posted on April 22, 2018 - 15:29 (UTC)</dd>
{{Note
<dt class="note">[[User:KC Grimes|KC Grimes]]</dt>
|user= Sa-Matra
<dd class="note">
|timestamp= 20240919083305
It seems that only global functions can be executed, as opposed to local.
|text= It is not possible to use two negative owners to exclude two clients, you'll end up REing all clients:
<code>&lt;params&gt; remoteExec ["fnc_someScriptedFunction", targets, JIP]; //Works</code>
<sqf>args remoteExec ["func", [-2, -3]]; // Doesn't work, gonna execute on every client</sqf>
<br>
}}
<code>&lt;params&gt; remoteExec ["_fnc_someScriptedFunction", targets, JIP]; //Does not work</code>
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 09:33, 19 September 2024

Hover & click on the images for description

Description

Description:
Asks the server to execute the given function or script command on the given target machine(s). Read Arma 3: Remote Execution for more information about remote execution, security features and JIP techniques.
remoteExec/remoteExecCall can be used in single player as well, as it is considered as player-hosted multiplayer.
The direct execution of call or spawn via remoteExec (or remoteExecCall) should be avoided to prevent issues in cases where the remote execution of call or spawn is blocked by CfgRemoteExec. It is instead recommended to create a function to be itself remote-executed.
The order of persistent remote execution for JIP players is not guaranteed, i.e. the order in which multiple calls are added is not necessarily the order they will be executed for joining player.
Multiplayer:
Remote executions are queued and are therefore executed in the same order on remote clients (see Example 8).
Groups:
Multiplayer

Syntax

Syntax:
params remoteExec [order, targets, JIP]
Parameters:
params: Anything but Structured Text - order's parameter
Structured Text is not meant to be sent over network.
order: String - function or command name; while any function or command can be used here, only those allowed by CfgRemoteExec will actually be executed
targets - (Optional, default 0):
  • Number (See also Machine network ID):
    • 0: the order will be executed globally, i.e. on the server and every connected client, including the machine where remoteExec originated
    • 2: the order will only be executed on the server - is both dedicated and hosted server. See for more info
    • Other number: the order will be executed on the machine where clientOwner matches the given number
    • Negative number: the effect is inverted: -2 means every client but not the server, -12 means the server and every client, except for the client where clientOwner returns 12
  • Object - the order will be executed where the given object is local
  • String - interpreted as an Identifier (variable name); the function / command will be executed where the object or group identified by the variable with the provided name is local
  • Side - the order will be executed on machines where the player is on the specified side
  • Group - the order will be executed on machines where the player is in the specified group (not where said group is local!)
  • Array - array of any combination of the types listed above
JIP - (Optional, default false):
  • Boolean - if true, a unique JIP ID is generated and the remoteExec statement is added to the JIP queue from which it will be executed for every JIP
  • String:
    • if the string is empty, it is interpreted as false
    • if the string is in format "Number:Number" (e.g. "0:0"), it is interpreted as a netId (see below)
    • else the string is treated as a custom JIP ID and the remoteExec statement is added to the JIP queue, replacing statements that have the same JIP ID
  • Object, Group or netId - the persistent execution of the remoteExec statement is attached to the given object or group, replacing any previous statement that has the same JIP ID.
    When the object / group is deleted, the remoteExec statement is automatically removed from the JIP queue
The JIP parameter can only be used if the targets parameter is 0 or a negative number.
See also Example 3 on how to remove statements from the JIP queue.
Return Value:
  • nil - In case of error.
  • String - In case of success (see remoteExecutedJIPID).
    • If the JIP parameter was false or an empty string, the return value is "".
    • If the JIP parameter was true or a custom JIP ID, the JIP ID is returned.
    • If the JIP parameter was an Object, a Group or a netId, the (corresponding) netId is returned.

Alternative Syntax

Syntax:
remoteExec [functionName, targets, JIP]
Parameters:
functionName: String - see the main syntax above for more details.
targets: Number, Object, String, Side, Group or Array - (Optional, default 0) see the main syntax above for more details.
JIP: Boolean, String, Object, Group or netId - (Optional, default false) see the main syntax above for more details.
Return Value:
nil or String - see the main syntax above for more details.

Examples

Example 1:
How to write remoteExec/remoteExecCall: hint "Hello"; // becomes ["Hello"] remoteExec ["hint"]; "Hello" remoteExec ["hint"]; // alternatively unit1 setFace "Miller"; // becomes [unit1, "Miller"] remoteExec ["setFace"]; cutRsc ["", "BLACK OUT"]; // becomes [["", "BLACK OUT"]] remoteExec ["cutRsc"]; // double brackets are needed as the unary command takes an array // functions, however, do not need double squared brackets ["line 1", "line 2"] spawn BIS_fnc_infoText; // becomes ["line 1", "line 2"] remoteExec ["BIS_fnc_infoText"];
Example 2:
send an order to specific machines:
"message" remoteExec ["hint", 0]; // sends a hint message to everyone, identical to "message" remoteExec ["hint"] "message" remoteExec ["hint", -2]; // sends a hint message to everybody but the server (also not hosted server) "message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local "message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine
Example 3:
Add statements to the JIP queue:
private _jipId = ["mission state: the car is broken"] remoteExec ["systemChat", 0, true]; // adds the hint to the JIP queue and returns the JIP queue order id waitUntil { canMove _car }; remoteExec ["", _jipId]; // the systemChat order is removed from the JIP queue
["mission state: the car is broken"] remoteExec ["systemChat", 0, _queueObject]; // ... remoteExec ["", _queueObject]; // the order attached to _queueObject is removed
private _jipId = ["mission state: the car is broken"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // _jipId is actually "MY_JIP_ID" now waitUntil { canMove _car }; ["mission state: the car is repaired"] remoteExec ["systemChat", 0, "MY_JIP_ID"]; // this order replaces the previous one // ... remoteExec ["", "MY_JIP_ID"]; // the "MY_JIP_ID" order is removed from the JIP queue
Example 4:
Some more complex examples:
["Open", true] remoteExec ["BIS_fnc_arsenal", MyTargetPlayer]; [MyCurator, [[MyObject1, MyObject2], false]] remoteExec ["addCuratorEditableObjects", 2];
Example 5:
A tricky example: executing player setAmmo [primaryWeapon player, 1]; (on machines where the player is in MyGroup):
[player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // WRONG: the local player object is used here! [{ player setAmmo [primaryWeapon player, 1]; }] remoteExec ["call", MyGroup]; // CORRECT: the remote player object is used here
Example 6:
Multiplayer Scripting "performance trick"
This [0, -2] select isDedicated check is worth it to avoid function server-side calculations only. See also Example 9 for an advanced solution.
["message"] remoteExec ["BIS_fnc_infoText"]; // not ideal - the function will still run on the dedicated server for nothing ["message"] remoteExec ["BIS_fnc_infoText", [0, -2] select isDedicated]; // ideal - the dedicated server will not run the code, a player-hosted server will ["message"] remoteExec ["hint", [0, -2] select isDedicated]; // the check is too expensive to be worthy - it becomes worthy if the server logs an RPT warning ["message"] remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface private _allPlayersTarget = [0, -2] select isDedicated; // caching the result for multiple usages makes it worthy - think of headless clients as well ["message 1"] remoteExec ["hint", _allPlayersTarget]; ["message 2"] remoteExec ["hint", _allPlayersTarget];
See Example 9 below for an advanced example.
Example 7:
As said in the description: commands will be executed in an unscheduled environment
[{ sleep 1 }] remoteExec ["call"]; // will throw an error: it is forbidden to use sleep (or waitUntil, etc) in unscheduled environment
Example 8:
"Message 1" remoteExec ["systemChat"]; "Message 2" remoteExec ["systemChat"]; // will result in // "Message 1" // "Message 2" // in this exact order on clients
Example 9:
It is possible to create a "to all players" remote exec target variable:
if (isServer) then { TO_ALL_PLAYERS = [0, -2] select isDedicated; publicVariable "TO_ALL_PLAYERS"; };

If Headless Clients are involved:

if (isServer) then { TO_ALL_PLAYERS = [0, -2] select isDedicated; private _allNegativeHCs = allPlayers apply { getPlayerID _x } select { _x != "-1" } // all valid playerIDs apply { getUserInfo _x } select { _x select 7 } // filter by HC apply { -(_x select 1) }; // get negative network ID if (_allNegativeHCs isNotEqualTo []) then { TO_ALL_PLAYERS = [TO_ALL_PLAYERS] + _allNegativeHCs; }; publicVariable "TO_ALL_PLAYERS"; addMissionEventHandler ["OnUserConnected", { params ["_networkId"]; private _userInfo = getUserInfo _networkId; if !(_userInfo select 7) exitWith {}; // not a HC if (TO_ALL_PLAYERS isEqualType 0) then // number to array conversion { if (TO_ALL_PLAYERS == 0) then // player-hosted { TO_ALL_PLAYERS = [-(_userInfo select 1)]; } else // -2, dedicated server { TO_ALL_PLAYERS = [TO_ALL_PLAYERS, -(_userInfo select 1)]; }; } else // already an array { TO_ALL_PLAYERS pushBackUnique -(_userInfo select 1); }; publicVariable "TO_ALL_PLAYERS"; }]; };

↑ Back to spoiler's top
// client or server will always target the good machines ["Yay!"] remoteExec ["hint", TO_ALL_PLAYERS];

Additional Information

See also:
Multiplayer Scripting remoteExecCall remoteExecutedOwner isRemoteExecuted isRemoteExecutedJIP Arma 3: Remote Execution canSuspend BIS_fnc_MP remoteExecutedJIPID

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note


AgentRev - c
Posted on Dec 29, 2015 - 20:28 (UTC)
remoteExec and remoteExecCall are currently filtered by BattlEye's remoteexec.txt, the string analyzed by BE is formatted the same way as the following example's output:
format ["%1 %2", functionName, str params]
If CfgRemoteExec class Functions is set to mode = 1;, the following remoteexec.txt exclusion can be used to safely allow all whitelisted *_fnc_* functions taking an array as parameter to go through:
!="\w+?_fnc_\w+? \[[\S\s]*\]"
Any attempt to exploit this exclusion using other RE methods like createUnit will run into "Error Missing ;" without any malicious code being executed. Mod makers should refrain from remote-executing raw commands from clients, as they require individual exclusions, and instead use *_fnc_* functions taking an array as parameter, which are covered by the above exclusion.
Pierre MGI - c
Posted on Jan 30, 2017 - 18:35 (UTC)
[someArgs] remoteExec ['someCommand', 2, true];
will fail, as you can't use JIP and remoteExec on server only
[someArgs] remoteExec ['someCommand', 2]; // works
7erra - c
Posted on Mar 05, 2021 - 00:48 (UTC)
The remoteExec'ed function only has to exist on the target machine. For example:
// initPlayerLocal.sqf TAG_fnc_testRemote = { hint "Remote Exec Received"; };
// executed on a DEDICATED server remoteExec ["TAG_fnc_testRemote", -2];
Will display a hint for every client. This is especially useful for when the server is running a mod that is not required by clients.
Sa-Matra - c
Posted on Sep 19, 2024 - 08:33 (UTC)
It is not possible to use two negative owners to exclude two clients, you'll end up REing all clients:
args remoteExec ["func", [-2, -3]]; // Doesn't work, gonna execute on every client