ACE3/addons/medical/functions/fnc_treatment.sqf

93 lines
3.2 KiB
Plaintext
Raw Normal View History

2015-02-20 21:04:01 +00:00
/*
2015-02-21 20:09:57 +00:00
* Author: Glowbal, KoffeinFlummi
2015-02-20 21:04:01 +00:00
* Starts the treatment process
*
* Arguments:
* 0: The medic <OBJECT>
* 1: The patient <OBJECT>
2015-02-21 20:09:57 +00:00
* 2: SelectionName <STRING>
* 3: Treatment classname <STRING>
2015-02-20 21:04:01 +00:00
*
* Return Value:
2015-02-21 20:09:57 +00:00
* Succesful treatment started <BOOL>
2015-02-20 21:04:01 +00:00
*
* Public: Yes
*/
#include "script_component.hpp"
2015-02-21 20:09:57 +00:00
private ["_caller", "_target", "_selectionName", "_className", "_config", "_availableLevels", "_medicRequired", "_items", "_locations", "_return", "_callbackSuccess", "_callbackFailure", "_onProgress", "_treatmentTime", "_callerAnim", "_patietAnim"];
_caller = _this select 0;
_target = _this select 1;
_selectionName = _this select 2;
_className = _this select 3;
2015-02-20 21:04:01 +00:00
2015-02-21 20:09:57 +00:00
_config = (ConfigFile >> "ACE_Medical_Treatments" >> _className);
if !(isClass _config) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-21 20:09:57 +00:00
_availableLevels = getArray (_config >> "availableLevels");
if !(GVAR(level) in _availableLevels) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-21 20:09:57 +00:00
_medicRequired = getNumber (_config >> "requiredMedic");
if !([_caller, _medicRequired] call FUNC(isMedic) || [_target, _medicRequired] call FUNC(isMedic)) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-21 20:09:57 +00:00
_items = getArray (_config >> "items");
if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-21 20:09:57 +00:00
_locations = getArray (_config >> "treatmentLocations");
if ("All" in _locations) exitwith {true};
_return = false;
{
if (_x == "field") exitwith {_return = true;};
if (_x == "MedicalFacility" && {[_caller, _target] call FUNC(inMedicalFacility)}) exitwith {_return = true;};
if (_x == "MedicalVehicle" && {[_caller, _target] call FUNC(inMedicalVehicle)}) exitwith {_return = true;};
}foreach _locations;
if !(_return) exitwith {false};
// Parse the config for the success callback
_callbackSuccess = getText (_config >> "callbackSuccess");
if (isNil _callbackSuccess) then {
_callbackSuccess = compile _callbackSuccess;
} else {
_callbackSuccess = missionNamespace getvariable _callbackSuccess;
};
// Parse the config for the failure callback
_callbackFailure = getText (_config >> "callbackFailure");
if (isNil _callbackFailure) then {
_callbackFailure = compile _callbackFailure;
} else {
_callbackFailure = missionNamespace getvariable _callbackFailure;
};
// Parse the config for the onProgress callback
_onProgress = getText (_config >> "onProgress");
if (isNil _onProgress) then {
_onProgress = compile _onProgress;
} else {
_onProgress = missionNamespace getvariable _onProgress;
};
_treatmentTime = getNumber (_config >> "treatmentTime");
[_treatmentTime, [_caller, _target, _selectionName, _className, _items], _callbackSuccess, _callbackFailure, (localize ""), _onProgress] call EFUNC(common,progressBar);
_callerAnim = getText (_config >> "animationCaller");
_patietAnim = getText (_confg >> "animationPatient");
if (_caller != _target && {vehicle _target == _target} && {_patietAnim != ""}) then {
[_target, _patietAnim] call EFUNC(common,doAnimation);
2015-02-21 20:09:57 +00:00
};
if (vehicle _caller == _caller && {_callerAnim != ""}) then {
if (primaryWeapon _caller == "") then {
_caller addWeapon "ACE_FakePrimaryWeapon";
};
_caller selectWeapon (primaryWeapon _caller);
_caller setvariable [QGVAR(treatmentPrevAnimCaller), animationState _target];
[_caller, _callerAnim] call EFUNC(common,doAnimation);
2015-02-21 20:09:57 +00:00
};
true;