Skip to content

Commit

Permalink
Exposed projectile event handlers for both blacklist use and other sh…
Browse files Browse the repository at this point in the history
…enanigans.
  • Loading branch information
lambdatiger committed May 19, 2024
1 parent b9aa3cb commit eaff498
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions addons/frag/functions/fnc_addBlacklist.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ params ["_projectile"];
TRACE_1("addBlackList",_projectile);

_projectile setVariable [QGVAR(blacklisted), true, true];
_projectile removeEventHandler ["HitPart", _projectile getVariable [QGVAR(hitPartEH), -1]];
_projectile removeEventHandler ["Explode", _projectile getVariable [QGVAR(explodeEH), -1]];
17 changes: 7 additions & 10 deletions addons/frag/functions/fnc_initRound.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ if (!isServer) exitWith {};
params ["_projectile"];

private _ammo = typeOf _projectile;
if (_ammo isEqualTo "" || {isNull _projectile}) exitWith {
TRACE_2("bad ammo or projectile",_ammo,_projectile);
if (_ammo isEqualTo "" || {isNull _projectile}
|| {_projectile getVariable [QGVAR(blacklisted), false]}) exitWith {
TRACE_2("bad ammo or projectile, or blackList",_ammo,_projectile);
};

if (_projectile getVariable [QGVAR(blacklisted), false]) exitWith {};

if (GVAR(enabled) && {_ammo call FUNC(shouldFrag)}) then {
_projectile addEventHandler [
private _explodeEH = _projectile addEventHandler [
"Explode",
{
params ["_projectile", "_posASL", "_velocity"];

if (_projectile getVariable [QGVAR(blacklisted), false]) exitWith {};

private _shotParents = _projectile getVariable [QGVAR(shotParent), getShotParents _projectile];
private _ammo = typeOf _projectile;
// wait for frag damage to kill units before spawning fragments
Expand All @@ -47,16 +44,15 @@ if (GVAR(enabled) && {_ammo call FUNC(shouldFrag)}) then {
};
}
];
_projectile setVariable [QGVAR(explodeEH), _explodeEH];
};

if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
_projectile addEventHandler [
private _hitPartEH = _projectile addEventHandler [
"HitPart",
{
params ["_projectile", "_hitObject", "", "_posASL", "_velocity", "_surfNorm", "", "", "_surfType"];

if (_projectile getVariable [QGVAR(blacklisted), false]) exitWith {};

// starting v2.18 it may be faster to use the instigator parameter, the same as the second entry shotParents, to recreate _shotParent
// The "explode" EH does not get the same parameter
private _shotParent = getShotParents _projectile;
Expand All @@ -72,6 +68,7 @@ if (GVAR(spallEnabled) && {_ammo call FUNC(shouldSpall)}) then {
] call CBA_fnc_execNextFrame;
}
];
_projectile setVariable [QGVAR(hitPartEH), _hitPartEH];
};
#ifdef DEBUG_MODE_DRAW
if (GVAR(debugOptions) && {_ammo call FUNC(shouldFrag) || {_ammo call FUNC(shouldSpall)}}) then {
Expand Down

0 comments on commit eaff498

Please sign in to comment.