Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit 516494d

Browse files
committed
Fixed escaping not giving you itemsTM and now when you escape ammo carries over
1 parent cff730d commit 516494d

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

StackingItems/StackEventHandler.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,22 @@ public void OnSetRole(PlayerSetRoleEvent ev)
225225
if (StackMain.checkSteamIDItemNum[ev.Player.SteamId].HasEscaped)
226226
{
227227
StackMain.checkSteamIDItemNum[ev.Player.SteamId].HasEscaped = false;
228-
Dictionary<int, int> EscapedItemList = new Dictionary<int, int>();
229-
foreach (KeyValuePair<int, int> keyValuePair in StackMain.checkSteamIDItemNum[ev.Player.SteamId].checkItemForNumOfItems)
230-
{
231-
EscapedItemList[keyValuePair.Key] = keyValuePair.Value;
232-
}
233228

234229
StackMain.checkSteamIDItemNum[ev.Player.SteamId].ResetToZero();
235-
230+
ev.Player.SetAmmo(AmmoType.DROPPED_9, StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo9 + ev.Player.GetAmmo(AmmoType.DROPPED_9));
231+
ev.Player.SetAmmo(AmmoType.DROPPED_7, StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo7 + ev.Player.GetAmmo(AmmoType.DROPPED_7));
232+
ev.Player.SetAmmo(AmmoType.DROPPED_5, StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo5 + ev.Player.GetAmmo(AmmoType.DROPPED_5));
236233
foreach (Smod2.API.ItemType item in (Smod2.API.ItemType[])Enum.GetValues(typeof(Smod2.API.ItemType)))
237234
{
238-
if (EscapedItemList.TryGetValue((int)item, out int value))
235+
if (StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList.TryGetValue((int)item, out int value))
239236
{
240237
for (int i = 0; i < value; i++)
241238
{
242239
ev.Items.Add(item);
243240
}
244241
}
245242
}
243+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList.Clear();
246244
}
247245
else
248246
{
@@ -295,13 +293,35 @@ public void OnUpdate(UpdateEvent ev) // OnHandCuffed is broke >:(
295293

296294
#region OnCheckEscape
297295
/// <summary>
298-
/// Checks if they have escaped to transfer item stacks over.
296+
/// Checks if they have escaped to transfer item stacks and ammo over.
299297
/// </summary>
300298
public void OnCheckEscape(PlayerCheckEscapeEvent ev)
301299
{
302300
if (StackMain.checkSteamIDItemNum.ContainsKey(ev.Player.SteamId) && StackMain.keepItemsOnExtract)
303301
{
304302
StackMain.checkSteamIDItemNum[ev.Player.SteamId].HasEscaped = true;
303+
foreach(KeyValuePair<int,int> kv in StackMain.checkSteamIDItemNum[ev.Player.SteamId].checkItemTypeForNumOfItems)
304+
{
305+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList[kv.Key] = kv.Value;
306+
}
307+
308+
foreach(Item item in ev.Player.GetInventory())
309+
{
310+
if (StackMain.checkSteamIDItemNum[ev.Player.SteamId].GetItemAmount((int)item.ItemType) != 0) continue;
311+
if (StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList.ContainsKey((int)item.ItemType))
312+
{
313+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList[(int)item.ItemType]++;
314+
}
315+
else
316+
{
317+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].EscapedItemList[(int)item.ItemType] = 1;
318+
}
319+
320+
}
321+
322+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo9 = ev.Player.GetAmmo(AmmoType.DROPPED_9);
323+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo7 = ev.Player.GetAmmo(AmmoType.DROPPED_7);
324+
StackMain.checkSteamIDItemNum[ev.Player.SteamId].ammo5 = ev.Player.GetAmmo(AmmoType.DROPPED_5);
305325
}
306326
else
307327
{

StackingItems/StackMain.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StackingItems
1111
name = "StackingItems",
1212
description = "Items stack to save inventory space.",
1313
id = "mith.StackingItems",
14-
version = "1.0.4",
14+
version = "1.0.5",
1515
SmodMajor = 3,
1616
SmodMinor = 2,
1717
SmodRevision = 2
@@ -64,7 +64,12 @@ public static void SetStackSize()
6464

6565
public class StackCheckSteamIDsforItemInts
6666
{
67-
public Dictionary<int, int> checkItemForNumOfItems = new Dictionary<int, int>();
67+
public Dictionary<int, int> checkItemTypeForNumOfItems = new Dictionary<int, int>();
68+
public Dictionary<int, int> EscapedItemList = new Dictionary<int, int>();
69+
70+
public int ammo9 = 0,
71+
ammo7 = 0,
72+
ammo5 = 0;
6873

6974
public bool fixUseMedKit = false;
7075
public bool fixthrowGrenade = false;
@@ -73,30 +78,30 @@ public class StackCheckSteamIDsforItemInts
7378

7479
public void ResetToZero()
7580
{
76-
checkItemForNumOfItems.Clear();
81+
checkItemTypeForNumOfItems.Clear();
7782
}
7883

7984
public int GetItemAmount(int ItemType)
8085
{
81-
if (checkItemForNumOfItems.TryGetValue(ItemType, out int value))
86+
if (checkItemTypeForNumOfItems.TryGetValue(ItemType, out int value))
8287
{
8388
return value;
8489
}
8590
else
8691
{
87-
return -1;
92+
return 0;
8893
}
8994
}
9095

9196
public void AddItemAmount(int ItemType, int Amount)
9297
{
93-
if (checkItemForNumOfItems.TryGetValue(ItemType, out int value))
98+
if (checkItemTypeForNumOfItems.TryGetValue(ItemType, out int value))
9499
{
95-
checkItemForNumOfItems[ItemType] += Amount;
100+
checkItemTypeForNumOfItems[ItemType] += Amount;
96101
}
97102
else
98103
{
99-
checkItemForNumOfItems[ItemType] = Amount;
104+
checkItemTypeForNumOfItems[ItemType] = Amount;
100105
}
101106
}
102107
}

0 commit comments

Comments
 (0)