C#:
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
namespace Oxide.Plugins
{
[Info("Clans", "https://discord.gg/2JZjauTVAs", "0.0.1")]
[Description("New Clans System")]
class WClans : RustPlugin
{
#region data
private Dictionary<string, Clan> C = new Dictionary<string, Clan>();
private class Clan
{
public string ClanTag { get; set; }
public ulong LeaderID { get; set; }
public string LeaderName { get; set; }
public string Avatar { get; set; }
public Dictionary<string, ulong> Members { get; set; }
public DateTime CreationTime { get; set; }
public DateTime LastOnlineTime { get; set; }
}
#endregion
#region config
internal class ConfigData
{
public class TagOptions
{
[JsonProperty(PropertyName = "Tag character limits")]
public Range TagLength;
[JsonProperty(PropertyName = "Tag opening character")]
public string TagOpen;
[JsonProperty(PropertyName = "Tag closing character")]
public string TagClose;
[JsonProperty(PropertyName = "Tag color (hex)")]
public string TagColor;
}
public class Range
{
public int Minimum { get; set; }
public int Maximum { get; set; }
public Range() { }
public Range(int minimum, int maximum)
{
this.Minimum = minimum;
this.Maximum = maximum;
}
}
}
private class Configuration
{
[JsonProperty(PropertyName = "Wipe clans on new map save")]
public bool WipeOnNewSave;
[JsonProperty(PropertyName = "Member limit")]
public int MemberLimit;
[JsonProperty(PropertyName = "Clan Tag Options")]
public ConfigData.TagOptions Tags { get; set; }
public static Configuration Generate()
{
return new Configuration
{
WipeOnNewSave = false,
MemberLimit = 8,
Tags = new ConfigData.TagOptions
{
TagClose = "]",
TagColor = "#aaff55",
TagLength = new ConfigData.Range(2, 5),
TagOpen = "[",
}
};
}
}
private static Configuration Settings;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
}
catch
{
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
#endregion
[PluginReference] Plugin ImageLibrary;
private bool wipeData;
private void OnNewSave(string str) => wipeData = Settings.WipeOnNewSave;
void OnServerInitialized()
{
// ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/noti.png", "jh");
RelationshipManager.maxTeamSize = Settings.MemberLimit;
if (wipeData)
{
Puts("Clear Clan Data");
}
foreach (var str in BasePlayer.allPlayerList.ToList()) { OnTeamCreate(str); }
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "Creat");
}
}
void OnPlayerConnected(BasePlayer player)
{
}
object OnTeamCreate(BasePlayer player)
{
var container = new CuiElementContainer();
CuiHelper.DestroyUi(player, "Creat");
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = "0.2 0.3", AnchorMax = "0.8 0.7" },
Image =
{
Color = "0 0 0 0.7"
},
CursorEnabled = true
}, "Overlay", "Creat");
container.Add(new CuiElement
{
Parent = "Creat",
Components =
{
new CuiTextComponent {Text = $"CLAN CREATE", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleCenter, FontSize = 20, Font = "robotocondensed-regular.ttf"},
new CuiRectTransformComponent { AnchorMin = $"0 0.8", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0.90 0.66 0.64 1", Distance = "0.5 0.5" }
}
});
CuiHelper.AddUi(player, container);
Puts("OnTeamCreate works!");
return null;
}
void CreateNewClan(string clanTag, BasePlayer leader)
{
var clan = new Clan
{
ClanTag = clanTag,
LeaderID = leader.userID,
LeaderName = leader.displayName,
Avatar = "",
Members = new Dictionary<string, ulong>
{
{leader.displayName, leader.userID},
},
CreationTime = DateTime.Now,
LastOnlineTime = DateTime.Now,
};
}
object OnTeamAcceptInvite(RelationshipManager.PlayerTeam team, BasePlayer player)
{
Puts("OnTeamAcceptInvite works!");
return null;
}
object OnTeamKick(RelationshipManager.PlayerTeam team, BasePlayer player, ulong target)
{
Puts("OnTeamKick works!");
return null;
}
object OnTeamDisband(RelationshipManager.PlayerTeam team)
{
Puts("OnTeamDisband works!");
return null;
}
}
}