C#:
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Core;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Oxide.Plugins
{
[Info("Announcement", "Cengizhanbucak", "1.0.5")]
class Announcement : RustPlugin
{
private string tagColor;
private int tagSize;
private string tagPrefix;
private string messageColor;
private ulong chatIcon;
private const string PERMISSION_ANNOUNCE = "announcement.announce";
private bool otomatikDuyuruEtkin;
private List<Dictionary<string, object>> otomatikDuyuruMetinleri;
private float otomatikDuyuruGecikme;
protected override void LoadDefaultConfig()
{
Puts("Creating a new config file.");
Config["tagPrefix"] = "Announcement";
Config["tagColor"] = "#43ACFF";
Config["tagSize"] = 15;
Config["messageColor"] = "white";
Config["chatIcon"] = 0UL; // Chat icon (SteamID64)
Config["AutoAnnouncementEnabled"] = false;
Config["AutoAnnouncementDelay"] = 60f;
Config["AutoAnnouncementTexts"] = new List<object>
{
new Dictionary<string, object>
{
{ "autoMessage", "Players playing on the server: {playerstats}" },
{ "Tip", "chat" }
},
new Dictionary<string, object>
{
{ "autoMessage", "Players playing on the server: {playerstats}" },
{ "Tip", "gui" },
{ "visibilityTime", 10.0 }
}
};
SaveConfig();
}
void Init()
{
LoadDefaultMessages();
tagColor = Config["tagColor"].ToString();
tagPrefix = Config["tagPrefix"].ToString();
tagSize = int.Parse(Config["tagSize"].ToString());
messageColor = Config["messageColor"].ToString();
chatIcon = ulong.Parse(Config["chatIcon"].ToString());
permission.RegisterPermission(PERMISSION_ANNOUNCE, this);
otomatikDuyuruEtkin = bool.Parse(Config["AutoAnnouncementEnabled"].ToString());
otomatikDuyuruGecikme = float.Parse(Config["AutoAnnouncementDelay"].ToString());
var duyuruMetinleri = Config["AutoAnnouncementTexts"] as List<object>;
if (duyuruMetinleri != null)
{
otomatikDuyuruMetinleri = duyuruMetinleri.ConvertAll(x => x as Dictionary<string, object>);
}
else
{
Puts("Yapılandırma dosyasındaki 'AutoAnnouncementTexts' değeri okunamadı. Lütfen yapılandırma dosyasını kontrol edin.");
return;
}
timer.In(10f, OtomatikDuyuruYayinla); // Örenek olarak her 60 saniyede bir otomatik duyuru yayınlayacak
}
private int otomatikDuyuruIndex = 0;
private void OtomatikDuyuruYayinla()
{
if (otomatikDuyuruEtkin)
{
if (otomatikDuyuruMetinleri == null || otomatikDuyuruMetinleri.Count == 0)
{
Puts("Otomatik duyuru metinleri bulunamadı. Lütfen yapılandırma dosyasını kontrol edin.");
return;
}
var duyuru = otomatikDuyuruMetinleri[otomatikDuyuruIndex];
otomatikDuyuruIndex = (otomatikDuyuruIndex + 1) % otomatikDuyuruMetinleri.Count;
if (!duyuru.ContainsKey("autoMessage") || !duyuru.ContainsKey("Tip"))
{
Puts("Bir duyuru metni veya tipi eksik. Lütfen yapılandırma dosyasını kontrol edin.");
return;
}
string metin = duyuru["autoMessage"].ToString();
string tip = duyuru["Tip"].ToString();
// Anlık oyuncu sayısını al ve metindeki {OyuncuSayisi} ifadesini bu değerle değiştir
int oyuncuSayisi = BasePlayer.activePlayerList.Count;
metin = metin.Replace("{playerstats}", oyuncuSayisi.ToString());
string renkliMetin = $"<size={tagSize}><color={tagColor}>{tagPrefix}</color>:</size>" + $" <color={messageColor}>" + metin + "</color>";
if (tip == "chat")
{
Server.Broadcast(renkliMetin, null, chatIcon);
}
else if (tip == "gui")
{
if (!duyuru.ContainsKey("visibilityTime"))
{
Puts("Bir GUI duyurusu için süre eksik. Lütfen yapılandırma dosyasını kontrol edin.");
return;
}
float gösterimSüresi = float.Parse(duyuru["visibilityTime"].ToString());
foreach (BasePlayer oyuncu in BasePlayer.activePlayerList)
{
ShowAnnouncement(oyuncu, renkliMetin, gösterimSüresi);
}
}
else
{
Puts("Geçersiz duyuru tipi. Lütfen yapılandırma dosyasını kontrol edin.");
}
}
timer.In(otomatikDuyuruGecikme, OtomatikDuyuruYayinla);
}
[ChatCommand("ann")]
private void RenkliYaz(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, PERMISSION_ANNOUNCE))
{
SendReply(player, lang.GetMessage("NoPermission", this, player.UserIDString));
return;
}
if (args.Length < 2)
{
SendReply(player, lang.GetMessage("InvalidArgs", this, player.UserIDString));
return;
}
string displayType = args[args.Length - 1].ToLower();
string message;
if (displayType == "gui")
{
message = string.Join(" ", args, 0, args.Length - 2);
}
else
{
message = string.Join(" ", args, 0, args.Length - 1);
}
string coloredMessage = $"<size={tagSize}><color={tagColor}>{tagPrefix}</color>:</size>" + $" <color={messageColor}>" + message + "</color>";
if (displayType == "chat")
{
Server.Broadcast(coloredMessage, null, chatIcon);
}
else if (displayType == "gui")
{
if (args.Length < 3)
{
SendReply(player, lang.GetMessage("InvalidTime", this, player.UserIDString));
return;
}
float displayTime;
if (!float.TryParse(args[args.Length - 2], out displayTime))
{
SendReply(player, lang.GetMessage("InvalidDisplayType", this, player.UserIDString));
return;
}
foreach (BasePlayer p in BasePlayer.activePlayerList)
{
ShowAnnouncement(p, coloredMessage, displayTime);
}
}
else
{
SendReply(player, lang.GetMessage("InvalidDisplayType", this, player.UserIDString));
}
}
private void ShowAnnouncement(BasePlayer player, string message, float displayTime)
{
var elements = new CuiElementContainer();
// Arka plan kutusu
string backgroundPanel = elements.Add(new CuiPanel
{
Image = { Color = "1 1 1 0.2" },
RectTransform = { AnchorMin = "0.3555 0.121", AnchorMax = "0.630 0.171" },
CursorEnabled = false
});
// Mesaj metni
elements.Add(new CuiLabel
{
Text = { Text = message, FontSize = 14, Align = TextAnchor.MiddleCenter },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }
}, backgroundPanel);
CuiHelper.AddUi(player, elements);
timer.Once(displayTime, () =>
{
CuiHelper.DestroyUi(player, backgroundPanel);
});
}
}
}