Difference between revisions of "onPlayerConnected"

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Added: MP behaviour description.)
m (Text replacement - "{{Command " to "{{RV|type=command ")
 
(61 intermediate revisions by 19 users not shown)
Line 1: Line 1:
{{Command|= Comments
+
{{RV|type=command
____________________________________________________________________________________________
 
  
| arma |= Game name
+
| arma1
  
|1.00|= Game version
+
|1.00
____________________________________________________________________________________________
 
  
| This statement is launched whenever a player is connected to a MP session. Variables _id and _name are set. |= Description
+
|gr1 = Multiplayer
____________________________________________________________________________________________
 
  
| '''onPlayerConnected''' statement |= Syntax
+
|gr2= Event Handlers
  
|p1= statement: [[String]] |= Parameter 1
+
|serverExec= server |Exec=
  
| [[Nothing]] |= Return value
+
| This command will execute attached code whenever a player is connected to a MP session. The code will receive a number of special variables:
 +
* '''_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.
 +
* '''_uid''': [[String]] - is [[getPlayerUID]] of the joining player. In Arma 3 it is also the same as Steam ID.
 +
* '''_name''': [[String]] - is [[profileName]] of the joining player.
 +
* '''_jip''': (''since Arma 3 v1.49'') [[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 [[Multiplayer Scripting#Join In Progress|JIP]], otherwise [[false]].
 +
* '''_owner''': (''since Arma 3 v1.49'') [[Number]] - is [[owner]] id of the joining player. Can be used for kick or ban purposes or just for [[publicVariableClient]].
 +
* '''_idstr''': (''since Arma 3 v1.95'') [[String]] - same as <tt>_id</tt> but in string format, so could be exactly compared to [[allMapMarkers | user marker]] ids.<br><br>
 +
{{Feature|arma3 | Since '''Arma 3''' ''v1.57'' a stackable MissionEventHandler is available and should be used: [[Arma_3:_Event_Handlers/addMissionEventHandler#PlayerConnected|PlayerConnected]].<br>
 +
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.}}
  
|mp= The ''statement'' is executed only on the server, not on the joining player's computer, nor on any other client.
+
| [[onPlayerConnected]] code
This happens even if '''onPlayerConnected''' was issued on all machines. |=
 
  
| [[onPlayerDisconnected]] |= See also
+
|p1= code: [[String]] or [[Code]]
  
}}
+
| [[Nothing]]
 +
 
 +
|x1= <code>[[onPlayerConnected]] "[_id, _name] [[execVM]] ""PlayerConnected.sqf""";</code>
 +
 
 +
|x2= <code>[[onPlayerConnected]] { [[diag_log]] [_id, _uid, _name] };</code>
 +
 
 +
|x3= From '''{{arma3}}''' v1.49:
 +
<code>[[onPlayerConnected]] {
 +
somevar = [[random]] 123;
 +
_owner [[publicVariableClient]] "somevar";
 +
{{cc|this will set somevar}}
 +
{{cc|joining player PC to a random value}}
 +
};</code>
 +
 
 +
|x4= From '''{{arma3}}''' v1.49:
 +
<code>[[onPlayerConnected]] { isJip = _jip; _owner [[publicVariableClient]] "isJip" };
 +
{{cc|Each player will now have variable isJip containing individual JIP info}}</code>
  
<h3 style="display:none">Notes</h3>
+
|mp= The ''statement'' is executed only on the server, not on the joining player's computer, nor on any other client.<br>
<dl class="command_description">
+
This happens even if '''onPlayerConnected''' was issued on all machines. <br>
<!-- Note Section BEGIN -->
+
Note that there is a player with the '''_name''' called __SERVER__ which will also connect to a multiplayer game, executing ''code''. |Multiplayer=
  
<!-- Note Section END -->
+
| [[onPlayerDisconnected]], [[didJIP]], [[didJIPOwner]]
</dl>
+
}}
  
<h3 style="display:none">Bottom Section</h3>
 
  
[[Category:Scripting Commands|ONPLAYERCONNECTED]]
+
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP Elite |ONPLAYERCONNECTED]]
+
{{GameCategory|ofpe|Scripting Commands}}
[[Category:Scripting Commands ArmA|ONPLAYERCONNECTED]]
+
{{GameCategory|arma1|Scripting Commands}}
 +
{{GameCategory|arma2|Scripting Commands}}
 +
{{GameCategory|arma3|Scripting Commands}}
 +
{{GameCategory|tkoh|Scripting Commands}}

Latest revision as of 11:05, 23 January 2021

Introduced with Armed Assault version 1.001.00This scripting command must be executed on the server to work properly in multiplayer
Hover & click on the images for descriptions

Description

Description:
This command will execute attached code whenever a player is connected to a MP session. The code will receive a number of special variables:
  • _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.
  • _uid: String - is getPlayerUID of the joining player. In Arma 3 it is also the same as Steam ID.
  • _name: String - is profileName of the joining player.
  • _jip: (since Arma 3 v1.49) Boolean - is a flag that indicates whether or not the player joined after the mission has started (Joined In Progress). true when the player is JIP, otherwise false.
  • _owner: (since Arma 3 v1.49) Number - is owner id of the joining player. Can be used for kick or ban purposes or just for publicVariableClient.
  • _idstr: (since Arma 3 v1.95) String - same as _id but in string format, so could be exactly compared to user marker ids.

Arma 3
Since Arma 3 v1.57 a stackable MissionEventHandler is available and should be used: PlayerConnected.
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.
Multiplayer:
The statement is executed only on the server, not on the joining player's computer, nor on any other client.
This happens even if onPlayerConnected was issued on all machines.
Note that there is a player with the _name called __SERVER__ which will also connect to a multiplayer game, executing code.

Syntax

Syntax:
onPlayerConnected code
Parameters:
code: String or Code
Return Value:
Nothing

Examples

Example 1:
onPlayerConnected "[_id, _name] execVM ""PlayerConnected.sqf""";
Example 2:
onPlayerConnected { diag_log [_id, _uid, _name] };
Example 3:
From Arma 3 v1.49: onPlayerConnected { somevar = random 123; _owner publicVariableClient "somevar"; // this will set somevar // joining player PC to a random value };
Example 4:
From Arma 3 v1.49: onPlayerConnected { isJip = _jip; _owner publicVariableClient "isJip" }; // Each player will now have variable isJip containing individual JIP info

Additional Information

See also:
onPlayerDisconnecteddidJIPdidJIPOwner
Groups:
MultiplayerEvent Handlers

Notes

i
Only post proven facts here. Report bugs on the Feedback Tracker and discuss on the Arma Discord or on the Forums.