From f8b8d7dd165eae627550c949e4b78def6af1bf99 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 28 Apr 2015 00:08:28 -0500 Subject: [PATCH] Set Lock on postInit so spawned vehicles are set --- addons/vehiclelock/CfgEventHandlers.hpp | 23 ++++++++ addons/vehiclelock/CfgVehicles.hpp | 57 ++++++++++++------- addons/vehiclelock/XEH_preInit.sqf | 1 + addons/vehiclelock/config.cpp | 4 ++ .../functions/fnc_handleVehicleInitPost.sqf | 39 +++++++++++++ .../vehiclelock/functions/fnc_moduleInit.sqf | 23 +------- .../functions/fnc_onOpenInventory.sqf | 2 +- 7 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf diff --git a/addons/vehiclelock/CfgEventHandlers.hpp b/addons/vehiclelock/CfgEventHandlers.hpp index cf704d000c..85db25d4a0 100644 --- a/addons/vehiclelock/CfgEventHandlers.hpp +++ b/addons/vehiclelock/CfgEventHandlers.hpp @@ -15,3 +15,26 @@ class Extended_InventoryOpened_EventHandlers { }; }; }; +class Extended_InitPost_EventHandlers { + class CAManBase { + class ADDON { + serverInit = QUOTE(_this call FUNC(handleUnitInitPost)); + }; + }; + 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 65ad0568d6..94bcf34317 100644 --- a/addons/vehiclelock/CfgVehicles.hpp +++ b/addons/vehiclelock/CfgVehicles.hpp @@ -1,50 +1,65 @@ #define MACRO_LOCK_ACTIONS \ - class ACE_MainActions { \ + class ACE_SelfActions { \ class ACE_unlockVehicle { \ displayName = "$STR_ACE_Vehicle_Action_UnLock"; \ - distance = 4; \ condition = QUOTE(([ARR_2(_player, _target)] call FUNC(hasKeyForVehicle)) && {(locked _target) in [ARR_2(2,3)]}); \ statement = QUOTE([ARR_3('VehicleLock_SetVehicleLock', [_target], [ARR_2(_target,false)])] call EFUNC(common,targetEvent)); \ - showDisabled = 0; \ priority = 0.3; \ icon = QUOTE(PATHTOF(UI\key_menuIcon_ca.paa)); \ }; \ class ACE_lockVehicle { \ displayName = "$STR_ACE_Vehicle_Action_Lock"; \ - distance = 4; \ condition = QUOTE(([ARR_2(_player, _target)] call FUNC(hasKeyForVehicle)) && {(locked _target) in [ARR_2(0,1)]}); \ statement = QUOTE([ARR_3('VehicleLock_SetVehicleLock', [_target], [ARR_2(_target,true)])] call EFUNC(common,targetEvent)); \ - showDisabled = 0; \ priority = 0.2; \ icon = QUOTE(PATHTOF(UI\key_menuIcon_ca.paa)); \ }; \ class ACE_lockpickVehicle { \ displayName = "$STR_ACE_Vehicle_Action_Lockpick"; \ - distance = 4; \ condition = QUOTE([ARR_3(_player, _target, 'canLockpick')] call FUNC(lockpick)); \ statement = QUOTE([ARR_3(_player, _target, 'startLockpick')] call FUNC(lockpick)); \ - showDisabled = 0; \ priority = 0.1; \ }; \ + }; \ + class ACE_Actions { \ + class ACE_MainActions { \ + class ACE_unlockVehicle { \ + displayName = "$STR_ACE_Vehicle_Action_UnLock"; \ + distance = 4; \ + condition = QUOTE(([ARR_2(_player, _target)] call FUNC(hasKeyForVehicle)) && {(locked _target) in [ARR_2(2,3)]}); \ + statement = QUOTE([ARR_3('VehicleLock_SetVehicleLock', [_target], [ARR_2(_target,false)])] call EFUNC(common,targetEvent)); \ + priority = 0.3; \ + icon = QUOTE(PATHTOF(UI\key_menuIcon_ca.paa)); \ + }; \ + class ACE_lockVehicle { \ + displayName = "$STR_ACE_Vehicle_Action_Lock"; \ + distance = 4; \ + condition = QUOTE(([ARR_2(_player, _target)] call FUNC(hasKeyForVehicle)) && {(locked _target) in [ARR_2(0,1)]}); \ + statement = QUOTE([ARR_3('VehicleLock_SetVehicleLock', [_target], [ARR_2(_target,true)])] call EFUNC(common,targetEvent)); \ + priority = 0.2; \ + icon = QUOTE(PATHTOF(UI\key_menuIcon_ca.paa)); \ + }; \ + class ACE_lockpickVehicle { \ + displayName = "$STR_ACE_Vehicle_Action_Lockpick"; \ + distance = 4; \ + condition = QUOTE([ARR_3(_player, _target, 'canLockpick')] call FUNC(lockpick)); \ + statement = QUOTE([ARR_3(_player, _target, 'startLockpick')] call FUNC(lockpick)); \ + priority = 0.1; \ + }; \ + }; \ }; class CfgVehicles { class LandVehicle; class Car: LandVehicle { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; + MACRO_LOCK_ACTIONS }; class Tank: LandVehicle { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; + MACRO_LOCK_ACTIONS }; class Air; class Helicopter: Air { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; + MACRO_LOCK_ACTIONS }; class Logic; @@ -55,7 +70,7 @@ class CfgVehicles { author = "$STR_ACE_Common_ACETeam"; category = "ACE"; displayName = "Vehicle Lock Setup"; - function = QUOTE(DFUNC(moduleInit)); + function = QFUNC(moduleInit); scope = 2; isGlobal = 0; icon = QUOTE(PATHTOF(UI\Icon_Module_VehicleLock_ca.paa)); @@ -67,9 +82,9 @@ class CfgVehicles { typeName = "BOOL"; defaultValue = 0; }; - class SetLockState { - displayName = "Set Lock State"; // Argument label - description = "Set lock state for all vehicles on map at start"; // Tooltip description + class VehicleStartingLockState { + displayName = "Vehicle Starting Lock State"; // Argument label + description = "Set lock state for all vehicles (removes ambiguous lock states)"; // Tooltip description typeName = "NUMBER"; // Value type, can be "NUMBER", "STRING" or "BOOL" class values { class None {name = "As Is"; value = 0; default = 1;}; @@ -93,7 +108,7 @@ class CfgVehicles { author = "$STR_ACE_Common_ACETeam"; category = "ACE"; displayName = "Vehicle Key Assign"; - function = QUOTE(DFUNC(moduleSync)); + function = QFUNC(moduleSync); scope = 2; isGlobal = 0; icon = QUOTE(PATHTOF(UI\Icon_Module_VehicleKey_ca.paa)); diff --git a/addons/vehiclelock/XEH_preInit.sqf b/addons/vehiclelock/XEH_preInit.sqf index bdab28fc75..18a7062c24 100644 --- a/addons/vehiclelock/XEH_preInit.sqf +++ b/addons/vehiclelock/XEH_preInit.sqf @@ -4,6 +4,7 @@ ADDON = false; PREP(addKeyForVehicle); PREP(getVehicleSideKey); +PREP(handleVehicleInitPost); PREP(hasKeyForVehicle); PREP(lockpick); PREP(moduleInit); diff --git a/addons/vehiclelock/config.cpp b/addons/vehiclelock/config.cpp index 248a1e7ca0..608a892b45 100644 --- a/addons/vehiclelock/config.cpp +++ b/addons/vehiclelock/config.cpp @@ -20,6 +20,10 @@ class ACE_Settings { class GVAR(LockVehicleInventory) { value = 0; typeName = "BOOL"; + }; + class GVAR(VehicleStartingLockState) { + value = -1; + typeName = "SCALAR"; }; }; diff --git a/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf b/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf new file mode 100644 index 0000000000..df875b1859 --- /dev/null +++ b/addons/vehiclelock/functions/fnc_handleVehicleInitPost.sqf @@ -0,0 +1,39 @@ +/* + * Author: PabstMirror + * Function for sync module. Assigns keys for all synced vehicles to any players that are synced. + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * None + * + * Example: + * [car] call ACE_VehicleLock_fnc_handleVehicleInitPost + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_1(_vehicle); + +if (!isServer) exitWith {}; +if (GVAR(VehicleStartingLockState) == -1) exitWith {}; + +[{ + private ["_lock"]; + PARAMS_1(_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) + _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); + ["VehicleLock_SetVehicleLock", [_vehicle], [_vehicle, _lock]] call EFUNC(common,targetEvent); + }; + }; + //Delay call until mission start (so everyone has the eventHandler's installed) +}, [_vehicle], 0.25, 0.25] call EFUNC(common,waitAndExecute); \ No newline at end of file diff --git a/addons/vehiclelock/functions/fnc_moduleInit.sqf b/addons/vehiclelock/functions/fnc_moduleInit.sqf index c26e8aacbd..510b8ec7be 100644 --- a/addons/vehiclelock/functions/fnc_moduleInit.sqf +++ b/addons/vehiclelock/functions/fnc_moduleInit.sqf @@ -17,8 +17,6 @@ */ #include "script_component.hpp" -private ["_sideKeysAssignment", "_setLockState", "_lock"]; - PARAMS_3(_logic,_syncedUnits,_activated); if (!_activated) exitWith {WARNING("Vehicle Lock Init Module - placed but not active");}; @@ -27,23 +25,4 @@ if (!isServer) exitWith {}; //Set the GVAR for default lockpick strength [_logic, QGVAR(DefaultLockpickStrength), "DefaultLockpickStrength"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(LockVehicleInventory), "LockVehicleInventory"] call EFUNC(common,readSettingFromModule); - -_setLockState = _logic getVariable["SetLockState", 0]; -[{ - PARAMS_1(_setLockState); - { - if ((_x isKindOf "Car") || {_x isKindOf "Tank"} || {_x isKindOf "Helicopter"}) then { - //set lock state (eliminates the ambigious 1-"Default" and 3-"Locked for Player" states) - _lock = switch (_setLockState) do { - case (0): {(locked _x) in [2, 3]}; - case (1):{true}; - case (2):{false}; - }; - if (((_lock) && {(locked _x) != 2}) || {(!_lock) && {(locked _x) != 0}}) then { - TRACE_3("Setting Lock State", _lock, (typeOf _x), _x); - ["VehicleLock_SetVehicleLock", [_x], [_x, _lock]] call EFUNC(common,targetEvent); - }; - }; - } forEach vehicles; - //Delay call until mission start (so everyone has the eventHandler's installed) -}, [_setLockState], 0.25, 0.25] call EFUNC(common,waitAndExecute); +[_logic, QGVAR(VehicleStartingLockState), "VehicleStartingLockState"] call EFUNC(common,readSettingFromModule); diff --git a/addons/vehiclelock/functions/fnc_onOpenInventory.sqf b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf index 65c3068dce..8199f4b850 100644 --- a/addons/vehiclelock/functions/fnc_onOpenInventory.sqf +++ b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf @@ -34,7 +34,7 @@ if (GVAR(LockVehicleInventory) && //if setting not enabled playSound "ACE_Sound_Click"; //don't open the vehicles inventory _handeled = true; - //Just opens a dummy groundContainer + //Just opens a dummy groundContainer (so the player can still see their own inventory) ACE_player action ["Gear", objNull]; };