{"name":"onPlayerConnected","title":"onPlayerConnected","type":"command","url":"https://community.bistudio.com/wiki/onPlayerConnected","revid":369528,"updated":"2024-09-15T18:22:20Z","groups":["Multiplayer","Event Handlers"],"status":"ok","games":{"ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","locality":{"server_exec":true},"description":"This command will execute the provided code on the server whenever a player connects to a multiplayer session.\n\n> [!NOTE]\n> **Arma 3:** Since Arma 3 v1.58 a stackable MissionEventHandler is available and should be used: PlayerConnected.\n> Before that, the functions BIS_fnc_addStackedEventHandler and BIS_fnc_removeStackedEventHandler should be used instead in order to keep compatibility between official and community content.","syntaxes":[{"syntax":"onPlayerConnected code","params":[{"name":"code","type":"String or Code","description":"has access to the following variables:\n\n- **_id**: Number - 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.\n- **_uid**: String - is getPlayerUID of the joining player. In Arma 3 it is also the same as Steam ID.\n- **_name**: String - is profileName of the joining player.\n- Arma 3 v1.50 **_jip**: Boolean - is a flag that indicates whether or not the player joined after the mission has started (**J**oined **I**n **P**rogress). true when the player is JIP, otherwise false.\n- Arma 3 v1.50 **_owner**: Number - is owner id of the joining player. Can be used for kick or ban purposes or just for publicVariableClient.\n- Arma 3 v1.96 **_idstr**: String - same as `_id` but in string format, so could be exactly compared to user marker ids.","type_expr":"String | Code"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"code"}}],"examples":[{"code":["onPlayerConnected \"[_id, _name] execVM 'PlayerConnected.sqf';\";"]},{"code":["onPlayerConnected { diag_log [_id, _uid, _name] };"]},{"text":"From Arma 3 v1.49:\n\n```sqf\nonPlayerConnected {\n    somevar = random 123;\n    _owner publicVariableClient \"somevar\";\n    // this will define \"somevar\" to a random value on the joining machine\n};\n```","code":["onPlayerConnected {\n\tsomevar = random 123;\n\t_owner publicVariableClient \"somevar\";\n\t// this will define \"somevar\" to a random value on the joining machine\n};"]}],"multiplayer":"> [!IMPORTANT]\n> A player with the **_name** `__SERVER__` will also connect to a multiplayer game, executing *code*.","see_also":["onPlayerDisconnected","didJIP","didJIPOwner"]}