-
Notifications
You must be signed in to change notification settings - Fork 5
/
CommandClearMag.cs
79 lines (65 loc) · 2.9 KB
/
CommandClearMag.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Items;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections.Generic;
namespace EasyAmmo
{
class CommandClearMag : IRocketCommand
{
public List<string> Aliases => new List<string> { "clearm", "cm" };
public AllowedCaller AllowedCaller => AllowedCaller.Player;
public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer uplayer = (UnturnedPlayer)caller;
//bool enterNumber = false;
//int enteredAmount = 0;
int magsRemoved = 0;
ItemAsset uItem = null;
/* if (command.Length == 1)
{
if (int.TryParse(command[0], out enteredAmount))
{
enterNumber = true;
}
} */
// this section of code is referenced from LeeIzaZombie's itemRestriction plugin here - https://dev.rocketmod.net/plugins/item-restrictions/
//original code - https://bitbucket.org/LeeIzaZombie/rocketmod_itemrestrictions/src/9646f79a3c4f051551cd209a9c86e8ee0ea0e829/RocketMod_ItemRestriction/IR_Plugin.cs?at=master&fileviewer=file-view-default
PlayerInventory inventory = uplayer.Player.inventory;
for (byte page = 0; page < 8; page++)
{
byte amountOfItems = inventory.getItemCount(page);
for (int index = amountOfItems - 1; index >= 0; index--)
{
try
{
uItem = UnturnedItems.GetItemAssetById(inventory.getItem(page, (byte)index).item.id);
}
catch (Exception)
{
//Logger.LogError("Error trying to get item at Page: " + page + " Index: " + index);
}
if (uItem != null)
{
if (uItem.type == EItemType.MAGAZINE)
{
// Logger.Log("removing id " + uItem.Id.ToString());
inventory.removeItem(page, (byte)index);
/* Logger.LogWarning("removed: " + uItem.id.ToString() + "from: " + "Page-" + page.ToString()
+ " index-" + index.ToString()); */
magsRemoved++;
}
}
uItem = null;
}
}
UnturnedChat.Say(caller, EasyAmmo.Instance.Translate("removed_mags", magsRemoved.ToString()));
}
public string Help => "clears empty ammo magazines from your inventory";
public string Name => "clearmag";
public List<string> Permissions => new List<string> { "clearmag" };
public string Syntax => "(ammo count)";
}
}