mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Medical Damage - Improve custom wound handling (#9310)
This commit is contained in:
parent
be23ae7ecd
commit
c8e7b6396b
@ -9,3 +9,9 @@ class Extended_PreInit_EventHandlers {
|
||||
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
|
||||
};
|
||||
};
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
|
||||
};
|
||||
};
|
||||
|
4
addons/medical_damage/XEH_postInit.sqf
Normal file
4
addons/medical_damage/XEH_postInit.sqf
Normal file
@ -0,0 +1,4 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
// Reload configs (handle functions being compiled after medical_damage's preInit)
|
||||
call FUNC(parseConfigForInjuries);
|
@ -10,11 +10,13 @@ PREP_RECOMPILE_END;
|
||||
|
||||
call FUNC(parseConfigForInjuries);
|
||||
|
||||
/*
|
||||
addMissionEventHandler ["Loaded",{
|
||||
INFO("Mission Loaded - Reloading medical configs for extension");
|
||||
// Reload configs into extension (handle full game restart)
|
||||
call FUNC(parseConfigForInjuries);
|
||||
}];
|
||||
*/
|
||||
|
||||
[QEGVAR(medical,woundReceived), LINKFUNC(woundReceived)] call CBA_fnc_addEventHandler;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "..\script_component.hpp"
|
||||
/*
|
||||
* Author: Pterolatypus
|
||||
* Read a list of wound handler entries from config, accounting for inheritance
|
||||
* Read a list of wound handler entries from config, accounting for inheritance.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: The config class containing the entries <CONFIG>
|
||||
@ -10,24 +10,43 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [configFile >> "ace_medical_injuries" >> "damageTypes"] call ace_medical_damage_fnc_parseWoundHandlersCfg
|
||||
* [configFile >> "ace_medical_injuries" >> "damageTypes" >> "woundHandlers"] call ace_medical_damage_fnc_parseWoundHandlersCfg
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_config"];
|
||||
|
||||
// read all valid entries from config and store
|
||||
// Read all valid entries from config and store
|
||||
private _entries = [];
|
||||
|
||||
{
|
||||
private _entryResult = call compile getText _x;
|
||||
if !(isNil "_entryResult") then {
|
||||
_entries pushBack _entryResult;
|
||||
}
|
||||
private _entryResult = getText _x;
|
||||
|
||||
if (_entryResult != "") then {
|
||||
if (ADDON) then {
|
||||
// Runs in postInit
|
||||
_entryResult = call compile _entryResult;
|
||||
|
||||
if (!isNil "_entryResult") then {
|
||||
if (_entryResult isEqualType {}) then {
|
||||
_entries pushBack _entryResult;
|
||||
} else {
|
||||
ERROR_2("Wound handler '%1' needs to be a function, but is of type %2.",configName _x,toLowerANSI typeName _entryResult);
|
||||
};
|
||||
};
|
||||
} else {
|
||||
// Runs in preInit
|
||||
// In case function doesn't exist yet, wrap in extra layer
|
||||
_entries pushBack (compile format ["call %1", _entryResult]);
|
||||
};
|
||||
};
|
||||
} forEach configProperties [_config, "isText _x", false];
|
||||
|
||||
private _parent = inheritsFrom _config;
|
||||
|
||||
if (isNull _parent) exitWith {_entries};
|
||||
|
||||
// recursive call for parent
|
||||
// can't use configProperties for inheritance since it returns entries in the wrong order
|
||||
([_parent] call FUNC(parseWoundHandlersCfg)) + _entries;
|
||||
// Recursive call for parent
|
||||
// Can't use configProperties for inheritance since it returns entries in the wrong order
|
||||
([_parent] call FUNC(parseWoundHandlersCfg)) + _entries // return
|
||||
|
@ -17,18 +17,23 @@
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_unit", "_allDamages", "_shooter", "_ammo"];
|
||||
|
||||
private _typeOfDamage = _ammo call FUNC(getTypeOfDamage);
|
||||
|
||||
if (_typeOfDamage in GVAR(damageTypeDetails)) then {
|
||||
(GVAR(damageTypeDetails) get _typeOfDamage) params ["", "", "_woundHandlers"];
|
||||
|
||||
private _damageData = [_unit, _allDamages, _typeOfDamage];
|
||||
|
||||
{
|
||||
_damageData = _damageData call _x;
|
||||
TRACE_1("Wound handler returned",_damageData);
|
||||
if !(_damageData isEqualType [] && {(count _damageData) >= 3}) exitWith {
|
||||
TRACE_1("Return invalid, terminating wound handling",_damageData);
|
||||
|
||||
// If invalid return, exit
|
||||
if (isNil "_damageData" || {!(_damageData isEqualType [])} || {(count _damageData) < 3}) exitWith {
|
||||
TRACE_1("Return invalid, skipping wound handling",_damageData);
|
||||
};
|
||||
} forEach _woundHandlers;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user