Mission Event Handlers – Arma 3

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Some wiki formatting)
Line 1: Line 1:
__NOEDITSECTION__
{{TOC|side}}
{{TOC|side}}
{{Icon|localEffect|32}}
{{Icon|localEffect|32}}
== Description ==


Mission event handlers are specific EHs that are anchored to the running mission and automatically removed when mission is over.
Mission event handlers are specific EHs that are anchored to the running mission and automatically removed when mission is over.
Line 10: Line 6:
For all other available EHs see the [[Arma_3:_Event_Handlers|Event Handlers main page]].
For all other available EHs see the [[Arma_3:_Event_Handlers|Event Handlers main page]].


{{Feature|Informative|'''OnUser...''' mission event handlers in combination with [[getUserInfo]] provide a way to track server users from the very early stage of joining a server to the very last stage of leaving the server. All these event handlers are designed to be used server side and return unique user network id in [[String]] format as the first param. These ids could also be obtained via [[getPlayerID]] and [[allUsers]] script commands. There may be other params specific to each event. See:
{{Feature|Informative|'''OnUser...''' mission event handlers used in combination with [[getUserInfo]] provide a way to track server users from the very early stage of joining a server to the very last stage of leaving the server. All these event handlers are designed to be used server side and return unique user network id in [[String]] format as the first param. These ids could also be obtained via [[getPlayerID]] and [[allUsers]] script commands. There may be other params specific to each event. See:
{{Columns|3|
* {{HashLink|#OnUserConnected}}
* {{HashLink|#OnUserConnected}}
* {{HashLink|#OnUserDisconnected}}
* {{HashLink|#OnUserDisconnected}}
Line 17: Line 14:
* {{HashLink|#OnUserSelectedPlayer}}
* {{HashLink|#OnUserSelectedPlayer}}
* {{HashLink|#OnUserKicked}}
* {{HashLink|#OnUserKicked}}
}}
}}
}}


Line 33: Line 31:
{{ArgTitle|4|BuildingChanged|{{GVI|arma3|1.68}}}}
{{ArgTitle|4|BuildingChanged|{{GVI|arma3|1.68}}}}
Fired each time a building model changes, for example due to stages of destruction.
Fired each time a building model changes, for example due to stages of destruction.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["BuildingChanged", {
addMissionEventHandler ["BuildingChanged", {
params ["_from", "_to", "_isRuin"];
params ["_from", "_to", "_isRuin"];
}];
}];
</syntaxhighlight>
</sqf>


* from: [[Object]] - building it changes from
* from: [[Object]] - building it changes from
Line 45: Line 43:


{{ArgTitle|4|CommandModeChanged|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|CommandModeChanged|{{GVI|arma3|1.58}}}}
Executes assigned code when user switches to/from HC command mode ({{hl|Left Shift + Space}}). Stackable version of [[onCommandModeChanged]].
Executes assigned code when user switches to/from HC command mode ({{KeyboardShortcut|Left Shift|Space}}). Stackable version of [[onCommandModeChanged]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["CommandModeChanged", {
addMissionEventHandler ["CommandModeChanged", {
params ["_isHighCommand", "_isForced"];
params ["_isHighCommand", "_isForced"];
}];
}];
</syntaxhighlight>
</sqf>


* isHighCommand: [[Boolean]] - same as {{hl|_isHighCommand}} param
* isHighCommand: [[Boolean]] - same as {{hl|_isHighCommand}} param
Line 58: Line 56:
{{ArgTitle|4|ControlsShifted|{{GVI|arma3|1.00}}}}
{{ArgTitle|4|ControlsShifted|{{GVI|arma3|1.00}}}}
Triggers when control of a vehicle is shifted (pilot->co-pilot, co-pilot->pilot), usually when user performs an [[action]] such as [[action/Arma_3_Actions_List#TakeVehicleControl | TakeVehicleControl]], [[action/Arma_3_Actions_List#SuspendVehicleControl | SuspendVehicleControl]], [[action/Arma_3_Actions_List#UnlockVehicleControl | UnlockVehicleControl]], [[action/Arma_3_Actions_List#LockVehicleControl | LockVehicleControl]], or when [[enableCopilot]] command is used. This event handler will always fire on the PC where [[action]] is triggered as well as where the vehicle is [[Multiplayer Scripting#Locality|local]] at the time. When control of the vehicle is shifted, the locality of the vehicle changes to the locality of the new controller. Since Arma 3 v1.96 this EH is extended with additional params.
Triggers when control of a vehicle is shifted (pilot->co-pilot, co-pilot->pilot), usually when user performs an [[action]] such as [[action/Arma_3_Actions_List#TakeVehicleControl | TakeVehicleControl]], [[action/Arma_3_Actions_List#SuspendVehicleControl | SuspendVehicleControl]], [[action/Arma_3_Actions_List#UnlockVehicleControl | UnlockVehicleControl]], [[action/Arma_3_Actions_List#LockVehicleControl | LockVehicleControl]], or when [[enableCopilot]] command is used. This event handler will always fire on the PC where [[action]] is triggered as well as where the vehicle is [[Multiplayer Scripting#Locality|local]] at the time. When control of the vehicle is shifted, the locality of the vehicle changes to the locality of the new controller. Since Arma 3 v1.96 this EH is extended with additional params.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["ControlsShifted", {
addMissionEventHandler ["ControlsShifted", {
params ["_newController", "_oldController", "_vehicle", "_copilotEnabled", "_controlsUnlocked"];
params ["_newController", "_oldController", "_vehicle", "_copilotEnabled", "_controlsUnlocked"];
}];
}];
</syntaxhighlight>
</sqf>


* newController: [[Object]] - unit currently controlling the vehicle
* newController: [[Object]] - unit currently controlling the vehicle
Line 74: Line 72:
Runs the EH code each frame in unscheduled environment. Client side EH only (presence of UI).
Runs the EH code each frame in unscheduled environment. Client side EH only (presence of UI).
Will stop executing when UI loses focus (if user Alt+Tabs for example). Usually used with [[drawIcon3D]], [[drawLine3D]].
Will stop executing when UI loses focus (if user Alt+Tabs for example). Usually used with [[drawIcon3D]], [[drawLine3D]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["Draw3D", {
addMissionEventHandler ["Draw3D", {
// no params
// no params
}];
}];
</syntaxhighlight>
</sqf>




{{ArgTitle|4|EachFrame|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|EachFrame|{{GVI|arma3|1.58}}}}
Executes assigned code each frame. Stackable version of [[onEachFrame]].
Executes assigned code each frame. Stackable version of [[onEachFrame]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["EachFrame", {
addMissionEventHandler ["EachFrame", {
// no params
// no params
}];
}];
</syntaxhighlight>
</sqf>




{{ArgTitle|4|Ended|{{GVI|arma3|0.50}}}}
{{ArgTitle|4|Ended|{{GVI|arma3|0.50}}}}
Triggered when mission ends, either using trigger of type "End", [[endMission]] command, [[BIS_fnc_endMission]] function or [[Arma 3: Cheats#ENDMISSION|ENDMISSION]] cheat.
Triggered when mission ends, either using trigger of type "End", [[endMission]] command, [[BIS_fnc_endMission]] function or [[Arma 3: Cheats#ENDMISSION|ENDMISSION]] cheat.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["Ended", {
addMissionEventHandler ["Ended", {
params ["_endType"];
params ["_endType"];
}];
}];
</syntaxhighlight>
</sqf>


* endType: [[String]] - mission end type. Used in [[Debriefing]] among other things.
* endType: [[String]] - mission end type. Used in [[Debriefing]] among other things.


{{ArgTitle|4|MPEnded|{{GVI|arma3|1.60}}}}
{{ArgTitle|4|MPEnded|{{GVI|arma3|1.60}}}}
Triggered when the server switches off from "playing" state (mission ends, server closes, etc.) It's only for MP games, it is called on server and also on clients. It's not called on clients when client disconnects from server (and mission continues). This EH has no arguments passed to the code.
Triggered when the server switches off from "playing" state (mission ends, server closes, etc.) It's only for MP games, it is called on server and also on clients. It is not called on clients when client disconnects from server (and mission continues). This EH has no arguments passed to the code.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["MPEnded", {
addMissionEventHandler ["MPEnded", {
// no params
// no params
}];
}];
</syntaxhighlight>
</sqf>
If you need to execute client code on disconnect, you can use this instead:
If client code must be executed on disconnect, this code can be used instead:
0 [[spawn]]
<sqf>
{
0 spawn
[[waitUntil]] { ![[isNull]] [[findDisplay]] 46 };
{
[[findDisplay]] 46 [[displayAddEventHandler]] ["Unload",
waitUntil { !isNull findDisplay 46 };
{
findDisplay 46 displayAddEventHandler ["Unload",
{{cc|code here gets executed on the client at end of mission, whether due to player abort, loss of connection, or mission ended by server; might not work on headless clients}}
{
}];
// code here gets executed on the client at end of mission, whether due to player abort, loss of connection, or mission ended by server; might not work on headless clients
};
}];
};
</sqf>


{{ArgTitle|4|EntityKilled|{{GVI|arma3|1.56}}}}
{{ArgTitle|4|EntityKilled|{{GVI|arma3|1.56}}}}
Triggered when an entity is killed.  
Triggered when an entity is killed.  
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["EntityKilled", {
addMissionEventHandler ["EntityKilled", {
params ["_unit", "_killer", "_instigator", "_useEffects"];
params ["_unit", "_killer", "_instigator", "_useEffects"];
}];
}];
</syntaxhighlight>
</sqf>


* unit: [[Object]] - entity that was killed
* unit: [[Object]] - entity that was killed
Line 132: Line 132:


It's worth noting that ''instigator'' param is [[objNull]] during road kill. To work around this issue try:
It's worth noting that ''instigator'' param is [[objNull]] during road kill. To work around this issue try:
[[addMissionEventHandler]] ["EntityKilled",
<sqf>
{
addMissionEventHandler ["EntityKilled", {
[[params]] ["_killed", "_killer", "_instigator"];
params ["_killed", "_killer", "_instigator"];
[[if]] ([[isNull]] _instigator) [[then]] {_instigator = [[UAVControl]] [[vehicle]] _killer [[select]] 0}; {{cc|UAV/UGV player operated road kill}}
if]] (isNull _instigator) then { _instigator = UAVControl vehicle _killer select 0 }; // UAV/UGV player operated road kill
[[if]] ([[isNull]] _instigator) [[then]] {_instigator = _killer}; {{cc|player driven vehicle road kill}}
if (isNull _instigator) then { _instigator = _killer }; // player driven vehicle road kill
[[hint]] [[format]] ["Killed By %1", [[name]] _instigator];
hint format ["Killed By %1", name _instigator];
}];
}];
</sqf>


{{ArgTitle|4|EntityRespawned|{{GVI|arma3|1.56}}}}
{{ArgTitle|4|EntityRespawned|{{GVI|arma3|1.56}}}}
Triggered when an entity is respawned.
Triggered when an entity is respawned.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["EntityRespawned", {
addMissionEventHandler ["EntityRespawned", {
params ["_newEntity", "_oldEntity"];
params ["_newEntity", "_oldEntity"];
}];
}];
</syntaxhighlight>
</sqf>


* newEntity: [[Object]] - respawned entity
* newEntity: [[Object]] - respawned entity
Line 154: Line 155:
{{ArgTitle|4|ExtensionCallback|{{GVI|arma3|1.96}}}}
{{ArgTitle|4|ExtensionCallback|{{GVI|arma3|1.96}}}}
Triggered when an [[callExtension | extension]] calls provided function pointer with 3 params.
Triggered when an [[callExtension | extension]] calls provided function pointer with 3 params.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["ExtensionCallback", {
addMissionEventHandler ["ExtensionCallback", {
params ["_name", "_function", "_data"];
params ["_name", "_function", "_data"];
}];
}];
</syntaxhighlight>
</sqf>


* name: [[String]] - user provided param
* name: [[String]] - user provided param
Line 167: Line 168:
{{ArgTitle|4|GroupCreated|{{GVI|arma3|2.04}}}}
{{ArgTitle|4|GroupCreated|{{GVI|arma3|2.04}}}}
Triggered when a [[Group]] is created. Note that the group contains '''no''' units at that point!
Triggered when a [[Group]] is created. Note that the group contains '''no''' units at that point!
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["GroupCreated", {
addMissionEventHandler ["GroupCreated", {
params ["_group"];
params ["_group"];
}];
}];
</syntaxhighlight>
</sqf>


* group: [[Group]] - the created group
* group: [[Group]] - the created group
Line 178: Line 179:
{{ArgTitle|4|GroupDeleted|{{GVI|arma3|2.04}}}}
{{ArgTitle|4|GroupDeleted|{{GVI|arma3|2.04}}}}
Triggered when a [[Group]] is [[deleteGroup|manually]] or [[deleteGroupWhenEmpty|automatically]] deleted.
Triggered when a [[Group]] is [[deleteGroup|manually]] or [[deleteGroupWhenEmpty|automatically]] deleted.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["GroupDeleted", {
addMissionEventHandler ["GroupDeleted", {
params ["_group"];
params ["_group"];
}];
}];
</syntaxhighlight>
</sqf>


* group: [[Group]] - the deleted group
* group: [[Group]] - the deleted group
Line 189: Line 190:
{{ArgTitle|4|GroupIconClick|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|GroupIconClick|{{GVI|arma3|1.58}}}}
Executes assigned code when user clicks on the HC group icon on the map. If [[groupIconSelectable]] is [[true]], LMB clicking (firing) at the HC group icon on the HUD will also trigger the event. To set group icon selectable use [[setGroupIconsSelectable]]. Stackable version of [[onGroupIconClick]].
Executes assigned code when user clicks on the HC group icon on the map. If [[groupIconSelectable]] is [[true]], LMB clicking (firing) at the HC group icon on the HUD will also trigger the event. To set group icon selectable use [[setGroupIconsSelectable]]. Stackable version of [[onGroupIconClick]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["GroupIconClick", {
addMissionEventHandler ["GroupIconClick", {
params [
params [
Line 197: Line 198:
];
];
}];
}];
</syntaxhighlight>
</sqf>


* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
Line 212: Line 213:
{{ArgTitle|4|GroupIconOverEnter|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|GroupIconOverEnter|{{GVI|arma3|1.58}}}}
'''Continuously''' executes assigned code when user hovers with pointer over the HC group icon, either on the HUD or the main map. [[groupIconSelectable]] must be set to [[true]] for this EH to work at all. To set group icon selectable use [[setGroupIconsSelectable]]. When EH fires over the HUD icon, X and Y coordinates will change depending on the position of the pointer in relation to the icon area. When over main map, the X and Y do not change and indicate icon center. Stackable version of [[onGroupIconOverEnter]].
'''Continuously''' executes assigned code when user hovers with pointer over the HC group icon, either on the HUD or the main map. [[groupIconSelectable]] must be set to [[true]] for this EH to work at all. To set group icon selectable use [[setGroupIconsSelectable]]. When EH fires over the HUD icon, X and Y coordinates will change depending on the position of the pointer in relation to the icon area. When over main map, the X and Y do not change and indicate icon center. Stackable version of [[onGroupIconOverEnter]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["GroupIconOverEnter", {
addMissionEventHandler ["GroupIconOverEnter", {
params [
params [
Line 220: Line 221:
];
];
}];
}];
</syntaxhighlight>
</sqf>


* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
Line 234: Line 235:
{{ArgTitle|4|GroupIconOverLeave|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|GroupIconOverLeave|{{GVI|arma3|1.58}}}}
Executes assigned code when user moves the pointer away from HC group icon it was over. Fires either for on the HUD icons or the main map HC icons. [[groupIconSelectable]] must be set to [[true]] for this EH to work at all. To set group icon selectable use [[setGroupIconsSelectable]]. Stackable version of [[onGroupIconOverLeave]].
Executes assigned code when user moves the pointer away from HC group icon it was over. Fires either for on the HUD icons or the main map HC icons. [[groupIconSelectable]] must be set to [[true]] for this EH to work at all. To set group icon selectable use [[setGroupIconsSelectable]]. Stackable version of [[onGroupIconOverLeave]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["GroupIconOverLeave", {
addMissionEventHandler ["GroupIconOverLeave", {
params [
params [
Line 242: Line 243:
];
];
}];
}];
</syntaxhighlight>
</sqf>


* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
* is3D: [[Boolean]] - [[true]] if HUD icon, [[false]] if main map icon
Line 256: Line 257:
{{ArgTitle|4|HandleAccTime|{{GVI|arma3|1.90}}}}
{{ArgTitle|4|HandleAccTime|{{GVI|arma3|1.90}}}}
Fires when user changes time acceleration with +/- keys in SP or [[setAccTime]] command. If the code returns [[true]] the on-screen message confirming the change is not displayed. Doesn't fire if desired value is already set.
Fires when user changes time acceleration with +/- keys in SP or [[setAccTime]] command. If the code returns [[true]] the on-screen message confirming the change is not displayed. Doesn't fire if desired value is already set.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["HandleAccTime", {
addMissionEventHandler ["HandleAccTime", {
params ["_currentTimeAcc", "_prevTimeAcc", "_messageSuppressed"];
params ["_currentTimeAcc", "_prevTimeAcc", "_messageSuppressed"];
}];
}];
</syntaxhighlight>
</sqf>


* currentTimeAcc: [[Number]] - current value
* currentTimeAcc: [[Number]] - current value
Line 274: Line 275:
{{Feature | Informative | Only the last added EH with override will be used to override the message.}}
{{Feature | Informative | Only the last added EH with override will be used to override the message.}}
{{Feature | Warning | Do not put any of the chat related script command such as [[systemChat]], [[sideChat]], etc in this EH code as it would naturally cause recursion and the game will freeze.}}
{{Feature | Warning | Do not put any of the chat related script command such as [[systemChat]], [[sideChat]], etc in this EH code as it would naturally cause recursion and the game will freeze.}}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["HandleChatMessage", {
addMissionEventHandler ["HandleChatMessage", {
params ["_channel", "_owner", "_from", "_text", "_person", "_name", "_strID", "_forcedDisplay", "_isPlayerMessage", "_sentenceType", "_chatMessageType"];
params ["_channel", "_owner", "_from", "_text", "_person", "_name", "_strID", "_forcedDisplay", "_isPlayerMessage", "_sentenceType", "_chatMessageType"];
}];
}];
</syntaxhighlight>
</sqf>


* channel: [[Number]] - See [[Description.ext#disableChannels|radio channel indexes]] (16 for system chat message for example)
* channel: [[Number]] - See [[Description.ext#disableChannels|radio channel indexes]] (16 for system chat message for example)
Line 302: Line 303:
{{ArgTitle|4|HandleDisconnect|{{GVI|arma3|1.32}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|HandleDisconnect|{{GVI|arma3|1.32}}&nbsp;{{Icon|serverExec|32}}}}
Triggered when player disconnects from the game. Similar to [[onPlayerDisconnected]] event but can be stacked and contains the unit occupied by player before disconnect. Must be added on the server and triggers only on the server.
Triggered when player disconnects from the game. Similar to [[onPlayerDisconnected]] event but can be stacked and contains the unit occupied by player before disconnect. Must be added on the server and triggers only on the server.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["HandleDisconnect", {
addMissionEventHandler ["HandleDisconnect", {
params ["_unit", "_id", "_uid", "_name"];
params ["_unit", "_id", "_uid", "_name"];
true;
true;
}];
}];
</syntaxhighlight>
</sqf>


* unit: [[Object]] - unit formerly occupied by player
* unit: [[Object]] - unit formerly occupied by player
Line 318: Line 319:
{{ArgTitle|4|HCGroupSelectionChanged|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|HCGroupSelectionChanged|{{GVI|arma3|1.58}}}}
Executes assigned code when user selects available HC group ({{hl|F1, F2…}}). Stackable version of [[onHCGroupSelectionChanged]].
Executes assigned code when user selects available HC group ({{hl|F1, F2…}}). Stackable version of [[onHCGroupSelectionChanged]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["HCGroupSelectionChanged", {
addMissionEventHandler ["HCGroupSelectionChanged", {
params ["_group", "_isSelected"];
params ["_group", "_isSelected"];
}];
}];
</syntaxhighlight>
</sqf>


* group: [[Group]] - group selected (same as {{hl|_group}} param)
* group: [[Group]] - group selected (same as {{hl|_group}} param)
Line 331: Line 332:
Triggered when mission is loaded from save. <br>
Triggered when mission is loaded from save. <br>
{{Feature | Warning | "Loaded" event handler should be added <u>BEFORE</u> the mission is loaded from save. Placing it in a [[Arma 3: Functions Library|function]] with preInit {{=}} 1; usually does the trick.}}
{{Feature | Warning | "Loaded" event handler should be added <u>BEFORE</u> the mission is loaded from save. Placing it in a [[Arma 3: Functions Library|function]] with preInit {{=}} 1; usually does the trick.}}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["Loaded", {
addMissionEventHandler ["Loaded", {
params ["_saveType"];
params ["_saveType"];
}];
}];
</syntaxhighlight>
</sqf>


* saveType: [[String]] - save type, can be have following values:
* saveType: [[String]] - save type, can be have following values:
Line 345: Line 346:
{{ArgTitle|4|Map|{{GVI|arma3|1.62}}}}
{{ArgTitle|4|Map|{{GVI|arma3|1.62}}}}
Triggered when map is opened or closed either by user action or script command [[openMap]].
Triggered when map is opened or closed either by user action or script command [[openMap]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["Map", {
addMissionEventHandler ["Map", {
params ["_mapIsOpened", "_mapIsForced"];
params ["_mapIsOpened", "_mapIsForced"];
}];
}];
</syntaxhighlight>
</sqf>


* mapIsOpened: [[Boolean]] - [[true]] if map is opened
* mapIsOpened: [[Boolean]] - [[true]] if map is opened
Line 359: Line 360:
* No arguments can be passed to the assigned code in comparison with the original EH
* No arguments can be passed to the assigned code in comparison with the original EH
* Does not have engine default functionality override like the original EH
* Does not have engine default functionality override like the original EH
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["MapSingleClick", {
addMissionEventHandler ["MapSingleClick", {
params ["_units", "_pos", "_alt", "_shift"];
params ["_units", "_pos", "_alt", "_shift"];
}];
}];
</syntaxhighlight>
</sqf>


* units: [[Array]] - leader selected units, same as [[groupSelectedUnits]] (same as {{hl|_units}} param)
* units: [[Array]] - leader selected units, same as [[groupSelectedUnits]] (same as {{hl|_units}} param)
Line 372: Line 373:
{{ArgTitle|4|MarkerCreated|{{GVI|arma3|2.02}}}}
{{ArgTitle|4|MarkerCreated|{{GVI|arma3|2.02}}}}
Executes when a marker is created either by a user or via script command.
Executes when a marker is created either by a user or via script command.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["MarkerCreated", {
addMissionEventHandler ["MarkerCreated", {
params ["_marker", "_channelNumber", "_owner", "_local"];
params ["_marker", "_channelNumber", "_owner", "_local"];
}];
}];
</syntaxhighlight>
</sqf>
* marker: [[String]] - The name of the created marker, can be used with the [[:Category:Command_Group:_Markers|marker commands]]
* marker: [[String]] - The name of the created marker, can be used with the [[:Category:Command_Group:_Markers|marker commands]]
* channelNumber: [[Number]] - [[Channel IDs|Channel]] in which the marker was created
* channelNumber: [[Number]] - [[Channel IDs|Channel]] in which the marker was created
Line 384: Line 385:
{{ArgTitle|4|MarkerDeleted|{{GVI|arma3|2.02}}}}
{{ArgTitle|4|MarkerDeleted|{{GVI|arma3|2.02}}}}
Executes when a marker is deleted either by a user or via script command.
Executes when a marker is deleted either by a user or via script command.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["MarkerDeleted", {
addMissionEventHandler ["MarkerDeleted", {
params ["_marker", "_local"];
params ["_marker", "_local"];
}];
}];
</syntaxhighlight>
</sqf>
* marker: [[String]] - The name of the deleted marker
* marker: [[String]] - The name of the deleted marker
* {{GVI|arma3|2.04}} local: [[Boolean]] - [[true]] if the event originated locally, [[false]] if it came over the network
* {{GVI|arma3|2.04}} local: [[Boolean]] - [[true]] if the event originated locally, [[false]] if it came over the network
Line 395: Line 396:
Executes when a marker is changed.
Executes when a marker is changed.
{{Feature|Warning|Changing the marker in the EH code will lead to an infinite loop and the game will crash!}}
{{Feature|Warning|Changing the marker in the EH code will lead to an infinite loop and the game will crash!}}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["MarkerUpdated", {
addMissionEventHandler ["MarkerUpdated", {
params ["_marker", "_local"];
params ["_marker", "_local"];
}];
}];
</syntaxhighlight>
</sqf>
* marker: [[String]] - The name of the marker
* marker: [[String]] - The name of the marker
* {{GVI|arma3|2.04}} local: [[Boolean]] - [[true]] if the event originated locally, [[false]] if it came over the network
* {{GVI|arma3|2.04}} local: [[Boolean]] - [[true]] if the event originated locally, [[false]] if it came over the network
Line 406: Line 407:
{{ArgTitle|4|OnUserConnected|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserConnected|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code on user joining server.
Executes assigned code on user joining server.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserConnected", {
addMissionEventHandler ["OnUserConnected", {
params ["_networkId", "_clientStateNumber", "_clientState"];
params ["_networkId", "_clientStateNumber", "_clientState"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]]) - always 1
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]]) - always 1
Line 418: Line 419:
{{ArgTitle|4|OnUserDisconnected|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserDisconnected|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code on user leaving server.
Executes assigned code on user leaving server.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserDisconnected", {
addMissionEventHandler ["OnUserDisconnected", {
params ["_networkId", "_clientStateNumber", "_clientState"];
params ["_networkId", "_clientStateNumber", "_clientState"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]]) - always 0
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]]) - always 0
Line 430: Line 431:
{{ArgTitle|4|OnUserClientStateChanged|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserClientStateChanged|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code for every stage of user client state change.  
Executes assigned code for every stage of user client state change.  
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserClientStateChanged", {
addMissionEventHandler ["OnUserClientStateChanged", {
params ["_networkId", "_clientStateNumber", "_clientState"];
params ["_networkId", "_clientStateNumber", "_clientState"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]])
* clientStateNumber: [[Number]] - client state number (see [[getClientStateNumber]])
Line 442: Line 443:
{{ArgTitle|4|OnUserAdminStateChanged|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserAdminStateChanged|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code after user logs in, gets voted in or logs out as admin.
Executes assigned code after user logs in, gets voted in or logs out as admin.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserAdminStateChanged", {
addMissionEventHandler ["OnUserAdminStateChanged", {
params ["_networkId", "_loggedIn", "_votedIn"];
params ["_networkId", "_loggedIn", "_votedIn"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* loggedIn: [[Boolean]] - [[true]] if user logged in or got voted in as admin, [[false]] if logged out (see [[admin]])
* loggedIn: [[Boolean]] - [[true]] if user logged in or got voted in as admin, [[false]] if logged out (see [[admin]])
Line 454: Line 455:
{{ArgTitle|4|OnUserSelectedPlayer|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserSelectedPlayer|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code after player object is selected for user to take over control, the ownership information is broadcast and request to sync is made but the object is still owned by previous owner for a short time.  
Executes assigned code after player object is selected for user to take over control, the ownership information is broadcast and request to sync is made but the object is still owned by previous owner for a short time.  
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserSelectedPlayer", {
addMissionEventHandler ["OnUserSelectedPlayer", {
params ["_networkId", "_playerObject"];
params ["_networkId", "_playerObject"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* playerObject: [[Object]] - player object to be controlled by the user (see [[player]], [[selectPlayer]])
* playerObject: [[Object]] - player object to be controlled by the user (see [[player]], [[selectPlayer]])
{{Feature|Important|This is the earliest the player object is known, but it is not local to the user yet, so there is a wait time depending on network connection. The best approach to handle this matter and get notified about completion of the transfer of the ownership is to use [[Arma_3:_Event_Handlers#Local|"Local"]] entity event handler, like so:
{{Feature|Important|This is the earliest the player object is known, but it is not local to the user yet, so there is a wait time depending on network connection. The best approach to handle this matter and get notified about completion of the transfer of the ownership is to use [[Arma_3:_Event_Handlers#Local|"Local"]] entity event handler, like so:
<code>[[addMissionEventHandler]] ["OnUserSelectedPlayer",  
<sqf>
{
addMissionEventHandler ["OnUserSelectedPlayer", {
[[params]] ["_networkId", "_playerObject"];
params ["_networkId", "_playerObject"];
_playerObject [[addEventHandler]] ["Local",  
_playerObject [[addEventHandler]] ["Local",  
{
{
[[removeEventHandler]] ["Local", _thisEventHandler];
removeEventHandler ["Local", _thisEventHandler];
[[params]] ["_player"];
params ["_player"];
{{cc|code to handle _player}}
// code to handle _player
}];
}];
}];</code>
}];
</sqf>
Note that the player object would change locality again if the user goes to lobby.}}
Note that the player object would change locality again if the user goes to lobby.}}


Line 477: Line 479:
{{ArgTitle|4|OnUserKicked|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|OnUserKicked|{{GVI|arma3|2.06}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code after after a user has been kicked from the server providing kick reason. The possible values for 'kickTypeNumber' and 'kickType' are:<br>0 : {{hl|"TIMEOUT"}}, 1 : {{hl|"DISCONNECTED"}}, 2 : {{hl|"KICKED"}}, 3 : {{hl|"BANNED"}}, 4 : {{hl|"MISSING ADDON"}}, 5 : {{hl|"BAD CD KEY"}}, 6 : {{hl|"CD KEY IN USE"}}, 7 : {{hl|"SESSION LOCKED"}}, 8 : {{hl|"BATTLEYE"}}, 9 : {{hl|"STEAM CHECK"}}, 10 : {{hl|"DLC CONTENT"}}, 11 : {{hl|"GS TIMEOUT"}}, 12 : {{hl|"SCRIPT"}}, 13 : {{hl|"OTHER"}}
Executes assigned code after after a user has been kicked from the server providing kick reason. The possible values for 'kickTypeNumber' and 'kickType' are:<br>0 : {{hl|"TIMEOUT"}}, 1 : {{hl|"DISCONNECTED"}}, 2 : {{hl|"KICKED"}}, 3 : {{hl|"BANNED"}}, 4 : {{hl|"MISSING ADDON"}}, 5 : {{hl|"BAD CD KEY"}}, 6 : {{hl|"CD KEY IN USE"}}, 7 : {{hl|"SESSION LOCKED"}}, 8 : {{hl|"BATTLEYE"}}, 9 : {{hl|"STEAM CHECK"}}, 10 : {{hl|"DLC CONTENT"}}, 11 : {{hl|"GS TIMEOUT"}}, 12 : {{hl|"SCRIPT"}}, 13 : {{hl|"OTHER"}}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["OnUserKicked", {
addMissionEventHandler ["OnUserKicked", {
params ["_networkId", "_kickTypeNumber", "_kickType", "_kickReason", "_kickMessageIncReason"];
params ["_networkId", "_kickTypeNumber", "_kickType", "_kickReason", "_kickMessageIncReason"];
}];
}];
</syntaxhighlight>
</sqf>
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* networkId: [[String]] - user network id (see [[getPlayerID]], [[allUsers]])
* kickTypeNumber: [[Number]] - kick type number (see above)
* kickTypeNumber: [[Number]] - kick type number (see above)
Line 491: Line 493:
{{ArgTitle|4|PlayerConnected|{{GVI|arma3|1.58}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|PlayerConnected|{{GVI|arma3|1.58}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code when client joins the mission in MP. Stackable version of [[onPlayerConnected]].
Executes assigned code when client joins the mission in MP. Stackable version of [[onPlayerConnected]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["PlayerConnected",
addMissionEventHandler ["PlayerConnected", {
{
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
}];
}];
</syntaxhighlight>
</sqf>


* id: [[Number]] - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as {{hl|_id}} param)
* id: [[Number]] - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as {{hl|_id}} param)
Line 508: Line 509:
If dedicated server was started without '-autoInit' option and this EH was created on server, on first GUI client this EH also fires against server, but after first client.
If dedicated server was started without '-autoInit' option and this EH was created on server, on first GUI client this EH also fires against server, but after first client.
In mission's initServer.sqf:
In mission's initServer.sqf:
handlercon = [[addMissionEventHandler]] ["PlayerConnected",
<sqf>
{
addMissionEventHandler ["PlayerConnected", {
[[diag_log]] "Client connected";
diag_log "Client connected";
[[diag_log]] [[Magic Variables#this|_this]];
diag_log _this;
}];
}];
In RPT:
In RPT:
  2016/12/16, 15:39:09 "Client connected"
  2016/12/16, 15:39:09 "Client connected"
Line 526: Line 527:
{{ArgTitle|4|PlayerDisconnected|{{GVI|arma3|1.58}}&nbsp;{{Icon|serverExec|32}}}}
{{ArgTitle|4|PlayerDisconnected|{{GVI|arma3|1.58}}&nbsp;{{Icon|serverExec|32}}}}
Executes assigned code when client leaves the mission in MP. Stackable version of [[onPlayerDisconnected]].
Executes assigned code when client leaves the mission in MP. Stackable version of [[onPlayerDisconnected]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["PlayerDisconnected",
addMissionEventHandler ["PlayerDisconnected", {
{
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"];
}];
}];
</syntaxhighlight>
</sqf>


* id: [[Number]] - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as {{hl|_id}} param)
* id: [[Number]] - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as {{hl|_id}} param)
Line 543: Line 543:
{{ArgTitle|4|PlayerViewChanged|{{GVI|arma3|1.66}}}}
{{ArgTitle|4|PlayerViewChanged|{{GVI|arma3|1.66}}}}
Fired on player view change. Player view changes when player is changing body due to [[teamSwitch]], gets in out of a vehicle or operates UAV for example.
Fired on player view change. Player view changes when player is changing body due to [[teamSwitch]], gets in out of a vehicle or operates UAV for example.
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["PlayerViewChanged", {
addMissionEventHandler ["PlayerViewChanged", {
params [
params [
Line 550: Line 550:
];
];
}];
}];
</syntaxhighlight>
</sqf>


* oldUnit: [[Object]] - player body before EH fired
* oldUnit: [[Object]] - player body before EH fired
Line 563: Line 563:
Executes assigned code before the mission preload screen. Stackable version of [[onPreloadStarted]].<br>
Executes assigned code before the mission preload screen. Stackable version of [[onPreloadStarted]].<br>
{{Feature | important | This event handler also fires on client after user closes the main map. }}
{{Feature | important | This event handler also fires on client after user closes the main map. }}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["PreloadStarted", {
addMissionEventHandler ["PreloadStarted", {
// no params
// no params
}];
}];
</syntaxhighlight>
</sqf>




Line 573: Line 573:
Executes assigned code after the mission preload screen. Stackable version of [[onPreloadFinished]].<br>
Executes assigned code after the mission preload screen. Stackable version of [[onPreloadFinished]].<br>
{{Feature | important | This event handler also fires on client after user closes the main map. }}
{{Feature | important | This event handler also fires on client after user closes the main map. }}
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["PreloadFinished", {
addMissionEventHandler ["PreloadFinished", {
// no params
// no params
}];
}];
</syntaxhighlight>
</sqf>




==== SelectedActionPerformed ====
==== SelectedActionPerformed ====
RTM helicopter user action event
RTM helicopter user action event
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["SelectedActionPerformed", {
addMissionEventHandler ["SelectedActionPerformed", {
params ["_caller", "_target", "_enumNumber", "_actionId"];
params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
}];
</syntaxhighlight>
</sqf>


{{Feature|important|Limited or non-existent functionality}}
{{Feature|important|Limited or non-existent functionality}}
Line 593: Line 593:
==== SelectedActionChanged ====
==== SelectedActionChanged ====
RTM helicopter user action event
RTM helicopter user action event
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["SelectedActionChanged", {
addMissionEventHandler ["SelectedActionChanged", {
params ["_caller", "_target", "_enumNumber", "_actionId"];
params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
}];
</syntaxhighlight>
</sqf>


{{Feature|important|Limited or non-existent functionality}}
{{Feature|important|Limited or non-existent functionality}}
Line 604: Line 604:
==== SelectedRotorLibActionPerformed ====
==== SelectedRotorLibActionPerformed ====
RTM helicopter user action event
RTM helicopter user action event
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["SelectedRotorLibActionPerformed", {
addMissionEventHandler ["SelectedRotorLibActionPerformed", {
params ["_caller", "_target", "_enumNumber", "_actionId"];
params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
}];
</syntaxhighlight>
</sqf>


{{Feature|important|Works only for key press combination {{hl|RightCtrl}} + {{hl|W}}, which is the binding for helicopter wheels brakes. It fires with or without Advanced Flight Model enabled. The enum number returned is 4 and 5, probably because the enum is structured like this:<br>
{{Feature|important|Works only for key press combination {{hl|RightCtrl}} + {{hl|W}}, which is the binding for helicopter wheels brakes. It fires with or without Advanced Flight Model enabled. The enum number returned is 4 and 5, probably because the enum is structured like this:<br>
Line 622: Line 622:
==== SelectedRotorLibActionChanged ====
==== SelectedRotorLibActionChanged ====
RTM helicopter user action event
RTM helicopter user action event
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["SelectedRotorLibActionChanged", {
addMissionEventHandler ["SelectedRotorLibActionChanged", {
params ["_caller", "_target", "_enumNumber", "_actionId"];
params ["_caller", "_target", "_enumNumber", "_actionId"];
}];
}];
</syntaxhighlight>
</sqf>


{{Feature|important|Limited or non-existent functionality}}
{{Feature|important|Limited or non-existent functionality}}
Line 633: Line 633:
{{ArgTitle|4|TeamSwitch|{{GVI|arma3|1.58}}}}
{{ArgTitle|4|TeamSwitch|{{GVI|arma3|1.58}}}}
Executes assigned code when player teamswitches. Stackable version of [[onTeamSwitch]].
Executes assigned code when player teamswitches. Stackable version of [[onTeamSwitch]].
<syntaxhighlight lang="cpp">
<sqf>
addMissionEventHandler ["TeamSwitch", {
addMissionEventHandler ["TeamSwitch", {
params ["_previousUnit", "_newUnit"];
params ["_previousUnit", "_newUnit"];
}];
}];
</syntaxhighlight>
</sqf>


* previousUnit: [[Object]] - switching from unit (same as {{hl|_from}} param)
* previousUnit: [[Object]] - switching from unit (same as {{hl|_from}} param)

Revision as of 13:00, 27 March 2022

LELocal

Mission event handlers are specific EHs that are anchored to the running mission and automatically removed when mission is over. These events fire only on the machine where they have been added.
For all other available EHs see the Event Handlers main page.

OnUser... mission event handlers used in combination with getUserInfo provide a way to track server users from the very early stage of joining a server to the very last stage of leaving the server. All these event handlers are designed to be used server side and return unique user network id in String format as the first param. These ids could also be obtained via getPlayerID and allUsers script commands. There may be other params specific to each event. See:


Related Commands


Events

BuildingChanged

Fired each time a building model changes, for example due to stages of destruction.

addMissionEventHandler ["BuildingChanged", { params ["_from", "_to", "_isRuin"]; }];

  • from: Object - building it changes from
  • to: Object - building it changes to
  • isRuin: Boolean - true if changes to ruins


CommandModeChanged

Executes assigned code when user switches to/from HC command mode (Left Shift + Space). Stackable version of onCommandModeChanged.

addMissionEventHandler ["CommandModeChanged", { params ["_isHighCommand", "_isForced"]; }];

  • isHighCommand: Boolean - same as _isHighCommand param
  • isForced: Boolean - true if command mode was forced


ControlsShifted

Triggers when control of a vehicle is shifted (pilot->co-pilot, co-pilot->pilot), usually when user performs an action such as TakeVehicleControl, SuspendVehicleControl, UnlockVehicleControl, LockVehicleControl, or when enableCopilot command is used. This event handler will always fire on the PC where action is triggered as well as where the vehicle is local at the time. When control of the vehicle is shifted, the locality of the vehicle changes to the locality of the new controller. Since Arma 3 v1.96 this EH is extended with additional params.

addMissionEventHandler ["ControlsShifted", { params ["_newController", "_oldController", "_vehicle", "_copilotEnabled", "_controlsUnlocked"]; }];

  • newController: Object - unit currently controlling the vehicle
  • oldController: Object - unit previously controlling the vehicle
  • vehicle: Object - the vehicle for which controls shifted
  • copilotEnabled: Boolean - true if copilot is enabled
  • controlsUnlocked: Boolean - true if controls are unlocked


Draw3D

Runs the EH code each frame in unscheduled environment. Client side EH only (presence of UI). Will stop executing when UI loses focus (if user Alt+Tabs for example). Usually used with drawIcon3D, drawLine3D.

addMissionEventHandler ["Draw3D", { // no params }];


EachFrame

Executes assigned code each frame. Stackable version of onEachFrame.

addMissionEventHandler ["EachFrame", { // no params }];


Ended

Triggered when mission ends, either using trigger of type "End", endMission command, BIS_fnc_endMission function or ENDMISSION cheat.

addMissionEventHandler ["Ended", { params ["_endType"]; }];

MPEnded

Triggered when the server switches off from "playing" state (mission ends, server closes, etc.) It's only for MP games, it is called on server and also on clients. It is not called on clients when client disconnects from server (and mission continues). This EH has no arguments passed to the code.

addMissionEventHandler ["MPEnded", { // no params }];
If client code must be executed on disconnect, this code can be used instead:
0 spawn { waitUntil { !isNull findDisplay 46 }; findDisplay 46 displayAddEventHandler ["Unload", { // code here gets executed on the client at end of mission, whether due to player abort, loss of connection, or mission ended by server; might not work on headless clients }]; };

EntityKilled

Triggered when an entity is killed.

addMissionEventHandler ["EntityKilled", { params ["_unit", "_killer", "_instigator", "_useEffects"]; }];

  • unit: Object - entity that was killed
  • killer: Object - the killer (vehicle or person)
  • Arma 3 logo black.png1.66 instigator: Object - person who pulled the trigger
  • Arma 3 logo black.png1.68 useEffects: Boolean - same as useEffects in setDamage alt syntax

It's worth noting that instigator param is objNull during road kill. To work around this issue try:

addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if]] (isNull _instigator) then { _instigator = UAVControl vehicle _killer select 0 }; // UAV/UGV player operated road kill if (isNull _instigator) then { _instigator = _killer }; // player driven vehicle road kill hint format ["Killed By %1", name _instigator]; }];

EntityRespawned

Triggered when an entity is respawned.

addMissionEventHandler ["EntityRespawned", { params ["_newEntity", "_oldEntity"]; }];

  • newEntity: Object - respawned entity
  • oldEntity: Object - corpse/wreck


ExtensionCallback

Triggered when an extension calls provided function pointer with 3 params.

addMissionEventHandler ["ExtensionCallback", { params ["_name", "_function", "_data"]; }];

  • name: String - user provided param
  • function: String - user provided param
  • data: String - user provided param


GroupCreated

Triggered when a Group is created. Note that the group contains no units at that point!

addMissionEventHandler ["GroupCreated", { params ["_group"]; }];

  • group: Group - the created group


GroupDeleted

Triggered when a Group is manually or automatically deleted.

addMissionEventHandler ["GroupDeleted", { params ["_group"]; }];

  • group: Group - the deleted group


GroupIconClick

Executes assigned code when user clicks on the HC group icon on the map. If groupIconSelectable is true, LMB clicking (firing) at the HC group icon on the HUD will also trigger the event. To set group icon selectable use setGroupIconsSelectable. Stackable version of onGroupIconClick.

addMissionEventHandler ["GroupIconClick", { params [ "_is3D", "_group", "_waypointId", "_mouseButton", "_posX", "_posY", "_shift", "_control", "_alt" ]; }];

  • is3D: Boolean - true if HUD icon, false if main map icon
  • group: Group - group the icon belonds to
  • waypointId: Number - waypoint ID
  • mouseButton: Number - mouse button: 0 - LMB, 1 - RMB (only applicable to IconClick)
  • posX: Number - screen X of the mouse
  • posY: Number - screen Y of the mouse
  • shift: Boolean - true if Shift key was pressed
  • ctrl: Boolean - true if Ctrl key was pressed
  • alt: Boolean - true if Alt key was pressed


GroupIconOverEnter

Continuously executes assigned code when user hovers with pointer over the HC group icon, either on the HUD or the main map. groupIconSelectable must be set to true for this EH to work at all. To set group icon selectable use setGroupIconsSelectable. When EH fires over the HUD icon, X and Y coordinates will change depending on the position of the pointer in relation to the icon area. When over main map, the X and Y do not change and indicate icon center. Stackable version of onGroupIconOverEnter.

addMissionEventHandler ["GroupIconOverEnter", { params [ "_is3D", "_group", "_waypointId", "_posX", "_posY", "_shift", "_control", "_alt" ]; }];


GroupIconOverLeave

Executes assigned code when user moves the pointer away from HC group icon it was over. Fires either for on the HUD icons or the main map HC icons. groupIconSelectable must be set to true for this EH to work at all. To set group icon selectable use setGroupIconsSelectable. Stackable version of onGroupIconOverLeave.

addMissionEventHandler ["GroupIconOverLeave", { params [ "_is3D", "_group", "_waypointId", "_posX", "_posY", "_shift", "_control", "_alt" ]; }];

  • is3D: Boolean - true if HUD icon, false if main map icon
  • group: Group - group the icon belonds to
  • waypointId: Number - waypoint ID
  • posX: Number - screen X of the mouse
  • posY: Number - screen Y of the mouse (Y is always 0 when leaving HUD icon for some reason)
  • shift: Boolean - true if Shift key was pressed
  • ctrl: Boolean - true if Ctrl key was pressed
  • alt: Boolean - true if Alt key was pressed


HandleAccTime

Fires when user changes time acceleration with +/- keys in SP or setAccTime command. If the code returns true the on-screen message confirming the change is not displayed. Doesn't fire if desired value is already set.

addMissionEventHandler ["HandleAccTime", { params ["_currentTimeAcc", "_prevTimeAcc", "_messageSuppressed"]; }];

  • currentTimeAcc: Number - current value
  • prevTimeAcc: Number - previous value
  • messageSuppressed: Boolean - true if on-screen message was suppressed


HandleChatMessage

Fires when a message is received, before adding it to the chat feed. Fires clientside. The output message could be overridden:

  • Return true to block incoming chat message from being added to the chat feed.
  • Return String to replace the chat message content but not the sender name.
  • Return Array [from, text] to replace both the chat message content and the the sender's name.
Only the last added EH with override will be used to override the message.
Do not put any of the chat related script command such as systemChat, sideChat, etc in this EH code as it would naturally cause recursion and the game will freeze.

addMissionEventHandler ["HandleChatMessage", { params ["_channel", "_owner", "_from", "_text", "_person", "_name", "_strID", "_forcedDisplay", "_isPlayerMessage", "_sentenceType", "_chatMessageType"]; }];

  • channel: Number - See radio channel indexes (16 for system chat message for example)
  • owner: Number - owner id of the sender:
  • from: String - sender's formatted name as appeared on the chat
  • text: String - the chat message
  • person: Object - sender's object
  • name: String - sender's name, could be different from from
  • strID: String - sender's network player ID (marker id):
  • forcedDisplay: Boolean - if the message should be displayed when the chat list is disabled (when enableRadio is set to false radio protocol messages won't display)
  • isPlayerMessage: Boolean - if the message is addressed to player
  • sentenceType: Number - 0: Normal type, 1: Protocol type
  • chatMessageType: Number - 0: Generic type, 1: SimpleMove type, 2: KillConfirmation type


HandleDisconnect

Triggered when player disconnects from the game. Similar to onPlayerDisconnected event but can be stacked and contains the unit occupied by player before disconnect. Must be added on the server and triggers only on the server.

addMissionEventHandler ["HandleDisconnect", { params ["_unit", "_id", "_uid", "_name"]; true; }];

Override: If this EH code returns true, the unit, previously occupied by player, gets transferred to the server, becomes AI and continues to live, even with description.ext param disabledAI = 1;


HCGroupSelectionChanged

Executes assigned code when user selects available HC group (F1, F2…). Stackable version of onHCGroupSelectionChanged.

addMissionEventHandler ["HCGroupSelectionChanged", { params ["_group", "_isSelected"]; }];

  • group: Group - group selected (same as _group param)
  • isSelected: Boolean - true if selected (same as _isSelected param)


Loaded

Triggered when mission is loaded from save.

"Loaded" event handler should be added BEFORE the mission is loaded from save. Placing it in a function with preInit = 1; usually does the trick.

addMissionEventHandler ["Loaded", { params ["_saveType"]; }];

  • saveType: String - save type, can be have following values:
    • "save" - custom save, achieved by pressing SAVE button in the pause menu
    • "autosave" - automatic checkpoint, saved using saveGame command
    • "continue" - saved when leaving a mission to the main menu


Map

Triggered when map is opened or closed either by user action or script command openMap.

addMissionEventHandler ["Map", { params ["_mapIsOpened", "_mapIsForced"]; }];


MapSingleClick

Executes assigned code when user clicks anywhere on the main map. Stackable version of onMapSingleClick with some limitations:

  • No arguments can be passed to the assigned code in comparison with the original EH
  • Does not have engine default functionality override like the original EH

addMissionEventHandler ["MapSingleClick", { params ["_units", "_pos", "_alt", "_shift"]; }];

  • units: Array - leader selected units, same as groupSelectedUnits (same as _units param)
  • pos: Array - world Position3D of the click in format [x,y,0] (same as _pos param)
  • alt: Boolean - true if Alt key was pressed (same as _alt param)
  • shift: Boolean - true if Shift key was pressed (same as _shift param)

MarkerCreated

Executes when a marker is created either by a user or via script command.

addMissionEventHandler ["MarkerCreated", { params ["_marker", "_channelNumber", "_owner", "_local"]; }];

MarkerDeleted

Executes when a marker is deleted either by a user or via script command.

addMissionEventHandler ["MarkerDeleted", { params ["_marker", "_local"]; }];

  • marker: String - The name of the deleted marker
  • Arma 3 logo black.png2.04 local: Boolean - true if the event originated locally, false if it came over the network

MarkerUpdated

Executes when a marker is changed.

Changing the marker in the EH code will lead to an infinite loop and the game will crash!

addMissionEventHandler ["MarkerUpdated", { params ["_marker", "_local"]; }];

  • marker: String - The name of the marker
  • Arma 3 logo black.png2.04 local: Boolean - true if the event originated locally, false if it came over the network


OnUserConnected

Executes assigned code on user joining server.

addMissionEventHandler ["OnUserConnected", { params ["_networkId", "_clientStateNumber", "_clientState"]; }];


OnUserDisconnected

Executes assigned code on user leaving server.

addMissionEventHandler ["OnUserDisconnected", { params ["_networkId", "_clientStateNumber", "_clientState"]; }];


OnUserClientStateChanged

Executes assigned code for every stage of user client state change.

addMissionEventHandler ["OnUserClientStateChanged", { params ["_networkId", "_clientStateNumber", "_clientState"]; }];


OnUserAdminStateChanged

Executes assigned code after user logs in, gets voted in or logs out as admin.

addMissionEventHandler ["OnUserAdminStateChanged", { params ["_networkId", "_loggedIn", "_votedIn"]; }];


OnUserSelectedPlayer

Executes assigned code after player object is selected for user to take over control, the ownership information is broadcast and request to sync is made but the object is still owned by previous owner for a short time.

addMissionEventHandler ["OnUserSelectedPlayer", { params ["_networkId", "_playerObject"]; }];

This is the earliest the player object is known, but it is not local to the user yet, so there is a wait time depending on network connection. The best approach to handle this matter and get notified about completion of the transfer of the ownership is to use "Local" entity event handler, like so:

addMissionEventHandler ["OnUserSelectedPlayer", { params ["_networkId", "_playerObject"]; _playerObject [[addEventHandler]] ["Local", { removeEventHandler ["Local", _thisEventHandler]; params ["_player"]; // code to handle _player }]; }];

Note that the player object would change locality again if the user goes to lobby.


OnUserKicked

Executes assigned code after after a user has been kicked from the server providing kick reason. The possible values for 'kickTypeNumber' and 'kickType' are:
0 : "TIMEOUT", 1 : "DISCONNECTED", 2 : "KICKED", 3 : "BANNED", 4 : "MISSING ADDON", 5 : "BAD CD KEY", 6 : "CD KEY IN USE", 7 : "SESSION LOCKED", 8 : "BATTLEYE", 9 : "STEAM CHECK", 10 : "DLC CONTENT", 11 : "GS TIMEOUT", 12 : "SCRIPT", 13 : "OTHER"

addMissionEventHandler ["OnUserKicked", { params ["_networkId", "_kickTypeNumber", "_kickType", "_kickReason", "_kickMessageIncReason"]; }];

  • networkId: String - user network id (see getPlayerID, allUsers)
  • kickTypeNumber: Number - kick type number (see above)
  • kickType: String - kick type (see above)
  • kickReason: String - reason given for the kick by the admin or by other means
  • kickMessageIncReason: String - formatted engine message including the given reason


PlayerConnected

Executes assigned code when client joins the mission in MP. Stackable version of onPlayerConnected.

addMissionEventHandler ["PlayerConnected", { params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"]; }];

  • id: Number - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as _id param)
  • uid: String - getPlayerUID of the joining client. The same as Steam ID (same as _uid param)
  • name: String - profileName of the joining client (same as _name param)
  • jip: Boolean - didJIP of the joining client (same as _jip param)
  • owner: Number - owner id of the joining client (same as _owner param)
  • idstr: String - same as id but in string format, so could be exactly compared to user marker ids

If dedicated server was started without '-autoInit' option and this EH was created on server, on first GUI client this EH also fires against server, but after first client. In mission's initServer.sqf:

addMissionEventHandler ["PlayerConnected", { diag_log "Client connected"; diag_log _this; }]; In RPT: 2016/12/16, 15:39:09 "Client connected" 2016/12/16, 15:39:09 [1.51343e+009,"7xxxxxxxxxxxxxxx1","longbow",false,3,"1513430065"] 2016/12/16, 15:39:34 Mission id: 5071d20b183e9580d0ee4f95f413ca18681d6165 2016/12/16, 15:39:34 "Client connected" 2016/12/16, 15:39:34 [2,"","__SERVER__",false,2,"2"] That happens only for GUI clients, if HC client connects first, EH does not fire for server.<br> If dedicated server was started with -autoInit option, this EH does not fire against server, only for future clients, and all further clients appear to be JIPped.<br> Interesting moment for headless clients, for headless clients instead of [[getPlayerUID]], handler gets string like "HC12160", where '12160' is headless client process ID (matches HC's PID observed in windows task manager) {{ArgTitle|4|PlayerDisconnected|{{GVI|arma3|1.58}}&nbsp;{{Icon|serverExec|32}}}} Executes assigned code when client leaves the mission in MP. Stackable version of [[onPlayerDisconnected]]. <sqf> addMissionEventHandler ["PlayerDisconnected", { params ["_id", "_uid", "_name", "_jip", "_owner", "_idstr"]; }];

  • id: Number - unique DirectPlay ID (very large number). It is also the same id used for user placed markers (same as _id param)
  • uid: String - getPlayerUID of the leaving client. The same as Steam ID (same as _uid param)
  • name: String - profileName of the leaving client (same as _name param)
  • jip: Boolean - didJIP of the leaving client (same as _jip param)
  • owner: Number - owner id of the leaving client (same as _owner param)
  • idstr: String - same as id but in string format, so could be exactly compared to user marker ids


PlayerViewChanged

Fired on player view change. Player view changes when player is changing body due to teamSwitch, gets in out of a vehicle or operates UAV for example.

addMissionEventHandler ["PlayerViewChanged", { params [ "_oldUnit", "_newUnit", "_vehicleIn", "_oldCameraOn", "_newCameraOn", "_uav" ]; }];

  • oldUnit: Object - player body before EH fired
  • newUnit: Object - player body after EH fired
  • vehicleIn: Object - vehicle player is in (objNull if not in vehicle)
  • oldCameraOn: Object - cameraOn before EH fired
  • newCameraOn: Object - cameraOn after EH fired
  • uav: Object - UAV reference if player is operating one (objNull if not operating UAV)


PreloadStarted

Executes assigned code before the mission preload screen. Stackable version of onPreloadStarted.

This event handler also fires on client after user closes the main map.

addMissionEventHandler ["PreloadStarted", { // no params }];


PreloadFinished

Executes assigned code after the mission preload screen. Stackable version of onPreloadFinished.

This event handler also fires on client after user closes the main map.

addMissionEventHandler ["PreloadFinished", { // no params }];


SelectedActionPerformed

RTM helicopter user action event

addMissionEventHandler ["SelectedActionPerformed", { params ["_caller", "_target", "_enumNumber", "_actionId"]; }];

Limited or non-existent functionality


SelectedActionChanged

RTM helicopter user action event

addMissionEventHandler ["SelectedActionChanged", { params ["_caller", "_target", "_enumNumber", "_actionId"]; }];

Limited or non-existent functionality


SelectedRotorLibActionPerformed

RTM helicopter user action event

addMissionEventHandler ["SelectedRotorLibActionPerformed", { params ["_caller", "_target", "_enumNumber", "_actionId"]; }];

Works only for key press combination RightCtrl + W, which is the binding for helicopter wheels brakes. It fires with or without Advanced Flight Model enabled. The enum number returned is 4 and 5, probably because the enum is structured like this:

0: HelicopterAutoTrimOn
1: HelicopterAutoTrimOff
2: HelicopterTrimOn
3: HelicopterTrimOff
4: WheelsBrakeOn

5: WheelsBrakeOff


SelectedRotorLibActionChanged

RTM helicopter user action event

addMissionEventHandler ["SelectedRotorLibActionChanged", { params ["_caller", "_target", "_enumNumber", "_actionId"]; }];

Limited or non-existent functionality


TeamSwitch

Executes assigned code when player teamswitches. Stackable version of onTeamSwitch.

addMissionEventHandler ["TeamSwitch", { params ["_previousUnit", "_newUnit"]; }];

  • previousUnit: Object - switching from unit (same as _from param)
  • newUnit: Object - switching to unit (same as _to param)