Skip to content

Commit

Permalink
Vehicle Lock - Enable for planes (#6646)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
commy2 authored and PabstMirror committed Oct 21, 2018
1 parent 6f6b0d1 commit 001942b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 46 deletions.
18 changes: 0 additions & 18 deletions addons/vehiclelock/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
};
};
3 changes: 3 additions & 0 deletions addons/vehiclelock/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CfgVehicles {
class Helicopter: Air {
MACRO_LOCK_ACTIONS
};
class Plane: Air {
MACRO_LOCK_ACTIONS
};
class Motorcycle: LandVehicle {
MACRO_LOCK_ACTIONS
};
Expand Down
14 changes: 10 additions & 4 deletions addons/vehiclelock/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
36 changes: 13 additions & 23 deletions addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 <OBJECT>
Expand All @@ -16,28 +16,18 @@
* Public: No
*/

if (!isServer) exitWith {};

params ["_vehicle"];
TRACE_1("params",_vehicle);

[{
//If the module wasn't placed, just exit (needs to be in wait because objectInitEH is before moduleInit)
if (GVAR(VehicleStartingLockState) == -1) exitWith {};
TRACE_1("handleVehicleInitPost",_vehicle);

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};
};
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;
};
//Delay call until mission start (so everyone has the eventHandler's installed)
}, [_vehicle], 0.25] call CBA_fnc_waitAndExecute;
};
4 changes: 3 additions & 1 deletion addons/vehiclelock/functions/fnc_moduleSync.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions addons/vehiclelock/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 001942b

Please sign in to comment.