Change the way that forced PvP works
This commit is contained in:
parent
8b7e8772da
commit
02820c0172
3 changed files with 30 additions and 50 deletions
|
|
@ -2134,37 +2134,17 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (id != args.Player.Index)
|
if (id != args.Player.Index)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
string pvpMode = TShock.Config.PvPMode.ToLowerInvariant();
|
||||||
|
if (pvpMode == "disabled" || pvpMode == "always" || (DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5)
|
||||||
{
|
{
|
||||||
|
args.Player.SendData(PacketTypes.TogglePvp, "", id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TShock.Config.PvPMode == "disabled")
|
args.Player.LastPvPTeamChange = DateTime.UtcNow;
|
||||||
{
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.TPlayer.hostile != pvp)
|
|
||||||
{
|
|
||||||
long seconds = (long) (DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
|
|
||||||
if (seconds > 5)
|
|
||||||
{
|
|
||||||
TSPlayer.All.SendMessage(string.Format("{0} has {1} PvP!", args.Player.Name, pvp ? "enabled" : "disabled"),
|
|
||||||
Main.teamColor[args.Player.Team]);
|
|
||||||
}
|
|
||||||
args.Player.LastPvpChange = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
args.TPlayer.hostile = pvp;
|
|
||||||
|
|
||||||
if (TShock.Config.PvPMode == "always")
|
|
||||||
{
|
|
||||||
if (!pvp)
|
|
||||||
args.Player.Spawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
NetMessage.SendData((int) PacketTypes.TogglePvp, -1, -1, "", args.Player.Index);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
|
private static bool HandlePlayerTeam(GetDataHandlerArgs args)
|
||||||
|
|
@ -2175,15 +2155,16 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (id != args.Player.Index)
|
if (id != args.Player.Index)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
args.TPlayer.team = team;
|
if ((DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5)
|
||||||
|
{
|
||||||
|
args.Player.SendData(PacketTypes.PlayerTeam, "", id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
NetMessage.SendData((int)PacketTypes.PlayerTeam, -1, -1, "", args.Player.Index);
|
args.Player.LastPvPTeamChange = DateTime.UtcNow;
|
||||||
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
|
private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
|
||||||
|
|
@ -2244,11 +2225,6 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red);
|
args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (TShock.Config.PvPMode == "always" && !args.TPlayer.hostile)
|
|
||||||
{
|
|
||||||
args.Player.SendMessage("PvP is forced! Enable PvP or else you can't do anything!",
|
|
||||||
Color.Red);
|
|
||||||
}
|
|
||||||
var lastTileX = args.Player.LastNetPosition.X;
|
var lastTileX = args.Player.LastNetPosition.X;
|
||||||
var lastTileY = args.Player.LastNetPosition.Y - 48;
|
var lastTileY = args.Player.LastNetPosition.Y - 48;
|
||||||
if (!args.Player.Teleport(lastTileX, lastTileY))
|
if (!args.Player.Teleport(lastTileX, lastTileY))
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ namespace TShockAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The last time the player changed their team or pvp status.
|
/// The last time the player changed their team or pvp status.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime LastPvpChange;
|
public DateTime LastPvPTeamChange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Temp points for use in regions and other plugins.
|
/// Temp points for use in regions and other plugins.
|
||||||
|
|
|
||||||
|
|
@ -1183,13 +1183,17 @@ namespace TShockAPI
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.LoginMS= DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
|
||||||
|
player.LoginMS = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
||||||
|
|
||||||
Utils.ShowFileToUser(player, "motd.txt");
|
Utils.ShowFileToUser(player, "motd.txt");
|
||||||
|
|
||||||
if (Config.PvPMode == "always" && !player.TPlayer.hostile)
|
string pvpMode = Config.PvPMode.ToLowerInvariant();
|
||||||
|
if (pvpMode == "always")
|
||||||
{
|
{
|
||||||
player.SendMessage("PvP is forced! Enable PvP else you can't do anything!", Color.Red);
|
player.TPlayer.hostile = true;
|
||||||
|
player.SendData(PacketTypes.TogglePvp, "", player.Index);
|
||||||
|
TSPlayer.All.SendData(PacketTypes.TogglePvp, "", player.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.IsLoggedIn)
|
if (!player.IsLoggedIn)
|
||||||
|
|
@ -1199,7 +1203,7 @@ namespace TShockAPI
|
||||||
player.SendMessage(
|
player.SendMessage(
|
||||||
player.IgnoreActionsForInventory = "Server side characters is enabled! Please /register or /login to play!",
|
player.IgnoreActionsForInventory = "Server side characters is enabled! Please /register or /login to play!",
|
||||||
Color.Red);
|
Color.Red);
|
||||||
player.LoginHarassed = true;
|
player.LoginHarassed = true;
|
||||||
}
|
}
|
||||||
else if (Config.RequireLogin)
|
else if (Config.RequireLogin)
|
||||||
{
|
{
|
||||||
|
|
@ -1208,14 +1212,14 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.LastNetPosition = new Vector2(Main.spawnTileX*16f, Main.spawnTileY*16f);
|
player.LastNetPosition = new Vector2(Main.spawnTileX * 16f, Main.spawnTileY * 16f);
|
||||||
|
|
||||||
if (Config.RememberLeavePos && (RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero) && !player.LoginHarassed)
|
if (Config.RememberLeavePos && (RememberedPos.GetLeavePos(player.Name, player.IP) != Vector2.Zero) && !player.LoginHarassed)
|
||||||
{
|
{
|
||||||
player.RPPending=3;
|
player.RPPending = 3;
|
||||||
player.SendMessage("You will be teleported to your last known location...", Color.Red);
|
player.SendMessage("You will be teleported to your last known location...", Color.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1739,7 +1743,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static bool CheckIgnores(TSPlayer player)
|
public static bool CheckIgnores(TSPlayer player)
|
||||||
{
|
{
|
||||||
return Config.PvPMode == "always" && !player.TPlayer.hostile || player.IgnoreActionsForInventory != "none" || player.IgnoreActionsForCheating != "none" || player.IgnoreActionsForDisabledArmor != "none" || player.IgnoreActionsForClearingTrashCan || !player.IsLoggedIn && Config.RequireLogin;;
|
return player.IgnoreActionsForInventory != "none" || player.IgnoreActionsForCheating != "none" || player.IgnoreActionsForDisabledArmor != "none" || player.IgnoreActionsForClearingTrashCan || !player.IsLoggedIn && Config.RequireLogin;;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnConfigRead(ConfigFile file)
|
public void OnConfigRead(ConfigFile file)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue