Add support for prefixes in /item and /give
This commit is contained in:
parent
3f0d82e5be
commit
a2a1486ea1
3 changed files with 73 additions and 20 deletions
|
|
@ -2497,7 +2497,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (args.Parameters.Count < 1)
|
if (args.Parameters.Count < 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /item <item name/id> [item amount]", Color.Red);
|
args.Player.SendMessage("Invalid syntax! Proper syntax: /item <item name/id> [item amount] [prefix name/id]", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.Parameters[0].Length == 0)
|
if (args.Parameters[0].Length == 0)
|
||||||
|
|
@ -2506,7 +2506,16 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int itemAmount = 0;
|
int itemAmount = 0;
|
||||||
int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount);
|
int prefix = 0;
|
||||||
|
if (args.Parameters.Count == 2)
|
||||||
|
int.TryParse(args.Parameters[1], out itemAmount);
|
||||||
|
else if (args.Parameters.Count == 3)
|
||||||
|
{
|
||||||
|
int.TryParse(args.Parameters[1], out itemAmount);
|
||||||
|
var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[2]);
|
||||||
|
if (found.Count == 1)
|
||||||
|
prefix = found[0];
|
||||||
|
}
|
||||||
var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]);
|
var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]);
|
||||||
if (items.Count == 0)
|
if (items.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -2525,7 +2534,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (itemAmount == 0 || itemAmount > item.maxStack)
|
if (itemAmount == 0 || itemAmount > item.maxStack)
|
||||||
itemAmount = item.maxStack;
|
itemAmount = item.maxStack;
|
||||||
args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount);
|
args.Player.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix);
|
||||||
args.Player.SendMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name));
|
args.Player.SendMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -2544,7 +2553,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (args.Parameters.Count < 2)
|
if (args.Parameters.Count < 2)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /give <item type/id> <player> [item amount]", Color.Red);
|
args.Player.SendMessage("Invalid syntax! Proper syntax: /give <item type/id> <player> [item amount] [prefix id/name]", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.Parameters[0].Length == 0)
|
if (args.Parameters[0].Length == 0)
|
||||||
|
|
@ -2558,13 +2567,20 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int itemAmount = 0;
|
int itemAmount = 0;
|
||||||
|
int prefix = 0;
|
||||||
var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]);
|
var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]);
|
||||||
args.Parameters.RemoveAt(0);
|
args.Parameters.RemoveAt(0);
|
||||||
string plStr = args.Parameters[0];
|
string plStr = args.Parameters[0];
|
||||||
args.Parameters.RemoveAt(0);
|
args.Parameters.RemoveAt(0);
|
||||||
if (args.Parameters.Count > 0)
|
if (args.Parameters.Count == 1)
|
||||||
int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount);
|
int.TryParse(args.Parameters[0], out itemAmount);
|
||||||
|
else if (args.Parameters.Count == 2)
|
||||||
|
{
|
||||||
|
int.TryParse(args.Parameters[0], out itemAmount);
|
||||||
|
var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[1]);
|
||||||
|
if (found.Count == 1)
|
||||||
|
prefix = found[0];
|
||||||
|
}
|
||||||
|
|
||||||
if (items.Count == 0)
|
if (items.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -2595,7 +2611,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (itemAmount == 0 || itemAmount > item.maxStack)
|
if (itemAmount == 0 || itemAmount > item.maxStack)
|
||||||
itemAmount = item.maxStack;
|
itemAmount = item.maxStack;
|
||||||
plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount);
|
plr.GiveItem(item.type, item.name, item.width, item.height, itemAmount, prefix);
|
||||||
args.Player.SendMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.name));
|
args.Player.SendMessage(string.Format("Gave {0} {1} {2}(s).", plr.Name, itemAmount, item.name));
|
||||||
plr.SendMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.name));
|
plr.SendMessage(string.Format("{0} gave you {1} {2}(s).", args.Player.Name, itemAmount, item.name));
|
||||||
}
|
}
|
||||||
|
|
@ -2618,39 +2634,29 @@ namespace TShockAPI
|
||||||
int radius = 50;
|
int radius = 50;
|
||||||
if (args.Parameters.Count > 0)
|
if (args.Parameters.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (args.Parameters[0].ToLower() == "all")
|
if (args.Parameters[0].ToLower() == "all")
|
||||||
{
|
{
|
||||||
|
|
||||||
radius = Int32.MaxValue / 16;
|
radius = Int32.MaxValue / 16;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
radius = Convert.ToInt32(args.Parameters[0]);
|
radius = Convert.ToInt32(args.Parameters[0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception) { args.Player.SendMessage("Please either enter the keyword \"all\", or the block radius you wish to delete all items from.", Color.Red); return; }
|
catch (Exception) { args.Player.SendMessage("Please either enter the keyword \"all\", or the block radius you wish to delete all items from.", Color.Red); return; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < 200; i++)
|
for (int i = 0; i < 200; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((Math.Sqrt(Math.Pow(Main.item[i].position.X - args.Player.X, 2) + Math.Pow(Main.item[i].position.Y - args.Player.Y, 2)) < radius * 16) && (Main.item[i].active))
|
if ((Math.Sqrt(Math.Pow(Main.item[i].position.X - args.Player.X, 2) + Math.Pow(Main.item[i].position.Y - args.Player.Y, 2)) < radius * 16) && (Main.item[i].active))
|
||||||
{
|
{
|
||||||
|
|
||||||
Main.item[i].active = false;
|
Main.item[i].active = false;
|
||||||
NetMessage.SendData(0x15, -1, -1, "", i, 0f, 0f, 0f, 0);
|
NetMessage.SendData(0x15, -1, -1, "", i, 0f, 0f, 0f, 0);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted.");
|
args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted.");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -268,9 +268,9 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void GiveItem(int type, string name, int width, int height, int stack)
|
public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||||
{
|
{
|
||||||
int itemid = Item.NewItem((int)X, (int)Y, width, height, type, stack, true);
|
int itemid = Item.NewItem((int)X, (int)Y, width, height, type, stack, true, prefix);
|
||||||
// This is for special pickaxe/hammers/swords etc
|
// This is for special pickaxe/hammers/swords etc
|
||||||
Main.item[itemid].SetDefaults(name);
|
Main.item[itemid].SetDefaults(name);
|
||||||
// The set default overrides the wet and stack set by NewItem
|
// The set default overrides the wet and stack set by NewItem
|
||||||
|
|
|
||||||
|
|
@ -309,10 +309,12 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
return (id > 0 && id < Main.maxBuffs) ? Main.buffName[id] : "null";
|
return (id > 0 && id < Main.maxBuffs) ? Main.buffName[id] : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetBuffDescription(int id)
|
public string GetBuffDescription(int id)
|
||||||
{
|
{
|
||||||
return (id > 0 && id < Main.maxBuffs) ? Main.buffTip[id] : "null";
|
return (id > 0 && id < Main.maxBuffs) ? Main.buffTip[id] : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<int> GetBuffByName(string name)
|
public List<int> GetBuffByName(string name)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < Main.maxBuffs; i++)
|
for (int i = 1; i < Main.maxBuffs; i++)
|
||||||
|
|
@ -329,6 +331,51 @@ namespace TShockAPI
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetPrefixById(int id)
|
||||||
|
{
|
||||||
|
var item = new Item();
|
||||||
|
item.SetDefaults(0);
|
||||||
|
item.prefix = (byte)id;
|
||||||
|
item.AffixName();
|
||||||
|
return item.name.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<int> GetPrefixByName(string name)
|
||||||
|
{
|
||||||
|
Item item = new Item();
|
||||||
|
for (int i = 1; i < 83; i++)
|
||||||
|
{
|
||||||
|
item.prefix = (byte) i;
|
||||||
|
item.AffixName();
|
||||||
|
if (item.name.Trim() == name)
|
||||||
|
return new List<int> { i };
|
||||||
|
}
|
||||||
|
var found = new List<int>();
|
||||||
|
for (int i = 1; i < 83; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
item.prefix = (byte) i;
|
||||||
|
if (item.name.Trim().ToLower() == name.ToLower())
|
||||||
|
return new List<int> { i };
|
||||||
|
if (item.name.Trim().ToLower().StartsWith(name.ToLower()))
|
||||||
|
found.Add(i);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<int> GetPrefixByIdOrName(string idOrName)
|
||||||
|
{
|
||||||
|
int type = -1;
|
||||||
|
if (int.TryParse(idOrName, out type) && type > 0 && type < 84)
|
||||||
|
{
|
||||||
|
return new List<int> {type};
|
||||||
|
}
|
||||||
|
return GetPrefixByName(idOrName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Kicks all player from the server without checking for immunetokick permission.
|
/// Kicks all player from the server without checking for immunetokick permission.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue