From ab6bc998c21a0056e71173182c0671d589829829 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 22 Feb 2015 15:01:31 +0100 Subject: [PATCH] Added canAccessMedicalEquipment check --- addons/medical/XEH_preInit.sqf | 1 + .../fnc_canAccessMedicalEquipment.sqf | 31 +++++++++++++++++++ addons/medical/functions/fnc_hasItem.sqf | 2 +- addons/medical/functions/fnc_useItem.sqf | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 addons/medical/functions/fnc_canAccessMedicalEquipment.sqf diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 5ccedcf2a8..400fefaa7f 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -50,6 +50,7 @@ PREP(hasTourniquetAppliedTo); PREP(isMedic); PREP(isInMedicalFacility); PREP(isMedicalVehicle); +PREP(canAccessMedicalEquipment); GVAR(injuredUnitCollection) = []; call FUNC(parseConfigForInjuries); diff --git a/addons/medical/functions/fnc_canAccessMedicalEquipment.sqf b/addons/medical/functions/fnc_canAccessMedicalEquipment.sqf new file mode 100644 index 0000000000..4b1940b7e3 --- /dev/null +++ b/addons/medical/functions/fnc_canAccessMedicalEquipment.sqf @@ -0,0 +1,31 @@ +/* + * Author: Glowbal + * Check if caller can access targets medical equipment, based upon accessLevel. + * + * Arguments: + * 0: The caller + * 1: The target + * + * ReturnValue: + * Can Treat + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_target", "_caller", "_accessLevel", "_return"]; +_caller = _this select 0; +_target = _this select 1; + +_accessLevel = _target getvariable [QGVAR(allowSharedEquipmentAccess), -1]; + +_return = false; + +if (_accessLevel >= 0) then { + if (_accessLevel == 0) exitwith { _return = true; }; + if (_accessLevel == 1) exitwith { _return = (side _target == side _caller); }; + if (_accessLevel == 2) exitwith { _return = (group _target == group _caller); }; +}; + +_return; \ No newline at end of file diff --git a/addons/medical/functions/fnc_hasItem.sqf b/addons/medical/functions/fnc_hasItem.sqf index 35668361d2..d02abb9187 100644 --- a/addons/medical/functions/fnc_hasItem.sqf +++ b/addons/medical/functions/fnc_hasItem.sqf @@ -35,7 +35,7 @@ _return = false; if ([vehicle _medic] call FUNC(isMedicalVehicle) && {(vehicle _medic != _medic)}) then { _crew = crew vehicle _medic; { - if ([_x, _medic] call FUNC(canAccessMedicalEquipment) && {([_x, _item] call EFUNC(common,hasItem))}) exitwith { + if ([_medic, _x] call FUNC(canAccessMedicalEquipment) && {([_x, _item] call EFUNC(common,hasItem))}) exitwith { _return = true; }; }foreach _crew; diff --git a/addons/medical/functions/fnc_useItem.sqf b/addons/medical/functions/fnc_useItem.sqf index af77b4eb69..291d30bc91 100644 --- a/addons/medical/functions/fnc_useItem.sqf +++ b/addons/medical/functions/fnc_useItem.sqf @@ -38,7 +38,7 @@ _return = false; if ([vehicle _medic] call FUNC(isMedicalVehicle) && {vehicle _medic != _medic}) then { _crew = crew vehicle _medic; { - if ([_x, _medic] call FUNC(canAccessMedicalEquipment) && {([_x, _item] call EFUNC(common,hasItem))}) exitwith { + if ([_medic, _x] call FUNC(canAccessMedicalEquipment) && {([_x, _item] call EFUNC(common,hasItem))}) exitwith { _return = true; [[_x, _item], QUOTE(EFUNC(common,useItem)), _x] call EFUNC(common,execRemoteFnc); };