From f98df0e4a30a90b62393374a874b034bb5d984ea Mon Sep 17 00:00:00 2001 From: Zoom L1 <46046453+AgaSpace@users.noreply.github.com> Date: Wed, 24 Nov 2021 13:52:47 +0700 Subject: [PATCH] Merge pull request #2447 from AgaSpace/patch-1 Add the ability to change the player's pvp mode --- TShockAPI/TSPlayer.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 7dfc377b..e6ceac32 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1562,6 +1562,18 @@ namespace TShockAPI Main.player[Index].team = team; NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, NetworkText.Empty, Index); } + + /// + /// Sets the player's pvp. + /// + /// The state of the pvp mode. + public virtual void SetPvP(bool mode, bool withMsg = false) + { + Main.player[Index].hostile = mode; + NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, NetworkText.Empty, Index); + if (withMsg) + TSPlayer.All.SendMessage(Language.GetTextValue(mode ? "LegacyMultiplayer.11" : "LegacyMultiplayer.12", Name), Main.teamColor[Team]); + } private DateTime LastDisableNotification = DateTime.UtcNow;