Added GiveItem in TSPlayer
/heal using GiveItem from TSPlayer Added GetItemById and GetItemByName in Tools
This commit is contained in:
parent
8dc1bcff0d
commit
4dc5d7f58e
3 changed files with 58 additions and 21 deletions
|
|
@ -1170,6 +1170,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
private static void Heal(CommandArgs args)
|
private static void Heal(CommandArgs args)
|
||||||
{
|
{
|
||||||
|
TSPlayer playerToHeal;
|
||||||
if (args.Parameters.Count > 0)
|
if (args.Parameters.Count > 0)
|
||||||
{
|
{
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
|
|
@ -1177,45 +1178,42 @@ namespace TShockAPI
|
||||||
if (players.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (players.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = players[0];
|
playerToHeal = players[0];
|
||||||
DropHearts(plr.X, plr.Y, 20);
|
|
||||||
if (plr == args.Player)
|
|
||||||
{
|
|
||||||
args.Player.SendMessage("You just got healed!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
args.Player.SendMessage(string.Format("You just healed {0}", plr.Name));
|
|
||||||
plr.SendMessage(string.Format("{0} just healed you!", args.Player.Name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!args.Player.RealPlayer)
|
else if (!args.Player.RealPlayer)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("You cant heal yourself!");
|
args.Player.SendMessage("You cant heal yourself!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DropHearts(args.Player.X, args.Player.Y, 20);
|
playerToHeal = args.Player;
|
||||||
|
}
|
||||||
|
|
||||||
|
Item heart = Tools.GetItemById(58);
|
||||||
|
Item star = Tools.GetItemById(184);
|
||||||
|
for (int i = 0; i < 20; i++)
|
||||||
|
playerToHeal.GiveItem(heart.type, heart.name, heart.width, heart.height, heart.maxStack);
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
playerToHeal.GiveItem(star.type, star.name, star.width, star.height, star.maxStack);
|
||||||
|
if (playerToHeal == args.Player)
|
||||||
|
{
|
||||||
args.Player.SendMessage("You just got healed!");
|
args.Player.SendMessage("You just got healed!");
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
private static void DropHearts(float x, float y, int count)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
int itemid = Terraria.Item.NewItem(1, 1, 1, 1, 58);
|
args.Player.SendMessage(string.Format("You just healed {0}", playerToHeal.Name));
|
||||||
Main.item[itemid].position.X = x;
|
playerToHeal.SendMessage(string.Format("{0} just healed you!", args.Player.Name));
|
||||||
Main.item[itemid].position.Y = y;
|
|
||||||
NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,16 @@ namespace TShockAPI
|
||||||
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void GiveItem(int type, string name, int width, int height, int stack)
|
||||||
|
{
|
||||||
|
int itemid = Terraria.Item.NewItem((int)X, (int)Y, width, height, type, stack, true);
|
||||||
|
// This is for special pickaxe/hammers/swords etc
|
||||||
|
Main.item[itemid].SetDefaults(name);
|
||||||
|
Main.item[itemid].owner = Index;
|
||||||
|
NetMessage.SendData((int)PacketTypes.ItemDrop, -1, -1, "", itemid, 0f, 0f, 0f);
|
||||||
|
NetMessage.SendData((int)PacketTypes.ItemOwner, -1, -1, "", itemid, 0f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SendMessage(string msg)
|
public virtual void SendMessage(string msg)
|
||||||
{
|
{
|
||||||
SendMessage(msg, 0, 255, 0);
|
SendMessage(msg, 0, 255, 0);
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,35 @@ namespace TShockAPI
|
||||||
return !Main.tile[tileX, tileY].active;
|
return !Main.tile[tileX, tileY].active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Item GetItemById(int id)
|
||||||
|
{
|
||||||
|
Item item = new Item();
|
||||||
|
item.SetDefaults(id);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Item> GetItemByName(string name)
|
||||||
|
{
|
||||||
|
//Method #1 - must be exact match, allows support for different pickaxes/hammers/swords etc
|
||||||
|
for (int i = 1; i < Main.maxItemTypes; i++)
|
||||||
|
{
|
||||||
|
Item item = new Item();
|
||||||
|
item.SetDefaults(name);
|
||||||
|
if (item.name == name)
|
||||||
|
return new List<Item> { item };
|
||||||
|
}
|
||||||
|
//Method #2 - allows impartial matching
|
||||||
|
var found = new List<Item>();
|
||||||
|
for (int i = 1; i < Main.maxItemTypes; i++)
|
||||||
|
{
|
||||||
|
Item item = new Item();
|
||||||
|
item.SetDefaults(i);
|
||||||
|
if (item.name.ToLower().StartsWith(name.ToLower()))
|
||||||
|
found.Add(item);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
public static NPC GetNPCById(int id)
|
public static NPC GetNPCById(int id)
|
||||||
{
|
{
|
||||||
NPC npc = new NPC();
|
NPC npc = new NPC();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue