Esempio n. 1
0
        public static void RandomTeleport(IServerPlayer player, int range = -1)
        {
            try
            {
                ICoreServerAPI api = player.Entity.Api as ICoreServerAPI;

                int x, y, z;
                if (range != -1)
                {
                    x = api.World.Rand.Next(range * 2) - range + player.Entity.Pos.XYZInt.X;
                    z = api.World.Rand.Next(range * 2) - range + player.Entity.Pos.XYZInt.Z;
                }
                else
                {
                    x = api.World.Rand.Next(api.WorldManager.MapSizeX);
                    z = api.World.Rand.Next(api.WorldManager.MapSizeZ);
                }

                //y = (api.WorldManager.GetSurfacePosY(x, z) ?? api.WorldManager.MapSizeY);
                //y += 2;

                y = api.WorldManager.MapSizeY;

                player.SendMessageAsClient("/tp =" + x + " " + y + " =" + z);
                player.Entity.PositionBeforeFalling = new Vec3d(x, 0, z);
            }
            catch (Exception e)
            {
                player?.Entity?.Api?.Logger?.ModError("Failed to teleport player to random location.");
                player?.Entity?.Api?.Logger?.ModError(e.Message);
            }
        }