---
name: "onPlayerConnected"
type: command
status: ok
groups: ["Multiplayer", "Event Handlers"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": true}
source: https://community.bistudio.com/wiki/onPlayerConnected
revid: 369528
updated: 2024-09-15T18:22:20Z
---

# onPlayerConnected

*Command · Multiplayer, Event Handlers · Arma 3 v0.50 · introduced in Operation Flashpoint: Elite v1.00*

Locality: **server execution only**

## Description

This command will execute the provided code on the server whenever a player connects to a multiplayer session.

> [!NOTE]
> **Arma 3:** Since Arma 3 v1.58 a stackable MissionEventHandler is available and should be used: [PlayerConnected](../topics/Mission_Event_Handlers.md#playerconnected).
> Before that, the functions [BIS_fnc_addStackedEventHandler](../functions/BIS_fnc_addStackedEventHandler.md) and [BIS_fnc_removeStackedEventHandler](../functions/BIS_fnc_removeStackedEventHandler.md) should be used instead in order to keep compatibility between official and community content.

## Syntax

```sqf
onPlayerConnected code
```

**Parameters:**

- `code`: [String](../topics/String.md) or [Code](../topics/Code.md) - has access to the following variables:
  - **_id**: [Number](../topics/Number.md) - is the unique DirectPlay ID. Quite useless as the number is too big for in-built string representation and gets rounded. It is also the same id used for user placed markers.
  - **_uid**: [String](../topics/String.md) - is [getPlayerUID](../commands/getPlayerUID.md) of the joining player. In Arma 3 it is also the same as Steam ID.
  - **_name**: [String](../topics/String.md) - is [profileName](../commands/profileName.md) of the joining player.
  - Arma 3 v1.50 **_jip**: [Boolean](../topics/Boolean.md) - is a flag that indicates whether or not the player joined after the mission has started (**J**oined **I**n **P**rogress). [true](../commands/true.md) when the player is [JIP](../topics/Multiplayer_Scripting.md#join-in-progress), otherwise [false](../commands/false.md).
  - Arma 3 v1.50 **_owner**: [Number](../topics/Number.md) - is [owner](../commands/owner.md) id of the joining player. Can be used for kick or ban purposes or just for [publicVariableClient](../commands/publicVariableClient.md).
  - Arma 3 v1.96 **_idstr**: [String](../topics/String.md) - same as `_id` but in string format, so could be exactly compared to [user marker](../commands/allMapMarkers.md) ids.

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
onPlayerConnected "[_id, _name] execVM 'PlayerConnected.sqf';";
```

### Example 2

```sqf
onPlayerConnected { diag_log [_id, _uid, _name] };
```

### Example 3

From Arma 3 v1.49:

```sqf
onPlayerConnected {
    somevar = random 123;
    _owner publicVariableClient "somevar";
    // this will define "somevar" to a random value on the joining machine
};
```

## Multiplayer

> [!IMPORTANT]
> A player with the **_name** `__SERVER__` will also connect to a multiplayer game, executing *code*.

## See also

[onPlayerDisconnected](../commands/onPlayerDisconnected.md) · [didJIP](../commands/didJIP.md) · [didJIPOwner](../commands/didJIPOwner.md)

<sub>Source: [BI Community Wiki — onPlayerConnected](https://community.bistudio.com/wiki/onPlayerConnected) (revision 369528).</sub>
