Moved Teleport to TSPlayer and added Spawn
Warn player teleport is not possible if custom spawn point is set. /home now take you to spawnpoint (custom if set else main spawn point)
This commit is contained in:
parent
2d9ccb3738
commit
aa9d627f69
3 changed files with 42 additions and 31 deletions
|
|
@ -654,16 +654,16 @@ namespace TShockAPI
|
||||||
|
|
||||||
private static void Home(CommandArgs args)
|
private static void Home(CommandArgs args)
|
||||||
{
|
{
|
||||||
TShock.Teleport(args.Player.Index, args.TPlayer.SpawnX * 16 + 8 - args.TPlayer.width / 2,
|
args.Player.Spawn();
|
||||||
args.TPlayer.SpawnY * 16 - args.TPlayer.height);
|
|
||||||
args.Player.SendMessage("Teleported to your spawnpoint.");
|
args.Player.SendMessage("Teleported to your spawnpoint.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Spawn(CommandArgs args)
|
private static void Spawn(CommandArgs args)
|
||||||
{
|
{
|
||||||
TShock.Teleport(args.Player.Index, Main.spawnTileX * 16 + 8 - args.TPlayer.width / 2,
|
if (args.Player.Teleport(Main.spawnTileX, Main.spawnTileY))
|
||||||
Main.spawnTileY * 16 - args.TPlayer.height);
|
|
||||||
args.Player.SendMessage("Teleported to the map's spawnpoint.");
|
args.Player.SendMessage("Teleported to the map's spawnpoint.");
|
||||||
|
else
|
||||||
|
args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TP(CommandArgs args)
|
private static void TP(CommandArgs args)
|
||||||
|
|
@ -683,8 +683,10 @@ namespace TShockAPI
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = players[0];
|
var plr = players[0];
|
||||||
TShock.Teleport(args.Player.Index, plr.X, plr.Y);
|
if (args.Player.Teleport(plr.TileX, plr.TileY))
|
||||||
args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name));
|
args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name));
|
||||||
|
else
|
||||||
|
args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -709,10 +711,15 @@ namespace TShockAPI
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = players[0];
|
var plr = players[0];
|
||||||
TShock.Teleport(plr.Index, args.Player.X, args.Player.Y);
|
if (plr.Teleport(args.Player.TileX, args.Player.TileY))
|
||||||
|
{
|
||||||
plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name));
|
plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name));
|
||||||
args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name));
|
args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
args.Player.SendMessage("Can't teleport because target player has set custom spawnpoint.", Color.Red);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Teleport Commands
|
#endregion Teleport Commands
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,31 @@ namespace TShockAPI
|
||||||
NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f);
|
NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Teleport(int tileX, int tileY)
|
||||||
|
{
|
||||||
|
if (TPlayer.SpawnX >= 0 && TPlayer.SpawnY >= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int oldSpawnX = Main.spawnTileX;
|
||||||
|
int oldSpawnY = Main.spawnTileY;
|
||||||
|
Main.spawnTileX = tileX;
|
||||||
|
Main.spawnTileY = tileY;
|
||||||
|
//Send only that player the new spawn point data
|
||||||
|
NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f);
|
||||||
|
//Force them to respawn
|
||||||
|
Spawn();
|
||||||
|
//Reset to old spawnpoint and send spawn data back to player
|
||||||
|
Main.spawnTileX = (int)oldSpawnX;
|
||||||
|
Main.spawnTileY = (int)oldSpawnY;
|
||||||
|
NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Spawn()
|
||||||
|
{
|
||||||
|
NetMessage.SendData((int)PacketTypes.PlayerSpawn, Index, -1, "", Index, 0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SendTileSquare(int x, int y, int size = 10)
|
public virtual void SendTileSquare(int x, int y, int size = 10)
|
||||||
{
|
{
|
||||||
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
||||||
|
|
|
||||||
|
|
@ -417,27 +417,6 @@ namespace TShockAPI
|
||||||
* Useful stuff:
|
* Useful stuff:
|
||||||
* */
|
* */
|
||||||
|
|
||||||
public static void Teleport(int ply, int x, int y)
|
|
||||||
{
|
|
||||||
int oldSpawnX = Main.spawnTileX;
|
|
||||||
int oldSpawnY = Main.spawnTileY;
|
|
||||||
Main.spawnTileX = x/16;
|
|
||||||
Main.spawnTileY = y/16;
|
|
||||||
//Send only that player the new spawn point data
|
|
||||||
NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f);
|
|
||||||
//Force them to respawn
|
|
||||||
NetMessage.SendData(12, ply, -1, "", ply, 0.0f, 0.0f, 0.0f);
|
|
||||||
//Reset to old spawnpoint and send spawn data back to player
|
|
||||||
Main.spawnTileX = (int)oldSpawnX;
|
|
||||||
Main.spawnTileY = (int)oldSpawnY;
|
|
||||||
NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Teleport(int ply, float x, float y)
|
|
||||||
{
|
|
||||||
Teleport(ply, (int)x, (int)y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void StartInvasion()
|
public static void StartInvasion()
|
||||||
{
|
{
|
||||||
Main.invasionType = 1;
|
Main.invasionType = 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue