Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Add ace_common_fnc_addExplosionEventHandler #10243

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ PREP(_handleRequestAllSyncedEvents);
// other eventhandlers
PREP(addActionEventHandler);
PREP(addActionMenuEventHandler);
PREP(addExplosionEventHandler);
PREP(addMapMarkerCreatedEventHandler);
PREP(addPlayerEH);

Expand Down
38 changes: 38 additions & 0 deletions addons/common/functions/fnc_addExplosionEventHandler.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "..\script_component.hpp"
/*
* Author: johnb432, PabstMirror
* Adds event hander for explosions (for local projectiles)
* Warning: For shots that are tracers and explosive the event will trigger on all machines in range
* This function may be changed after 2.18!
*
* Arguments:
* 0: Code to execute <CODE>
*
* Return Value:
* The CBA Event Handler Index <NUMBER>
*
* Example:
* [{systemChat "boom"}] call ace_common_fnc_addExplosionEventHandler
*
* Public: No (maybe after 2.18)
*/

params [["_code", {}, [{}]]];

if !(missionNamespace getVariable [QGVAR(addExplosionEventHandlerActive), false]) then {
GVAR(addExplosionEventHandlerActive) = true;

PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
addMissionEventHandler ["ProjectileCreated", {
params ["_projectile"];
TRACE_2("pc",typeOf _projectile,local _projectile);

if (!local _projectile) exitWith {}; // Rockets only explode on local clients

_projectile addEventHandler ["Explode", {
TRACE_1("exp",_this);
[QGVAR(explosion), _this] call CBA_fnc_localEvent;
}];
}];
};

[QGVAR(explosion), _code] call CBA_fnc_addEventHandler
21 changes: 11 additions & 10 deletions addons/hearing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ if (isServer) then {
// Only install event handler if combat deafness is enabled
if (!GVAR(enableCombatDeafness)) exitWith {};

addMissionEventHandler ["ProjectileCreated", {
params ["_projectile"];

if (!local _projectile) exitWith {};

// Rockets only explode on local clients
_projectile addEventHandler ["Explode", {
[QGVAR(explosion), _this] call CBA_fnc_globalEvent;
}];
}];
[{ // Convert ace_common's local explosion to a hearing global explosion event
params ["_projectile", "_pos"];
TRACE_1("Explode",_this);

// If projectile is local only, don't raise event globally
if (isMultiplayer && {(netId _projectile) == "0:0"}) then { // TODO: netId always returns valid after 2.18
PabstMirror marked this conversation as resolved.
Show resolved Hide resolved
[QGVAR(explosion), [_projectile, _pos]] call CBA_fnc_localEvent;
} else {
[QGVAR(explosion), [_projectile, _pos]] call CBA_fnc_globalEvent;
};
}] call EFUNC(common,addExplosionEventHandler);
}] call CBA_fnc_addEventHandler;

if (!hasInterface) exitWith {};
Expand Down
3 changes: 1 addition & 2 deletions addons/hearing/functions/fnc_explosion.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* Arguments:
* 0: Projectile <OBJECT>
* 1: Explosion position ASL <ARRAY>
* 2: Velocity <ARRAY> (unused)
*
* Return Value:
* None
*
* Example:
* [_projectile, [0, 0, 0], [0, 0, 0]] call ace_hearing_fnc_explosion
* [_projectile, [0, 0, 0]] call ace_hearing_fnc_explosion
*
* Public: No
*/
Expand Down