From 726bf8d407c969213595363f5d45119727dbf04a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 15 Mar 2015 11:27:21 -0500 Subject: [PATCH] Headers, Formating, Fixes, Lock Inventory Option --- addons/vehiclelock/CfgEventHandlers.hpp | 12 ++ addons/vehiclelock/CfgMagazines.hpp | 15 +- addons/vehiclelock/CfgVehicles.hpp | 191 +++++++++--------- addons/vehiclelock/CfgWeapons.hpp | 76 +++---- addons/vehiclelock/XEH_postInit.sqf | 5 + addons/vehiclelock/XEH_preInit.sqf | 5 +- addons/vehiclelock/config.cpp | 4 + .../functions/fnc_addKeyForVehicle.sqf | 67 +++--- .../functions/fnc_getVehicleSideKey.sqf | 40 ++-- .../functions/fnc_hasKeyForVehicle.sqf | 44 ++-- addons/vehiclelock/functions/fnc_lockpick.sqf | 105 +++++----- .../vehiclelock/functions/fnc_moduleInit.sqf | 80 ++++---- .../vehiclelock/functions/fnc_moduleSync.sqf | 79 ++++---- .../functions/fnc_onOpenInventory.sqf | 40 ++++ .../functions/fnc_serverSetupCustomKeyEH.sqf | 36 ++-- .../functions/fnc_setVehicleLockEH.sqf | 42 ++-- 16 files changed, 433 insertions(+), 408 deletions(-) create mode 100644 addons/vehiclelock/XEH_postInit.sqf create mode 100644 addons/vehiclelock/functions/fnc_onOpenInventory.sqf diff --git a/addons/vehiclelock/CfgEventHandlers.hpp b/addons/vehiclelock/CfgEventHandlers.hpp index b928bc2de6..cf704d000c 100644 --- a/addons/vehiclelock/CfgEventHandlers.hpp +++ b/addons/vehiclelock/CfgEventHandlers.hpp @@ -3,3 +3,15 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; +class Extended_InventoryOpened_EventHandlers { + class CAManBase { + class ADDON { + clientInventoryOpened = QUOTE(_this call FUNC(onOpenInventory);); + }; + }; +}; diff --git a/addons/vehiclelock/CfgMagazines.hpp b/addons/vehiclelock/CfgMagazines.hpp index 198c617509..100df8065b 100644 --- a/addons/vehiclelock/CfgMagazines.hpp +++ b/addons/vehiclelock/CfgMagazines.hpp @@ -1,9 +1,10 @@ class CfgMagazines { - class CA_Magazine; - class ACE_key_customKeyMagazine: CA_Magazine { - picture = QUOTE(PATHTOF(ui\keyBlack.paa)); - displayName = "ACE Vehicle Key"; //!!!CANNONT be localized!!!, because it is used as part of the magazineDetail string - descriptionShort = "$STR_ACE_Vehicle_Item_Custom_Description"; - count = 1; - }; + class CA_Magazine; + class ACE_key_customKeyMagazine: CA_Magazine { + picture = QUOTE(PATHTOF(ui\keyBlack.paa)); + displayName = "ACE Vehicle Key"; //!!!CANNOT be localized!!!: because it is used as part of the magazineDetail string + descriptionShort = "$STR_ACE_Vehicle_Item_Custom_Description"; + count = 1; + mass = 0; + }; }; diff --git a/addons/vehiclelock/CfgVehicles.hpp b/addons/vehiclelock/CfgVehicles.hpp index 5be796c126..1a7da461ca 100644 --- a/addons/vehiclelock/CfgVehicles.hpp +++ b/addons/vehiclelock/CfgVehicles.hpp @@ -1,102 +1,107 @@ #define MACRO_LOCK_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('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('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_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)); \ + 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 CfgVehicles { - class LandVehicle; - class Car: LandVehicle { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; - }; - class Tank: LandVehicle { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; - }; - class Air; - class Helicopter: Air { - class ACE_Actions { - MACRO_LOCK_ACTIONS - }; - }; - - class Logic; - class Module_F: Logic { - class ArgumentsBaseUnits {}; - class ModuleDescription {}; - }; - class ACE_VehicleLock_ModuleSetup: Module_F { - author = "$STR_ACE_Common_ACETeam"; - category = "ACE"; - displayName = "Vehicle Lock Setup"; - function = "ACE_VehicleLock_fnc_moduleInit"; - scope = 2; - isGlobal = 1; - icon = QUOTE(PATHTOF(ui\IconLock_ca.paa)); - functionPriority = 0; - class Arguments { - class SetLockState { - displayName = "Set Lock State"; // Argument label - description = "Set lock state for all vehicles on map at start"; // Tooltip description - typeName = "NUMBER"; // Value type, can be "NUMBER", "STRING" or "BOOL" - class values { - class None {name = "As Is"; value = 0; default = 1;}; - class Side {name = "Locked"; value = 1;}; - class Unique {name = "Unlocked"; value = 2;}; + class LandVehicle; + class Car: LandVehicle { + class ACE_Actions { + MACRO_LOCK_ACTIONS }; - }; - class LockpickStrength { - displayName = "Global Lockpick Strength"; - description = "Global Time to lockpick (in seconds). Default: 10"; - typeName = "NUMBER"; // Value type, can be "NUMBER", "STRING" or "BOOL" - defaultValue = "10"; // Default text filled in the input box - }; }; - class ModuleDescription: ModuleDescription { - description = "Settings for lockpick strength and initial vehicle lock state. Removes ambiguous lock states.
Source: vehiclelock.pbo"; + class Tank: LandVehicle { + class ACE_Actions { + MACRO_LOCK_ACTIONS + }; + }; + class Air; + class Helicopter: Air { + class ACE_Actions { + MACRO_LOCK_ACTIONS + }; }; - }; - class ACE_VehicleLock_ModuleSyncedAssign: Module_F { - author = "$STR_ACE_Common_ACETeam"; - category = "ACE"; - displayName = "Vehicle Key Assign"; - function = "ACE_VehicleLock_fnc_moduleSync"; - scope = 2; - isGlobal = 1; - icon = QUOTE(PATHTOF(ui\IconLock_ca.paa)); - functionPriority = 0; - class Arguments {}; - class ModuleDescription: ModuleDescription { - description = "Sync with vehicles and players. Will handout custom keys to players for every synced vehicle. Only valid for objects present at mission start.
Source: vehiclelock.pbo"; - sync[] = {"AnyPlayer", "AnyVehicle"}; + class Logic; + class Module_F: Logic { + class ModuleDescription {}; + }; + class ACE_VehicleLock_ModuleSetup: Module_F { + author = "$STR_ACE_Common_ACETeam"; + category = "ACE"; + displayName = "Vehicle Lock Setup"; + function = QUOTE(DFUNC(moduleInit)); + scope = 2; + isGlobal = 0; + icon = QUOTE(PATHTOF(ui\IconLock_ca.paa)); + functionPriority = 0; + class Arguments { + class LockVehicleInventory { + displayName = "Lock Vehicle Inventory"; + description = "Locks the inventory of locked vehicles"; + 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 + typeName = "NUMBER"; // Value type, can be "NUMBER", "STRING" or "BOOL" + class values { + class None {name = "As Is"; value = 0; default = 1;}; + class Side {name = "Locked"; value = 1;}; + class Unique {name = "Unlocked"; value = 2;}; + }; + }; + class DefaultLockpickStrength { + displayName = "Default Lockpick Strength"; + description = "Default Time to lockpick (in seconds). Default: 10"; + typeName = "NUMBER"; // Value type, can be "NUMBER", "STRING" or "BOOL" + defaultValue = "10"; // Default text filled in the input box + }; + }; + class ModuleDescription: ModuleDescription { + description = "Settings for lockpick strength and initial vehicle lock state. Removes ambiguous lock states.
Source: vehiclelock.pbo"; + }; + }; + + class ACE_VehicleLock_ModuleSyncedAssign: Module_F { + author = "$STR_ACE_Common_ACETeam"; + category = "ACE"; + displayName = "Vehicle Key Assign"; + function = QUOTE(DFUNC(moduleSync)); + scope = 2; + isGlobal = 0; + icon = QUOTE(PATHTOF(ui\IconLock_ca.paa)); + functionPriority = 0; + class Arguments {}; + class ModuleDescription: ModuleDescription { + description = "Sync with vehicles and players. Will handout custom keys to players for every synced vehicle. Only valid for objects present at mission start.
Source: vehiclelock.pbo"; + sync[] = {"AnyPlayer", "AnyVehicle"}; + }; }; - }; }; diff --git a/addons/vehiclelock/CfgWeapons.hpp b/addons/vehiclelock/CfgWeapons.hpp index 157fb4bf60..4b20de15d7 100644 --- a/addons/vehiclelock/CfgWeapons.hpp +++ b/addons/vehiclelock/CfgWeapons.hpp @@ -1,41 +1,41 @@ class CfgWeapons { - class InventoryItem_Base_F; - class ACE_ItemCore; + class InventoryItem_Base_F; + class ACE_ItemCore; - class ACE_key_master: ACE_ItemCore { - author = "$STR_ACE_Common_ACETeam"; - displayName = "Vehicle Key: Master"; - descriptionShort = "$STR_ACE_Vehicle_Item_Master_Description"; - model = "\A3\weapons_F\ammo\mag_univ.p3d"; - picture = QUOTE(PATHTOF(ui\keyBlack.paa)); - scope = 2; - class ItemInfo: InventoryItem_Base_F { - mass = 0.1; - }; - }; - class ACE_key_lockpick: ACE_key_master { - displayName = "Lockpick"; - descriptionShort = "$STR_ACE_Vehicle_Item_Lockpick_Description"; - picture = QUOTE(PATHTOF(ui\lockpick.paa)); - }; - class ACE_key_west: ACE_key_master { - displayName = "Vehicle Key: West"; - descriptionShort = "$STR_ACE_Vehicle_Item_West_Description"; - picture = QUOTE(PATHTOF(ui\keyBlue.paa)); - }; - class ACE_key_east: ACE_key_master { - displayName = "Vehicle Key: East"; - descriptionShort = "$STR_ACE_Vehicle_Item_East_Description"; - picture = QUOTE(PATHTOF(ui\keyRed.paa)); - }; - class ACE_key_indp: ACE_key_master { - displayName = "Vehicle Key: Independent"; - descriptionShort = "$STR_ACE_Vehicle_Item_Indp_Description"; - picture = QUOTE(PATHTOF(ui\keyPurple.paa)); - }; - class ACE_key_civ: ACE_key_master { - displayName = "Vehicle Key: Civilian"; - descriptionShort = "$STR_ACE_Vehicle_Item_Civ_Description"; - picture = QUOTE(PATHTOF(ui\keyGreen.paa)); - }; + class ACE_key_master: ACE_ItemCore { + author = "$STR_ACE_Common_ACETeam"; + displayName = "Vehicle Key: Master"; + descriptionShort = "$STR_ACE_Vehicle_Item_Master_Description"; + model = "\A3\weapons_F\ammo\mag_univ.p3d"; + picture = QUOTE(PATHTOF(ui\keyBlack.paa)); + scope = 2; + class ItemInfo: InventoryItem_Base_F { + mass = 0; + }; + }; + class ACE_key_lockpick: ACE_key_master { + displayName = "Lockpick"; + descriptionShort = "$STR_ACE_Vehicle_Item_Lockpick_Description"; + picture = QUOTE(PATHTOF(ui\lockpick.paa)); + }; + class ACE_key_west: ACE_key_master { + displayName = "Vehicle Key: West"; + descriptionShort = "$STR_ACE_Vehicle_Item_West_Description"; + picture = QUOTE(PATHTOF(ui\keyBlue.paa)); + }; + class ACE_key_east: ACE_key_master { + displayName = "Vehicle Key: East"; + descriptionShort = "$STR_ACE_Vehicle_Item_East_Description"; + picture = QUOTE(PATHTOF(ui\keyRed.paa)); + }; + class ACE_key_indp: ACE_key_master { + displayName = "Vehicle Key: Independent"; + descriptionShort = "$STR_ACE_Vehicle_Item_Indp_Description"; + picture = QUOTE(PATHTOF(ui\keyPurple.paa)); + }; + class ACE_key_civ: ACE_key_master { + displayName = "Vehicle Key: Civilian"; + descriptionShort = "$STR_ACE_Vehicle_Item_Civ_Description"; + picture = QUOTE(PATHTOF(ui\keyGreen.paa)); + }; }; diff --git a/addons/vehiclelock/XEH_postInit.sqf b/addons/vehiclelock/XEH_postInit.sqf new file mode 100644 index 0000000000..c635de2bd3 --- /dev/null +++ b/addons/vehiclelock/XEH_postInit.sqf @@ -0,0 +1,5 @@ +#include "script_component.hpp" + +//Add Event Handlers +["VehicleLock_SetupCustomKey", {_this call FUNC(serverSetupCustomKeyEH)}] call EFUNC(common,addEventHandler); +["VehicleLock_SetVehicleLock", {_this call FUNC(setVehicleLockEH)}] call EFUNC(common,addEventHandler); diff --git a/addons/vehiclelock/XEH_preInit.sqf b/addons/vehiclelock/XEH_preInit.sqf index 80d1d6335f..bdab28fc75 100644 --- a/addons/vehiclelock/XEH_preInit.sqf +++ b/addons/vehiclelock/XEH_preInit.sqf @@ -8,11 +8,8 @@ PREP(hasKeyForVehicle); PREP(lockpick); PREP(moduleInit); PREP(moduleSync); +PREP(onOpenInventory); PREP(serverSetupCustomKeyEH); PREP(setVehicleLockEH); -//Add Event Handlers -["SetupCustomKey", {_this call FUNC(serverSetupCustomKeyEH)}] call EFUNC(common,addEventHandler); -["SetVehicleLock", {_this call FUNC(setVehicleLockEH)}] call EFUNC(common,addEventHandler); - ADDON = true; diff --git a/addons/vehiclelock/config.cpp b/addons/vehiclelock/config.cpp index 9031987315..700e27b3cb 100644 --- a/addons/vehiclelock/config.cpp +++ b/addons/vehiclelock/config.cpp @@ -17,6 +17,10 @@ class ACE_Settings { value = 10; typeName = "SCALAR"; }; + class GVAR(LockVehicleInventory) { + value = 0; + typeName = "BOOL"; + }; }; #include "CfgEventHandlers.hpp" diff --git a/addons/vehiclelock/functions/fnc_addKeyForVehicle.sqf b/addons/vehiclelock/functions/fnc_addKeyForVehicle.sqf index c64a0f890d..d683073286 100644 --- a/addons/vehiclelock/functions/fnc_addKeyForVehicle.sqf +++ b/addons/vehiclelock/functions/fnc_addKeyForVehicle.sqf @@ -1,45 +1,40 @@ /* - Name: ACE_VehicleLock_fnc_addKeyForVehicle - - Author: Pabst Mirror - - Description: - Adds a key to a unit that will open a vehicle - - Parameters: - 0: OBJECT - unit - 1: OBJECT - vehicle - 2: BOOL - custom key (true: custom key (magazine) - false: side key (item)) - - Returns: - Nothing - - Example: - [bob, car1, true] call ACE_VehicleLock_fnc_addKeyForVehicle; -*/ - + * Author: PabstMirror + * Adds a key to a unit that will open a vehicle + * Note: has global effects for Unit (will add items to remote unit) + * + * Arguments: + * 0: Unit + * 1: Vehicle + * 2: custom key (true: custom key (magazine) - false: side key (item)) + * + * Return Value: + * None + * + * Example: + * [ACE_player, car, true] call ACE_VehicleLock_fnc_addKeyForVehicle + * + * Public: Yes + */ #include "script_component.hpp" -private ["_unit","_veh","_useCustom","_previousMags","_newMags","_keyMagazine","_keyName"]; +private ["_previousMags","_newMags","_keyMagazine","_keyName"]; -_unit = [_this, 0, objNull, [objNull]] call bis_fnc_param; -_veh = [_this, 1, objNull, [objNull]] call bis_fnc_param; -_useCustom = [_this, 2, false, [false]] call bis_fnc_param; +PARAMS_3(_unit,_veh,_useCustom); -if (isNull _unit) exitWith {["addKeyForVehicleClient: null unit"] call BIS_fnc_error;}; -if (isNull _veh) exitWith {["addKeyForVehicleClient: null vehicle"] call BIS_fnc_error;}; +if (isNull _unit) exitWith {ERROR("null unit");}; +if (isNull _veh) exitWith {ERROR("null vehicle");}; if (_useCustom) then { - _previousMags = magazinesDetail _unit; - _unit addMagazine ["ACE_key_customKeyMagazine", 1]; - _newMags = (magazinesDetail _unit) - _previousMags; - if ((count _newMags) == 0) exitWith { - ["ACE_VehicleLock_fnc_addKeyForVehicle: failed to add magazine (inventory full?)"] call BIS_fnc_error; - }; - _keyMagazine = _newMags select 0; - TRACE_2("setting up key on server",_veh,_keyMagazine); - ["SetupCustomKey", [_veh, _keyMagazine]] call EFUNC(common,serverEvent); + _previousMags = magazinesDetail _unit; + _unit addMagazine ["ACE_key_customKeyMagazine", 1]; //addMagazine array has global effects + _newMags = (magazinesDetail _unit) - _previousMags; + if ((count _newMags) == 0) exitWith {ERROR("failed to add magazine (inventory full?)");}; + _keyMagazine = _newMags select 0; + TRACE_2("setting up key on server",_veh,_keyMagazine); + //Have the server run add the key to the vehicle's key array: + ["VehicleLock_SetupCustomKey", [_veh, _keyMagazine]] call EFUNC(common,serverEvent); } else { - _keyName = [_veh] call FUNC(getVehicleSideKey); - _unit addItem _keyName; + _keyName = [_veh] call FUNC(getVehicleSideKey); + _unit addItem _keyName; //addItem has global effects }; diff --git a/addons/vehiclelock/functions/fnc_getVehicleSideKey.sqf b/addons/vehiclelock/functions/fnc_getVehicleSideKey.sqf index 819c13c332..999f471ac3 100644 --- a/addons/vehiclelock/functions/fnc_getVehicleSideKey.sqf +++ b/addons/vehiclelock/functions/fnc_getVehicleSideKey.sqf @@ -1,27 +1,25 @@ /* -Name: ACE_VehicleLock_fnc_getVehicleSideKey - -Author: Pabst Mirror - -Description: - Returns the side specifc key for a vehicle - -Parameters: - 0: OBJECT - vehicle - -Returns: - STRING - Key Classname - -Example: - [tank1] call ACE_VehicleLock_fnc_getVehicleSideKey; -*/ - + * Author: PabstMirror + * Returns the side specifc key for a vehicle + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * The vehicle's side key classname + * + * Example: + * [tank1] call ACE_VehicleLock_fnc_getVehicleSideKey; + * + * Public: No + */ #include "script_component.hpp" -private ["_veh","_vehConfigSide","_vehSide","_returnValue"]; +private ["_vehConfigSide","_vehSide","_returnValue"]; -_veh = [_this, 0, objNull, [objNull]] call bis_fnc_param; -if (isNull _veh) exitWith {["ACE_VehicleLock_fnc_getVehicleSideKey: null vehicle"] call BIS_fnc_error; ""}; +PARAMS_1(_veh); + +if (isNull _veh) exitWith {ERROR("null vehicle"); "error"}; _vehConfigSide = [_veh, true] call BIS_fnc_objectSide; _vehSide = _veh getVariable [QGVAR(lockSide), _vehConfigSide]; @@ -32,7 +30,7 @@ switch (_vehSide) do { case (west): {_returnValue = "ACE_key_west"}; case (east): {_returnValue = "ACE_key_east"}; case (resistance): {_returnValue = "ACE_key_indp"}; -case (civilian): {_returnValue = "ACE_key_civ"}; + default {_returnValue = "ACE_key_civ"}; }; _returnValue diff --git a/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf b/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf index a1c899edad..779f4a363e 100644 --- a/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf +++ b/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf @@ -1,31 +1,27 @@ /* -Name: ACE_VehicleLock_fnc_hasKeyForVehicle - -Author: Pabst Mirror - -Description: - Returns if user has a valid key for the vehicle - -Parameters: - 0: OBJECT - unit - 1: OBJECT - vehicle - -Returns: - BOOL - unit has key for vehicle - -Example: - [bob, car] call ACE_VehicleLock_fnc_hasKeyForVehicle; -*/ - + * Author: PabstMirror + * Returns if user has a valid key for the vehicle + * + * Arguments: + * 0: Unit + * 1: Vehicle + * + * Return Value: + * unit has key for vehicle + * + * Example: + * [bob, car] call ACE_VehicleLock_fnc_hasKeyForVehicle; + * + * Public: No + */ #include "script_component.hpp" -private ["_unit","_veh","_returnValue","_sideKeyName","_customKeys"]; +private ["_returnValue","_sideKeyName","_customKeys"]; -_unit = [_this, 0, objNull, [objNull]] call bis_fnc_param; -_veh = [_this, 1, objNull, [objNull]] call bis_fnc_param; +PARAMS_2(_unit,_veh); -if (isNull _unit) exitWith {["ACE_VehicleLock_fnc_hasKeyForVehicle: null unit"] call BIS_fnc_error; false}; -if (isNull _veh) exitWith {["ACE_VehicleLock_fnc_hasKeyForVehicle: null vehicle"] call BIS_fnc_error; false}; +if (isNull _unit) exitWith {ERROR("null unit"); false}; +if (isNull _veh) exitWith {ERROR("null vehicle"); false}; _returnValue = false; @@ -39,7 +35,7 @@ if (_sideKeyName in (items _unit)) then {_returnValue = true}; //Check custom keys _customKeys = _veh getVariable [QGVAR(customKeys), []]; { - if (_x in (magazinesDetail _unit)) then {_returnValue = true;}; + if (_x in (magazinesDetail _unit)) then {_returnValue = true;}; } forEach _customKeys; _returnValue diff --git a/addons/vehiclelock/functions/fnc_lockpick.sqf b/addons/vehiclelock/functions/fnc_lockpick.sqf index c6a6369515..4fee354824 100644 --- a/addons/vehiclelock/functions/fnc_lockpick.sqf +++ b/addons/vehiclelock/functions/fnc_lockpick.sqf @@ -1,79 +1,66 @@ /* -Name: ACE_VehicleLock_fnc_lockpick - -Author: Pabst Mirror - -Description: - Handles lockpick functionality from action menu. - -Parameters: - 0: OBJECT - unit - 1: OBJECT - vehicle - 2: STRING - function type - "canLockpick": returns BOOL if lockpick is possible - "startLockpick": starts the process - "finishLockpick": on completions, opens the lock - -Returns: - BOOL - -Example: - [ACE_player, ACE_Interaction_Target, 'canLockpick'] call ACE_VehicleLock_fnc_lockpick -*/ - + * Author: PabstMirror + * Handles lockpick functionality. Three different functions: + * "canLockpick": returns BOOL if lockpick is possible + * "startLockpick": starts the process + * "finishLockpick": on completions, opens the lock + * + * Arguments: + * 0: Unit (player) + * 1: Vehicle + * 2: Function Type + * + * Return Value: + * "canLockpick" + * + * Example: + * [ACE_player, ACE_Interaction_Target, 'canLockpick'] call ACE_VehicleLock_fnc_lockpick + * + * Public: No + */ #include "script_component.hpp" -private ["_unit","_veh","_funcType","_vehLockpickStrenth","_returnValue", "_condition"]; +private ["_vehLockpickStrenth","_condition","_returnValue"]; -_unit = [_this, 0, objNull, [objNull]] call bis_fnc_param; -_veh = [_this, 1, objNull, [objNull]] call bis_fnc_param; -_funcType = [_this, 2, "", [""]] call bis_fnc_param; +PARAMS_3(_unit,_veh,_funcType); -if (isNull _unit) exitWith { - ["ACE_VehicleLock_fnc_lockpick: null unit"] call BIS_fnc_error; - false -}; -if (isNull _veh) exitWith { - ["ACE_VehicleLock_fnc_lockpick: null vehicle"] call BIS_fnc_error; - false -}; +if (isNull _unit) exitWith {ERROR("null unit"); false}; +if (isNull _veh) exitWith {ERROR("null vehicle"); false}; //need lockpick item -if (!("ACE_key_lockpick" in (items _unit))) exitWith { - false -}; +if (!("ACE_key_lockpick" in (items _unit))) exitWith {false}; _vehLockpickStrenth = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)]; -if (typeName _vehLockpickStrenth != "SCALAR") exitWith { - ["ACE_VehicleLock_fnc_lockpick: 'ACE_vehicleLock_LockpickStrength' invalid: (%1)", _veh] call BIS_fnc_error; - false -}; +if (typeName _vehLockpickStrenth != "SCALAR") exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false}; //-1 indicates unpickable lock -if (_vehLockpickStrenth < 0) exitWith { - false +if (_vehLockpickStrenth < 0) exitWith {false}; + +//Condition check for progressBar +_condition = { + PARAMS_1(_args); + EXPLODE_2_PVT(_args,_unit,_veh); + ((_unit distance _veh) < 5) && {(speed _veh) < 0.1} }; +if (!([[_unit, _veh]] call _condition)) exitWith {false}; + _returnValue = false; - switch (true) do { case (_funcType == "canLockpick"): { - _returnValue = true; - }; -case (_funcType == "startLockpick"): { - _condition = { - PARAMS_1(_args); - EXPLODE_2_PVT(_args,_unit,_veh); - ([_unit, objNull, []] call EFUNC(common,canInteractWith)) && ((_unit distance _veh) < 5) && ((speed _veh) < 1) + _returnValue = true; + }; +case (_funcType == "startLockpick"): { + [_vehLockpickStrenth, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize "STR_ACE_Vehicle_Action_LockpickInUse"), _condition] call EFUNC(common,progressBar); + _returnValue = true; }; - [_vehLockpickStrenth, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize "STR_ACE_Vehicle_Action_LockpickInUse"), _condition] call EFUNC(common,progressBar); - }; case (_funcType == "finishLockpick"): { - ["SetVehicleLock", [_veh], [_veh, false]] call EFUNC(common,targetEvent); - }; - default { - ["ACE_VehicleLock_fnc_lockpick: bad function type"] call BIS_fnc_error; - }; + ["VehicleLock_SetVehicleLock", [_veh], [_veh, false]] call EFUNC(common,targetEvent); + _returnValue = true; + }; + default { + ERROR("bad function type"); + }; }; -_returnValue; +_returnValue diff --git a/addons/vehiclelock/functions/fnc_moduleInit.sqf b/addons/vehiclelock/functions/fnc_moduleInit.sqf index a344185ab0..c26e8aacbd 100644 --- a/addons/vehiclelock/functions/fnc_moduleInit.sqf +++ b/addons/vehiclelock/functions/fnc_moduleInit.sqf @@ -1,22 +1,20 @@ /* -Name: ACE_VehicleLock_fnc_moduleInit - -Author: Pabst Mirror - -Description: - Function for setup module. Sets default lockpick strength, auto handout keys, and default lock state. - -Parameters: - 0: OBJECT - logic - 1: ignored - 2: BOOL - Module Activated -Returns: - Nothing - -Example: - called from module -*/ - + * Author: PabstMirror + * Function for setup module. Sets default lockpick strength and default lock state. + * + * Arguments: + * 0: The Module Logic Object + * 1: synced objects + * 2: Activated + * + * Return Value: + * None + * + * Example: + * [fromModule] call ACE_VehicleLock_fnc_hasKeyForVehicle; + * + * Public: No + */ #include "script_component.hpp" private ["_sideKeysAssignment", "_setLockState", "_lock"]; @@ -24,28 +22,28 @@ private ["_sideKeysAssignment", "_setLockState", "_lock"]; PARAMS_3(_logic,_syncedUnits,_activated); if (!_activated) exitWith {WARNING("Vehicle Lock Init Module - placed but not active");}; +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); -_sideKeysAssignment = _logic getVariable["SideKeysAssignment", 0]; _setLockState = _logic getVariable["SetLockState", 0]; - -if (isServer) then { - [_logic, QGVAR(DefaultLockpickStrength), "LockpickStrength"] call EFUNC(common,readSettingFromModule); -}; - -//Run at mission start (anyone besides JIPs) -if (isServer || {player == player}) then { - { - if ((local _x) && {(_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); - ["SetVehicleLock", [_x, _lock]] call EFUNC(common,localEvent); - }; - }; - } forEach vehicles; -}; +[{ + 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); diff --git a/addons/vehiclelock/functions/fnc_moduleSync.sqf b/addons/vehiclelock/functions/fnc_moduleSync.sqf index 60c23c5195..feed42e3ab 100644 --- a/addons/vehiclelock/functions/fnc_moduleSync.sqf +++ b/addons/vehiclelock/functions/fnc_moduleSync.sqf @@ -1,22 +1,20 @@ /* -Name: ACE_VehicleLock_fnc_moduleSync - -Author: Pabst Mirror - -Description: - Function for sync module. Assigns keys for all synced vehicles to any players that are synced. - -Parameters: - 0: OBJECT - logic - 1: ARRAY - synced objects (only objects at mission start, so JIP without AI won't be present) - -Returns: - Nothing - -Example: - called from module -*/ - + * Author: PabstMirror + * Function for sync module. Assigns keys for all synced vehicles to any players that are synced. + * + * Arguments: + * 0: The Module Logic Object + * 1: synced objects + * 2: Activated + * + * Return Value: + * None + * + * Example: + * [fromModule] call ACE_VehicleLock_fnc_moduleSync; + * + * Public: No + */ #include "script_component.hpp" PARAMS_3(_logic,_syncedObjects,_activated); @@ -24,29 +22,28 @@ PARAMS_3(_logic,_syncedObjects,_activated); if !(_activated) exitWith {WARNING("Vehicle Lock Sync Module - placed but not active");}; if (!isServer) exitWith {}; -_addKeyAfterGearAssign = { - private ["_syncedObjects", "_listOfVehicles"]; - _syncedObjects = _this select 0; - _listOfVehicles = []; - { - if ((_x isKindOf "Car") || (_x isKindOf "Tank") || (_x isKindOf "Helicopter")) then { - _listOfVehicles pushBack _x; +[{ + private ["_listOfVehicles"]; + PARAMS_1(_syncedObjects); + _listOfVehicles = []; + { + if ((_x isKindOf "Car") || (_x isKindOf "Tank") || (_x isKindOf "Helicopter")) then { + _listOfVehicles pushBack _x; + }; + } forEach _syncedObjects; + + if ((count _listOfVehicles) == 0) exitWith { //Verbose error for mission makers (only shows on server) + ["ACE_VehicleLock_fnc_moduleSync: no vehicles synced"] call BIS_fnc_error; }; - } forEach _syncedObjects; - if ((count _listOfVehicles) == 0) exitWith { //Verbose error for mission makers - ["ACE_VehicleLock_fnc_moduleSync: no vehicles synced"] call BIS_fnc_error; - }; + { + _unit = _x; + if (_unit isKindOf "CAManBase") then { + { + [_unit, _x, true] call FUNC(addKeyForVehicle); + } forEach _listOfVehicles; + }; + } forEach _syncedObjects; - { - _unit = _x; - if (_unit isKindOf "CAManBase") then { - { - [_unit, _x, true] call FUNC(addKeyForVehicle); - } forEach _listOfVehicles; - }; - } forEach _syncedObjects; -}; - -//Wait to add keys until various gear assigns have finished (~5 seconds) -[_addKeyAfterGearAssign, [_syncedObjects], 5, 1] call EFUNC(common,waitAndExecute); + //Wait to add keys until various gear assigns have finished (~5 seconds) +}, [_syncedObjects], 5, 1] call EFUNC(common,waitAndExecute); diff --git a/addons/vehiclelock/functions/fnc_onOpenInventory.sqf b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf new file mode 100644 index 0000000000..55fee28cc6 --- /dev/null +++ b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf @@ -0,0 +1,40 @@ +/* + * Author: PabstMirror + * Handles the inventory opening. + * + * Arguments: + * 0: Unit + * 1: Container + * + * Return Value: + * Handeled + * + * Example: + * [player, car] call ACE_VehicleLock_fnc_onOpenInventory; + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_2(_unit,_container); + +//Only check for player: +if (_unit != ace_player) exitWith {false}; + +_handeled = false; + +if (GVAR(LockVehicleInventory) && //if setting not enabled + {(vehicle ace_player) == ace_player} && //Player dismounted + {(_container isKindOf "Car") || (_container isKindOf "Tank") || (_container isKindOf "Helicopter")} && //container is a lockable veh + {(locked _container) in [2,3]} && //Vehicle is locked + {!([ace_player, _container] call FUNC(hasKeyForVehicle))} //player doesn't have key + ) then { + //Give feedback that vehicle is locked + playSound "ACE_Sound_Click"; + //don't open the vehicles inventory + _handeled = true; + //Just opens a dummy groundContainer + ACE_player action ["Gear", objNull]; +}; + +_handeled diff --git a/addons/vehiclelock/functions/fnc_serverSetupCustomKeyEH.sqf b/addons/vehiclelock/functions/fnc_serverSetupCustomKeyEH.sqf index f9a420841e..9d8a396e31 100644 --- a/addons/vehiclelock/functions/fnc_serverSetupCustomKeyEH.sqf +++ b/addons/vehiclelock/functions/fnc_serverSetupCustomKeyEH.sqf @@ -1,22 +1,19 @@ - /* - Name: ACE_VehicleLock_fnc_serverSetupCustomKeyEH - - Author: Pabst Mirror - - Description: - Adds a key (magazineDetail name) to approved keys for a vehicle - - Parameters: - 0: OBJECT - vehicle - 1: STRING - Magazine Name - - Returns: - Nothing - - Example: - [tank1, "someMagainze [id xx:yy]"] call ACE_VehicleLock_fnc_serverSetupCustomKeyEH; -*/ - +/* + * Author: PabstMirror + * On the server: Adds a key (magazineDetail name) to approved keys for a vehicle. + * + * Arguments: + * 0: Vehicle + * 1: Magazine Name + * + * Return Value: + * None + * + * Example: + * [tank1, "someMagainze [id xx:yy]"] call ACE_VehicleLock_fnc_serverSetupCustomKeyEH + * + * Public: Yes + */ #include "script_component.hpp" private ["_currentKeys"]; @@ -24,6 +21,7 @@ private ["_currentKeys"]; PARAMS_2(_veh,_key); if (!isServer) exitWith {ERROR("only run on server");}; +if (isNull _veh) exitWith {ERROR("null vehicle");}; if (_key == "") exitWith {ERROR("empty key string");}; _currentKeys = _veh getVariable [QGVAR(customKeys), []]; diff --git a/addons/vehiclelock/functions/fnc_setVehicleLockEH.sqf b/addons/vehiclelock/functions/fnc_setVehicleLockEH.sqf index 7aaa9b154c..cb51cb27a8 100644 --- a/addons/vehiclelock/functions/fnc_setVehicleLockEH.sqf +++ b/addons/vehiclelock/functions/fnc_setVehicleLockEH.sqf @@ -1,33 +1,25 @@ /* - Name: ACE_VehicleLock_fnc_setVehicleLockEH - - Author: Pabst Mirror - - Description: - Sets a vehicle lock state because of a "SetVehicleLock" event - - Parameters: - 0: OBJECT - vehicle - 1: BOOL - new lock state - - Returns: - Nothing - - Example: - [tank1, false] call ACE_VehicleLock_fnc_setVehicleLockEH; -*/ - + * Author: PabstMirror + * Sets a vehicle lock state because of a "VehicleLock_SetVehicleLock" event + * + * Arguments: + * 0: Vehicle + * 1: New lock state + * + * Return Value: + * None + * + * Example: + * [tank1, false] call ACE_VehicleLock_fnc_setVehicleLockEH; + * + * Public: Yes + */ #include "script_component.hpp" -private ["_veh","_isLocked","_lockNumber"]; +private ["_lockNumber"]; -_veh = [_this, 0, objNull, [objNull]] call bis_fnc_param; -_isLocked = [_this, 1, false, [false]] call bis_fnc_param; +PARAMS_2(_veh,_isLocked); _lockNumber = if (_isLocked) then {2} else {0}; - TRACE_2("Setting Lock State", _veh, _lockNumber); - _veh lock _lockNumber; - -// _veh setVariable ["ACE_LockedInventory", _isLocked, true]; //todo inventory lock