add example for /heal and custom heal amount

code is mostly based from /slap, now users will be able to heal a target player by a custom HP amount. I deliberately changed the static 600 HP amount to statLifeMax2 so it would use whatever max HP the target player has, this should make it work better w/ plugins that allow you to set your max HP beyond the base game's 600.
This commit is contained in:
stacey 2021-08-07 09:50:29 -04:00
parent 4c217bac65
commit 72dab02a61

View file

@ -6121,45 +6121,51 @@ namespace TShockAPI
private static void Heal(CommandArgs args) private static void Heal(CommandArgs args)
{ {
TSPlayer playerToHeal; // heal <player> [amount]
if (args.Parameters.Count > 0) // To-Do: break up heal self and heal other into two separate permissions
var user = args.Player;
if (args.Parameters.Count < 1 || args.Parameters.Count > 2)
{ {
string plStr = String.Join(" ", args.Parameters); user.SendMessage("Heal Syntax and Example", Color.White);
var players = TSPlayer.FindByNameOrID(plStr); user.SendMessage($"{"heal".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> [{"amount".Color(Utils.GreenHighlight)}]", Color.White);
if (players.Count == 0) user.SendMessage($"Example usage: {"heal".Color(Utils.BoldHighlight)} {user.Name.Color(Utils.RedHighlight)} {"100".Color(Utils.GreenHighlight)}", Color.White);
{ user.SendMessage($"If no amount is specified, it will default to healing the target player by their max HP.", Color.White);
args.Player.SendErrorMessage("Invalid player!"); user.SendMessage($"To execute this command silently, use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)}", Color.White);
return; return;
} }
else if (players.Count > 1) if (args.Parameters[0].Length == 0)
{ {
args.Player.SendMultipleMatchError(players.Select(p => p.Name)); user.SendErrorMessage($"You didn't put a player name.");
return; return;
} }
else
{
playerToHeal = players[0];
}
}
else if (!args.Player.RealPlayer)
{
args.Player.SendErrorMessage("You can't heal yourself!");
return;
}
else
{
playerToHeal = args.Player;
}
playerToHeal.Heal(); string targetName = args.Parameters[0];
if (playerToHeal == args.Player) var players = TSPlayer.FindByNameOrID(targetName);
{ if (players.Count == 0)
args.Player.SendSuccessMessage("You just got healed!"); user.SendErrorMessage($"Unable to find any players named \"{targetName}\"");
} else if (players.Count > 1)
user.SendMultipleMatchError(players.Select(p => p.Name));
else else
{ {
args.Player.SendSuccessMessage(string.Format("You just healed {0}", playerToHeal.Name)); var target = players[0];
playerToHeal.SendSuccessMessage(string.Format("{0} just healed you!", args.Player.Name)); int amount = target.TPlayer.statLifeMax2;
if (target.Dead)
{
user.SendErrorMessage("You can't heal a dead player!");
return;
}
if (args.Parameters.Count == 2)
{
int.TryParse(args.Parameters[1], out amount);
}
target.Heal(amount);
if (args.Silent)
user.SendSuccessMessage($"You healed {(target == user ? "yourself" : target.Name)} for {amount} HP.");
else
TSPlayer.All.SendInfoMessage($"{user.Name} healed {(target == user ? (target.TPlayer.Male ? "himself" : "herself") : target.Name)} for {amount} HP.");
} }
} }