From 001942b2ed6b56f10b2b79b56d67dd0cc5bf62a4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 21 Oct 2018 23:37:16 +0200 Subject: [PATCH] Vehicle Lock - Enable for planes (#6646) * enable vehicle lock module for planes * Add actions to planes * improved lazy eval * remove superfluous parent class check * IS_KIND_OF_ANY macro * Update addons/vehiclelock/functions/fnc_moduleSync.sqf * Improve handleVehicleInitPost XEH --- addons/vehiclelock/CfgEventHandlers.hpp | 18 ---------- addons/vehiclelock/CfgVehicles.hpp | 3 ++ addons/vehiclelock/XEH_postInit.sqf | 14 +++++--- .../functions/fnc_handleVehicleInitPost.sqf | 36 +++++++------------ .../vehiclelock/functions/fnc_moduleSync.sqf | 4 ++- addons/vehiclelock/script_component.hpp | 2 ++ 6 files changed, 31 insertions(+), 46 deletions(-) diff --git a/addons/vehiclelock/CfgEventHandlers.hpp b/addons/vehiclelock/CfgEventHandlers.hpp index 712cc2be1c..becf395052 100644 --- a/addons/vehiclelock/CfgEventHandlers.hpp +++ b/addons/vehiclelock/CfgEventHandlers.hpp @@ -16,21 +16,3 @@ class Extended_PostInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; - -class Extended_InitPost_EventHandlers { - class Car { - class ADDON { - serverInit = QUOTE(_this call FUNC(handleVehicleInitPost)); - }; - }; - class Tank { - class ADDON { - serverInit = QUOTE(_this call FUNC(handleVehicleInitPost)); - }; - }; - class Helicopter { - class ADDON { - serverInit = QUOTE(_this call FUNC(handleVehicleInitPost)); - }; - }; -}; diff --git a/addons/vehiclelock/CfgVehicles.hpp b/addons/vehiclelock/CfgVehicles.hpp index 1115928057..4cbfd5aa6a 100644 --- a/addons/vehiclelock/CfgVehicles.hpp +++ b/addons/vehiclelock/CfgVehicles.hpp @@ -58,6 +58,9 @@ class CfgVehicles { class Helicopter: Air { MACRO_LOCK_ACTIONS }; + class Plane: Air { + MACRO_LOCK_ACTIONS + }; class Motorcycle: LandVehicle { MACRO_LOCK_ACTIONS }; diff --git a/addons/vehiclelock/XEH_postInit.sqf b/addons/vehiclelock/XEH_postInit.sqf index a50168dd92..64bd4fd642 100644 --- a/addons/vehiclelock/XEH_postInit.sqf +++ b/addons/vehiclelock/XEH_postInit.sqf @@ -4,12 +4,18 @@ [QGVAR(setupCustomKey), {_this call FUNC(serverSetupCustomKeyEH)}] call CBA_fnc_addEventHandler; [QGVAR(setVehicleLock), {_this call FUNC(setVehicleLockEH)}] call CBA_fnc_addEventHandler; -if (!hasInterface) exitwith {}; - ["ace_settingsInitialized", { - TRACE_1("SettingsInitialized eh",GVAR(LockVehicleInventory)); + TRACE_2("SettingsInitialized eh",GVAR(LockVehicleInventory),GVAR(VehicleStartingLockState)); - if (GVAR(LockVehicleInventory)) then { + if (hasInterface && {GVAR(LockVehicleInventory)}) then { ["CAManBase", "InventoryOpened", {_this call FUNC(onOpenInventory)}] call CBA_fnc_addClassEventHandler; }; + if (isServer && {GVAR(VehicleStartingLockState) != -1}) then { + [{ + TRACE_1("adding lock handler",GVAR(VehicleStartingLockState)); + { + [_x, "initpost", LINKFUNC(handleVehicleInitPost), true, [], true] call CBA_fnc_addClassEventHandler; + } forEach ["Car", "Tank", "Air"]; + }, [], 0.25] call CBA_fnc_waitAndExecute; + }; }] call CBA_fnc_addEventHandler; diff --git a/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf b/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf index e79a7b1573..eb0ecb21a7 100644 --- a/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf +++ b/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf @@ -2,7 +2,7 @@ /* * Author: PabstMirror * For every lockable vehicle, sets the starting lock state to a sane value. - * Only run if the InitModule is placed. + * Only run if the enabled via settings * * Arguments: * 0: Vehicle @@ -16,28 +16,18 @@ * Public: No */ -if (!isServer) exitWith {}; - params ["_vehicle"]; -TRACE_1("params",_vehicle); +TRACE_1("handleVehicleInitPost",_vehicle); -[{ - //If the module wasn't placed, just exit (needs to be in wait because objectInitEH is before moduleInit) - if (GVAR(VehicleStartingLockState) == -1) exitWith {}; - - params ["_vehicle"]; - - if ((_vehicle isKindOf "Car") || {_vehicle isKindOf "Tank"} || {_vehicle isKindOf "Helicopter"}) then { - //set lock state (eliminates the ambigious 1-"Default" and 3-"Locked for Player" states) - private _lock = switch (GVAR(VehicleStartingLockState)) do { - case (0): { (locked _vehicle) in [2, 3] }; - case (1): { true }; - case (2): { false }; - }; - if ((_lock && {(locked _vehicle) != 2}) || {!_lock && {(locked _vehicle) != 0}}) then { - TRACE_3("Setting Lock State",_lock,(typeOf _vehicle),_vehicle); - [QGVAR(SetVehicleLock), [_vehicle, _lock], [_vehicle]] call CBA_fnc_targetEvent; - }; +if (alive _vehicle) then { + //set lock state (eliminates the ambigious 1-"Default" and 3-"Locked for Player" states) + private _lock = switch (GVAR(VehicleStartingLockState)) do { + case 0: {locked _vehicle in [2, 3]}; + case 1: {true}; + case 2: {false}; }; - //Delay call until mission start (so everyone has the eventHandler's installed) -}, [_vehicle], 0.25] call CBA_fnc_waitAndExecute; + if ((_lock && {locked _vehicle != 2}) || {!_lock && {locked _vehicle != 0}}) then { + TRACE_3("Setting Lock State",_lock,typeOf _vehicle,_vehicle); + [QGVAR(SetVehicleLock), [_vehicle, _lock], [_vehicle]] call CBA_fnc_targetEvent; + }; +}; diff --git a/addons/vehiclelock/functions/fnc_moduleSync.sqf b/addons/vehiclelock/functions/fnc_moduleSync.sqf index 75fef647d1..5aede3f620 100644 --- a/addons/vehiclelock/functions/fnc_moduleSync.sqf +++ b/addons/vehiclelock/functions/fnc_moduleSync.sqf @@ -28,7 +28,9 @@ if !(_activated) exitWith {WARNING("Vehicle Lock Sync Module - placed but not ac params ["_syncedObjects"]; private _listOfVehicles = _syncedObjects select { - (_x isKindOf "Car") || {(_x isKindOf "Tank") || {_x isKindOf "Helicopter"}} + private _object = _x; + #define CLASSNAMES ["Car", "Tank", "Air"] + IS_KIND_OF_ANY(_object,CLASSNAMES) }; if (_listOfVehicles isEqualTo []) exitWith { //Verbose error for mission makers (only shows on server) diff --git a/addons/vehiclelock/script_component.hpp b/addons/vehiclelock/script_component.hpp index 77b7186373..066e4ea8b6 100644 --- a/addons/vehiclelock/script_component.hpp +++ b/addons/vehiclelock/script_component.hpp @@ -15,3 +15,5 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define IS_KIND_OF_ANY(object,classnames) ((classnames) findIf {(object) isKindOf _x} > -1)