diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index e7e777e0..f2970f9a 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -398,6 +398,11 @@ namespace TShockAPI AllowServer = false, HelpText = "Teleports a player to yourself." }); + add(new Command(Permissions.tpnpcs, TPNpc, "tpnpc") + { + AllowServer = false, + HelpText = "Teleports you to an npc" + }); add(new Command(Permissions.tppos, TPPos, "tppos") { AllowServer = false, @@ -2084,6 +2089,43 @@ namespace TShockAPI } } + private static void TPNpc(CommandArgs args) + { + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /tpnpc "); + return; + } + + var npcStr = string.Join(" ", args.Parameters); + var matches = new List(); + foreach (var npc in Main.npc.Where(npc => npc.active)) + { + if (string.Equals(npc.name, npcStr, StringComparison.CurrentCultureIgnoreCase)) + { + matches = new List { npc }; + break; + } + if (npc.name.ToLower().StartsWith(npcStr.ToLower())) + matches.Add(npc); + } + + if (matches.Count > 1) + { + TShock.Utils.SendMultipleMatchError(args.Player, matches.Select(n => n.name)); + return; + } + if (matches.Count == 0) + { + args.Player.SendErrorMessage("Invalid Npc!"); + return; + } + + var target = matches[0]; + args.Player.Teleport(target.position.X, target.position.Y); + args.Player.SendSuccessMessage("Teleported to the {0}", target.name); + } + private static void TPPos(CommandArgs args) { if (args.Parameters.Count != 2) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 2c024529..2809c84d 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -213,6 +213,9 @@ namespace TShockAPI [Description("User can teleport to tile positions.")] public static readonly string tppos = "tshock.tp.pos"; + [Description("User can teleport to npcs.")] + public static readonly string tpnpcs = "tshock.tp.npcs"; + [Description("Users can stop people from teleporting.")] public static readonly string tpallow = "tshock.tp.block";