{"name":"onPlayerConnected","operator":null,"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","replaced_by":[],"games":[{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":true},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"code","type":"String or Code","optional":false,"default":null,"description":"has access to the following variables:\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.","types":["String","Code"],"since":null,"text":"code: String or Code - has access to the following variables:\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."}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"unary","operator":null,"left":null,"right":{"text":"code","types":["String","Code"]}}],"examples":[{"text":"```sqf\nonPlayerConnected \"[_id, _name] execVM 'PlayerConnected.sqf';\";\n```","code":["onPlayerConnected \"[_id, _name] execVM 'PlayerConnected.sqf';\";"]},{"text":"```sqf\nonPlayerConnected { diag_log [_id, _uid, _name] };\n```","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*.","problems":null,"aliases":[],"see_also":["onPlayerDisconnected","didJIP","didJIPOwner"],"notes":[],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Event Handlers","Command Group: Multiplayer","Introduced with Operation Flashpoint: Elite version 1.00","Operation Flashpoint: Elite: New Scripting Commands","Operation Flashpoint: Elite: Scripting Commands","Scripting Commands","Scripting Commands: Server Execution","Take On Helicopters: Scripting Commands"]}