From 98f1af65fa282972b02f5f82edf416ab3a7978d3 Mon Sep 17 00:00:00 2001 From: k0rd Date: Thu, 12 Jun 2014 04:03:16 -0400 Subject: [PATCH] new command: /renamenpc Change a town NPC's name to anything you want! requires permission tshock.renamenpc requested by our friends from /tg/ --- TShockAPI/Commands.cs | 57 +++++++++++++++++++++++++++++++++++++++- TShockAPI/Permissions.cs | 3 +++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 33148d64..42a8342f 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -501,6 +501,10 @@ namespace TShockAPI { HelpText = "Kills another player." }); + add(new Command(Permissions.renamenpc, RenameNPC, "renamenpc") + { + HelpText = "Renames an NPC." + }); add(new Command(Permissions.cantalkinthird, ThirdPerson, "me") { HelpText = "Sends an action message to everyone." @@ -4496,7 +4500,58 @@ namespace TShockAPI args.Player.SendErrorMessage("Your inventory seems full."); } } - + + private static void RenameNPC(CommandArgs args) + { + if (args.Parameters.Count != 2) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /renameNPC "); + return; + } + int npcId = 0; + if (args.Parameters.Count == 2) + { + List npcs = TShock.Utils.GetNPCByIdOrName(args.Parameters[0]); + if (npcs.Count == 0) + { + args.Player.SendErrorMessage("Invalid mob type!"); + return; + } + else if (npcs.Count > 1) + { + TShock.Utils.SendMultipleMatchError(args.Player, npcs.Select(n => n.name)); + return; + } + else if (args.Parameters[1].Length >200) + { + args.Player.SendErrorMessage("New name is too large!"); + return; + } + else + { + npcId = npcs[0].netID; + } + } + int done=0; + for (int i = 0; i < Main.npc.Length; i++) + { + if (Main.npc[i].active && ((npcId == 0 && !Main.npc[i].townNPC) || (Main.npc[i].netID == npcId && Main.npc[i].townNPC))) + { + Main.npc[i].displayName= args.Parameters[1]; + NetMessage.SendData(56, -1, -1, args.Parameters[1], i, 0f, 0f, 0f, 0); + done++; + } + } + if (done >0 ) + { + TSPlayer.All.SendInfoMessage("{0} renamed the {1}.", args.Player.Name, args.Parameters[0]); + } + else + { + args.Player.SendErrorMessage("Could not rename {0}!", args.Parameters[0]); + } + } + private static void Give(CommandArgs args) { if (args.Parameters.Count < 2) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index b31c15d3..ee2a9cba 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -295,6 +295,9 @@ namespace TShockAPI [Description("User can kill others.")] public static readonly string kill = "tshock.kill"; + [Description("User can rename NPCs.")] + public static readonly string renamenpc = "tshock.renamenpc"; + [Description("Allows you to bypass the max slots for up to 5 slots above your max.")] public static readonly string reservedslot = "tshock.reservedslot";