using System;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("AutoTeleportPlugin", "YourName", "1.0.0")]
class AutoTeleportPlugin : RustPlugin
{
private DynamicConfigFile data;
private Timer teleportTimer;
private float teleportInterval = 300f; // Интервал телепортации в секундах
private Vector3 teleportPosition = new Vector3(0, 0, 0); // Начальные координаты для телепортации
private void Init()
{
data = Interface.Oxide.DataFileSystem.GetFile("AutoTeleportPluginData");
LoadDefaultConfig();
}
private void LoadDefaultConfig()
{
Config["TeleportInterval"] = teleportInterval;
Config["TeleportPosition"] = $"{teleportPosition.x},{teleportPosition.y},{teleportPosition.z}";
SaveConfig();
}
private void LoadConfigData()
{
teleportInterval = GetConfig("TeleportInterval", teleportInterval);
string[] position = GetConfig("TeleportPosition", $"{teleportPosition.x},{teleportPosition.y},{teleportPosition.z}").Split(',');
teleportPosition = new Vector3(float.Parse(position[0]), float.Parse(position[1]), float.Parse(position[2]));
}
private void OnServerInitialized()
{
LoadConfigData();
StartTeleportTimer();
}
private void StartTeleportTimer()
{
teleportTimer = timer.Every(teleportInterval, () =>
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
TeleportPlayer(player, teleportPosition);
}
});
}
private void TeleportPlayer(BasePlayer player, Vector3 position)
{
player.Teleport(position);
}
[ChatCommand("teleport")]
private void TeleportCommand(BasePlayer player, string command, string[] args)
{
if (args.Length < 3)
{
player.ChatMessage("Использование: /teleport X Y Z");
return;
}
float x, y, z;
if (!float.TryParse(args[0], out x) || !float.TryParse(args[1], out y) || !float.TryParse(args[2], out z))
{
player.ChatMessage("Неверные координаты. Используйте числа.");
return;
}
Vector3 teleportPosition = new Vector3(x, y, z);
TeleportPlayer(player, teleportPosition);
player.ChatMessage("Вы успешно телепортировались!");
}
}
}