Skip to content

Player Events

commy2 edited this page May 22, 2016 · 11 revisions

Player Events

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>]
  • "weapon": This event is executed when the player changes the current active weapon. This does not include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedWeapon <STRING>]
  • "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>]
  • "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>]
  • "turret": This event will be executed when the player changes the turret position.
    Parameters: [_playerUnit <OBJECT>, _newTurret <ARRAY>]
  • "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>]
  • "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>]
  • "visibleMap": This event will be executed when the player opens or closes the map.
    Parameters: [_playerUnit <OBJECT>, _isMapShown <BOOLEN>]

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