fn_unitInEnabledVehicleSeat.sqf 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Name: cTab_fnc_unitInEnabledVehicleSeat
  3. Author(s):
  4. Gundy
  5. Description:
  6. Determines if a unit sits in the front-section of a cTab enabled vehicle.
  7. The front seciton-of a vehilce is defined as:
  8. - Ground vehicles, everyone in the same compartment as the driver, including the driver. Excluded are people sitting in the cargo / passenger compartment of a Truck or APC
  9. - Aircraft, pilot and co-pilot / gunner, but not door gunners or any passengers
  10. Parameters:
  11. 0: OBJECT - Unit object to check
  12. 1: OBJECT - Vehicle to check against
  13. 2: STRING - String of device to check for (current options are: "FBCB2" and "TAD")
  14. Returns:
  15. BOOLEAN - True if unit is in the front-section of a cTab enabled vehicle, false if not
  16. Example:
  17. _playerHasCtabItem = [player,["ItemcTab","ItemAndroid","ItemMicroDAGR"]] call cTab_fnc_unitInEnabledVehicleSeat;
  18. */
  19. private ["_return","_unit","_vehicle","_type","_typeClassList","_cargoIndex","_cargoCompartments","_cargoIsCoDriver","_transportSoldier"];
  20. _return = false;
  21. _unit = _this select 0;
  22. _vehicle = _this select 1;
  23. _type = _this select 2;
  24. // Check if vehicle is a parachute, if so, return false
  25. if (_vehicle isKindOf "ParachuteBase") exitWith {false};
  26. switch (_type) do {
  27. case "FBCB2": {_typeClassList = cTab_vehicleClass_has_FBCB2;};
  28. case "TAD": {_typeClassList = cTab_vehicleClass_has_TAD;};
  29. default {_typeClassList = [];};
  30. };
  31. {
  32. if (_vehicle isKindOf _x) exitWith {
  33. call {
  34. if (_unit == driver _vehicle) exitWith {_return = true;};
  35. if (_type == "FBCB2") exitWith {
  36. call {
  37. _cargoIndex = _vehicle getCargoIndex _unit; // 0-based seat number in cargo, -1 if not in cargo
  38. if (_cargoIndex == -1) exitWith {_return = true;}; // if not in cargo, _unit must be gunner or commander
  39. _cargoCompartments = getArray (configFile/"CfgVehicles"/typeOf _vehicle/"cargoCompartments");
  40. if (count _cargoCompartments > 1) then {
  41. // assume the vehicle setup is correct if there is more than one cargo compartment
  42. _cargoIsCoDriver = getArray (configFile/"CfgVehicles"/typeOf _vehicle/"cargoIsCoDriver");
  43. if (_cargoIndex < count _cargoIsCoDriver - 1) then {_return = true;};
  44. } else {
  45. // assume the vehicle setup is not correct if there is just one cargo compartment
  46. _transportSoldier = getNumber (configFile/"CfgVehicles"/typeOf _vehicle/"transportSoldier");
  47. // assume that if a vehicle carries less than 5 passengers, they all sit with the driver
  48. If (_transportSoldier < 5) then {_return = true;};
  49. };
  50. };
  51. };
  52. if (_type == "TAD") then {
  53. if (_unit == _vehicle call cTab_fnc_getCopilot) then {_return = true};
  54. };
  55. };
  56. };
  57. } forEach _typeClassList;
  58. _return