Skip to content

Player Events

commy2 edited this page Mar 13, 2020 · 11 revisions

What are CBA Player Events?

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.

Adding and removing Player Events

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.

https://community.bistudio.com/wikidata/images/5/52/effects_local.gif
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.

Available events

  • "unit": This event is executed when the players controlled avatar changes. This includes player-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 the player-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>, _oldSelectedWeapon <STRING>]
["weapon", {
    params ["_unit", "_newWeapon", "_oldWeapon"];
    systemChat str "Weapon changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "turretWeapon": This event is executed when the player's turret changes the current active weapon.
    Parameters: [_playerUnit <OBJECT>, _newSelectedWeapon <STRING>, _oldSelectedWeapon <STRING>]
["turretWeapon", {
    params ["_unit", "_newWeapon", "_oldWeapon"];
    systemChat str "Turret Weapon changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "muzzle": This event is executed when the player changes the current selected muzzle. This does include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedMuzzle <STRING>, _oldSelectedMuzzle <STRING>]
["muzzle", {
    params ["_unit", "_newMuzzle", "_oldMuzzle"];
    systemChat str "Muzzle changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "weaponMode": This event is executed when the player changes the weapon mode, including when they switch the weapon. This does include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedWeapon <STRING>, _oldSelectedWeapon <STRING>]
["weaponMode", {
    params ["_unit", "_newWeaponMode", "_oldWeaponMode"];
    systemChat str "Weapon Mode 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>, _oldUnitLoadout <ARRAY>]
["loadout", {
    params ["_unit", "_newUnitLoadout", "_oldUnitLoadout"];
    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 from getInMan since it also triggers if the player is moved into the vehicle via moveInDriver, zeus or similar.
    Parameters: [_playerUnit <OBJECT>, _newVehicle <OBJECT>, _oldVehicle <OBJECT>]
["vehicle", {
    params ["_unit", "_newVehicle", "_oldVehicle"];
    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>, _oldTurret <ARRAY>]
["turret", {
    params ["_unit", "_newTurret", "_oldTurret"];
    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>, _newCamera <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>, _oldCameraMode <STRING>]
["cameraView", {
    params ["_unit", "_newCameraMode", "_oldCameraMode"];
    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>, _oldVisionMode <NUMBER>]
["visionMode", {
    params ["_unit", "_newVisionMode", "_oldVisionMode"];
    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>, _newGroup <GROUP>]
["group", {
    params ["_unit", "_oldGroup", "_newGroup"];
    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>, _newLeader <OBJECT>]
["leader", {
    params ["_unit", "_oldLeader", "_newLeader"];
    systemChat str "Group Leader changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

Examples

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;
};