From 9f25641f54062cbf9251a38c3a8a75d5ec0bfcae Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 17 Mar 2015 14:43:50 -0500 Subject: [PATCH] Verify Mag counts, headers, check animation --- addons/disarming/CfgVehicles.hpp | 2 +- addons/disarming/XEH_preInit.sqf | 1 + addons/disarming/functions/fnc_canDisarm.sqf | 15 +++++-- .../functions/fnc_disarmDropItems.sqf | 25 +++++------ .../functions/fnc_getAllGearContainer.sqf | 22 ++++++++-- .../functions/fnc_getAllGearUnit.sqf | 15 +++++++ .../functions/fnc_openDisarmDialog.sqf | 31 +++++++++---- .../functions/fnc_showItemsInListbox.sqf | 3 +- .../functions/fnc_verifyMagazinesMoved.sqf | 44 +++++++++++++++++++ addons/disarming/script_component.hpp | 3 +- addons/disarming/stringtable.xml | 8 +++- 11 files changed, 134 insertions(+), 35 deletions(-) create mode 100644 addons/disarming/functions/fnc_verifyMagazinesMoved.sqf diff --git a/addons/disarming/CfgVehicles.hpp b/addons/disarming/CfgVehicles.hpp index 31c4c58497..a91b0bcec4 100644 --- a/addons/disarming/CfgVehicles.hpp +++ b/addons/disarming/CfgVehicles.hpp @@ -4,7 +4,7 @@ class CfgVehicles { class ACE_Actions { class ACE_MainActions { class ACE_DisarmInventory { - displayName = "Open Inventory"; + displayName = "$STR_ACE_Disarming_OpenInventory"; distance = 4; condition = QUOTE([_target] call FUNC(canDisarm)); statement = QUOTE([ARR_2(_player,_target)] call FUNC(openDisarmDialog)); diff --git a/addons/disarming/XEH_preInit.sqf b/addons/disarming/XEH_preInit.sqf index 24d240f087..2d19f3bb5b 100644 --- a/addons/disarming/XEH_preInit.sqf +++ b/addons/disarming/XEH_preInit.sqf @@ -11,5 +11,6 @@ PREP(getAllGearContainer); PREP(getAllGearUnit); PREP(openDisarmDialog); PREP(showItemsInListbox); +PREP(verifyMagazinesMoved); ADDON = true; diff --git a/addons/disarming/functions/fnc_canDisarm.sqf b/addons/disarming/functions/fnc_canDisarm.sqf index 207d5d5078..33edafed3a 100644 --- a/addons/disarming/functions/fnc_canDisarm.sqf +++ b/addons/disarming/functions/fnc_canDisarm.sqf @@ -3,7 +3,7 @@ * Checks the conditions for being able to disarm a unit * * Arguments: - * 0: target + * 0: Target * * Return Value: * The return value @@ -15,11 +15,18 @@ */ #include "script_component.hpp" -PARAMS_2(_target); +PARAMS_1(_target); + +//Check animationState for putDown anim: +_animationStateCfgMoves = getText (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState _target) >> "actions"); +if (_animationStateCfgMoves == "") exitWith {false}; +_putDownAnim = getText (configFile >> "CfgMovesBasic" >> "Actions" >> _animationStateCfgMoves >> "PutDown"); +if (_putDownAnim != "") exitWith {false}; + (alive _target) && -{(abs (speed _target)) < 0.1} && +{(abs (speed _target)) < 1} && +{(vehicle _target) == _target} && {(_target getVariable ["ACE_isUnconscious", false]) || {_target getVariable [QEGVAR(captives,isHandcuffed), false]} || {_target getVariable [QEGVAR(captives,isSurrendering), false]}} - \ No newline at end of file diff --git a/addons/disarming/functions/fnc_disarmDropItems.sqf b/addons/disarming/functions/fnc_disarmDropItems.sqf index ded9cf2a7a..186ebffa86 100644 --- a/addons/disarming/functions/fnc_disarmDropItems.sqf +++ b/addons/disarming/functions/fnc_disarmDropItems.sqf @@ -1,6 +1,6 @@ /* * Author: PabstMirror - * + * Makes a unit drop items: * * Arguments: * 0: caller (player) @@ -19,8 +19,6 @@ #include "script_component.hpp" #define TIME_MAX_WAIT 5 -#define DUMMY_ITEM "ACE_DebugPotato" -#define UNIQUE_MAGAZINES ["ACE_key_customKeyMagazine"] PARAMS_3(_caller,_target,_listOfItemsToRemove); DEFAULT_PARAM(3,_doNotDropAmmo,false); //By default units drop all weapon mags when dropping a weapon @@ -91,13 +89,13 @@ if ( ({(_x select 0) in _listOfItemsToRemove} count _targetMagazinesEnd) != 0) e _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Didn't Remove Magazines"] call FUNC(eventTargetFinish); }; -//Verify holder has mags unit had (lazy count for now) -if (((count _targetMagazinesStart) - (count _targetMagazinesEnd)) != ((count _holderMagazinesEnd) - (count _holderMagazinesStart))) exitWith { +//Verify holder has mags unit had +if (!([_targetMagazinesStart, _targetMagazinesEnd, _holderMagazinesStart, _holderMagazinesEnd] call FUNC(verifyMagazinesMoved))) then { + ERR = [_targetMagazinesStart, _targetMagazinesEnd, _holderMagazinesStart, _holderMagazinesEnd]; _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Crate Magazines not in holder"] call FUNC(eventTargetFinish); }; - //Remove Items, Assigned Items and NVG _holderItemsStart = getitemCargo _holder; _targetItemsStart = (assignedItems _target) + (items _target); @@ -134,9 +132,8 @@ _targetItemsEnd = (assignedItems _target) + (items _target); if ((headgear _target) != "") then {_targetItemsEnd pushBack (headgear _target);}; if ((goggles _target) != "") then {_targetItemsEnd pushBack (goggles _target);}; -//Verify Items Added (lazy count) +//Verify Items Added if (((count _targetItemsStart) - (count _targetItemsEnd)) != ([_addToCrateCount] call _fncSumArray)) exitWith { - ERR = [_targetItemsStart, _targetItemsEnd, _addToCrateClassnames, _addToCrateCount]; _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Items Not Removed From Player"] call FUNC(eventTargetFinish); }; @@ -167,9 +164,7 @@ systemChat format ["PFEh start %1", time]; _needToRemoveVest = ((vest _target) != "") && {(vest _target) in _listOfItemsToRemove}; _needToRemoveUniform = ((uniform _target) != "") && {(uniform _target) in _listOfItemsToRemove}; - // systemChat format ["%1 - (%2 %3 %4 %5)", time, _maxWaitTime, _needToRemoveWeapon, _needToRemoveMagazines, _needToRemoveBackpack]; - - if ((time < _maxWaitTime) && {_needToRemoveWeapon || _needToRemoveMagazines || _needToRemoveBackpack}) then { + if ((time < _maxWaitTime) && {[_target] call FUNC(canDisarm)} && {_needToRemoveWeapon || _needToRemoveMagazines || _needToRemoveBackpack}) then { //action drop weapons (keeps loaded magazine and attachements) { if (_x in _listOfItemsToRemove) then { @@ -220,7 +215,6 @@ systemChat format ["PFEh start %1", time]; //If we added a dummy item, remove it now if (_holderIsEmpty && {!((getItemCargo _holder) isEqualTo [[DUMMY_ITEM],[1]])}) exitWith { - _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Holder should only have dummy item"] call FUNC(eventTargetFinish); }; @@ -234,7 +228,12 @@ systemChat format ["PFEh start %1", time]; _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Drop Actions Timeout"] call FUNC(eventTargetFinish); }; - + //If target lost disarm status: + if (!([_target] call FUNC(canDisarm))) exitWith { + _holder setVariable [QGVAR(holderInUse), false]; + [_caller, _target, "Debug: Target cannot be disarmed"] call FUNC(eventTargetFinish); + }; + if (_needToRemoveVest && {!((vestItems _target) isEqualTo [])}) exitWith { _holder setVariable [QGVAR(holderInUse), false]; [_caller, _target, "Debug: Vest Not Empty"] call FUNC(eventTargetFinish); diff --git a/addons/disarming/functions/fnc_getAllGearContainer.sqf b/addons/disarming/functions/fnc_getAllGearContainer.sqf index 827aac7dc3..c5b2c445ab 100644 --- a/addons/disarming/functions/fnc_getAllGearContainer.sqf +++ b/addons/disarming/functions/fnc_getAllGearContainer.sqf @@ -1,13 +1,29 @@ +/* + * Author: PabstMirror + * Helper function to get all gear of a container + * + * Arguments: + * 0: Container + * + * Return Value: + * Array of 2 arrays, classnames and count + * + * Example: + * [["ace_bandage"],[2]] = [box] call ace_disarming_fnc_getAllGearContainer + * + * Public: No + */ #include "script_component.hpp" PARAMS_1(_target); +private ["_allGear"]; + _allGear = [[],[]]; { - //todo: Use 1.40 Append - _allGear set [0, (_allGear select 0) + (_x select 0)]; - _allGear set [1, (_allGear select 1) + (_x select 1)]; + (_allGear select 0) append (_x select 0); + (_allGear select 1) append (_x select 1); } forEach [(getWeaponCargo _target), (getItemCargo _target), (getMagazineCargo _target), (getBackpackCargo _target)]; _allGear diff --git a/addons/disarming/functions/fnc_getAllGearUnit.sqf b/addons/disarming/functions/fnc_getAllGearUnit.sqf index e07b941bb4..d07f40c972 100644 --- a/addons/disarming/functions/fnc_getAllGearUnit.sqf +++ b/addons/disarming/functions/fnc_getAllGearUnit.sqf @@ -1,3 +1,18 @@ +/* + * Author: PabstMirror + * Helper function to get all gear of a unit. + * + * Arguments: + * 0: Target + * + * Return Value: + * Array of 2 arrays, classnames and count + * + * Example: + * [["ace_bandage"],[2]] = [bob] call ace_disarming_fnc_getAllGearUnit + * + * Public: No + */ #include "script_component.hpp" PARAMS_1(_target); diff --git a/addons/disarming/functions/fnc_openDisarmDialog.sqf b/addons/disarming/functions/fnc_openDisarmDialog.sqf index 4c97575039..fb7a3d35e3 100644 --- a/addons/disarming/functions/fnc_openDisarmDialog.sqf +++ b/addons/disarming/functions/fnc_openDisarmDialog.sqf @@ -1,5 +1,19 @@ -//openDisarmDialog - +/* + * Author: PabstMirror + * Opens the disarm dialog (allowing a person to remove items) + * + * Arguments: + * 0: Caller (player) + * 1: Target + * + * Return Value: + * None + * + * Example: + * [player, bob] call ace_disarming_fnc_openDisarmDialog + * + * Public: No + */ #include "script_component.hpp" PARAMS_2(_caller,_target); @@ -9,7 +23,7 @@ if (_caller != ACE_player) exitwith {ERROR("Player isn't caller?");}; if (!([_target] call FUNC(canDisarm))) exitWith {ERROR("Unit Cannot Be Disarmed");}; if (!([] call EGVAR(common,canInteract))) exitWith {ERROR("Player cannot Interact");}; -closeDialog 0; +if (dialog) then {closeDialog 0;}; createDialog QGVAR(remoteInventory); disableSerialization; @@ -26,10 +40,10 @@ GVAR(disarmTarget) = _target; EXPLODE_3_PVT((_itemInfo select 0),_displayText,_value,_data); if (isNull GVAR(disarmTarget)) exitWith {ERROR("disarmTarget is null");}; - + systemChat format ["Debug: Droping %1 from %2", _data, GVAR(disarmTarget)]; ["DisarmDropItems", [GVAR(disarmTarget)], [ACE_player, GVAR(disarmTarget), [_data]]] call EFUNC(common,targetEvent); - + false //not sure what this does }]; @@ -39,12 +53,11 @@ GVAR(disarmTarget) = _target; EXPLODE_2_PVT(_this,_args,_pfID); EXPLODE_3_PVT(_args,_player,_target,_display); - if ((!([_target] call FUNC(canDisarm))) || {isNull _display} || {_player != ACE_player} || - {!([] call EGVAR(common,canInteract))}) then { - + {!([_player, _target, []] call EFUNC(common,canInteractWith))}) then { + systemChat "Debug: closeing dialog"; [_pfID] call CBA_fnc_removePerFrameHandler; GVAR(disarmTarget) = objNull; if (!isNull _display) then {closeDialog 0;}; //close dialog if still open @@ -60,10 +73,10 @@ GVAR(disarmTarget) = _target; lbClear _groundContainer; lbClear _targetContainer; + //Show the items in the ground disarmTarget's inventory _targetUniqueItems = [GVAR(disarmTarget)] call FUNC(getAllGearUnit); [_targetContainer, _targetUniqueItems] call FUNC(showItemsInListbox); - _holder = objNull; { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { diff --git a/addons/disarming/functions/fnc_showItemsInListbox.sqf b/addons/disarming/functions/fnc_showItemsInListbox.sqf index aeea724a36..f76336bd36 100644 --- a/addons/disarming/functions/fnc_showItemsInListbox.sqf +++ b/addons/disarming/functions/fnc_showItemsInListbox.sqf @@ -1,6 +1,6 @@ /* * Author: PabstMirror - * Checks the conditions for being able to disarm + * Shows a list of inventory items in a listBox control. * * Arguments: * 0: RscListBox @@ -19,7 +19,6 @@ disableSerialization; PARAMS_2(_listBoxCtrl,_itemsCountArray); - { _displayName = ""; _picture = ""; diff --git a/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf new file mode 100644 index 0000000000..cd2babd985 --- /dev/null +++ b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf @@ -0,0 +1,44 @@ +/* + * Author: PabstMirror + * Verifies magazines moved with exact ammo counts preserved. + * Arrays will be in format from magazinesAmmo/magazinesAmmoCargo + * e.g.: [["30Rnd_65x39_caseless_mag",15], ["30Rnd_65x39_caseless_mag",30]] + * + * Arguments: + * 0: Start on container A + * 1: End on container A + * 2: Start on container B + * 3: End on container B + * + * Return Value: + * Verified Good + * + * Example: + * [] call ace_disarming_fnc_verifyMagazinesMoved + * + * Public: No + */ +#include "script_component.hpp" + +private ["_problem", "_beginingArray"]; + +PARAMS_4(_startA,_endA,_startB,_endB); + +//Quick Lazy Count Check +if (((count _startA) + (count _startB)) != ((count _endA) + (count _endB))) exitWith { + systemChat format ["%1 - %2", ((count _startA) + (count _startB)), ((count _endA) + (count _endB))]; + false +}; + +_beginingArray = (_startA + _startB); + +_problem = false; +{ + _index = _beginingArray find _x; + if (_index == -1) exitWith {_problem = true;}; + _beginingArray deleteAt _index; +} forEach (_endA + _endB); + +systemChat format ["%1 - %2", _problem, _beginingArray]; + +(!_problem) && {_beginingArray isEqualTo []} diff --git a/addons/disarming/script_component.hpp b/addons/disarming/script_component.hpp index 36f251950d..3e13697397 100644 --- a/addons/disarming/script_component.hpp +++ b/addons/disarming/script_component.hpp @@ -11,4 +11,5 @@ #include "\z\ace\addons\main\script_macros.hpp" -#define DANGEROUS_ITEMS ["ACE_Clacker", "ACE_M26_Clacker", "ACE_DeadManSwitch"] +#define DUMMY_ITEM "ACE_DebugPotato" +#define UNIQUE_MAGAZINES ["ACE_key_customKeyMagazine"] \ No newline at end of file diff --git a/addons/disarming/stringtable.xml b/addons/disarming/stringtable.xml index 893221713e..845d0c286e 100644 --- a/addons/disarming/stringtable.xml +++ b/addons/disarming/stringtable.xml @@ -1,5 +1,9 @@  - + - + + + Open Inventory + + \ No newline at end of file