fn_getCopilot.sqf 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Name: cTab_fnc_getCopilot
  3. Author(s):
  4. Gundy
  5. Description:
  6. Returns the unit in the passed vehicle's co-pilot seat
  7. Parameters:
  8. Object - Vehicle
  9. Returns:
  10. OBJECT - Unit occupying the vehicle's co-pilot seat, objNull if there is no co-pilot
  11. Example:
  12. _copilot = (vehicle player) call cTab_fnc_getCopilot;
  13. */
  14. private ["_copilotTurret","_turretNumber","_turrets","_i","_turretConfigPath"];
  15. // default co-pilot turret
  16. _copilotTurret = 0;
  17. // if this is a helicopter, find the turret number that has isCopilot set to 1
  18. if (_this isKindOf "Helicopter") then {
  19. _turretNumber = -1;
  20. _copilotTurret = -1;
  21. // get a list of all turrets
  22. _turrets = configFile >> "CfgVehicles" >> (typeOf _this) >> "Turrets";
  23. // iterate through the list of turrets
  24. for "_i" from 0 to (count _turrets -1) do {
  25. _turretConfigPath = _turrets select _i;
  26. // filter non classes; count turrets; find out if this is the co-pilot's turret (we assume that there is just one co-pilot), if so exit the loop
  27. if (isClass(_turretConfigPath) && {_turretNumber = _turretNumber + 1; getNumber(_turretConfigPath >> "isCopilot") == 1}) exitWith {
  28. _copilotTurret = _turretNumber;
  29. };
  30. };
  31. };
  32. _this turretUnit [_copilotTurret]