-
Notifications
You must be signed in to change notification settings - Fork 150
Player Events
commy2 edited this page Oct 2, 2019
·
11 revisions
Player Events are event handlers that are based around properties of the players avatar that are pretty usefull, but unfortunately require polling. Multiple addons can make use of this framework to minimize calculation time.
Player Events are added via CBA_fnc_addPlayerEventHandler
. The function returns a ID that can be ignored, or used to remove the event with CBA_fnc_removePlayerEventHandler
later.
The events will only be executed if they were added on the local machine and will only execute on the machine were the player
-object is local.
-
"unit"
: This event is executed when the players controlled avatar changes. This includesplayer
-object initialization (if the event is added during preInit), remote controlling a unit via zeus and respawning. This event is essential to make a feature based around theplayer
-object "zeus compatible".
Parameters: [_newPlayerUnit
<OBJECT>,_oldPlayerUnit
<OBJECT>]
["unit", {
params ["_newUnit", "_oldUnit"];
systemChat str "Unit changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"weapon"
: This event is executed when the player changes the current active weapon. This does not include vehicles.
Parameters: [_playerUnit
<OBJECT>,_newSelectedWeapon
<STRING>]
["weapon", {
params ["_unit", "_newWeapon"];
systemChat str "Weapon changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"loadout"
: This event is executed when the players loadout changes. It is not executed when the ammunition counter is decreased after firing a weapon.
Parameters: [_playerUnit
<OBJECT>,_newUnitLoadout
<ARRAY>]
["loadout", {
params ["_unit", "_newLoadout"];
systemChat str "Inventory changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"vehicle"
: This event is executed when the player enters or leaves a vehicle. If the player leaves a vehicle, the player object will be passed as argument. This is different fromgetInMan
since it also triggers if the player is moved into the vehicle viamoveInDriver
, zeus or similar.
Parameters: [_playerUnit
<OBJECT>,_newVehicle
<OBJECT>]
["vehicle", {
params ["_unit", "_newVehicle"];
systemChat str "Vehicle changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"turret"
: This event will be executed when the player changes the turret position.
Parameters: [_playerUnit
<OBJECT>,_newTurret
<ARRAY>]
["turret", {
params ["_unit", "_newTurret"];
systemChat str "Turret changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"featureCamera"
: This event will be executed when the active camera changes (Curator, Arsenal, Spectator etc.).
Parameters: [_playerUnit
<OBJECT>,_newTurret
<ARRAY>]
["featureCamera", {
params ["_unit", "_newCamera"];
systemChat str "Camera changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"cameraView"
: This event will be executed when the player changes the camera mode. Camera modes are:"INTERNAL"
,"EXTERNAL"
,"GUNNER"
and"GROUP"
(commander view)
Parameters: [_playerUnit
<OBJECT>,_newCameraMode
<STRING>]
["cameraView", {
params ["_unit", "_newCameraMode"];
systemChat str "Camera Mode changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"visionMode"
: This event will be executed when the player changes the vision mode. Vision modes are: 0 (day), 1 (night vision) or 2 (thermal vision)
Parameters: [_playerUnit
<OBJECT>,_newVisionMode
<NUMBER>]
["visionMode", {
params ["_unit", "_newVisionMode"];
systemChat str "Vision Mode changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"visibleMap"
: This event will be executed when the player opens or closes the map.
Parameters: [_playerUnit
<OBJECT>,_isMapShown
<BOOLEAN>]
["visibleMap", {
params ["_unit", "_isMapShown"];
systemChat str "Map opened or closed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"group"
: This event will be executed when the player's group changes.
Parameters: [_playerUnit
<OBJECT>,_oldGroup
<GROUP>]
["group", {
params ["_unit", "_oldGroup"];
private _newGroup = group _unit;
systemChat str "Group changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
-
"leader"
: This event will be executed when the leader of the player's group changed.
Parameters: [_playerUnit
<OBJECT>,_oldLeader
<OBJECT>]
["leader", {
params ["_unit", "_oldLeader"];
private _newLeader = leader _unit;
systemChat str "Group Leader changed.";
}, true] call CBA_fnc_addPlayerEventHandler;
Event that prints the selected weapons name into the chat:
if (hasInterface) then {
["weapon", {
params ["_player", "_weapon"];
private _weaponName = getText (_weapon call CBA_fnc_getItemConfig >> "displayName");
systemChat format ["%1: %2", name _player, _weaponName];
}] call CBA_fnc_addPlayerEventHandler;
};