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

Add turret event #1237

Merged
merged 9 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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/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