Page tree
Skip to end of metadata
Go to start of metadata

Introduced in




Executes the code on all computers, where condition equals true.

Note: If a command is a "relative" action (for example, incrementally increasing damage, or moving something in steps), executing it on more than one machine has a cumulative effect, since it is executed several times. For example, if 10 machines are on the network, and the following command is executed, then the tank gets fully destroyed after publicExec runs: publicExec ["true","tank1 setDamage (getDamage tank1)+.1"]


Syntax:publicExec [condition, code, object, executeOnThisClient]
  • condition: String - Condition that must return true for the code to be executed.
  • code: String - Code that should be executed, if the condition is true.
  • object: Object, Array, or Group - The object (or group, in V3.5+), or an array containing multiples of either, which can be referred to in the condition  or code parameter, in _this (optional)
  • executeOnThisClient: Boolean - If true, then code is also executed on the current client. If false, it only executes on the other connected clients (optional, default: true).
Return Value:Nothing


Examples:Execute on all logged-in clients:
publicExec ["true","titleText ['You won','plain']"]

Execute on the machine, where object "tank1" is local:
publicExec ["local _this","_this setFuel 0",tank1]

Execute for all players on the "EAST" side:
publicExec ["side player == EAST","player setDammage 1"]

Execute only on server:
publicExec ["isServer","_this setVelocity [0,0,10]",_veh]

Additional Information

See also: local (Command), executeWhereLocal


Posted on Apr 30, 2014
While you can pass just a single object to the publicExec command. It's better to pass that object as an array instead, for example:

publicExec ["local (_this select 0)","(_this select 0) setFuel 0",[tank1]]

The reason being, if for some reason the object is no longer valid, the publicExec command will convert that null object to an empty array [] and pass it the condition and execution code. This can often happen with clients disconnecting from a Multi Player session, resulting in the following error:

Type Array, expected Object; CurrentValue: []

If you pass your single object as an array instead, the null object will be converted as follows [objNull]. Which in the majority of cases, will be processed without generating any errors or any adverse impact.

Posted on Nov 06, 2008
General Barron
Note that you can only pass an object or an array of objects in to the code's _this variable.

If you try to pass a null object, the object will NOT be passed. While this would be an odd thing to do, there could be a situation where a variable turns into a null object unexpectedly, and you then try to pass it into the code.

To pass other data types into the code, you need to use the format command to modify the code string. Example:

_num = random 1;
publicExec ["true", format["setOvercast %1", _num]];

You can only pass String, Number, Boolean, Array and side data types in this way.