remoteExec: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Edited my note)
(Fix description, examples and notes)
Line 7: Line 7:


|descr= Asks the server to execute the given function or script command on the given target machine(s).
|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.
* 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.<br>
* Script commands are executed in the [[Scheduler#Unscheduled Environment|unscheduled environment]]; suspension is not allowed (see {{HashLink|#Example 7}}).
 
Read [[Arma 3: Remote Execution]] for more information about remote execution, security features and JIP techniques.
Read [[Arma 3: Remote Execution]] for more information about remote execution, security features and JIP techniques.


{{Feature|Informative|Just like [[remoteExecCall]], [[remoteExec]] can be used in SP; the behaviour is the same as in MP.}}
{{Feature|informative|[[remoteExec]]/[[remoteExecCall]] can be used in single player as well, as it is considered as player-hosted multiplayer.}}


{{Feature|Informative|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]]. Instead it is recommended to create a function which is then excecuted by [[remoteExec]] (or [[remoteExecCall]]).}}
{{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.}}


{{Feature|Informative|[[remoteExec]] executions are queued and are therefore executed in the same order on remote clients:
|mp= Remote executions are queued and are therefore executed in the same order on remote clients (see {{HashLink|#Example 8}}).
"Message 1" [[remoteExec]] ["[[systemChat]]"];
"Message 2" [[remoteExec]] ["[[systemChat]]"];
will result in
Message 1
Message 2
on all clients.}}


|s1= params [[remoteExec]] [functionName, targets, JIP]
|s1= params [[remoteExec]] [order, targets, JIP]


|p1= '''params''': [[Anything]] - The parameter(s) for the function / command specified in the '''functionName''' parameter.
|p1= '''params''': [[Anything]] - ''order''<nowiki/>'s parameter


|p2= '''functionName''': [[String]] - Function or command name.<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
While any function or command can be used here, only those allowed by [[Arma_3:_CfgRemoteExec|CfgRemoteExec]] will actually be executed.


|p3= '''targets''' (Optional, default: 0):
|p3= '''targets''' (Optional, default: 0):
* [[Number]] (See also [[Multiplayer_Scripting#Machine_network_ID|Machine network ID]]) -
* [[Number]] (See also [[Multiplayer_Scripting#Machine_network_ID|Machine network ID]]):
** '''0:''' The function / command will be executed globally, i.e. on the server and every connected client, including the machine where [[remoteExec]] originated.
** '''0:''' the order will be executed globally, i.e. on the server and every connected client, including the machine where [[remoteExec]] originated
** '''2:''' The function / command will only be executed on the server.
** '''2:''' the order will only be executed on the server
** '''Other number:''' The function / command will be executed on the machine where [[clientOwner]] matches the given number.
** '''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.
** '''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 function / command will be executed where the given object is [[Multiplayer Scripting#Locality|local]].
* [[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]].
* [[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 function / command will be executed on machines where the player is on the specified side.
* [[Side]] - The order will be executed on machines where the player is on the specified side
* [[Group]] - The function / command will be executed on machines where the player is in the specified group.
* [[Group]] - The order will be executed on machines where the player is in the specified group
* [[Array]] - Array of any combination of the types listed above.
* [[Array]] - Array of any combination of the types listed above


|p4= '''JIP''' (Optional, default: [[false]]):
|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.
* [[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]] -
* [[String]]:
** If the string is empty, it is interpreted as [[false]].
** 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).
** 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.
** 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.<br>When the object / group is deleted, the [[remoteExec]] statement is automatically removed from the JIP queue.
* [[Object]], [[Group]] or [[netId]] - The persistent execution of the [[remoteExec]] statement is attached to the given object or group.<br>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.<br>See also [[#Example 3|Example 3]] on how to remove statements from the JIP queue.
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= <div>
|r1=
* [[nil]] - In case of error.
* [[nil]] - In case of error.
* [[String]] - In case of success.
* [[String]] - In case of success.
** If the '''JIP''' parameter was [[false]] or an empty string, the return value is "".
** 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 [[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.</div>
** If the '''JIP''' parameter was an [[Object]], a [[Group]] or a [[netId]], the (corresponding) [[netId]] is returned.


|s2= [[remoteExec]] [functionName, targets, JIP]
|s2= [[remoteExec]] [functionName, targets, JIP]
Line 69: Line 63:
|r2= [[nil]] or [[String]] - See the main syntax above for more details.
|r2= [[nil]] or [[String]] - See the main syntax above for more details.


    <!-- Please try to avoid placing links within strings in these examples. -->
|x1= Execute {{ic|[[hint]] "Example 1";}} on various machines:
<code>"Example 1" [[remoteExec]] ["hint"]; {{cc|Executed on all machines.}}
"Example 1" [[remoteExec]] ["hint", 3]; {{cc|Executed only on the first connected client.}}
"Example 1" [[remoteExec]] ["hint", -2]; {{cc|Executed everywhere except on the server.}}</code>


|x2= Execute {{ic|[[hint]] "Example 2";}} on various machines and add it to the JIP queue:
<!-- Don't place links within strings in these examples. -->
<code>_result = "Example 2" [[remoteExec]] ["hint", -2, [[true]]]; {{cc|_result is a unique JIP ID, e.g. "3_1".}}
 
_result = "Example 2" [[remoteExec]] ["hint", -2, "My_JIP_ID"]; {{cc|_result is "My_JIP_ID".}}
 
_result = "Example 2" [[remoteExec]] ["hint", 0, MyObject]; {{cc|_result is the unique [[netId]] of MyObject, e.g. "2:3".}}</code>
|x1= How to write [[remoteExec]]/[[remoteExecCall]]:
Note that if there already was a statement with the JIP ID "My_JIP_ID" in the JIP queue, that statement has now been overwritten.
<code>{{Color|darkorange|hint}} {{Color|teal|"Hello"}};
{{cc|becomes}}
[{{Color|teal|"Hello"}}] [[remoteExec]] ["{{Color|darkorange|hint}}"];
 
{{Color|green|unit1}} {{Color|darkorange|setFace}} {{Color|teal|"Miller"}};
{{cc|becomes}}
[{{Color|green|unit1}}, {{Color|teal|"Miller"}}] [[remoteExec]] ["{{Color|darkorange|setFace}}"];
 
{{Color|darkorange|cutRsc}} {{Color|darkred|["", "BLACK OUT"]}};
{{cc|becomes}}
[{{Color|darkred|["", "BLACK OUT"]}}] [[remoteExec]] ["{{Color|darkorange|cutRsc}}"];
 
{{cc|functions, however, do not need double squared brackets}}
{{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>
 
|x2= send an order to specific machines:
<code>"message" [[remoteExec]] ["hint", 0]; {{cc|sends a hint message to everyone, identical to {{ic|"message" [[remoteExec]] ["hint"]}}}}
"message" [[remoteExec]] ["hint", -2]; {{cc|sends a hint message to everybody '''but''' the server}}
"message" [[remoteExec]] ["hint", -[[clientOwner]]]; {{cc|sends a hint message to everybody '''but''' the current machine}}
"message" [[remoteExec]] ["hint", myCar]; {{cc|sends a hint message where myCar is [[local]]}}
</code>


|x3= <!-- This example is referenced in the Syntax section. -->
|x3= <!-- This example is referenced in the Syntax section. -->
Remove statements from the JIP queue:
Add statements to the JIP queue:
<code>[[remoteExec]] ["", "My_JIP_ID"]; {{cc|The persistent statement with the JIP ID "My_JIP_ID" is removed from the JIP queue.}}
<code>[[private]] _jipId = ["mission state: the car is broken"] [[remoteExec]] ["systemChat", 0, [[true]]]; {{cc|adds the hint to the JIP queue and returns the JIP queue order id}}
[[remoteExec]] ["", MyObject]; {{cc|The persistent statement attached to MyObject is removed from the JIP queue.}}</code>
[[waitUntil]] { [[canMove]] _car };
[[remoteExec]] ["", _jipId]; {{cc|the systemChat order is removed from the JIP queue}}
</code>
 
<code>["mission state: the car is broken"] [[remoteExec]] ["systemChat", 0, _queueObject];
{{cc|...}}
[[remoteExec]] ["", _queueObject]; {{cc|the order attached to <tt>_queueObject</tt> is removed}}</code>
 
<code>[[private]] _jipId = ["mission state: the car is broken"] [[remoteExec]] ["systemChat", 0, "MY_JIP_ID"]; {{cc|_jipId is actually "MY_JIP_ID" now}}
[[waitUntil]] { [[canMove]] _car };
["mission state: the car is repaired"] [[remoteExec]] ["systemChat", 0, "MY_JIP_ID"]; {{cc|this order replaces the previous one}}
{{cc|...}}
[[remoteExec]] ["", "MY_JIP_ID]; {{cc|the order attached to <tt>_queueObject</tt> is removed}}</code>


|x4= Some more complex examples:
|x4= Some more complex examples:
Line 94: Line 118:
<nowiki>[</nowiki>[[player]], [<nowiki/>[[primaryWeapon]] [[player]], 1]] [[remoteExec]] ["setAmmo", MyGroup]; {{cc|Statement 2}}</code>
<nowiki>[</nowiki>[[player]], [<nowiki/>[[primaryWeapon]] [[player]], 1]] [[remoteExec]] ["setAmmo", MyGroup]; {{cc|Statement 2}}</code>
Both statements look very similar, but only Statement 1 has the intended effect. This is because in Statement 2, the arguments {{ic|[[player]]}} and {{ic|[[primaryWeapon]] [[player]]}} are not resolved on the target machine(s), but on the machine executing [[remoteExec]].
Both statements look very similar, but only Statement 1 has the intended effect. This is because in Statement 2, the arguments {{ic|[[player]]}} and {{ic|[[primaryWeapon]] [[player]]}} are not resolved on the target machine(s), but on the machine executing [[remoteExec]].
|x6= [[Multiplayer Scripting]] "trick"<br>
This {{ic| [0, -2] [[select]] [[isDedicated]]}} check is worth to avoid '''function''' server-side calculations only:
<code>"message" [[remoteExec]] ["hint", [0, -2] [[select]] [[isDedicated]]]; {{cc|the check is too costy to be worthy}}
"message" [[remoteExec]] ["hint"]; {{cc|the (dedicated) server will automatically ditch [[hint]] usage due to it not having an [[hasInterface|interface]]}}
["message"] [[remoteExec]] ["BIS_fnc_infoText"]; {{cc|not ideal - the function will still run on the dedicated server for nothing}}
["message"] [[remoteExec]] ["BIS_fnc_infoText", [0, -2] [[select]] [[isDedicated]]]; {{cc|ideal - the dedicated server will not run the code, a player-hosted server will}}</code>
|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]]
<code>[{ [[sleep]] 1 }] [[remoteExec]] ["call"]; {{cc|will throw an error: it is forbidden to use [[sleep]] (or [[waitUntil]], etc) in [[Scheduler#Unscheduled Environment|unscheduled environment]]}}</code>
|x8= <!-- This example is referenced in the Description section. -->
<code>"Message 1" [[remoteExec]] ["systemChat"];
"Message 2" [[remoteExec]] ["systemChat"];
{{cc|will result in}}
{{cc|- "Message 1"}}
{{cc|- "Message 2"}}
{{cc|in this exact order on all clients}}
</code>


|seealso= [[remoteExecCall]] [[remoteExecutedOwner]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[Arma 3: Remote Execution]] [[canSuspend]] [[BIS_fnc_MP]]
|seealso= [[remoteExecCall]] [[remoteExecutedOwner]] [[isRemoteExecuted]] [[isRemoteExecutedJIP]] [[Arma 3: Remote Execution]] [[canSuspend]] [[BIS_fnc_MP]]
}}
}}


{{GameCategory|arma3|Remote Execution}}
{{GameCategory|arma3|Remote Execution}}


<dl class="command_description">


<dt></dt>
{{Note
<dd class="notedate">Posted on December 29, 2015 - 20:28 (UTC)</dd>
|user= AgentRev
<dt class="note">[[User:AgentRevolution|AgentRev]]</dt>
|timestamp= 20151229202800
<dd class="note">
|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:
[[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>
<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:
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>
<code>!="\w+?_fnc_\w+? \[<nowiki/>[\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.
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 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>


<dt><dt>
{{Note
<dd class="notedate">Posted on May 28, 2016 - 20:51 (UTC)</dd>
|user= Pierre MGI
<dt class="note">[[User:R3vo|R3vo]]</dt>
|timestamp= 20170130183500
<dd class="note">
|text= <code>[some params] [[remoteExec]] ['some command',2,true];</code>  
While KK's solution works fine in sp missions and on dedicated servers, it will not work properly for hosted missions.<br>
will fail, as you can't use JIP and remoteExec on server only
'''Solution:'''
<code>[some params] [[remoteExec]] ['some command',2]; {{cc|works}}</code>
<code>[0,0.5] [[remoteExec]] ['[[fadeRadio]]',[0,-2] [[select]] [[isDedicated]],[[true]]];</code><br>
}}
Singleplayer: isDedicated returns false -> code is executed everywhere (0)<br>
Hosted: isDedicated returns false -> code is executed everywhere '''including host''' (0)<br>
Dedicated: isDedicated returns true -> code is executed everywhere '''excluding server'''(-2)
</dd>


<dt><dt>
{{Note
<dd class="notedate">Posted on Jan 30, 2017 - 18:35 (UTC)</dd>
|user= KC Grimes
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
|timestamp= 20180422152900
<dd class="note">
|text= It seems that only global functions can be executed, as opposed to local.  
<code>[some params] [[remoteExec]] ['some command',2,true];</code>
<code>''params'' [[remoteExec]] ["fnc_someScriptedFunction", targets, JIP]; {{cc|works}}</code>
will fail, as you can't use JIP and remoteExec on server only<br>
<code>[some params] [[remoteExec]] ['some command',2]; // works</code><br>
</dd>
 
<dt><dt>
<dd class="notedate">Posted on May 10, 2017 - 20:10 (UTC)</dd>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
To [[remoteExec]]:
<code>[[titleText]] ["Test Message", "PLAIN", 1];</code>
Use
<code><nowiki>[</nowiki>["Test Message", "PLAIN", 1]] [[remoteExec]] ["titleText"];</code>
</dd>
 
<dt><dt>
<dd class="notedate">Posted on April 22, 2018 - 15:29 (UTC)</dd>
<dt class="note">[[User:KC Grimes|KC Grimes]]</dt>
<dd class="note">
It seems that only global functions can be executed, as opposed to local.  
<code>&lt;params&gt; remoteExec ["fnc_someScriptedFunction", targets, JIP]; //Works</code>
<br>
<br>
<code>&lt;params&gt; remoteExec ["_fnc_someScriptedFunction", targets, JIP]; //Does not work</code>
<code>''params'' [[remoteExec]] ["_fnc_someScriptedFunction", targets, JIP]; {{cc|does not work}}</code>
</dd>
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on March 5, 2021 - 00:48 (UTC)</dd>
|user= 7erra
<dt class="note">[[User:7erra|7erra]]</dt>
|timestamp= 20210305004800
<dd class="note">
|text= The [[remoteExec]]'ed function only has to exist on the target machine. For example:
The [[remoteExec]]'ed function only has to exist on the target machine. For example:
<code>{{cc|initPlayerLocal.sqf}}
<code>{{cc|initPlayerLocal.sqf}}
TAG_fnc_testRemote {{=}} {
TAG_fnc_testRemote = {
[[hint]] "Remote Exec Received";
[[hint]] "Remote Exec Received";
};</code>
};</code>
<code>{{cc|Execute on dedicated server:}}
<code>{{cc|Execute on '''dedicated''' server:}}
[] [[remoteExec]] ["TAG_fnc_testRemote", -2];</code>
[] [[remoteExec]] ["TAG_fnc_testRemote", -2];</code>
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.
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>
<dt></dt>
<dd class="notedate">Posted on June 26, 2021 - 08:46 (UTC)</dd>
<dt class="note">[[User:1Dragster|1Dragster]]</dt>
<dd class="note">
Returning an example for scripted commands:
<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>
</dd>
</dl>
{{Note
|user= Leopard20
|timestamp= 20211104113126
|text= Note that {{ic|[code] [[remoteExec]] ["call"]}} is '''unscheduled''', even if the current environment is scheduled. For example, the following code will result in an error:
<code>[] [[spawn]] {
    [{[[sleep]] 1; [[hint]] "Hello";}] [[remoteExec]] ["call"];
}</code>
But it would be valid without [[remoteExec]] (see [[Scheduler|Scheduler]]):
<code>[] [[spawn]] {
    [[call]] {[[sleep]] 1; [[hint]] "Hello";}
}</code>
}}
}}

Revision as of 15:38, 5 November 2021

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.
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 - order's parameter
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
    • 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
  • 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.
    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.
    • 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 (Optional, default: 0): Number, Object, String, Side, Group or Array - See the main syntax above for more details.
JIP (Optional, default: false): Boolean, String, Object, Group or netId - 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"]; unit1 setFace "Miller"; // becomes [unit1, "Miller"] remoteExec ["setFace"]; cutRsc ["", "BLACK OUT"]; // becomes [["", "BLACK OUT"]] remoteExec ["cutRsc"]; // 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 "message" remoteExec ["hint", -clientOwner]; // sends a hint message to everybody but the current machine "message" remoteExec ["hint", myCar]; // sends a hint message where myCar is local
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 order attached to _queueObject is removed
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: Trying to execute player setAmmo [primaryWeapon player, 1]; (on machines where the player is in MyGroup). Consider the following statements: {player setAmmo [primaryWeapon player, 1];} remoteExec ["call", MyGroup]; // Statement 1 [player, [primaryWeapon player, 1]] remoteExec ["setAmmo", MyGroup]; // Statement 2 Both statements look very similar, but only Statement 1 has the intended effect. This is because in Statement 2, the arguments player and primaryWeapon player are not resolved on the target machine(s), but on the machine executing remoteExec.
Example 6:
Multiplayer Scripting "trick"
This [0, -2] select isDedicated check is worth to avoid function server-side calculations only: "message" remoteExec ["hint", [0, -2] select isDedicated]; // the check is too costy to be worthy "message" remoteExec ["hint"]; // the (dedicated) server will automatically ditch hint usage due to it not having an interface ["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
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 all clients

Additional Information

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

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)
[some params] remoteExec ['some command',2,true]; will fail, as you can't use JIP and remoteExec on server only [some params] remoteExec ['some command',2]; // works
KC Grimes - c
Posted on Apr 22, 2018 - 15:29 (UTC)
It seems that only global functions can be executed, as opposed to local. params remoteExec ["fnc_someScriptedFunction", targets, JIP]; // works
params remoteExec ["_fnc_someScriptedFunction", targets, JIP]; // does not work
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"; }; // Execute on 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.