diff --git a/addons/disarming/CfgVehicles.hpp b/addons/disarming/CfgVehicles.hpp index a91b0bcec4..871dbcfa4e 100644 --- a/addons/disarming/CfgVehicles.hpp +++ b/addons/disarming/CfgVehicles.hpp @@ -6,9 +6,9 @@ class CfgVehicles { class ACE_DisarmInventory { displayName = "$STR_ACE_Disarming_OpenInventory"; distance = 4; - condition = QUOTE([_target] call FUNC(canDisarm)); + condition = QUOTE([ARR_2(_player,_target)] call FUNC(canPlayerDisarmUnit)); statement = QUOTE([ARR_2(_player,_target)] call FUNC(openDisarmDialog)); - icon = "\a3\Modules_F_Curator\Data\portraitRespawnInventory_ca.paa"; //todo + icon = "\a3\Modules_F_Curator\Data\portraitRespawnInventory_ca.paa"; selection = "spine3"; exceptions[] = {}; }; diff --git a/addons/disarming/XEH_preInit.sqf b/addons/disarming/XEH_preInit.sqf index 2d19f3bb5b..84534e41b4 100644 --- a/addons/disarming/XEH_preInit.sqf +++ b/addons/disarming/XEH_preInit.sqf @@ -2,7 +2,8 @@ ADDON = false; -PREP(canDisarm); +PREP(canBeDisarmed); +PREP(canPlayerDisarmUnit); PREP(disarmDropItems); PREP(eventCallerFinish); PREP(eventTargetFinish); diff --git a/addons/disarming/functions/fnc_canDisarm.sqf b/addons/disarming/functions/fnc_canBeDisarmed.sqf similarity index 74% rename from addons/disarming/functions/fnc_canDisarm.sqf rename to addons/disarming/functions/fnc_canBeDisarmed.sqf index 33edafed3a..04171a900d 100644 --- a/addons/disarming/functions/fnc_canDisarm.sqf +++ b/addons/disarming/functions/fnc_canBeDisarmed.sqf @@ -6,10 +6,10 @@ * 0: Target * * Return Value: - * The return value + * Can Be Disarmed * * Example: - * [cursorTarget] call ace_disarming_fnc_canDisarm + * [cursorTarget] call ace_disarming_fnc_canBeDisarmed * * Public: No */ @@ -17,7 +17,9 @@ PARAMS_1(_target); -//Check animationState for putDown anim: +//Check animationState for putDown anim +//This ensures the unit doesn't have to actualy do any animation to drop something +//This should always be true for the 3 possible status effects that allow disarming _animationStateCfgMoves = getText (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState _target) >> "actions"); if (_animationStateCfgMoves == "") exitWith {false}; _putDownAnim = getText (configFile >> "CfgMovesBasic" >> "Actions" >> _animationStateCfgMoves >> "PutDown"); diff --git a/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf b/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf new file mode 100644 index 0000000000..ec9e975ec2 --- /dev/null +++ b/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf @@ -0,0 +1,22 @@ +/* + * Author: PabstMirror + * Checks the conditions for being able to disarm a unit + * + * Arguments: + * 0: Player + * 1: Target + * + * Return Value: + * Can Be Disarm Target + * + * Example: + * [player, cursorTarget] call ace_disarming_fnc_canPlayerDisarmUnit + * + * Public: No + */ +#include "script_component.hpp" + +PARAMS_2(_player,_target); + +([_target] call FUNC(canBeDisarmed)) && +{([_player, _target, []] call EFUNC(common,canInteractWith))} diff --git a/addons/disarming/functions/fnc_disarmDropItems.sqf b/addons/disarming/functions/fnc_disarmDropItems.sqf index 186ebffa86..cbed44be23 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: + * Makes a unit drop items * * Arguments: * 0: caller (player) @@ -30,7 +30,7 @@ _fncSumArray = { }; //Sanity Checks -if (!([_target] call FUNC(canDisarm))) exitWith { +if (!([_target] call FUNC(canBeDisarmed))) exitWith { [_caller, _target, "Debug: Cannot disarm target"] call FUNC(eventTargetFinish); }; if (_doNotDropAmmo && {({_x in _listOfItemsToRemove} count (magazines _target)) > 0}) exitWith { @@ -38,20 +38,23 @@ if (_doNotDropAmmo && {({_x in _listOfItemsToRemove} count (magazines _target)) }; _holder = objNull; + +//If not dropping ammo, don't use an existing container if (!_doNotDropAmmo) then { - //Try to use the same container, if one exists { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { _holder = _x; }; - } forEach ((getpos _target) nearObjects ["GroundWeaponHolder", 3]); + } forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); }; if (isNull _holder) then { - _dropPos = _target modelToWorld [-0.75, 0.75, 0]; - _dropPos set [2, 0]; + _dropPos = _target modelToWorld [0, 0.75, 0]; + _dropPos set [2, ((getPosASL _target) select 2)]; // _holder = createVehicle ["WeaponHolderSimulated", _dropPos, [], 0, "CAN_COLLIDE"]; - _holder = createVehicle ["GroundWeaponHolder", _dropPos, [], 0, "CAN_COLLIDE"]; + _holder = createVehicle [DISARM_CONTAINER, _dropPos, [], 0, "CAN_COLLIDE"]; + _holder setPosASL _dropPos; + _holder setVariable [QGVAR(holderInUse), false]; _holder setVariable [QGVAR(disarmUnit), _target, true]; }; @@ -59,12 +62,12 @@ if (isNull _holder) then { if (isNull _holder) exitWith { [_caller, _target, "Debug: Null Holder"] call FUNC(eventTargetFinish); }; -//Make sure only one drop operation at a time... +//Make sure only one drop operation at a time (using PFEH system as a queue) if (_holder getVariable [QGVAR(holderInUse), false]) exitWith { systemChat format ["Debug: %1 - Ground Container In Use, waiting until free", time]; [{ _this call FUNC(disarmDropItems); - }, _this, 0.05, 0.05] call EFUNC(common,waitAndExecute); + }, _this, 0, 0] call EFUNC(common,waitAndExecute); }; _holder setVariable [QGVAR(holderInUse), true]; @@ -164,7 +167,7 @@ systemChat format ["PFEh start %1", time]; _needToRemoveVest = ((vest _target) != "") && {(vest _target) in _listOfItemsToRemove}; _needToRemoveUniform = ((uniform _target) != "") && {(uniform _target) in _listOfItemsToRemove}; - if ((time < _maxWaitTime) && {[_target] call FUNC(canDisarm)} && {_needToRemoveWeapon || _needToRemoveMagazines || _needToRemoveBackpack}) then { + if ((time < _maxWaitTime) && {[_target] call FUNC(canBeDisarmed)} && {_needToRemoveWeapon || _needToRemoveMagazines || _needToRemoveBackpack}) then { //action drop weapons (keeps loaded magazine and attachements) { if (_x in _listOfItemsToRemove) then { @@ -222,18 +225,16 @@ systemChat format ["PFEh start %1", time]; systemChat "Debug: Deleting Dummy"; clearItemCargoGlobal _holder; }; - //Verify we didn't timeout waiting on drop action if (time >= _maxWaitTime) exitWith { _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 { + if (!([_target] call FUNC(canBeDisarmed))) 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_eventCallerFinish.sqf b/addons/disarming/functions/fnc_eventCallerFinish.sqf index 2acc1d4346..c87cb434b3 100644 --- a/addons/disarming/functions/fnc_eventCallerFinish.sqf +++ b/addons/disarming/functions/fnc_eventCallerFinish.sqf @@ -1,6 +1,6 @@ /* * Author: PabstMirror - * Starts the disarming process from the caller + * Recieves a possible error code from FUNC(eventTargetFinish) * * Arguments: * 0: caller (player) @@ -11,7 +11,7 @@ * None * * Example: - * TODO + * [player1, player2, "Someting fucked up"] call ace_disarming_fnc_eventCallerFinish * * Public: No */ @@ -22,4 +22,4 @@ PARAMS_3(_caller,_target,_errorMsg); if (_caller != ACE_player) exitWith {}; systemChat format ["Debug-Caller: Disarm finished from [%1] with code [%2]", _target, _errorMsg]; -[format ["Problem Removing Item
%1", _errorMsg]] call EFUNC(common,displayTextStructured); \ No newline at end of file +diag_log text format ["[ACE_Disarming] %1 - eventCallerFinish: %2", time, _this]; diff --git a/addons/disarming/functions/fnc_eventTargetFinish.sqf b/addons/disarming/functions/fnc_eventTargetFinish.sqf index fa217056b0..286b0d8c57 100644 --- a/addons/disarming/functions/fnc_eventTargetFinish.sqf +++ b/addons/disarming/functions/fnc_eventTargetFinish.sqf @@ -1,6 +1,7 @@ /* * Author: PabstMirror - * TODO + * After FUNC(disarmDropItems) has completed, passing a possible error code. + * Passes that error back to orginal caller. * * Arguments: * 0: caller @@ -11,7 +12,7 @@ * Nothing * * Example: - * eventTargetFinish + * [player1, player2, "Someting fucked up"] call ace_disarming_fnc_eventTargetFinish * * Public: No */ @@ -21,6 +22,6 @@ PARAMS_3(_caller,_target,_errorMsg); if (_errorMsg != "") then { - systemChat _errorMsg; + diag_log text format ["[ACE_Disarming] %1 - eventTargetFinish: %2", time, _this]; ["DisarmDebugCallback", [_caller], [_caller, _target, _errorMsg]] call EFUNC(common,targetEvent); }; diff --git a/addons/disarming/functions/fnc_eventTargetStart.sqf b/addons/disarming/functions/fnc_eventTargetStart.sqf index 942d114e5d..c91f717e2a 100644 --- a/addons/disarming/functions/fnc_eventTargetStart.sqf +++ b/addons/disarming/functions/fnc_eventTargetStart.sqf @@ -1,6 +1,7 @@ /* * Author: PabstMirror - * TODO + * Disarm Event Handler, Starting func, called on the target. + * If target has to remove uniform/vest, this will add all uniform/vest items to the drop list. * * Arguments: * 0: caller (player) diff --git a/addons/disarming/functions/fnc_openDisarmDialog.sqf b/addons/disarming/functions/fnc_openDisarmDialog.sqf index fb7a3d35e3..9fc5fa2c21 100644 --- a/addons/disarming/functions/fnc_openDisarmDialog.sqf +++ b/addons/disarming/functions/fnc_openDisarmDialog.sqf @@ -16,18 +16,28 @@ */ #include "script_component.hpp" +#define TEXTURES_RANKS [ \ + "", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\private_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\corporal_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\sergeant_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\lieutenant_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\captain_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\major_gs.paa", \ + "\A3\Ui_f\data\GUI\Cfg\Ranks\colonel_gs.paa" \ + ] + PARAMS_2(_caller,_target); //Sanity Checks 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");}; - -if (dialog) then {closeDialog 0;}; -createDialog QGVAR(remoteInventory); +if (!([_player, _target] call FUNC(canPlayerDisarmUnit))) exitWith {ERROR("Can't Disarm Unit");}; +if (dialog) then {ERROR("Dialog open when trying to open disarm dialog"); closeDialog 0;}; disableSerialization; +createDialog QGVAR(remoteInventory); + _display = uiNamespace getVariable ["ACE_remoteInventory", displayNull]; if (isNull _display) exitWith {ERROR("Display is Null");}; @@ -53,11 +63,12 @@ GVAR(disarmTarget) = _target; EXPLODE_2_PVT(_this,_args,_pfID); EXPLODE_3_PVT(_args,_player,_target,_display); - if ((!([_target] call FUNC(canDisarm))) || + if ((!([_player, _target] call FUNC(canPlayerDisarmUnit))) || {isNull _display} || - {_player != ACE_player} || - {!([_player, _target, []] call EFUNC(common,canInteractWith))}) then { + {_player != ACE_player}) then { + systemChat "Debug: closeing dialog"; + [_pfID] call CBA_fnc_removePerFrameHandler; GVAR(disarmTarget) = objNull; if (!isNull _display) then {closeDialog 0;}; //close dialog if still open @@ -67,9 +78,12 @@ GVAR(disarmTarget) = _target; _playerName = _display displayCtrl 111; _rankPicture = _display displayCtrl 1203; - _rankPicture ctrlSetText "\A3\Ui_f\data\GUI\Cfg\Ranks\corporal_gs.paa"; + //Show rank and name (just like BIS's inventory) + _rankIndex = ["PRIVATE", "CORPORAL", "SERGEANT", "LIEUTENANT", "CAPTAIN", "MAJOR", "COLONEL"] find (rank _target); + _rankPicture ctrlSetText (TEXTURES_RANKS select _rankIndex); _playerName ctrlSetText ([GVAR(disarmTarget)] call EFUNC(common,getName)); + //Clear both inventory lists: lbClear _groundContainer; lbClear _targetContainer; @@ -77,17 +91,18 @@ GVAR(disarmTarget) = _target; _targetUniqueItems = [GVAR(disarmTarget)] call FUNC(getAllGearUnit); [_targetContainer, _targetUniqueItems] call FUNC(showItemsInListbox); + //Try to find a holder that the target is using to drop items into: _holder = objNull; { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { _holder = _x; }; - } forEach ((getpos _target) nearObjects ["GroundWeaponHolder", 3]); + } forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); + //If a holder exists, show it's inventory if (!isNull _holder) then { _holderUniqueItems = [_holder] call FUNC(getAllGearContainer); [_groundContainer, _holderUniqueItems] call FUNC(showItemsInListbox); }; - }; -}, 0.05, [_caller, _target, _display]] call CBA_fnc_addPerFrameHandler; +}, 0, [_caller, _target, _display]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/disarming/functions/fnc_showItemsInListbox.sqf b/addons/disarming/functions/fnc_showItemsInListbox.sqf index f76336bd36..3b2d1bfc87 100644 --- a/addons/disarming/functions/fnc_showItemsInListbox.sqf +++ b/addons/disarming/functions/fnc_showItemsInListbox.sqf @@ -4,7 +4,7 @@ * * Arguments: * 0: RscListBox - * 1: ItemArray [["items"],[counts]] + * 1: ItemArray [["itemClassnames"],[counts]] * * Return Value: * Nothing @@ -19,32 +19,39 @@ disableSerialization; PARAMS_2(_listBoxCtrl,_itemsCountArray); +private "_classname"; + { _displayName = ""; _picture = ""; + + _classname = _x; _count = (_itemsCountArray select 1) select _forEachIndex; - switch (true) do { - case (isClass (configFile >> "CfgWeapons" >> _x)): { - _displayName = getText (configFile >> "CfgWeapons" >> _x >> "displayName"); - _picture = getText (configFile >> "CfgWeapons" >> _x >> "picture"); + if (_classname != DUMMY_ITEM) then { //Don't show the dummy potato + + switch (true) do { + case (isClass (configFile >> "CfgWeapons" >> _classname)): { + _displayName = getText (configFile >> "CfgWeapons" >> _classname >> "displayName"); + _picture = getText (configFile >> "CfgWeapons" >> _classname >> "picture"); + }; + case (isClass (configFile >> "CfgMagazines" >> _classname)): { + _displayName = getText (configFile >> "CfgMagazines" >> _classname >> "displayName"); + _picture = getText (configFile >> "CfgMagazines" >> _classname >> "picture"); + }; + case (isClass (configFile >> "CfgVehicles" >> _classname)): { + _displayName = getText (configFile >> "CfgVehicles" >> _classname >> "displayName"); + _picture = getText (configFile >> "CfgVehicles" >> _classname >> "picture"); + }; + case (isClass (configFile >> "CfgGlasses" >> _classname)): { + _displayName = getText (configFile >> "CfgGlasses" >> _classname >> "displayName"); + _picture = getText (configFile >> "CfgGlasses" >> _classname >> "picture"); + }; }; - case (isClass (configFile >> "CfgMagazines" >> _x)): { - _displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName"); - _picture = getText (configFile >> "CfgMagazines" >> _x >> "picture"); - }; - case (isClass (configFile >> "CfgVehicles" >> _x)): { - _displayName = getText (configFile >> "CfgVehicles" >> _x >> "displayName"); - _picture = getText (configFile >> "CfgVehicles" >> _x >> "picture"); - }; - case (isClass (configFile >> "CfgGlasses" >> _x)): { - _displayName = getText (configFile >> "CfgGlasses" >> _x >> "displayName"); - _picture = getText (configFile >> "CfgGlasses" >> _x >> "picture"); - }; - }; - _listBoxCtrl lbAdd format ["%1", _displayName]; - _listBoxCtrl lbSetData [_forEachIndex, _x]; - _listBoxCtrl lbSetPicture [_forEachIndex, _picture]; - _listBoxCtrl lbSetTextRight [_forEachIndex, str _count]; + _listBoxCtrl lbAdd format ["%1", _displayName]; + _listBoxCtrl lbSetData [_forEachIndex, _classname]; + _listBoxCtrl lbSetPicture [_forEachIndex, _picture]; + _listBoxCtrl lbSetTextRight [_forEachIndex, str _count]; + }; } forEach (_itemsCountArray select 0); diff --git a/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf index cd2babd985..779a5e39ba 100644 --- a/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf +++ b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf @@ -14,7 +14,7 @@ * Verified Good * * Example: - * [] call ace_disarming_fnc_verifyMagazinesMoved + * [stuff] call ace_disarming_fnc_verifyMagazinesMoved * * Public: No */ @@ -26,7 +26,6 @@ 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 }; @@ -39,6 +38,4 @@ _problem = false; _beginingArray deleteAt _index; } forEach (_endA + _endB); -systemChat format ["%1 - %2", _problem, _beginingArray]; - (!_problem) && {_beginingArray isEqualTo []} diff --git a/addons/disarming/gui_disarm.hpp b/addons/disarming/gui_disarm.hpp index c8316a859e..8ccc61a8ec 100644 --- a/addons/disarming/gui_disarm.hpp +++ b/addons/disarming/gui_disarm.hpp @@ -1,3 +1,6 @@ +//The disarming dialog +//Meant to mimic the real BIS inventory (so people understand how to use it) + class RscText; class RscPicture; class RscActiveText; @@ -13,8 +16,7 @@ class GVAR(remoteInventory) { fadein = 0; fadeout = 0; - class Colors - { + class Colors { dragValidBgr[] = {"(profilenamespace getvariable ['IGUI_TEXT_RGB_R',0])","(profilenamespace getvariable ['IGUI_TEXT_RGB_G',1])","(profilenamespace getvariable ['IGUI_TEXT_RGB_B',1])",0.5}; dragInvalidBgr[] = {"(profilenamespace getvariable ['IGUI_ERROR_RGB_R',0.8])","(profilenamespace getvariable ['IGUI_ERROR_RGB_G',0.0])","(profilenamespace getvariable ['IGUI_ERROR_RGB_B',0.0])",0.5}; dragValidBar[] = {"(profilenamespace getvariable ['IGUI_WARNING_RGB_R',0.8])","(profilenamespace getvariable ['IGUI_WARNING_RGB_G',0.5])","(profilenamespace getvariable ['IGUI_WARNING_RGB_B',0.0])",0.5}; @@ -86,7 +88,7 @@ class GVAR(remoteInventory) { h = "1 * ((safeZoneH / 1.2) / 25)"; colorText[] = {1,1,1,0.7}; colorActive[] = {1,1,1,1}; - tooltip = "Close"; + tooltip = "$str_disp_close"; }; class ExternalContainerBackground: RscPicture { colorText[] = {1,1,1,0.1}; @@ -121,16 +123,16 @@ class GVAR(remoteInventory) { }; class GroundContainer: RscListBox { idc = 632; - sizeEx = "0.8 * ( ( ((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; - sizeEx2 = "0.8 * ( ( ((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; - rowHeight = "1.75 * ( ( ((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + sizeEx = "0.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + sizeEx2 = "0.8 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + rowHeight = "1.75 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; canDrag = 0; colorText[] = {1,1,1,1}; colorBackground[] = {0,0,0,0}; itemBackground[] = {1,1,1,0.2}; itemSpacing = 0.001; - x = "1.5 * (safeZoneH / 40) + (safezoneX + (safezoneW - safeZoneH)/2)"; - y = "2.5 * ((safeZoneH / 1.2) / 25) + (safezoneY + (safezoneH - (safeZoneH / 1.2))/2)"; + x = "1.5 * (safeZoneH / 40) + (safezoneX + (safezoneW - safeZoneH)/2)"; + y = "2.5 * ((safeZoneH / 1.2) / 25) + (safezoneY + (safezoneH - (safeZoneH / 1.2))/2)"; w = "11 * (safeZoneH / 40)"; h = "21.5 * ((safeZoneH / 1.2) / 25)"; }; diff --git a/addons/disarming/script_component.hpp b/addons/disarming/script_component.hpp index 3e13697397..d9bec366dc 100644 --- a/addons/disarming/script_component.hpp +++ b/addons/disarming/script_component.hpp @@ -11,5 +11,6 @@ #include "\z\ace\addons\main\script_macros.hpp" +#define DISARM_CONTAINER "GroundWeaponHolder" #define DUMMY_ITEM "ACE_DebugPotato" #define UNIQUE_MAGAZINES ["ACE_key_customKeyMagazine"] \ No newline at end of file