Skip to content

Commit

Permalink
Merge pull request #1237 from neilzar/turret-event
Browse files Browse the repository at this point in the history
Add turret event
  • Loading branch information
commy2 committed Oct 12, 2019
2 parents f9f0d02 + 7bb6cd1 commit e4a00b3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/events/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CfgFunctions {
PATHTO_FNC(serverEvent);
PATHTO_FNC(remoteEvent);
PATHTO_FNC(targetEvent);
PATHTO_FNC(turretEvent);
PATHTO_FNC(ownerEvent);
PATHTO_FNC(addMarkerEventHandler);
PATHTO_FNC(removeMarkerEventHandler);
Expand Down
1 change: 1 addition & 0 deletions addons/events/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (isServer) then {

if (isServer) then {
TEVENT_PVAR_STR addPublicVariableEventHandler {(_this select 1) call CBA_fnc_targetEvent};
TUEVENT_PVAR_STR addPublicVariableEventHandler {(_this select 1) call CBA_fnc_turretEvent};
};
};

Expand Down
52 changes: 52 additions & 0 deletions addons/events/fnc_turretEvent.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_turretEvent
Description:
Raises a CBA event on the machine where the vehicle's turret is local.
Parameters:
_eventName - Type of event to publish. <STRING>
_params - Parameters to pass to the event handlers. <ANY>
_vehicle - Vehicle to which the turret belongs. <OBJECT>
_turretPath - The turret to execute on. Will accept both [] and [-1] for driver's turret. <ARRAY>
Returns:
None
Examples:
(begin example)
["test", ["turret"], cursorObject, [-1]] call CBA_fnc_turretEvent;
(end)
Author:
NeilZar
---------------------------------------------------------------------------- */
SCRIPT(turretEvent);

params [["_eventName", "", [""]], ["_params", []], ["_vehicle", objNull, [objNull]], ["_turretPath", [-1], [[]]]];

if (_turretPath isEqualTo []) then {
_turretPath = [-1];
};

if (_vehicle turretLocal _turretPath) exitWith {
CALL_EVENT(_params,_eventName);
};

if (isServer) then {
// retrieve the turret owner and send the event
private "_turretOwner";
if (_turretPath isEqualTo [-1]) then {
_turretOwner = owner _vehicle;
} else {
_turretOwner = _vehicle turretOwner _turretPath;
};

SEND_EVENT_TO_CLIENT(_params,_eventName,_turretOwner);
} else {
// only server knows turret owners. let server handle the event.
SEND_TUEVENT_TO_SERVER(_params,_eventName,_vehicle,_turretPath);
};

nil
6 changes: 6 additions & 0 deletions addons/events/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#define SEND_TEVENT_TO_SERVER(params,name,targets) TEVENT_PVAR = [name, params, targets]; publicVariableServer TEVENT_PVAR_STR

// turret events
#define TUEVENT_PVAR CBAv
#define TUEVENT_PVAR_STR QUOTE(TUEVENT_PVAR)

#define SEND_TUEVENT_TO_SERVER(params,name,vehicle,turret) TUEVENT_PVAR = [name, params, vehicle, turret]; publicVariableServer TUEVENT_PVAR_STR

#define CALL_EVENT(args,event) {\
if !(isNil "_x") then {\
args call _x;\
Expand Down

0 comments on commit e4a00b3

Please sign in to comment.