C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("TeleportManagerV2", "TuNombre", "1.0.0")]
[Description("Permite a los jugadores teletransportarse a múltiples ubicaciones con configuraciones personalizadas para grupos.")]
public class TeleportManagerV2 : RustPlugin
{
private PluginConfig config;
#region Configuration
private class TeleportLocation
{
[JsonProperty("Command")]
public string Command { get; set; }
[JsonProperty("Coordinates (x, y, z)")]
public List<float> Coordinates { get; set; }
[JsonProperty("Cooldown (seconds)")]
public int Cooldown { get; set; } = 60;
[JsonProperty("Countdown (seconds)")]
public int Countdown { get; set; } = 5;
[JsonProperty("Message")]
public string Message { get; set; } = "¡Bienvenido!";
}
private class GroupConfig
{
[JsonProperty("Teleport Locations")]
public List<TeleportLocation> TeleportLocations { get; set; } = new List<TeleportLocation>();
}
private class PluginConfig
{
[JsonProperty("Default Group")]
public GroupConfig DefaultGroup { get; set; } = new GroupConfig();
[JsonProperty("VIP Group")]
public GroupConfig VIPGroup { get; set; } = new GroupConfig();
}
protected override void LoadDefaultConfig()
{
config = new PluginConfig
{
DefaultGroup = new GroupConfig
{
TeleportLocations = new List<TeleportLocation>
{
new TeleportLocation
{
Command = "evento1",
Coordinates = new List<float> { 100, 50, 200 },
Cooldown = 120,
Countdown = 5,
Message = "¡Bienvenido al evento 1!"
},
new TeleportLocation
{
Command = "evento2",
Coordinates = new List<float> { 200, 75, 250 },
Cooldown = 150,
Countdown = 8,
Message = "¡Bienvenido al evento 2!"
},
new TeleportLocation
{
Command = "evento3",
Coordinates = new List<float> { 300, 100, 300 },
Cooldown = 180,
Countdown = 10,
Message = "¡Bienvenido al evento 3!"
}
}
},
VIPGroup = new GroupConfig
{
TeleportLocations = new List<TeleportLocation>
{
new TeleportLocation
{
Command = "evento1",
Coordinates = new List<float> { 150, 60, 220 },
Cooldown = 60,
Countdown = 5,
Message = "¡Bienvenido al evento 1 VIP!"
},
new TeleportLocation
{
Command = "evento2",
Coordinates = new List<float> { 250, 80, 270 },
Cooldown = 90,
Countdown = 8,
Message = "¡Bienvenido al evento 2 VIP!"
},
new TeleportLocation
{
Command = "evento3",
Coordinates = new List<float> { 350, 110, 320 },
Cooldown = 120,
Countdown = 10,
Message = "¡Bienvenido al evento 3 VIP!"
}
}
}
};
SaveConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
}
protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Commands
private void Init()
{
// Registrar permisos globales
RegisterPermission("teleportmanagerv2.default");
RegisterPermission("teleportmanagerv2.vip");
// Registrar comandos
RegisterCommands(config.DefaultGroup);
RegisterCommands(config.VIPGroup);
}
private void RegisterPermission(string permissionName)
{
if (!string.IsNullOrEmpty(permissionName) && !permission.PermissionExists(permissionName))
{
permission.RegisterPermission(permissionName, this);
}
}
private void RegisterCommands(GroupConfig groupConfig)
{
foreach (var location in groupConfig.TeleportLocations)
{
cmd.RemoveChatCommand(location.Command, this);
cmd.AddChatCommand(location.Command, this, nameof(HandleTeleportCommand));
}
}
private void HandleTeleportCommand(BasePlayer player, string command, string[] args)
{
// Determinar el grupo del jugador
GroupConfig groupConfig;
string groupPermission;
if (permission.UserHasPermission(player.UserIDString, "teleportmanagerv2.vip"))
{
groupConfig = config.VIPGroup;
groupPermission = "teleportmanagerv2.vip";
}
else if (permission.UserHasPermission(player.UserIDString, "teleportmanagerv2.default"))
{
groupConfig = config.DefaultGroup;
groupPermission = "teleportmanagerv2.default";
}
else
{
player.ChatMessage("No tienes permiso para usar este teletransporte.");
return;
}
// Verificar si la ubicación existe
var location = groupConfig.TeleportLocations.Find(loc => loc.Command.ToLower() == command.ToLower());
if (location == null)
{
player.ChatMessage($"El comando '{command}' no está configurado.");
return;
}
// Verificar cooldown
if (HasCooldown(player, command, location.Cooldown))
{
player.ChatMessage($"Debes esperar antes de usar este teletransporte nuevamente.");
return;
}
// Iniciar cuenta atrás
StartCountdown(player, location.Countdown, location);
SetCooldown(player, command);
}
#endregion
#region Helpers
private Dictionary<ulong, Dictionary<string, float>> cooldowns = new Dictionary<ulong, Dictionary<string, float>>();
private bool HasCooldown(BasePlayer player, string command, int cooldown)
{
if (!cooldowns.ContainsKey(player.userID)) cooldowns[player.userID] = new Dictionary<string, float>();
if (!cooldowns[player.userID].ContainsKey(command)) return false;
float remaining = cooldowns[player.userID][command] - UnityEngine.Time.realtimeSinceStartup;
return remaining > 0;
}
private void SetCooldown(BasePlayer player, string command)
{
if (!cooldowns.ContainsKey(player.userID)) cooldowns[player.userID] = new Dictionary<string, float>();
cooldowns[player.userID][command] = UnityEngine.Time.realtimeSinceStartup + config.DefaultGroup.TeleportLocations.Find(loc => loc.Command == command)?.Cooldown ?? 0;
}
#endregion
#region Teleportation and Countdown
private void StartCountdown(BasePlayer player, int seconds, TeleportLocation location)
{
timer.Once(1f, () =>
{
CuiHelper.DestroyUi(player, "CountdownPanel");
if (seconds <= 0)
{
TeleportPlayer(player, location);
}
else
{
ShowCountdownUI(player, seconds);
StartCountdown(player, seconds - 1, location);
}
});
}
private void ShowCountdownUI(BasePlayer player, int seconds)
{
CuiHelper.DestroyUi(player, "CountdownPanel");
var elements = new CuiElementContainer();
var panel = new CuiPanel
{
Image = { Color = "0.1 0.1 0.1 0.8" },
RectTransform = { AnchorMin = "0.85 0.4", AnchorMax = "0.98 0.5" },
CursorEnabled = false
};
elements.Add(panel, "Overlay", "CountdownPanel");
var label = new CuiLabel
{
Text = { Text = seconds.ToString(), FontSize = 24, Align = TextAnchor.MiddleCenter, Color = "0.8 0.9 1 1" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }
};
elements.Add(label, "CountdownPanel");
CuiHelper.AddUi(player, elements);
}
private void TeleportPlayer(BasePlayer player, TeleportLocation location)
{
var position = new Vector3(location.Coordinates[0], location.Coordinates[1], location.Coordinates[2]);
player.Teleport(position);
player.ChatMessage(location.Message);
}
#endregion
}
}