From b9213e8abc7cb68281385e13a05da3e0e6c44e83 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sun, 22 Feb 2015 00:34:16 +0100 Subject: [PATCH] Added use and has item functions for medical --- addons/medical/XEH_preInit.sqf | 2 + addons/medical/functions/fnc_hasItem.sqf | 44 +++++++++++++++++ .../fnc_treatmentAdvanced_bandage.sqf | 2 +- .../fnc_treatmentAdvanced_medication.sqf | 2 +- addons/medical/functions/fnc_treatmentIV.sqf | 2 +- .../functions/fnc_treatmentTourniquet.sqf | 2 +- addons/medical/functions/fnc_useItem.sqf | 48 +++++++++++++++++++ 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 addons/medical/functions/fnc_hasItem.sqf create mode 100644 addons/medical/functions/fnc_useItem.sqf diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 531ad4d2dc..3ffe1815c7 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -42,6 +42,8 @@ PREP(addToTriageCard); PREP(actionPlaceInBodyBag); PREP(onTreatmentCompleted); PREP(reactionToDamage); +PREP(useItem); +PREP(hasItem); GVAR(injuredUnitCollection) = []; call FUNC(parseConfigForInjuries); diff --git a/addons/medical/functions/fnc_hasItem.sqf b/addons/medical/functions/fnc_hasItem.sqf new file mode 100644 index 0000000000..35668361d2 --- /dev/null +++ b/addons/medical/functions/fnc_hasItem.sqf @@ -0,0 +1,44 @@ +/* + * Author: Glowbal + * Check if the item is present between the patient and the medic + * + * Arguments: + * 0: Medic + * 1: Patient + * 2: Item + * + * ReturnValue: + * + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_medic", "_patient", "_item", "_return"]; +_medic = _this select 0; +_patient = _this select 1; +_item = _this select 2; + +if (isnil QGVAR(setting_allowSharedEquipment)) then { + GVAR(setting_allowSharedEquipment) = true; +}; +if (GVAR(setting_allowSharedEquipment) && {[_patient, _item] call EFUNC(common,hasItem)}) exitwith { + true; +}; + +if ([_medic, _item] call EFUNC(common,hasItem)) exitwith { + true; +}; + +_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 { + _return = true; + }; + }foreach _crew; +}; + +_return; diff --git a/addons/medical/functions/fnc_treatmentAdvanced_bandage.sqf b/addons/medical/functions/fnc_treatmentAdvanced_bandage.sqf index ecfa717313..9e77a1b5ec 100644 --- a/addons/medical/functions/fnc_treatmentAdvanced_bandage.sqf +++ b/addons/medical/functions/fnc_treatmentAdvanced_bandage.sqf @@ -26,7 +26,7 @@ _items = _this select 4; if (count _items == 0) exitwith {}; -if ([_caller, _target, _items] call FUNC(useEquipment)) then { +if ([_caller, _target, _items] call FUNC(useItem)) then { [[_target, _className], QUOTE(FUNC(treatmentBandageLocal)), _target] call EFUNC(common,execRemoteFnc); { if (_x != "") then { diff --git a/addons/medical/functions/fnc_treatmentAdvanced_medication.sqf b/addons/medical/functions/fnc_treatmentAdvanced_medication.sqf index 51b7cf45df..7ee88c5627 100644 --- a/addons/medical/functions/fnc_treatmentAdvanced_medication.sqf +++ b/addons/medical/functions/fnc_treatmentAdvanced_medication.sqf @@ -26,7 +26,7 @@ _items = _this select 4; if (count _items == 0) exitwith {}; -if ([_caller, _target, _items] call FUNC(useEquipment)) then { +if ([_caller, _target, _items] call FUNC(useItem)) then { [[_target, _className], QUOTE(FUNC(treatmentMedicationLocal)), _target] call EFUNC(common,execRemoteFnc); { if (_x != "") then { diff --git a/addons/medical/functions/fnc_treatmentIV.sqf b/addons/medical/functions/fnc_treatmentIV.sqf index 55f5a0638a..14aca5178e 100644 --- a/addons/medical/functions/fnc_treatmentIV.sqf +++ b/addons/medical/functions/fnc_treatmentIV.sqf @@ -26,7 +26,7 @@ _items = _this select 4; if (count _items == 0) exitwith {}; -if ([_caller, _target, _items] call FUNC(useEquipment)) then { +if ([_caller, _target, _items] call FUNC(useItem)) then { _removeItem = _items select 0; [[_target, _removeItem], QUOTE(FUNC(treatmentIVLocal)), _target] call EFUNC(common,execRemoteFnc); ["Medical_treatmentCompleted", [_caller, _target, _selectionName, _className, true]] call ace_common_fnc_localEvent; diff --git a/addons/medical/functions/fnc_treatmentTourniquet.sqf b/addons/medical/functions/fnc_treatmentTourniquet.sqf index 7c520fda47..81b10135f9 100644 --- a/addons/medical/functions/fnc_treatmentTourniquet.sqf +++ b/addons/medical/functions/fnc_treatmentTourniquet.sqf @@ -38,7 +38,7 @@ if ((_tourniquets select _part) > 0) exitwith { false; }; -if ([_caller, _target, _items] call FUNC(useEquipment)) then { +if ([_caller, _target, _items] call FUNC(useItem)) then { _removeItem = _items select 0; [[_target, _removeItem], QUOTE(FUNC(treatmentTourniquetLocal)), _target] call EFUNC(common,execRemoteFnc); ["Medical_treatmentCompleted", [_caller, _target, _selectionName, _className, true]] call ace_common_fnc_localEvent; diff --git a/addons/medical/functions/fnc_useItem.sqf b/addons/medical/functions/fnc_useItem.sqf new file mode 100644 index 0000000000..af77b4eb69 --- /dev/null +++ b/addons/medical/functions/fnc_useItem.sqf @@ -0,0 +1,48 @@ +/* + * Author: Glowbal + * Use Equipment if any is available. Priority: 1) Medic, 2) Patient. If in vehicle: 3) Crew + * + * Arguments: + * 0: Medic + * 1: Patient + * 2: Item + * + * ReturnValue: + * + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_medic", "_patient", "_item", "_return","_crew"]; +_medic = _this select 0; +_patient = _this select 1; +_item = _this select 2; + +if (isnil QGVAR(setting_allowSharedEquipment)) then { + GVAR(setting_allowSharedEquipment) = true; +}; + +if (GVAR(setting_allowSharedEquipment) && {[_patient, _item] call EFUNC(common,hasItem)}) exitwith { + [[_patient, _item], QUOTE(EFUNC(common,useItem)), _patient] call EFUNC(common,execRemoteFnc); + true; +}; + +if ([_medic, _item] call EFUNC(common,hasItem)) exitwith { + [[_medic, _item], QUOTE(EFUNC(common,useItem)), _medic] call EFUNC(common,execRemoteFnc); + true; +}; + +_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 { + _return = true; + [[_x, _item], QUOTE(EFUNC(common,useItem)), _x] call EFUNC(common,execRemoteFnc); + }; + }foreach _crew; +}; + +_return;