From 23c464970b06c66b26ff1aa0e80819e741b2cd51 Mon Sep 17 00:00:00 2001 From: He-Man Date: Thu, 4 Apr 2019 21:14:56 +0200 Subject: [PATCH] Heal / Revive - Usage of HandleDamage EH --- .../event_handlers/EPOCH_HandleDamage.sqf | 61 +++++++++++++++++++ .../functions/EPOCH_fnc_playerFired.sqf | 1 + .../customs/EPOCH_custom_EH_HandleDamage.sqf | 21 +++++++ Sources/epoch_code/init/client_init.sqf | 3 + .../Configs/CfgClientFunctions.hpp | 2 + .../epoch_config/Configs/CfgEpochClient.hpp | 6 +- .../EPOCH_server_revivePlayer.sqf | 7 ++- 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 Sources/epoch_code/compile/event_handlers/EPOCH_HandleDamage.sqf create mode 100644 Sources/epoch_code/customs/EPOCH_custom_EH_HandleDamage.sqf diff --git a/Sources/epoch_code/compile/event_handlers/EPOCH_HandleDamage.sqf b/Sources/epoch_code/compile/event_handlers/EPOCH_HandleDamage.sqf new file mode 100644 index 00000000..e66115c1 --- /dev/null +++ b/Sources/epoch_code/compile/event_handlers/EPOCH_HandleDamage.sqf @@ -0,0 +1,61 @@ +/* + Author: He-Man - EpochMod.com + + Contributors: + + Description: + HandleDamage Eventhandler for A3 Epoch + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/EPOCH_HandleDamage.sqf +*/ +params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"]; +if !(_source isEqualTo _unit) then { + switch _projectile do { + case "B_EnergyPack": { + if (_source distance _unit > 10) exitwith {}; + if (missionnamespace getvariable ["EPOCH_OldRevive",false]) exitwith {}; + if ((missionnamespace getvariable ["EPOCH_HandleDamageTimeOut",diag_ticktime]) > diag_ticktime) exitwith {}; // prevent multiple actions here + EPOCH_HandleDamageTimeOut = diag_ticktime + 0.1; + _attachments = handgunItems _source; + if ("Heal_EPOCH" in _attachments) then { + if (lifeState _unit == "INCAPACITATED") exitwith { + EPOCH_HandleDamageTimeOut = diag_ticktime + 1; + _unit setUnconscious false; + _unit playMoveNow 'AmovPercMstpSnonWnonDnon'; + }; + _highestDMG = 0; + _currentHIT = -1; + _currentDMG = 0; + { + _currentDMG = _x; + if (_currentDMG > _highestDMG) then{ + _highestDMG = _currentDMG; + _currentHIT = _forEachIndex; + }; + }forEach((getAllHitPointsDamage _unit) param[2,[]]); + if (_highestDMG > 0) then { + _newDMG = 0; + [_unit,[[_currentHIT,_newDMG]]] call EPOCH_client_repairVehicle; + } else { + if ((damage _unit) > 0) then { + [_unit,["ALL",0],player,Epoch_personalToken] remoteExec ["EPOCH_server_repairVehicle",2]; + }; + }; + }; + if ("Defib_EPOCH" in _attachments) then { + if !(alive _unit) then { + EPOCH_HandleDamageTimeOut = diag_ticktime + 1; + [_unit,_source,Epoch_personalToken] remoteExec ["EPOCH_server_revivePlayer",2]; + }; + }; + }; + case "B_KnockOut": { + _unit setUnconscious true; + }; + }; +}; +_damage diff --git a/Sources/epoch_code/compile/functions/EPOCH_fnc_playerFired.sqf b/Sources/epoch_code/compile/functions/EPOCH_fnc_playerFired.sqf index 0dc80d0d..2192d57d 100644 --- a/Sources/epoch_code/compile/functions/EPOCH_fnc_playerFired.sqf +++ b/Sources/epoch_code/compile/functions/EPOCH_fnc_playerFired.sqf @@ -41,6 +41,7 @@ switch true do { _attachments = handgunItems player; _heal = false; if (_cursorTarget isKindOf "Man") then { + if !(missionnamespace getvariable ["EPOCH_OldRevive",false]) exitwith {}; if ("Heal_EPOCH" in _attachments) then { _heal = true; }; diff --git a/Sources/epoch_code/customs/EPOCH_custom_EH_HandleDamage.sqf b/Sources/epoch_code/customs/EPOCH_custom_EH_HandleDamage.sqf new file mode 100644 index 00000000..26d0c9ef --- /dev/null +++ b/Sources/epoch_code/customs/EPOCH_custom_EH_HandleDamage.sqf @@ -0,0 +1,21 @@ +/* + Author: He-Man - EpochMod.com + + Contributors: + + Description: + Custom A3 Epoch HandleDamage Eventhandler + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/custom/EPOCH_custom_EH_HandleDamage.sqf +*/ +params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"]; + + + + + +_damage diff --git a/Sources/epoch_code/init/client_init.sqf b/Sources/epoch_code/init/client_init.sqf index 397101f5..65e1e770 100644 --- a/Sources/epoch_code/init/client_init.sqf +++ b/Sources/epoch_code/init/client_init.sqf @@ -89,6 +89,9 @@ EPOCH_maxBuildingHeight = ["CfgEpochClient", "maxBuildingHeight", 100] call EPOC EPOCH_MaxBuildingTilt = ["CfgEpochClient", "MaxBuildingTilt", 180] call EPOCH_fnc_returnConfigEntryV2; Epoch_NuisanceMulti = ["CfgEpochClient", "NuisanceMulti", 0.5] call EPOCH_fnc_returnConfigEntryV2; +// Use Eventhandler "Fired" on Reviver instead of Eventhandler "HandeDamage" on Client to be revived for Heal / Revive Player +EPOCH_OldRevive = ["CfgEpochClient", "UseOldRevive", false] call EPOCH_fnc_returnConfigEntryV2; + //ON INIT and RESPAWN call EPOCH_clientInit; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index b338363c..799cd1eb 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -101,6 +101,7 @@ class CfgClientFunctions { class getInMan {}; class getOutMan {}; + class HandleDamage {}; class InventoryClosed {}; class InventoryOpened {}; }; @@ -232,6 +233,7 @@ class CfgClientFunctions class custom_EH_FiredNear {}; class custom_EH_GetInMan {}; class custom_EH_GetOutMan {}; + class custom_EH_HandleDamage {}; class custom_EH_Hit {}; class custom_EH_InventoryClosed {}; class custom_EH_InventoryOpened {}; diff --git a/Sources/epoch_config/Configs/CfgEpochClient.hpp b/Sources/epoch_config/Configs/CfgEpochClient.hpp index 5c2e045f..30e95dc3 100644 --- a/Sources/epoch_config/Configs/CfgEpochClient.hpp +++ b/Sources/epoch_config/Configs/CfgEpochClient.hpp @@ -18,6 +18,8 @@ class CfgEpochClient ArmAVersion = 176; debug = "true"; // true = enable extra rpt debug lines, false to disable + UseOldRevive = "false"; // Revive / Heal Player has been changed to use "HandleDamage" Eventhandler. If scripts are breaking it for you, set it to true (not recommended!) + antagonistRngChance = 100; // increase number to reduce chances and reduce to increase. Default 100 NuisanceMulti = 0.5; // Multi for Nuisance increase on shooting - higher Nuisance effect at least antagonist spawn change. (0-1, default 0.5) @@ -199,7 +201,7 @@ class CfgEpochClient displayAddEventHandler[] = {"keyDown","keyUp"}; keyDown = "(_this call EPOCH_KeyDown)"; keyUp = "(_this call EPOCH_KeyUp)"; - addEventHandler[] = {"Respawn","Put","Take","InventoryClosed","InventoryOpened","FiredMan","Killed","HandleRating","HandleScore","GetInMan","GetOutMan","Hit","SeatSwitchedMan","FiredNear"}; + addEventHandler[] = {"Respawn","Put","Take","InventoryClosed","InventoryOpened","FiredMan","Killed","HandleRating","HandleScore","HandleDamage","GetInMan","GetOutMan","Hit","SeatSwitchedMan","FiredNear"}; Respawn = "(_this select 0) call EPOCH_clientRespawn"; Put = "(_this select 1) call EPOCH_interact;_this call EPOCH_PutHandler;_this call Epoch_custom_EH_Put"; Take = "(_this select 1) call EPOCH_interact;_this call EPOCH_UnisexCheck;_this call Epoch_custom_EH_Take"; @@ -209,7 +211,7 @@ class CfgEpochClient Killed = "_this call EPOCH_fnc_playerDeath;_this call Epoch_custom_EH_Killed"; HandleRating = "0"; HandleScore = ""; - HandleDamage = ""; + HandleDamage = "_this call EPOCH_HandleDamage;_this call EPOCH_custom_EH_HandleDamage"; HandleHeal = ""; Dammaged = ""; Hit = "_this call EPOCH_custom_EH_Hit"; diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_revivePlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_revivePlayer.sqf index 54bf15ca..9f6fa2d9 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_revivePlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_revivePlayer.sqf @@ -13,12 +13,13 @@ https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_server_revivePlayer.sqf */ //[[[cog import generate_private_arrays ]]] -private ["_loadabs","_loadout","_CorpseCrypto","_PlayerCrypto","_attachments","_cIndex","_class","_currwh","_deleteprimary","_deletesecondary","_dir","_droppedPrimary","_droppedSecondary","_droppedWeapons","_equipped","_group","_garbage","_location","_newPlyr","_playerGroup","_playerUID","_token","_type","_vars","_wMags","_wMagsArray","_weapon","_wh","_kIndex","_reviver","_reviverCStats","_reviverKarma","_reviverKarmaAdj"]; +private ["_caller","_loadabs","_loadout","_CorpseCrypto","_PlayerCrypto","_attachments","_cIndex","_class","_currwh","_deleteprimary","_deletesecondary","_dir","_droppedPrimary","_droppedSecondary","_droppedWeapons","_equipped","_group","_garbage","_location","_newPlyr","_playerGroup","_playerUID","_token","_type","_vars","_wMags","_wMagsArray","_weapon","_wh","_kIndex","_reviver","_reviverCStats","_reviverKarma","_reviverKarmaAdj"]; //[[[end]]] params ["_player","_reviver",["_token","",[""]] ]; - -if !([_reviver, _token] call EPOCH_server_getPToken) exitWith{}; +_caller = if (remoteExecutedOwner == (owner _reviver)) then {_reviver} else {_player}; +if !([_caller, _token] call EPOCH_server_getPToken) exitWith{}; if (isNull _player) exitWith{}; +if !(isplayer _reviver) exitWith{}; if (_player distance _reviver > 20) exitWith{}; if (!local _player) then {