Locality in Multiplayer

From BISim Wiki
Jump to: navigation, search

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.

Basic Rules

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

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:

arguments local.gif
The object the command is applied to has to be local to the machine the script is running on. (e.g. playMove)
arguments global.gif
The command can be applied to any object in the mission, independently from its locality (e.g. getPos)
effects local.gif
The command will only affect the object (or the effect will only be visible) on the local machine (e.g. hint)
effects global.gif
The command will affect an object independently from its locality (and will be visible throughout the network) (e.g. setPos)

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).

The demo mission MP_Triggers.zip shows how to use different publicExec methods to execute a command either on all or only specific machines.

Personal tools