Running object initialization code on every machine

By Spooner and Mandoble

For that purpose, use the setVehicleInit command to set the init commands of your newly created units. This is similar to writing these commands in the init field of a unit placed in the editor, but setVehicleInit doesn't have any immediate effect. You may set the init field of one or many existing units by executing setVehicleInit, but then you must execute the processInitCommands command to actually execute all the commands configured with setVehicleInit.

For example:

_plane = createVehicle [_objectClass, _position, [], 0, "NONE"];
_plane setVehicleInit "eh = this addEventHandler [""IncomingMissile"",{_this execVM ""mando_missiles\mando_replacemissile.sqf""}];";
processInitCommands;

processInitCommands ensures that the configured init commands for the units are executed on every client connected, even these clients that connect after the command is executed (JIP).

This technique for sending information has the advantage that it is immediately recieved by all machines without needing to have a script polling a variable to see if data is being sent. Although this method is most often used on newly created objects, it can be used to run code on every machine at any stage in the lifetime of an object.