Jelajahi Sumber

Fix shield hit locality problem

m3ales 3 tahun lalu
induk
melakukan
5bfb97ac1a

+ 4 - 0
addons/RD501_Main/XEH_postinit.sqf

@@ -155,6 +155,10 @@ if(hasInterface) then {
 	_this call rd501_fnc_shield_onNormalHealth;
 }] call CBA_fnc_addEventHandler;
 
+["rd501_shield_hit", {
+	_this call rd501_fnc_shield_hitHandler;
+}] call CBA_fnc_addEventHandler;
+
 // Vehicle EMP
 ["All", "HitPart", {
 	_this call rd501_fnc_emp_hitHandler;

+ 1 - 0
addons/RD501_Main/XEH_preInit.sqf

@@ -172,6 +172,7 @@ macro_prep_xeh(shield\fnc_shield_getTextureSet.sqf,shield_getTextureSet)
 macro_prep_xeh(shield\fnc_shield_init.sqf,shield_init)
 macro_prep_xeh(shield\fnc_shield_onDestroy.sqf,shield_onDestroy)
 macro_prep_xeh(shield\fnc_shield_onHit.sqf,shield_onHit)
+macro_prep_xeh(shield\fnc_shield_hitHandler.sqf,shield_hitHandler)
 macro_prep_xeh(shield\fnc_shield_onLowHealth.sqf,shield_onLowHealth)
 macro_prep_xeh(shield\fnc_shield_onNormalHealth.sqf,shield_onNormalHealth)
 macro_prep_xeh(shield\fnc_shield_regenPerFrameHandler.sqf,shield_regenPerFrameHandler)

+ 26 - 0
addons/RD501_Main/functions/shield/fnc_shield_hitHandler.sqf

@@ -0,0 +1,26 @@
+
+params["_ammo", "_target"];
+
+private _health = _target getVariable ["rd501_shield_currentHealth", false];
+
+if(_health isEqualTo false) exitWith { systemChat "[RD501][Shield][Hit Handler] Health not found"; };
+
+_ammo params ["_directHit", "_indirectHit", "_indirectRange", "_explosionHit", "_ammoClass"];
+private _hit = _directHit + (_indirectHit/(_indirectRange max 0.1)) + _explosionHit;
+private _result = _health - _hit;
+
+
+if(_result <= 0) then {
+	_target setVariable ["rd501_shield_currentHealth", _result, true];
+	private _ehId = _target getVariable ["rd501_shield_ehId", -1];
+	["rd501_shield_destroy", [_target], _target] call cba_fnc_targetEvent;
+	_target  removeEventHandler ["HitPart", _ehId];
+}
+else
+{
+	// Set locally only to reduce network traffic
+	_target setVariable ["rd501_shield_currentHealth", _result];
+	[_target] call rd501_fnc_shield_checkState;
+	private _delay = _target getVariable["rd501_shield_regenDelay", 5];
+	_target setVariable ["rd501_shield_regenStartsAt", diag_tickTime + _delay];
+};

+ 1 - 1
addons/RD501_Main/functions/shield/fnc_shield_init.sqf

@@ -79,4 +79,4 @@ _target setVariable["rd501_shield_pfhId", _pfhId];
 
 private _ehId = _target addEventHandler["HitPart", {
 	_this call rd501_fnc_shield_onHit;
-}];
+}];

+ 1 - 22
addons/RD501_Main/functions/shield/fnc_shield_onHit.sqf

@@ -2,25 +2,4 @@
 
 if(_target isEqualTo objNull) exitWith { systemChat "Target is null idk why"; }; 
 
-private _health = _target getVariable ["rd501_shield_currentHealth", false];
-
-if(_health isEqualTo false) exitWith { systemChat "Health not found"; };
-
-_ammo params ["_directHit", "_indirectHit", "_indirectRange", "_explosionHit", "_ammoClass"];
-private _hit = _directHit + (_indirectHit/(_indirectRange max 0.1)) + _explosionHit;
-private _result = _health - _hit;
-
-if(_result <= 0) then {
-	_target setVariable ["rd501_shield_currentHealth", _result, true];
-	private _ehId = _target getVariable ["rd501_shield_ehId", -1];
-	["rd501_shield_destroy", [_target], _target] call cba_fnc_targetEvent;
-	_target  removeEventHandler ["HitPart", _ehId];
-}
-else
-{
-	// Set locally only to reduce network traffic
-	_target setVariable ["rd501_shield_currentHealth", _result];
-	[_target] call rd501_fnc_shield_checkState;
-	private _delay = _target getVariable["rd501_shield_regenDelay", 5];
-	_target setVariable ["rd501_shield_regenStartsAt", diag_tickTime + _delay];
-};
+["rd501_shield_hit", [_ammo, _target], _target] call CBA_fnc_targetEvent;

+ 1 - 1
addons/RD501_Main/functions/shield/fnc_shield_regenPerFrameHandler.sqf

@@ -8,7 +8,7 @@ if(_shield isEqualTo objNull || !alive _shield) exitWith {
 
 private _regenDelayTime = _shield getVariable ["rd501_shield_regenStartsAt", diag_tickTime];;
 if(diag_tickTime < _regenDelayTime) exitWith {
-	diag_log format["[RD501][Shield] Still waiting for delay before regen on %1", _regenDelayTime];
+	// diag_log format["[RD501][Shield] Still waiting for delay before regen on %1", diag_tickTime - _regenDelayTime];
 };
 
 private _maxHealth = _shield getVariable["rd501_shield_maxHealth", 100];