From 8ec358d99fde1f027c9f13355572834e709c625d Mon Sep 17 00:00:00 2001 From: Deathmax Date: Sun, 21 Aug 2011 12:15:15 +0800 Subject: [PATCH] Added /gbuff - buff other players --- TShockAPI/Commands.cs | 56 +++++++++++++++++++++++++++++++++++++--- TShockAPI/Permissions.cs | 5 +++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 17beedc8..d4b8fa26 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -182,6 +182,7 @@ namespace TShockAPI add(Permissions.item, Give, "give"); add(Permissions.heal, Heal, "heal"); add(Permissions.buff, Buff, "buff"); + add(Permissions.buffplayer, GBuff, "gbuff", "buffplayer"); } public static bool HandleCommand(TSPlayer player, string text) @@ -2409,7 +2410,7 @@ namespace TShockAPI { if (args.Parameters.Count < 1 || args.Parameters.Count > 2) { - args.Player.SendMessage("Invalid syntax! Proper syntax: /buff ", Color.Red); + args.Player.SendMessage("Invalid syntax! Proper syntax: /buff [time(seconds*60)]", Color.Red); return; } int id = 0; @@ -2433,14 +2434,63 @@ namespace TShockAPI } if (id > 0 && id < Main.maxBuffs) { - //args.TPlayer.AddBuff(id, 60); args.Player.SetBuff(id, time); args.Player.SendMessage(string.Format("You have buffed yourself with {0}({1}) for {2} seconds!", - Tools.GetBuffName(id), Tools.GetBuffDescription(id), Math.Round(((decimal)time / 60), 2)), Color.Green); + Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time / 60)), Color.Green); } else args.Player.SendMessage("Invalid buff ID!", Color.Red); } + + private static void GBuff(CommandArgs args) + { + if (args.Parameters.Count < 2 || args.Parameters.Count > 3) + { + args.Player.SendMessage("Invalid syntax! Proper syntax: /gbuff [time(seconds*60)]", Color.Red); + return; + } + int id = 0; + int time = 3600; + var foundplr = Tools.FindPlayer(args.Parameters[0]); + if (foundplr.Count == 0) + { + args.Player.SendMessage("Invalid player!", Color.Red); + return; + } + else if (foundplr.Count > 1) + { + args.Player.SendMessage(string.Format("More than one ({0}) player matched!", args.Parameters.Count), Color.Red); + return; + } + else + { + if (!int.TryParse(args.Parameters[1], out id)) + { + var found = Tools.GetBuffByName(args.Parameters[0]); + if (found.Count == 0) + { + args.Player.SendMessage("Invalid buff name!", Color.Red); + return; + } + else if (found.Count > 1) + { + args.Player.SendMessage(string.Format("More than one ({0}) buff matched!", found.Count), Color.Red); + return; + } + id = found[0]; + if (args.Parameters.Count == 3) + int.TryParse(args.Parameters[2], out time); + } + if (id > 0 && id < Main.maxBuffs) + { + args.Player.SetBuff(id, time); + args.Player.SendMessage(string.Format("You have buffed yourself with {0}({1}) for {2} seconds!", + Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time / 60)), Color.Green); + } + else + args.Player.SendMessage("Invalid buff ID!", Color.Red); + } + } #endregion Cheat Comamnds } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index f8744206..de55ebc6 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -126,9 +126,12 @@ namespace TShockAPI [Description("")] public static readonly string heal; - [Description("User can buff players")] + [Description("User can buff self")] public static readonly string buff; + [Description("User can buff other players")] + public static readonly string buffplayer; + static Permissions() { foreach (var field in typeof(Permissions).GetFields())