-
Notifications
You must be signed in to change notification settings - Fork 5
/
CommandDropAmmo.cs
164 lines (141 loc) · 6.07 KB
/
CommandDropAmmo.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Items;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System.Collections.Generic;
namespace EasyAmmo
{
class CommandDropAmmo : IRocketCommand
{
public List<string> Aliases => new List<string> {"dammo", "da", "dropa"};
public AllowedCaller AllowedCaller => AllowedCaller.Player;
public void Execute(IRocketPlayer caller, string[] command)
{
ushort ammoAmountToSpawn = 0;
bool enteredAmount = false;
ItemAsset currentEquiped;
var uPlayer = (UnturnedPlayer) caller;
if (command.Length >= 1)
{
if (ushort.TryParse(command[0], out ammoAmountToSpawn))
{
enteredAmount = true;
}
}
currentEquiped = uPlayer.Player.equipment.asset;
if (currentEquiped == null)
{
UnturnedChat.Say(caller, EasyAmmo.Instance.Translate("nothing_equipped"));
return;
}
if (currentEquiped.type != EItemType.GUN)
{
UnturnedChat.Say(caller, EasyAmmo.Instance.Translate("no_gun_equipped"));
return;
}
//debug prints
//UnturnedChat.Say(caller, " your current equipped item is \" id: " + currentEquiped + " / " + "name: " + currentEquiped.name);
//UnturnedChat.Say(caller, "item type: " + item.GetType().ToString());
if (!(currentEquiped is ItemGunAsset currentWeapon))
{
return;
}
if (EasyAmmo.CheckIfBlacklisted(caller, currentWeapon))
{
return;
}
if (enteredAmount && caller.HasPermission("dropammo.amount"))
{
if (EasyAmmo.Instance.Configuration.Instance.ClipLimitEnabled)
{
DropMagsWithLimit(ammoAmountToSpawn, caller, currentWeapon, uPlayer, command);
}
else
{
DropMags(ammoAmountToSpawn, caller, currentWeapon, uPlayer, command);
}
}
else
{
DropMags(ammoAmountToSpawn: 1, caller, currentWeapon, uPlayer, command);
}
}
public string Help => "drops the specified number of clips for your currently equipped weapon.";
public string Name => "dropammo";
public List<string> Permissions => new List<string> {"dropammo"};
public string Syntax => "(amount of ammo)";
public void DropMags(ushort ammoAmountToSpawn, IRocketPlayer caller, ItemGunAsset currentWeapon,
UnturnedPlayer uPlayer, string[] command)
{
UnturnedChat.Say(caller,
EasyAmmo.Instance.Translate("dropping_mags", ammoAmountToSpawn.ToString(),
UnturnedItems.GetItemAssetById(GetMagId(uPlayer, currentWeapon, command)).name,
GetMagId(uPlayer, currentWeapon, command).ToString()));
for (int ii = 0; ii < (int) ammoAmountToSpawn; ii++)
{
ItemManager.dropItem(new Item(GetMagId(uPlayer, currentWeapon, command), true), uPlayer.Position, true,
true, true);
}
}
public void DropMagsWithLimit(ushort ammoAmountToSpawn, IRocketPlayer caller, ItemGunAsset currentWeapon,
UnturnedPlayer uPlayer, string[] command)
{
if (ammoAmountToSpawn <= (ushort) EasyAmmo.Instance.Configuration.Instance.ClipLimit ||
caller.HasPermission("easyammo.bypasslimit"))
{
UnturnedChat.Say(caller,
EasyAmmo.Instance.Translate("dropping_mags", ammoAmountToSpawn.ToString(),
UnturnedItems.GetItemAssetById(GetMagId(uPlayer, currentWeapon, command)).name,
GetMagId(uPlayer, currentWeapon, command).ToString()));
for (int ii = 0; ii < (int) ammoAmountToSpawn; ii++)
{
ItemManager.dropItem(new Item(GetMagId(uPlayer, currentWeapon, command), true), uPlayer.Position,
true, true, true);
}
}
else
{
UnturnedItems.GetItemAssetById(1);
ushort amountoverlimit = ammoAmountToSpawn;
ammoAmountToSpawn = (ushort) EasyAmmo.Instance.Configuration.Instance.ClipLimit;
UnturnedChat.Say(caller,
EasyAmmo.Instance.Translate("over_clip_spawn_limit_dropping", amountoverlimit.ToString(),
EasyAmmo.Instance.Configuration.Instance.ClipLimit,
UnturnedItems.GetItemAssetById(GetMagId(uPlayer, currentWeapon, command)).name,
GetMagId(uPlayer, currentWeapon, command).ToString()));
for (int ii = 0; ii < (int) ammoAmountToSpawn; ii++)
{
ItemManager.dropItem(new Item(GetMagId(uPlayer, currentWeapon, command), true), uPlayer.Position,
true, true, true);
}
}
}
public ushort GetMagId(UnturnedPlayer player, ItemGunAsset gun, string[] command)
{
ushort magId = 0;
if (command.Length == 2 || command.Length == 1)
{
if (command.Length == 1)
{
if (command[0].ToLower() == "c")
{
magId = player.Player.equipment.state[8];
}
}
else if (command.Length == 2)
{
if (command[1].ToLower() == "c")
{
magId = player.Player.equipment.state[8];
}
}
}
if (magId == 0 || UnturnedItems.GetItemAssetById(magId).type != EItemType.MAGAZINE)
{
magId = gun.getMagazineID();
}
return magId;
}
}
}