Locality in Multiplayer
Entities in VBS2 are handled by one specific computer, which sends updates about this entity to other computers connected to the MP game.
A unit is said "local" when it is handled by the local computer.
To know if a unit is local, use the local script command.
The basic rules to determine locality are as follows:
server = The dedicated server or the client that is hosting the game
client = A game instance used by a player, normally each is on a separate computer
- The player's unit is always local to its client
- AI units are always local to the client of their leader
- A vehicle is always local to the client of its driver
- AI leaders are always local to the server, if placed in the mission editor
- AI units created after mission start via scripting will be local to the computer that issued the command
- Empty vehicles/objects placed in the mission editor are local to the server
- Empty vehicles/objects created after mission start via scripting (with createVehicle for example) are local to the machine that issued the command
Triggers and Waypoints
Commands executed in a trigger's or waypoint's "On Activation" field, will always be executed on all machines, even if the command normally only has a local effect, and requires the object to be local.
It is the equivalent of executing publicExec ["true","someAction"] (with the same cumulative effect as described in the publicExec article).
Effects of different localities
When using script commands in a MP scenario, be aware of the scope of these commands.
Some will only work with local objects, and/or the effect may be limited to the local machine.
It is also possible for a unit to change its locality during its lifetime. Typical cases are a player dying (his squad AI units are passed to server), use of a join command, or units or players entering or exiting vehicles.
The following icons in the command description specify any limitations:playMove)
To circumvent these limitations, the publicExec command can be used to specify where a command should be executed (e.g. on a specific machine, like the server, on every machine, or only on the machine where an object is local).