fn_onPlayerInventoryChanged.sqf 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Name: cTab_fnc_onPlayerInventoryChanged
  3. Author(s):
  4. Gundy
  5. Description:
  6. Handles ACE3 event that triggers upon player's inventory changed event. It will check to see if there is currently a cTab device that requires a an inventory item open and if that is the case, close that device.
  7. Parameters:
  8. 0: OBJECT - player object that an inventory change was detected for
  9. 1: ARRAY - list of the new player inventory as returned by ace_common_fnc_getAllGear
  10. Returns:
  11. BOOLEAN - TRUE
  12. Example:
  13. [ACE_player,[player] call ace_common_fnc_getAllGear] call cTab_fnc_onPlayerInventoryChanged;
  14. */
  15. private ["_displayName","_newPlayerInventory","_playerLostDevice","_itemsToCheck"];
  16. // is cTab oben? if not exit
  17. if (isNil "cTabIfOpen") exitWith {true};
  18. // are we looking at the same player object? if not exit
  19. if (_this select 0 != cTab_player) exitWith {true};
  20. // get the currently open cTab device
  21. _displayName = cTabIfOpen select 1;
  22. // get the current inventory state
  23. _newPlayerInventory = _this select 1;
  24. // add all the item areas we need to look through to one big array
  25. // index 17 of _newPlayerInventory is assignedItems, 3 is uniformItems, 5 is vestItems, 7 is backpackItems
  26. _itemsToCheck = (_newPlayerInventory select 17) + (_newPlayerInventory select 3) + (_newPlayerInventory select 5) + (_newPlayerInventory select 7);
  27. // see if we still have the correct device on us
  28. _playerLostDevice = call {
  29. if (_displayName == "cTab_Tablet_dlg") exitWith {
  30. !("ItemcTab" in _itemsToCheck)
  31. };
  32. if (_displayName in ["cTab_Android_dlg","cTab_Android_dsp"]) exitWith {
  33. !("ItemAndroid" in _itemsToCheck)
  34. };
  35. if (_displayName in ["cTab_microDAGR_dsp","cTab_microDAGR_dlg"]) exitWith {
  36. !("ItemMicroDAGR" in _itemsToCheck)
  37. };
  38. false
  39. };
  40. if (_playerLostDevice) then {[] call cTab_fnc_close};
  41. true