Skip to content
This repository was archived by the owner on Jun 21, 2025. It is now read-only.

Commit f30a546

Browse files
authored
Add more methods to removeitem (#173)
* Add more methods to removeitem removeitem by itembase * Add RemoveItem(ItemType itemType) removeitem by itemtype * rename to RemoveItems,add int number maybe fix the error? * Final changes * Add RemoveItems method in Player.cs Add RemoveItems method in Player.cs
1 parent fd8b0ae commit f30a546

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

NwPluginAPI/Core/Player.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,32 @@ public void IntercomUnmute(bool revokeMute)
11251125
/// </summary>
11261126
/// <param name="pickup">The item pickup.</param>
11271127
public void RemoveItem(ItemPickupBase pickup) => ReferenceHub.inventory.ServerRemoveItem(pickup.Info.Serial, pickup);
1128+
1129+
/// <summary>
1130+
/// Removes an specific item.
1131+
/// </summary>
1132+
/// <param name="item">The item base.</param>
1133+
public void RemoveItem(ItemBase item) => ReferenceHub.inventory.UserInventory.Items.Remove(item.ItemSerial);
1134+
1135+
/// <summary>
1136+
/// Removes all specific items.
1137+
/// </summary>
1138+
/// <param name="itemtype">The item type.</param>
1139+
/// <param name="number">The number of items that will be removed.</param>
1140+
public void RemoveItems(ItemType itemType, int number = 1)
1141+
{
1142+
int removed = 0;
1143+
for (int i = 0; i < ReferenceHub.inventory.UserInventory.Items.Count; i++)
1144+
{
1145+
var kvp = ReferenceHub.inventory.UserInventory.Items.ElementAt(i);
1146+
if (kvp.Value.ItemTypeId == itemType)
1147+
{
1148+
ReferenceHub.inventory.UserInventory.Items.Remove(kvp.Key);
1149+
if (++removed == number)
1150+
break;
1151+
}
1152+
}
1153+
}
11281154

11291155
/// <summary>
11301156
/// Drops an specific item.
@@ -1354,4 +1380,4 @@ public bool TryGetComponent<T>(out T component, bool globalSearch = false) where
13541380
#endregion
13551381

13561382
}
1357-
}
1383+
}

0 commit comments

Comments
 (0)