C#:
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("AutoChatMessage", "Kalvi", "1.0.0")]
[Description("Sends messages to the chat at specified intervals with color, size, underline, and italic support.")]
public class AutoChatMessage : CovalencePlugin
{
private ConfigData config;
private class ConfigData
{
public int Interval { get; set; }
public List<string> Messages { get; set; }
public bool RandomMessage { get; set; }
}
protected override void LoadDefaultConfig()
{
ConfigData defaultConfig = new ConfigData
{
Interval = 60, // Default interval in seconds
Messages = new List<string>
{
"<size=14><#03FCE7><u>Hello, player!</u></color> <#FCF403>Welcome to the server!</color></size>",
"<size=14><#FCB103>Plugin By:</color></size>/n<size=10><#FCF403><u>Kalvi</u></color></size>",
"<size=14><#A1FC03><i>Thank you for downloading the plugin</i></color></size>"
},
RandomMessage = false
};
Config.WriteObject(defaultConfig, true);
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<ConfigData>();
}
private void Init()
{
permission.RegisterPermission("AutoChatMessage.Admin", this);
AddCovalenceCommand("acm.reload", "CmdReload");
}
private void CmdReload(IPlayer player, string command, string[] args)
{
if (!player.HasPermission("AutoChatMessage.Admin"))
{
player.Reply("You do not have permission to use this command.");
return;
}
LoadConfig();
player.Reply("AutoChatMessage configuration reloaded.");
}
private void OnServerInitialized()
{
timer.Repeat(config.Interval, 0, () =>
{
string message = GetNextMessage();
string formattedMessage = message.Replace("/n", "\n");
server.Broadcast(formattedMessage);
});
}
private string GetNextMessage()
{
if (config.RandomMessage)
{
int randomIndex = UnityEngine.Random.Range(0, config.Messages.Count);
return config.Messages[randomIndex];
}
else
{
string message = config.Messages[0];
config.Messages.RemoveAt(0);
config.Messages.Add(message);
return message;
}
}
}
}