From 025c45dcccd6b81f026e00b5415031c2f5fdea79 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 10 Mar 2015 17:18:21 +0100 Subject: [PATCH] remove lockbackpacks code, add sound and camshake, ref #178 --- addons/backpacks/CfgEventHandlers.hpp | 6 ++ addons/backpacks/CfgVehicles.hpp | 31 -------- addons/backpacks/XEH_postInit.sqf | 3 + addons/backpacks/XEH_preInit.sqf | 1 + addons/backpacks/config.cpp | 3 +- .../functions/fnc_backpackOpened.sqf | 48 +++++++++++++ .../functions/fnc_onOpenInventory.sqf | 47 ++++--------- addons/backpacks/stringtable.xml | 70 ------------------- 8 files changed, 74 insertions(+), 135 deletions(-) delete mode 100644 addons/backpacks/CfgVehicles.hpp create mode 100644 addons/backpacks/XEH_postInit.sqf create mode 100644 addons/backpacks/functions/fnc_backpackOpened.sqf delete mode 100644 addons/backpacks/stringtable.xml diff --git a/addons/backpacks/CfgEventHandlers.hpp b/addons/backpacks/CfgEventHandlers.hpp index 9a26e6f614..1aad146690 100644 --- a/addons/backpacks/CfgEventHandlers.hpp +++ b/addons/backpacks/CfgEventHandlers.hpp @@ -5,6 +5,12 @@ class Extended_PreInit_EventHandlers { }; }; +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + class Extended_InventoryOpened_EventHandlers { class CAManBase { class GVAR(onOpenInventory) { diff --git a/addons/backpacks/CfgVehicles.hpp b/addons/backpacks/CfgVehicles.hpp deleted file mode 100644 index 5517d81525..0000000000 --- a/addons/backpacks/CfgVehicles.hpp +++ /dev/null @@ -1,31 +0,0 @@ - -class CfgVehicles { - class Man; - class CAManBase: Man { - class ACE_SelfActions { - class ACE_Equipment { - class ACE_LockBackpack { - displayName = "$STR_ACE_LockBackpacks_LockBackpack"; - condition = QUOTE([backpackContainer _player] call FUNC(isBackpack) && {!((backpackContainer _player) getVariable [ARR_2('ACE_LockedInventory', false)])}); - statement = QUOTE((backpackContainer _player) setVariable [ARR_3('ACE_LockedInventory', true, true)];); - showDisabled = 0; - priority = 2.5; - icon = ""; // @todo - hotkey = "L"; - enableInside = 1; - }; - - class ACE_UnlockBackpack { - displayName = "$STR_ACE_LockBackpacks_UnlockBackpack"; - condition = QUOTE([backpackContainer _player] call FUNC(isBackpack) && {(backpackContainer _player) getVariable [ARR_2('ACE_LockedInventory', false)]}); - statement = QUOTE((backpackContainer _player) setVariable [ARR_3('ACE_LockedInventory', false, true)];); - showDisabled = 0; - priority = 2.5; - icon = ""; // @todo - hotkey = "L"; - enableInside = 1; - }; - }; - }; - }; -}; diff --git a/addons/backpacks/XEH_postInit.sqf b/addons/backpacks/XEH_postInit.sqf new file mode 100644 index 0000000000..375fcd5f89 --- /dev/null +++ b/addons/backpacks/XEH_postInit.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +["backpackOpened", {_this call FUNC(backpackOpened)}] call EFUNC(common,addEventHandler); diff --git a/addons/backpacks/XEH_preInit.sqf b/addons/backpacks/XEH_preInit.sqf index c474ff625a..a47825d0b0 100644 --- a/addons/backpacks/XEH_preInit.sqf +++ b/addons/backpacks/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(backpackOpened); PREP(getBackpackAssignedUnit); PREP(isBackpack); PREP(onOpenInventory); diff --git a/addons/backpacks/config.cpp b/addons/backpacks/config.cpp index 0224b4b237..ddc7639921 100644 --- a/addons/backpacks/config.cpp +++ b/addons/backpacks/config.cpp @@ -5,7 +5,7 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_common","ace_interaction"}; + requiredAddons[] = {"ace_common"}; author[] = {"bux","commy2"}; authorUrl = "https://github.com/commy2/"; VERSION_CONFIG; @@ -13,4 +13,3 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" -#include "CfgVehicles.hpp" diff --git a/addons/backpacks/functions/fnc_backpackOpened.sqf b/addons/backpacks/functions/fnc_backpackOpened.sqf new file mode 100644 index 0000000000..13f330ca77 --- /dev/null +++ b/addons/backpacks/functions/fnc_backpackOpened.sqf @@ -0,0 +1,48 @@ +/* + * Author: commy2 + * + * Someone opened your backpack. Execute locally. + * + * Argument: + * 0: Who accessed your inventory? (Object) + * 1: Unit that wields the backpack (Object) + * 2: The backpack object (Object) + * + * Return value: + * None. + */ +#include "script_component.hpp" + +private ["_unit", "_target"]; + +_unit = _this select 0; +_target = _this select 1; +_backpack = _this select 2; + +// do cam shake if the target is the player +if ([_target] call EFUNC(common,isPlayer)) then { + addCamShake [4, 0.5, 5]; +}; + +// play a rustling sound +private ["_sounds", "_position"]; + +_sounds = [ + "a3\sounds_f\characters\ingame\AinvPknlMstpSlayWpstDnon_medic.wss", + "a3\sounds_f\characters\ingame\AinvPknlMstpSlayWrflDnon_medic.wss", + "a3\sounds_f\characters\ingame\AinvPpneMstpSlayWpstDnon_medic.wss", + "a3\sounds_f\characters\ingame\AinvPpneMstpSlayWrflDnon_medic.wss" +]; + +_position = _target modelToWorld (_target selectionPosition "Spine3"); +_position = _position call EFUNC(common,positionToASL); + +playSound3D [ + _sounds select floor random count _sounds, + objNull, + false, + _position, + 1, + 1, + 50 +]; diff --git a/addons/backpacks/functions/fnc_onOpenInventory.sqf b/addons/backpacks/functions/fnc_onOpenInventory.sqf index 9305bf3de7..63e4aa87a3 100644 --- a/addons/backpacks/functions/fnc_onOpenInventory.sqf +++ b/addons/backpacks/functions/fnc_onOpenInventory.sqf @@ -1,47 +1,30 @@ /* - * Author: bux, commy2 + * Author: commy2 * - * Handle the open inventory event. Don't open the inventory if it's locked and display message. + * Handle the open inventory event. Display message on traget client. * * Argument: * Input from "InventoryOpened" eventhandler * * Return value: - * Don't open the inventory dialog? (Bool) + * false. Always open the inventory dialog. (Bool) */ #include "script_component.hpp" -private ["_target", "_isBackpack", "_isLocked", "_return"]; +private ["_unit", "_backpack"]; -_target = _this select 1; +_unit = _this select 0; +_backpack = _this select 1; -_isBackpack = [_target] call FUNC(isBackpack); -_isLocked = _target getVariable ["ACE_LockedInventory", false]; +// exit if the target is not a backpack +if !([_backpack] call FUNC(isBackpack)) exitWith {}; -_return = false; -if (_isBackpack) then { - // target is a backpack - private "_unit"; - _unit = [_target] call FUNC(getBackpackAssignedUnit); +// get the unit that wears the backpack object +private "_target"; +_target = [_backpack] call FUNC(getBackpackAssignedUnit); - if (!alive _unit || {_unit getVariable ["ACE_isUnconscious", false]}) exitWith {}; +// raise event on target unit +["backpackOpened", _target, [_unit, _target, _backpack]] call EFUNC(common,targetEvent); - if (_isLocked) then { - // target is a locked backpack - [format [localize "STR_ACE_LockBackpacks_BackpackLocked", [_unit] call EFUNC(common,getName)]] call EFUNC(common,displayTextStructured); - _return = true; - } else { - // target is a not-locked backpack - if (_unit getVariable ["ACE_LockedInventory", false]) then { - [localize "STR_ACE_LockBackpacks_InventoryLocked"] call EFUNC(common,displayTextStructured); - _return = true; - }; - }; -} else { - // target is not a backpack - if (_isLocked) then { - [localize "STR_ACE_LockBackpacks_InventoryLocked"] call EFUNC(common,displayTextStructured); - _return = true; - }; -}; -_return +// return false to open inventory as usual +false diff --git a/addons/backpacks/stringtable.xml b/addons/backpacks/stringtable.xml deleted file mode 100644 index 85cd7f77d3..0000000000 --- a/addons/backpacks/stringtable.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - Take (Ventral) - Aufnehmen (Am Bauch) - Coger (Mochila delantera) - Załóż (brzuch) - Vzít (ventrální) - Prendre (Ventral) - Взять рюкзак (передний) - Felvétel (előre) - Pegar (Mochila Ventral) - Prendi - - - Take Off Backpack - Rucksack ablegen - Dejar mochila - Zdejmij (brzuch) - Odložit batoh - Enlever (Ventral) - Снять рюкзак (передний) - Táska levétele - Retirar Mochila - Togliere zaino - - - Lock Backpack - Rucksack verschließen - Verrouiller le sac à dos - Bloquear mochila - Zamknout batoh - Zablokuj plecak - Táska zárolása - Запереть рюкзак - - - Unlock Backpack - Rucksack aufschließen - Déverouiller le sac à dos - Desbloquear mochila - Odemknout batoh - Odblokuj plecak - Táska nyitása - Отпереть рюкзак - - - Backpack of %1 is locked - Der Rucksack von %1 ist verschlossen - Le sac à dos de %1 est verroullé - La mochila de %1 está bloqueada - %1 má zamčený batoh - Plecak %1 jest zablokowany - %1 táskája zárolva - Рюкзак %1 заперт - - - Inventory is locked - Das Inventar ist verschlossen - L'inventaire est verrouillé - Inventario bloqueado - Inventář je zamčený - Ekwipunek jest zablokowany - Felszerelés zárolt - Инвентарь заперт - - - \ No newline at end of file