From b031a995fd59a4fb3773d8a8ba8ebe0ae0f36da5 Mon Sep 17 00:00:00 2001 From: Deathmax Date: Wed, 1 Jun 2011 16:46:09 +0800 Subject: [PATCH] Added /item. --- TShockAPI/TShock.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index bbb5b350..6d6c453a 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -76,8 +76,8 @@ namespace TShockAPI NpcHooks.OnStrikeNpc -= new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc); } - /* - * Hooks: + /* + * Hooks: * */ void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e) @@ -317,6 +317,25 @@ namespace TShockAPI } } } + //ATM it just drops the item. Trying to find out can I update the player's inventory directly. + if (msg.StartsWith("/item") && msg.Split(' ').Length == 2) + { + var args = msg.Split(' ')[1]; + int type = 0; + if (int.TryParse(args, out type)) + { + if (type >= 1 && type <= 235) + { + int id = Item.NewItem(0, 0, 0, 0, type, 1, true); + Main.item[id].position.X = (float)x; + Main.item[id].position.Y = (float)y; + Main.item[id].stack = Main.item[id].maxStack; + NetMessage.SendData(21, -1, -1, "", id, 0f, 0f, 0f); + Tools.SendMessage(ply, "Spawned " + Main.item[id].name + "."); + handler.Handled = true; + } + } + } } if (msg == "/help") { @@ -378,8 +397,8 @@ namespace TShockAPI } } - /* - * Useful stuff: + /* + * Useful stuff: * */ public static void ShowUpdateReminder(int ply)