From 8a8166d8930120153149221aeccd22408d9b476f Mon Sep 17 00:00:00 2001 From: Ralfs Garkaklis Date: Tue, 20 Apr 2021 14:08:29 +0300 Subject: [PATCH] Add injury module, resolves #452 --- addons/damage/stringtable.xml | 9 ++ addons/modules/CfgVehicles.hpp | 5 + addons/modules/XEH_PREP.hpp | 1 + addons/modules/XEH_postInit.sqf | 9 ++ addons/modules/config.cpp | 1 + addons/modules/functions/fnc_moduleInjure.sqf | 112 ++++++++++++++++++ addons/modules/stringtable.xml | 3 + 7 files changed, 140 insertions(+) create mode 100644 addons/modules/functions/fnc_moduleInjure.sqf diff --git a/addons/damage/stringtable.xml b/addons/damage/stringtable.xml index 038edcf6f..c270ae537 100644 --- a/addons/damage/stringtable.xml +++ b/addons/damage/stringtable.xml @@ -655,5 +655,14 @@ 슬랫 뒤 スラット 後部 + + Head + + + Arms + + + Legs + diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 5965e98a9..aa70bad80 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -302,6 +302,11 @@ class CfgVehicles { displayName = CSTRING(ModuleHideZeus); function = QFUNC(moduleHideZeus); }; + class GVAR(moduleInjure): GVAR(moduleBase) { + curatorCanAttach = 1; + displayName = CSTRING(ModuleInjure); + function = QFUNC(moduleInjure); + }; class GVAR(moduleLightSource): GVAR(moduleBase) { category = "Effects"; displayName = CSTRING(ModuleLightSource); diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index 748115c6d..c41b5b69a 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -62,6 +62,7 @@ PREP(moduleGroupSide); PREP(moduleHeal); PREP(moduleHideTerrainObjects); PREP(moduleHideZeus); +PREP(moduleInjure); PREP(moduleLightSource); PREP(moduleMakeInvincible); PREP(moduleNuke); diff --git a/addons/modules/XEH_postInit.sqf b/addons/modules/XEH_postInit.sqf index a80c1bcfe..0a83fc386 100644 --- a/addons/modules/XEH_postInit.sqf +++ b/addons/modules/XEH_postInit.sqf @@ -99,3 +99,12 @@ if (isServer) then { _unit assignAsGunner _vehicle; [_unit] orderGetIn true; }] call CBA_fnc_addEventHandler; + +[QGVAR(injureUnit), { + params ["_unit", "_damageValues"]; + + { + _x params ["_hitpoint", "_damage"]; + _unit setHit [_hitpoint, _damage]; + } forEach _damageValues; +}] call CBA_fnc_addEventHandler; diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index 6150f0717..9a8df5b0a 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -45,6 +45,7 @@ class CfgPatches { QGVAR(moduleHeal), QGVAR(moduleHideTerrainObjects), QGVAR(moduleHideZeus), + QGVAR(moduleInjure), QGVAR(moduleLightSource), QGVAR(moduleMakeInvincible), QGVAR(moduleNuke), diff --git a/addons/modules/functions/fnc_moduleInjure.sqf b/addons/modules/functions/fnc_moduleInjure.sqf new file mode 100644 index 000000000..efbb61ff7 --- /dev/null +++ b/addons/modules/functions/fnc_moduleInjure.sqf @@ -0,0 +1,112 @@ +#include "script_component.hpp" +/* + * Author: CreepPork + * Zeus module function to injure a player or an AI. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleInjure + * + * Public: No + */ + +params ["_logic"]; + +private _unit = attachedTo _logic; +deleteVehicle _logic; + +if (isNull _unit) exitWith { + [LSTRING(NoUnitSelected)] call EFUNC(common,showMessage); +}; + +if !(_unit isKindOf "CAManBase") exitWith { + [LSTRING(OnlyInfantry)] call EFUNC(common,showMessage); +}; + +if (!alive _unit) exitWith { + [LSTRING(OnlyAlive)] call EFUNC(common,showMessage); +}; + +private _fnc_getDamageDefault = { + params ["_unit", "_hitpoint"]; + + private _damage = _unit getHit _hitpoint; + + // Ranges are used if a unit gets shot and it's not the precise value anymore + if (_damage == 0) exitWith { 0 }; // No damage + if (_damage > 0 && _damage < 0.5) exitWith { 1 }; // Low damage + if (_damage >= 0.5 && _damage < 0.9) exitWith { 2 }; // Medium (limping) damage + if (_damage >= 0.9) exitWith { 3 }; // Severe damage +}; + +[ + LSTRING(ModuleInjure), + [ + [ + "TOOLBOX", + ELSTRING(damage,HitHead), + [ + [_unit, "head"] call _fnc_getDamageDefault, + 1, + 4, + ["None", "Low", "Medium", "Severe"] + ], + true + ], + [ + "TOOLBOX", + ELSTRING(damage,HitBody), + [ + [_unit, "body"] call _fnc_getDamageDefault, + 1, + 4, + ["None", "Low", "Medium", "Severe"] + ], + true + ], + [ + "TOOLBOX", + ELSTRING(damage,HitHands), + [ + [_unit, "hands"] call _fnc_getDamageDefault, + 1, + 4, + ["None", "Low", "Medium", "Severe"] + ], + true + ], + [ + "TOOLBOX", + ELSTRING(damage,HitLegs), + [ + [_unit, "legs"] call _fnc_getDamageDefault, + 1, + 4, + ["None", "Low", "Limping", "Severe"] + ], + true + ] + ], + { + params ["_dialogValues", "_unit"]; + _dialogValues params ["_head", "_body", "_hands", "_legs"]; + private _damageValues = [0, 0.49, 0.7, 0.9]; + + [QGVAR(injureUnit), [ + _unit, + [ + ["head", _damageValues select _head], + ["body", _damageValues select _body], + ["hands", _damageValues select _hands], + ["legs", _damageValues select _legs] + ] + ], _unit] call CBA_fnc_targetEvent; + }, + {}, + _unit +] call EFUNC(dialog,create); diff --git a/addons/modules/stringtable.xml b/addons/modules/stringtable.xml index 9612d9f2e..c4e67f3fb 100644 --- a/addons/modules/stringtable.xml +++ b/addons/modules/stringtable.xml @@ -2444,5 +2444,8 @@ Vehicle must have other crew available 車両には空いている乗員席がありません + + Injure +