Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Add JIP synchronised information)
m (Update w/ links)
 
(106 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Informative|Future [[Multiplayer Scripting]] page}}
[[Category: Sandbox]]
{{SideTOC}}
{{Feature|informative|To go on [[Initialisation Order]].}}
{{Stub}}
== The basics ==


* In Multiplayer, players are connected to a server that distributes information among them.
{| class="wikitable sortable align-center align-left-col-1"
* The server can be either a dedicated machine, or hosted by a player; in the latter it means the server can have a [[player]] unit.
|+ Order of Initialisation (use column sorting for respective machine order)
* Players can join a game ''after'' it started: they are considered "[[Join In Progress|JIP]]" and scripting should be adapted to them.
! rowspan="2" class="unsortable" style="text-align: center" | Task
! rowspan="2" | Exec Environment
! rowspan="1" colspan="5" class="unsortable" | Machine
|-
! Single Player
! Dedicated Server
! Hosted Server
! Multiplayer Client
! [[Multiplayer Scripting#Join In Progress|JIP]] MP Client


{{Informative|In Singleplayer, the game acts as a player-hosted server ({{Inline code|[[isServer]]}} returns {{Inline code|[[true]]}}).}}
|-
{{Warning|Some Multiplayer commands will '''not''' work in Singleplayer, such as {{Inline code|[[netId]]}} !}}
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>recompile</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are recompiled
| {{n/a}}
| 1 <!-- Single Player -->
| 1 <!-- Dedicated Server -->
| 1 <!-- Hosted Server -->
| 1 <!-- Multiplayer Client -->
| 1 <!-- JIP MP Client -->


|-
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>preInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 2 <!-- Single Player -->
| 2 <!-- Dedicated Server -->
| 2 <!-- Hosted Server -->
| 2 <!-- Multiplayer Client -->
| 2 <!-- JIP MP Client -->


== Locality ==
|-
| Object Init Event Handlers are called
| [[Scheduler#Unscheduled Environment|Unscheduled]]
| 3 <!-- Single Player -->
| 3 <!-- Dedicated Server -->
| 3 <!-- Hosted Server -->
| 3 <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


=== Definitions ===
* '''LOCAL''' is an attribute for the machine where the command/script/function is executed.
* '''REMOTE''' means '''non local'''. All players are remote units to a dedicated server, for example.
* [[:Category:Scripting_Commands|commands]] arguments and effects can be either '''local''' or '''global''':
{|
|style="padding-right: 0.5em;"|{{EffArg|cmd|arg|local}}
|a '''local''' argument means an argument that is processed on the machine where the command is executed
|-
|{{EffArg|cmd|arg|global}}
|a '''global''' argument means any unit, even a remote one
|-
|{{EffArg|cmd|eff|local}}
|a '''local''' effect means that the effect will only happen on the machine where the command is executed
|-
|-
|{{EffArg|cmd|eff|global}}
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor entity attributes]] are called<ref name="isPlayer"><sqf inline>isPlayer _entity</sqf> does not return [[true]] immediately. Once the entity has become a [[player]], it is transferred to the client.</ref>
|a '''global''' effect means that all the computers will receive it
| [[Scheduler#Unscheduled Environment|Unscheduled]]
|}
| 4 <!-- Single Player -->
See [[Locality in Multiplayer]] for more information.
| 4 <!-- Dedicated Server -->
| 4 <!-- Hosted Server -->
| {{Icon|unchecked}} <!-- Multiplayer Client -->
| {{Icon|unchecked}} <!-- JIP MP Client -->


=== Different machines ===
{|class="bikitable"
!Machine
!Conditions
|-
|Dedicated Server
|{{Inline code|[[isDedicated]]}}
|-
|Player Server
|{{Inline code|[[hasInterface]] && [[isServer]]}}
|-
|Client
|{{Inline code|[[hasInterface]] && not [[isServer]]}}
|-
|[[Join In Progress|JIP]] Client
|{{Inline code|[[hasInterface]] && [[didJIP]]}}
|-
|-
|[[Arma 3 Headless Client|Headless Client]]
| Object initialisation fields are called
|{{Inline code|not [[hasInterface]] && not [[isDedicated]]}}
| [[Scheduler#Unscheduled Environment|Unscheduled]]
|}
| 5 <!-- Single Player -->
* If you want to know if the current machine is a server (Dedicated Server or Player Server), use {{Inline code|[[isServer]]}}.
| 5 <!-- Dedicated Server -->
* If you want to know if the current machine has a player (Player Server included), use {{Inline code|[[hasInterface]]}}.
| 5 <!-- Hosted Server -->
{{Warning|
| 4 <!-- Multiplayer Client -->
* a [[Arma 3 Headless Client|Headless Client]] '''can''' be [[Join In Progress|JIP]]
| 3 <!-- JIP MP Client -->
* even if it is highly unlikely, a server '''can''' be [[Join In Progress|JIP]], too!}}


=== General information about locality ===
|- style="background-color: #95F0AD"
* a [[player]]'s unit is '''always''' local to the player's machine.
| [[Event Scripts#init.sqs|init.sqs]] is executed
** a dedicated server doesn't have a [[player]] unit ({{Inline code|[[isNull]] [[player]] {{codecomment|// returns [[true]]}}}})
|
** to know if a certain unit is ''a'' player, use [[isPlayer]]
| 6 <!-- Single Player -->
* an AI group with a player-leader will be local to the player's computer.
| <!-- Dedicated Server -->
** a subordinate player being in a player-lead group will remain local to its computer (see bulletpoint #1)
| <!-- Hosted Server -->
* a driven vehicle is always local to its driver (not the commander, not the gunner)
| <!-- Multiplayer Client -->
** editor-placed objects and empty vehicles are local to the server
| <!-- JIP MP Client -->
** editor-placed '''triggers''' are created on every machine unless specified otherwise ("Server Only" [[Eden Editor]] option ticked)
** units created with [[createUnit]] will be local to the computer that issued the command
** objects and vehicles created with [[createVehicle]] will be local to the computer that issued the command


=== Locality changes ===
|- style="background-color: #95F0AD"
* if the player-leader dies, the AI is transferred where the new leader is local (server in case of AI, client in case of another player)
| [[Event Scripts#init.sqf|init.sqf]] is executed
* [[join|joining]] AI units will change locality to the new leader's computer
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits">Note '''in single player''' that while the environment is [[Scheduler#Scheduled Environment|Scheduled]] ([[canSuspend]] returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an [[Scheduler#Unscheduled Environment|Unscheduled environment]] - infinite loops will freeze the game, [[uiSleep]] may pause the game for up to ~20s (postInit), [[waitUntil]] can cause catastrophic issues, etc.</ref>
* a driver gets in an empty vehicle, locality will change from server to player
| <!-- Single Player -->
* locality can also change in the event of a ||Team Switch]] or usage of [[selectPlayer]]  
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


=== Code examples ===
{|class="bikitable"
!Code
!Argu-ments
!Effect
!Description
|-
|{{Inline code|remoteUnit [[setDamage]] 1;}}
|align="center"|{{EffArg|cmd|arg|global}}
|align="center"|{{EffArg|cmd|eff|global}}
|Any unit (local or remote) will die, and all the computers will know
|-
|{{Inline code|localUnit [[addMagazine]] "30Rnd_556x45_STANAG";}}
|align="center"|{{EffArg|cmd|arg|local}}
|align="center"|{{EffArg|cmd|eff|global}}
|Only a local unit can have its inventory edited with this command, but all the machines will be notified: if a player looks into the localUnit inventory, the added magazine will be there
|-
|{{Inline code|remoteUnit [[setFace]] "Miller";}}
|align="center"|{{EffArg|cmd|arg|global}}
|align="center"|{{EffArg|cmd|eff|local}}
|Any unit (local or remote) can get its face changed, but the new face will not be propagated through the network. Only the local machine's player will see the effect of the command
{{Informative|This command should ideally be '''executed on every machine''', for example with:
[remoteUnit, "Miller"] [[remoteExec]] ["setFace", 0, true];
See [[#Remote Execution|Remote Execution]] paragraph for more information.}}
|-
|-
|{{Inline code|localCamera [[cameraEffect]] ["Internal", "Back"];}}
| Expressions of [[Eden Editor: Configuring Attributes|Eden Editor scenario attributes]] are called<ref name="playerCommandNotAvailable">[[player]] is not available immediately.</ref>
|align="center"|{{EffArg|cmd|arg|local}}
| [[Scheduler#Unscheduled Environment|Unscheduled]]
|align="center"|{{EffArg|cmd|eff|local}}
| <!-- Single Player -->
|Only a local camera can be entered, and of course only the local machine will see through this camera
| <!-- Dedicated Server -->
|}
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|- style="background-color: #95DEF0"
| Persistent functions are called
|
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== PublicVariable commands ==
PublicVariable commands allow to send '''global''' variables to specified machines.
* Network reception is guaranteed
* Short variable names should be used for network performance
* These commands shouldn't be used intensely for the same reason
{|class="bikitable"
!Command
!Effect
|-
|-
|[[publicVariable]]
| [[Modules]] are initialised
|Set/update a variable value from the local machine to all the other machines (including server)
|
|-
| <!-- Single Player -->
|[[publicVariableServer]]
| <!-- Dedicated Server -->
|Set/update a variable value '''from a client to the server'''
| <!-- Hosted Server -->
|-
| <!-- Multiplayer Client -->
|[[publicVariableClient]]
| {{Icon|unchecked}} <!-- JIP MP Client -->
|Set/update a variable value '''from the local machine''' (not necessarily the server) '''to a specific client'''<br />{{Important|The information will be lost if the targeted client disconnects!}}
|}


=== How it works ===
|- style="background-color: #DEF0AD"
The server has the variable {{Inline code|ABC_Score}} to send to everyone, it then uses {{Inline code|[[publicVariable]] "ABC_Score"}} (do not forget the quotes!)<br />
| [[Event Scripts#initServer.sqf|initServer.sqf]] is executed
This sends the variable name and value to the clients.
| [[Scheduler#Scheduled Environment|Scheduled]]
* If the variable is not yet declared on their machine, it will declare it as well.
| <!-- Single Player -->
* If the variable already exists, '''the value is overridden''' by the server's value.
| <!-- Dedicated Server -->
* If the variable changes again on the server, it has to be manually [[publicVariable]]'d once again!
| <!-- Hosted Server -->
* A [[Join In Progress|JIP]] player will synchronise '''server's''' public variables '''before''' executing '''init.sqf'''. See [[Initialization Order]] for more information.
| {{n/a}} <!-- Multiplayer Client -->
** A JIP player will '''not''' synchronise [[publicVariableClient]]-received variables after he disconnects/reconnects. Only server-known public variables sent with [[publicVariable]] will be synchronised.
| {{n/a}} <!-- JIP MP Client -->


|- style="background-color: #DEF0AD"
| [[Event Scripts#initPlayerLocal.sqf|initPlayerLocal.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== Remote Execution ==
|- style="background-color: #DEF0AD"
{{arma2}} introduced the (now obsolete) [[Multiplayer framework]], used as follow:
| [[Event Scripts#initPlayerServer.sqf|initPlayerServer.sqf]] is executed on the server
waitUntil{ not isNil "BIS_MPF_InitDone"; };
| [[Scheduler#Scheduled Environment|Scheduled]]
[nil, nil, rHINT, "Message to everyone!"] call RE;
| <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| ?? <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


{{arma3}} alpha introduced [[BIS_fnc_MP]]:
|-
["Message to everyone, including JIP players!", "hint", true, true] call BIS_fnc_MP;
| [[Arma 3: Functions Library|Functions]] with <syntaxhighlight lang="cpp" inline>postInit</syntaxhighlight> {{Link|Arma 3: Functions Library#Attributes 3|attribute}} are called
| [[Scheduler#Scheduled Environment|Scheduled]]<ref name="enginewaits"/>
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


{{Warning|These two methods above are considered '''OBSOLETE''' since {{arma3}} v1.50 introduced two engine commands: [[remoteExec]] and [[remoteExecCall]].}}
|- style="background-color: #95DEF0"
| [[Event Scripts#init.sqs|init.sqs]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


|- style="background-color: #95DEF0"
| [[Event Scripts#init.sqf|init.sqf]] is executed
| [[Scheduler#Scheduled Environment|Scheduled]]
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


'''{{arma3}} (&gt; v1.50):'''
|-
["Message to everyone, including JIP players!", 0, true] remoteExec ["hint"];
| [[remoteExec]]'s [[Multiplayer Scripting#Join In Progress|JIP]] queue
See [[Arma 3 Remote Execution]] for more information.
| {{n/a}}
| {{n/a}} <!-- Single Player -->
| {{n/a}} <!-- Dedicated Server -->
| {{n/a}} <!-- Hosted Server -->
| {{n/a}} <!-- Multiplayer Client -->
| 42 <!-- JIP MP Client -->


|- style="background-color: #EEE"
| ''Scenario going''
| {{n/a}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->


== Join In Progress ==
A [[Join In Progress|JIP]] player will have many information synchronised by the game.
{|class="bikitable"
!Information
!{{arma2}}
!{{arma3}}
|-
|-
|date/time
| [[Event Scripts#exit.sqf|exit.sqf]]
|align="center"|{{task/}}
|
|align="center"|{{task/}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|-
|-
|date/time + [[setDate]]/[[skipTime]]
| [[Event Scripts#exit.sqs|exit.sqs]]
|align="center"|{{task}}
|
|align="center"|{{task/}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|-
|-
|weather ([[overcast]], [[fog]])
| {{Link|Arma 3: Mission Event Handlers#Ended|"Ended" Mission Event Handler}}
|align="center"|{{task/}}
|
|align="center"|{{task/}}
| <!-- Single Player -->
| <!-- Dedicated Server -->
| <!-- Hosted Server -->
| <!-- Multiplayer Client -->
| <!-- JIP MP Client -->
 
|-
|-
|weather + [[setOvercast]]/[[setFog]]/[[setRain]]
| {{Link|Arma 3: Mission Event Handlers#MPEnded|"MPEnded" Mission Event Handler}}
|align="center"|{{task}}
|
|align="center"|{{task/}}
| <!-- Single Player -->
|-
| <!-- Dedicated Server -->
|time passed since mission start ([[time]] command)
| <!-- Hosted Server -->
|align="center"|{{task/}}
| <!-- Multiplayer Client -->
|align="center"|{{task/}}
| <!-- JIP MP Client -->
|-
 
|[[publicVariable]]-sent variables
|align="center"|{{task/}}
|align="center"|{{task/}}
|-
|[[setVariable]]-assigned variables (when alternative syntax's ''public'' parameter is set to true)
|align="center"|{{task/}}
|align="center"|{{task/}}
|-
|[[remoteExec]]- and [[remoteExecCall]]-executed code if ''JIP'' prerequisites are met
|align="center"|''N/A''
|align="center"|{{task/}}
|}
|}
See [[Join In Progress]] for more information.
== See also ==
* [[Arma 3 Headless Client|Headless Client]]
* [[Locality in Multiplayer]]
* [[:Category:Commands by effects and arguments locality|Commands by effects and arguments locality]]
** [[:Category:Commands requiring server side execution|Server-only commands]]
* [[Initialization Order]]
* [[Arma 3 Remote Execution]]




[[Category: Scripting Topics]]
== See Also ==


[[Category:Sandbox]]
* [[Arma 3: Functions Library]]<!--
* [[Arma 2: Functions Library]] -->
* [[Arma 3: Remote Execution]], [[BIS_fnc_MP]] <!-- keep? -->
* [[Eden Editor: Configuring Attributes|Eden Editor: Configuring Attributes]]
* [[Event Scripts]]
* [[Scheduler]]

Latest revision as of 00:29, 18 March 2024

Order of Initialisation (use column sorting for respective machine order)
Task Exec Environment Machine
Single Player Dedicated Server Hosted Server Multiplayer Client JIP MP Client
Functions with recompile attribute are recompiled N/A 1 1 1 1 1
Functions with preInit attribute are called Unscheduled 2 2 2 2 2
Object Init Event Handlers are called Unscheduled 3 3 3 3 Unchecked
Expressions of Eden Editor entity attributes are called[1] Unscheduled 4 4 4 Unchecked Unchecked
Object initialisation fields are called Unscheduled 5 5 5 4 3
init.sqs is executed 6
init.sqf is executed Scheduled[2]
Expressions of Eden Editor scenario attributes are called[3] Unscheduled
Persistent functions are called
Modules are initialised Unchecked
initServer.sqf is executed Scheduled N/A N/A
initPlayerLocal.sqf is executed Scheduled N/A
initPlayerServer.sqf is executed on the server Scheduled N/A ??
Functions with postInit attribute are called Scheduled[2]
init.sqs is executed Scheduled
init.sqf is executed Scheduled
remoteExec's JIP queue N/A N/A N/A N/A N/A 42
Scenario going N/A
exit.sqf
exit.sqs
"Ended" Mission Event Handler
"MPEnded" Mission Event Handler


See Also

  1. isPlayer _entity does not return true immediately. Once the entity has become a player, it is transferred to the client.
  2. 2.0 2.1 Note in single player that while the environment is Scheduled (canSuspend returns true), the engine seems to wait until the script is done executing, essentially behaving similarly to an Unscheduled environment - infinite loops will freeze the game, uiSleep may pause the game for up to ~20s (postInit), waitUntil can cause catastrophic issues, etc.
  3. player is not available immediately.