Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Set "PublicVariable commands" presentation to tables)
m (Add local/global commands example and some other notes)
Line 10: Line 10:


{{Informative|In Singleplayer, the game acts as a player-hosted server ({{Inline code|[[isServer]]}} returns {{Inline code|[[true]]}}).}}
{{Informative|In Singleplayer, the game acts as a player-hosted server ({{Inline code|[[isServer]]}} returns {{Inline code|[[true]]}}).}}
{{Warning|Some commands will '''not''' work in Singleplayer, such as {{Inline code|[[netId]]}}!}}
{{Warning|Some Multiplayer commands will '''not''' work in Singleplayer, such as {{Inline code|[[netId]]}} !}}




Line 17: Line 17:
* '''LOCAL''' is an attribute for the machine where the command/script/function is executed.
* '''LOCAL''' is an attribute for the machine where the command/script/function is executed.
* '''REMOTE''' is an attribute for all the other machines. All clients are remote to a server, for example.
* '''REMOTE''' is an attribute for all the other machines. All clients are remote to a server, for example.
* A [[player]]'s unit is '''always''' local to the player's machine. A dedicated server doesn't have a [[player]] unit.
* [[:Category:Scripting_Commands|commands]] arguments and effects can be either '''local''' or '''global''':
* [[:Category:Scripting_Commands|commands]] arguments and effects can be either '''local''' or '''global''':
** a '''local''' argument means an argument that is processed on the machine where the command is executed
** a '''local''' argument means an argument that is processed on the machine where the command is executed
Line 22: Line 23:
** a '''local''' effect means that the effect will only happen on the machine where the command is executed
** a '''local''' effect means that the effect will only happen on the machine where the command is executed
** a '''global''' effect means that all the computers will receive it
** a '''global''' effect means that all the computers will receive it
=== Examples ===
{|class="bikitable"
!Code
!Arguments
!Effect
!Description
|-
|{{Inline code|remoteUnit [[setDamage]] 1;}}
|{{EffArg|cmd|arg|glob}}
|{{EffArg|cmd|eff|glob}}
|Any unit (local or remote) will die, and all the computers will know
|-
|{{Inline code|localUnit [[addMagazine]] "30Rnd_556x45_STANAG";}}
|{{EffArg|cmd|arg|loc}}
|{{EffArg|cmd|eff|glob}}
|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 [[addEventHandler]] ["FiredMan", { hint "remoteUnit fired"; }];}}
|{{EffArg|cmd|arg|glob}}
|{{EffArg|cmd|eff|loc}}
|An event handler can be added to any unit (local or remote), but the code will only execute on the machine that ran the code
|-
|{{Inline code|localCamera [[cameraEffect]] ["Internal", "Back"];}}
|{{EffArg|cmd|arg|loc}}
|{{EffArg|cmd|eff|loc}}
|Only a local camera can be entered, and of course only the local machine will see through this camera – no network traffic is generated here
|}
See [[Locality in Multiplayer]] for more information.
See [[Locality in Multiplayer]] for more information.


Line 71: Line 101:
* If the variable is not yet declared on their machine, it will declare it as well.
* If the variable is not yet declared on their machine, it will declare it as well.
* If the variable already exists, '''the value is overridden''' by the server's value.
* If the variable already exists, '''the value is overridden''' by the server's value.
* A [[Join In Progress|JIP]] player will synchronise public variables '''before''' executing '''init.sqf'''. See [[Initialization Order]] for more information.
* If the variable changes again on the server, it has to be manually [[publicVariable]]'d once again!
* A [[Join In Progress|JIP]] player will synchronise '''server's''' public variables '''before''' executing '''init.sqf'''. See [[Initialization Order]] for more information.
** A JIP player will '''not''' synchronise [[publicVariableClient]]-received variables after he disconnects/reconnects. Only server-known public variables sent with [[publicVariable]] will be synchronised.
 


== Network commands ==
== Network commands ==
Line 80: Line 113:
* [[remoteExec]]
* [[remoteExec]]
* [[remoteExecCall]]
* [[remoteExecCall]]




Line 87: Line 119:
* [[Locality in Multiplayer]]
* [[Locality in Multiplayer]]
* [[:Category:Commands_requiring_server_side_execution|Server-only commands]]
* [[:Category:Commands_requiring_server_side_execution|Server-only commands]]
* [[Initialization Order]]




[[Category:Sandbox]]
[[Category:Sandbox]]

Revision as of 02:35, 27 January 2019

Template:SideTOC Template:Stub

The basics

  • In Multiplayer, players are connected to a server that distributes information among them.
  • 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.
  • Players can join a game after it started: they are considered "JIP" and scripting should be adapted to them.
In Singleplayer, the game acts as a player-hosted server (isServer returns true).
Some Multiplayer commands will not work in Singleplayer, such as netId !


Locality

  • LOCAL is an attribute for the machine where the command/script/function is executed.
  • REMOTE is an attribute for all the other machines. All clients are remote to a server, for example.
  • A player's unit is always local to the player's machine. A dedicated server doesn't have a player unit.
  • commands arguments and effects can be either local or global:
    • a local argument means an argument that is processed on the machine where the command is executed
    • a global argument means any unit, even a remote one
    • a local effect means that the effect will only happen on the machine where the command is executed
    • a global effect means that all the computers will receive it

Examples

Code Arguments Effect Description
remoteUnit setDamage 1; Template:EffArg Template:EffArg Any unit (local or remote) will die, and all the computers will know
localUnit addMagazine "30Rnd_556x45_STANAG"; Template:EffArg Template:EffArg 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
remoteUnit addEventHandler ["FiredMan", { hint "remoteUnit fired"; }]; Template:EffArg Template:EffArg An event handler can be added to any unit (local or remote), but the code will only execute on the machine that ran the code
localCamera cameraEffect ["Internal", "Back"]; Template:EffArg Template:EffArg Only a local camera can be entered, and of course only the local machine will see through this camera – no network traffic is generated here

See Locality in Multiplayer for more information.

Different machines

Machine Conditions
Dedicated Server isDedicated
Player Server hasInterface && isServer
Client hasInterface && not isServer
JIP Client didJIP
Headless Client not hasInterface && not isDedicated
  • If you want to know if the current machine is a server (Dedicated Server or Player Server), use isServer.
  • If you want to know if the current machine has a player (Player Server included), use hasInterface.

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
Command Effect
publicVariable Set/update a variable value from the local machine to all the other machines (including server)
publicVariableServer Set/update a variable value from a client to the server
publicVariableClient Set/update a variable value from the local machine (not necessarily the server) to a specific client

How it works

The server has the variable ABC_Score to send to everyone, it then uses publicVariable "ABC_Score" (do not forget the quotes!)
This sends the variable name and value to the clients.

  • If the variable is not yet declared on their machine, it will declare it as well.
  • If the variable already exists, the value is overridden by the server's value.
  • If the variable changes again on the server, it has to be manually publicVariable'd once again!
  • A JIP player will synchronise server's public variables before executing init.sqf. See Initialization Order for more information.
    • A JIP player will not synchronise publicVariableClient-received variables after he disconnects/reconnects. Only server-known public variables sent with publicVariable will be synchronised.


Network commands


See also