Merge pull request #822 from WhiteXZ/general-devel
Add /tpnpc to allow teleportation to active npcs
This commit is contained in:
commit
4ce305b91d
2 changed files with 45 additions and 0 deletions
|
|
@ -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 <npc>");
|
||||
return;
|
||||
}
|
||||
|
||||
var npcStr = string.Join(" ", args.Parameters);
|
||||
var matches = new List<NPC>();
|
||||
foreach (var npc in Main.npc.Where(npc => npc.active))
|
||||
{
|
||||
if (string.Equals(npc.name, npcStr, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
matches = new List<NPC> { 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)
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue