Skip to content

Commit 96fe157

Browse files
authored
Better version of loot-to-crate while carrying the crate (#3878)
1 parent 5c57667 commit 96fe157

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

A3A/addons/core/functions/UtilityItems/fn_carryItem.sqf

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ Example:
1919

2020
params ["_item", "_player"]; // standard addAction
2121

22-
// Redo the checks, because this function might be delayed by script load
23-
if ((!isNull attachedTo _item) or (call A3A_fnc_isCarrying) or (!isNull objectParent _player)) exitWith {};
24-
if (_item isKindOf "StaticWeapon" and count crew _item != 0) exitWith {};
25-
2622
// Go unscheduled to keep the state consistent
2723
isNil {
24+
// Redo the checks, because this function might be delayed by script load
25+
if ((!isNull attachedTo _item) or (call A3A_fnc_isCarrying) or (!isNull objectParent _player)) exitWith {};
26+
if (_item isKindOf "StaticWeapon" and count crew _item != 0) exitWith {};
27+
2828
if (_item isKindOf "StaticWeapon") then { _item lock true };
29+
_item lockInventory true;
2930

3031
// Prevent killing players with item
3132
if (isNil {_item getVariable "A3A_originalMass"}) then { _item setVariable ["A3A_originalMass", getMass _item] };
@@ -49,9 +50,24 @@ isNil {
4950

5051
private _dropID = _player addAction [
5152
localize "STR_A3A_fn_UtilItem_dropOb_addact_drop",
52-
{ (_this#1) call A3A_fnc_dropItem }, _item, 4, true, true, "", "true"
53+
{ (_this#1) call A3A_fnc_dropItem }, _item, 5, true, true, "", "true"
5354
];
54-
_player setVariable ["A3A_actionIDdrop", _dropID];
55+
private _actionIDs = [_dropID];
56+
57+
// Add loot actions if it's a loot crate
58+
private _isUtility = typeOf _item in A3A_utilityItemHM;
59+
if (_isUtility and {"loot" in (A3A_utilityItemHM get typeOf _item) # 4}) then
60+
{
61+
_actionIDs pushBack (_player addAction [
62+
localize "STR_A3A_fn_ltc_init_addact_ltc",
63+
{ [_this#3, clientOwner] remoteExecCall ["A3A_fnc_canLoot", 2] }, _item, 4, true, true, "", "true"
64+
]);
65+
_actionIDs pushBack (_player addAction [
66+
localize "STR_A3A_fn_ltc_init_addact_ltv",
67+
{ [_this#3, clientOwner] remoteExecCall ["A3A_fnc_canTransfer", 2] }, _item, 3, true, true, "", "true"
68+
]);
69+
};
70+
_player setVariable ["A3A_carryActionIDs", _actionIDs];
5571

5672
[_player, _item] spawn {
5773
params ["_player", "_item"];

A3A/addons/core/functions/UtilityItems/fn_dropItem.sqf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
params ["_player"];
1414

15-
// Possible to fire this off twice at high script load
16-
private _dropID = _player getVariable "A3A_actionIDdrop";
17-
if (isNil "_dropID") exitWith {};
18-
1915
// Go unscheduled to keep the state consistent
2016
isNil {
21-
// Clear drop action
22-
_player removeAction _dropID;
23-
_player setVariable ["A3A_actionIDdrop", nil];
17+
// Possible to fire this off twice at high script load
18+
if (_player isNil "A3A_carryActionIDs") exitWith {};
19+
20+
// Clear drop/loot actions
21+
{ _player removeAction _x } forEach (_player getVariable "A3A_carryActionIDs");
22+
_player setVariable ["A3A_carryActionIDs", nil];
2423

2524
// Clear GetInMan EH
2625
private _eventIDcarry = _player getVariable "A3A_eventIDcarry";
@@ -62,6 +61,7 @@ isNil {
6261

6362
[_item, true] remoteExecCall ["enableSimulationGlobal", 2];
6463

64+
_item lockInventory false;
6565
if (_item isKindOf "StaticWeapon") then { _item lock false };
6666

6767
_item spawn {

0 commit comments

Comments
 (0)