From 909a87fdd3e3db45982861fa5a38552c3729b633 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sat, 21 Feb 2015 21:26:39 +0100 Subject: [PATCH] Added tourniquet treatment functions --- addons/medical/XEH_preInit.sqf | 4 +- .../functions/fnc_treatmentTourniquet.sqf | 46 ++++++++++++++++ .../fnc_treatmentTourniquetLocal.sqf | 54 +++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 addons/medical/functions/fnc_treatmentTourniquet.sqf create mode 100644 addons/medical/functions/fnc_treatmentTourniquetLocal.sqf diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 5de8dea30d..505489f356 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -24,6 +24,7 @@ PREP(setUnconscious); PREP(getUnconsciousCondition); PREP(addUnconsciousCondition); PREP(setDead); +PREP(parseConfigForInjuries); PREP(playInjuredSound); PREP(treatment); PREP(canTreat); @@ -33,7 +34,8 @@ PREP(treatmentAdvanced_medication); PREP(treatmentAdvanced_medicationLocal); PREP(teatmentIV); PREP(treatmentIVLocal); -PREP(parseConfigForInjuries); +PREP(treatmentTourniquet); +PREP(treatmentTourniquetLocal); GVAR(injuredUnitCollection) = []; call FUNC(parseConfigForInjuries); diff --git a/addons/medical/functions/fnc_treatmentTourniquet.sqf b/addons/medical/functions/fnc_treatmentTourniquet.sqf new file mode 100644 index 0000000000..2e16d73922 --- /dev/null +++ b/addons/medical/functions/fnc_treatmentTourniquet.sqf @@ -0,0 +1,46 @@ +/* + * Author: Glowbal + * Apply a tourniquet to the patient + * + * Arguments: + * 0: The medic + * 1: The patient + * 2: SelectionName + * 3: Treatment classname + * + * + * Return Value: + * + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_caller","_target","_part","_selectionName","_removeItem", "_tourniquets", "_items"]; +_caller = _this select 0; +_target = _this select 1; +_selectionName = _this select 2; +_className = _this select 3; +_items = _this select 4; + +if (count _items == 0) exitwith {}; + +_part = [_selectionName] call FUNC(selectionNameToNumber); +if (_part == 0 || _part == 1) exitwith { + // [_caller,"You cannot apply a CAT on this body part!"] call EFUNC(common,sendHintTo); + false; +}; + +_tourniquets = _target getvariable [QGVAR(tourniquets), [0,0,0,0,0,0]]; +if ((_tourniquets select _part) > 0) exitwith { + // [_caller,"There is already a tourniquet on this body part!"] call EFUNC(common,sendHintTo); // display message + false; +}; + +if ([_caller, _target, _items] call FUNC(useEquipment)) then { + _removeItem = _items select 0; + [[_target, _removeItem], QUOTE(FUNC(treatmentTourniquetLocal)), _target] call EFUNC(common,execRemoteFnc); +}; + +true; diff --git a/addons/medical/functions/fnc_treatmentTourniquetLocal.sqf b/addons/medical/functions/fnc_treatmentTourniquetLocal.sqf new file mode 100644 index 0000000000..064761aea0 --- /dev/null +++ b/addons/medical/functions/fnc_treatmentTourniquetLocal.sqf @@ -0,0 +1,54 @@ +/* + * Author: Glowbal + * Apply a tourniquet to the patient, local callback. + * + * Arguments: + * 0: The patient + * 1: Item used classname + * + * Return Value: + * nil + * + * Public: No + */ +#include "script_component.hpp" + +private ["_target", "_tourniquetItem", "_part", "_tourniquets", "_applyingTo"]; +_target = _this select 0; +_tourniquetItem = _this select 1; + +//[_target,"treatment",format["%1 applied a tourniquet on %2",[_caller] call EFUNC(common,getName),_selectionName]] call FUNC(addActivityToLog); +//[_target,_removeItem] call FUNC(addToTriageList); +[_target] call FUNC(addToInjuredCollection); + + +_part = [_selectionName] call FUNC(selectionNameToNumber); + +// Place a tourniquet on the bodypart +_tourniquets = _target getvariable [QGVAR(tourniquets), [0,0,0,0,0,0]]; +_applyingTo = (_tourniquets select _part) + 1 + round(random(100)); +_tourniquets set[_part, _applyingTo]; +_target setvariable [QGVAR(tourniquets), _tourniquets, true]; + +[{ + private ["_args","_target","_applyingTo","_part", "_tourniquets"]; + _args = _this select 0; + _target = _args select 0; + _applyingTo = _args select 1; + _part = _args select 2; + _time = _args select 3; + if (!alive _target) exitwith { + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; + + _tourniquets = _target getvariable [QGVAR(tourniquets), [0,0,0,0,0,0]]; + if !((_tourniquets select _part) == _applyingTo) exitwith { + // Tourniquet has been removed + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; + if (time - _time > 120) then { + _target setvariable [QGVAR(pain), (_target getvariable [QGVAR(pain), 0]) + 0.005]; + }; +}, 5, [_target, _applyingTo, _part, time] ] call CBA_fnc_addPerFrameHandler; + +true;