I have coded a plugin specialized for my server but despite a total lack of (compiler-)errors it is not working and I have absolutely no idea why and sadly not even any indications.
(Because I have no clue what nor where the problem is I have to put the hole code in here but I insist that this is not an illegitimate plugin release because this plugin is specialized for something we want to do on our server. Maybe I will modify it later so make it more universally usable but at this point it is solely made for our server so it has little use for anyone else.)
I hope that someone that knows more about coding plugins with Oxide can find the problem and tell me how to solve it.
Thanks in advance.
(Because I have no clue what nor where the problem is I have to put the hole code in here but I insist that this is not an illegitimate plugin release because this plugin is specialized for something we want to do on our server. Maybe I will modify it later so make it more universally usable but at this point it is solely made for our server so it has little use for anyone else.)
I hope that someone that knows more about coding plugins with Oxide can find the problem and tell me how to solve it.
using System.Collections.Generic;
using CodeHatch.Common;
using CodeHatch.Engine.Core.Consoles;
using CodeHatch.Engine.Modules.SocialSystem;
using CodeHatch.Engine.Networking;
using CodeHatch.Networking.Events.Entities;
using CodeHatch.Thrones.SocialSystem;
using CodeHatch.UserInterface.Dialogues;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("Kingdoms", "GPU", "0.0.1")]
public class Kingdoms : ReignOfKingsPlugin
{
static List<Player> AClaims = new List<Player>();
static List<Player> BClaims = new List<Player>();
static List<Player> CClaims = new List<Player>();
static List<Player> DClaims = new List<Player>();
static List<Player> EClaims = new List<Player>();
static List<Player> FClaims = new List<Player>();
static bool AFirstClaim = true;
static bool BFirstClaim = true;
static bool CFirstClaim = true;
static bool DFirstClaim = true;
static bool EFirstClaim = true;
static bool FFirstClaim = true;
#region Inherited Classes
private class Kingdom
{
public string Name { get; set; }
public ulong Ruler { get; set; }
public double Taxrate { get; set; }
public List<uint> MemberGuildsCrests { get; set; }
public Kingdom() { }
public Kingdom(string name, ulong ruler, double taxrate, List<uint> memberGuildsCrests)
{
Name = name;
Ruler = ruler;
Taxrate = taxrate;
MemberGuildsCrests = memberGuildsCrests;
}
}
/*
private class PlayerData
{
public string Id;
public string Name;
public Dictionary<string, int> Tax;
public PlayerData()
{
}
public PlayerData(Player player)
{
Id = player.Id.ToString();
Name = player.DisplayName;
Tax = new Dictionary<string, int>();
}
}
*/
#endregion
static List<Kingdom> KingdomsList = new List<Kingdom>();
//static Dictionary<Player, PlayerData> PlayersDataList = new Dictionary<Player, PlayerData>();
#region List loading and saving
void Loaded()
{
LoadLists();
}
void Unload()
{
SaveLists();
}
void OnServerSave()
{
SaveLists();
}
void OnServerShutdown()
{
SaveLists();
}
void LoadLists()
{
KingdomsList = Interface.GetMod().DataFileSystem.ReadObject<List<Kingdom>>("KingdomsList");
//PlayersDataList = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<Player, PlayerData>>("PlayersDataList");
}
void SaveLists()
{
Interface.GetMod().DataFileSystem.WriteObject("KingdomsList", KingdomsList);
//Interface.GetMod().DataFileSystem.WriteObject("PlayersDataList", PlayersDataList);
}
#endregion
#region Commands
[ChatCommand("kingdoms")]
void ShowKingdoms(Player player)
{
LoadLists();
string ShowKingdomsList = "";
for (int i = 0; i <= 5; i++)
{
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom A"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[000000]A[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" +"\n";
}
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom B"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FF0000]B[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
}
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom C"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FFFF00]C[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
}
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom D"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[0000FF]D[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
}
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom E"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FF00FF]E[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
}
if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom F"))
{
ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[00FF00]F[FFFFFF]]:" + "\n";
ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
}
List<string> KingdomMemberGuildnames = new List<string>();
for (int ii = 0; ii < KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Count; ii++)
{
uint crestId = KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.GetAt<uint>(ii);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (!KingdomMemberGuildnames.Contains(" ∙ " + crestGuildname))
{
KingdomMemberGuildnames.Add(" ∙ " + crestGuildname);
}
}
ShowKingdomsList = ShowKingdomsList + KingdomMemberGuildnames.JoinToString("\n") + "\n";
}
player.ShowPopup("Kingdoms:", ShowKingdomsList);
}
[ChatCommand("crests")]
void GetAllCrests(Player player, string command, string[] args)
{
if (!player.HasPermission("admin"))
{
return;
}
string unknownCrests = "";
foreach (Player p in Server.AllPlayers)
{
Crest crest = SocialAPI.Get<CrestScheme>().GetCrest(p.Id);
if (crest != null)
{
for (int i = 0; i <= 5; i++)
{
if (!KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Contains(crest.ObjectGUID))
{
unknownCrests = unknownCrests + "∙ " + crest.GuildName + "'s Crest [" + crest.ObjectGUID.ToString() + "] at " + crest.Position.ToString() + "\n";
}
}
}
}
player.ShowPopup("Unknown Crests:", unknownCrests);
SendReply(player, "Unknown Crests:" + "\n" + unknownCrests);
}
[ChatCommand("initialize")]
void GetCrest(Player player, string command, string[] args)
{
if (!player.HasPermission("admin"))
{
return;
}
Options selection1 = new Options();
if (KingdomsList.Count != 0)
{
player.ShowConfirmPopup("WARNING: Reinitializing Kingdoms?", "You are about to reinitialize the Kingdoms. \n All Data will be lost. \n\n Do you want to precede?", "Confirm", "Cancel", (selection, dialogue, contextData) => selection1 = selection);
}
if (selection1 == Options.Cancel)
{
return;
}
Kingdom A = new Kingdom();
Kingdom B = new Kingdom();
Kingdom C = new Kingdom();
Kingdom D = new Kingdom();
Kingdom E = new Kingdom();
Kingdom F = new Kingdom();
KingdomsList.Add(A);
KingdomsList.Add(B);
KingdomsList.Add(C);
KingdomsList.Add(D);
KingdomsList.Add(E);
KingdomsList.Add(F);
}
[ChatCommand("claim")]
void ClaimKingdom(Player player, string command, string[] args)
{
int bonuses = 0;
var kingdom = args[0].ToLower();
if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(0).Ruler != 0)
{
player.SendError("The Kingdom A already has a Ruler.");
return;
}
if (AClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom A");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name.ToString())
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom A.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
AClaims.Add(player);
}
if (AFirstClaim == true)
{
AFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(0).Ruler = DetermineRuler(AClaims));
timer.Once(605, () => AClaims.Clear());
timer.Once(610, () => AFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).SendNews("You are now the Ruler of the Kingdom A. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).DisplayName + " is the new Ruler of A.", Server.ClientPlayers, Severity.Urgent));
}
}
if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(1).Ruler != 0)
{
player.SendError("The Kingdom B already has a Ruler.");
return;
}
if (BClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom B");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name)
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom B.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
BClaims.Add(player);
}
if (BFirstClaim == true)
{
BFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(1).Ruler = DetermineRuler(BClaims));
timer.Once(605, () => BClaims.Clear());
timer.Once(610, () => BFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).SendNews("You are now the Ruler of the Kingdom B. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).DisplayName + " is the new Ruler of B.", Server.ClientPlayers, Severity.Urgent));
}
}
if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(2).Ruler != 0)
{
player.SendError("The Kingdom C already has a Ruler.");
return;
}
if (CClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom C");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name)
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom C.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
CClaims.Add(player);
}
if (CFirstClaim == true)
{
CFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(2).Ruler = DetermineRuler(CClaims));
timer.Once(605, () => CClaims.Clear());
timer.Once(610, () => CFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).SendNews("You are now the Ruler of the Kingdom C. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).DisplayName + " is the new Ruler of C.", Server.ClientPlayers, Severity.Urgent));
}
}
if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(3).Ruler != 0)
{
player.SendError("The Kingdom D already has a Ruler.");
return;
}
if (DClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom D");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name)
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom D.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
DClaims.Add(player);
}
if (DFirstClaim == true)
{
DFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(3).Ruler = DetermineRuler(DClaims));
timer.Once(605, () => DClaims.Clear());
timer.Once(610, () => DFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).SendNews("You are now the Ruler of the Kingdom D. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).DisplayName + " is the new Ruler of D.", Server.ClientPlayers, Severity.Urgent));
}
}
if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(4).Ruler != 0)
{
player.SendError("The Kingdom E already has a Ruler.");
return;
}
if (EClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom E");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name)
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom E.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
EClaims.Add(player);
}
if (EFirstClaim == true)
{
EFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(4).Ruler = DetermineRuler(EClaims));
timer.Once(605, () => EClaims.Clear());
timer.Once(610, () => EFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).SendNews("You are now the Ruler of the Kingdom E. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).DisplayName + " is the new Ruler of E.", Server.ClientPlayers, Severity.Urgent));
}
}
if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
{
if (KingdomsList.GetAt<Kingdom>(5).Ruler != 0)
{
player.SendError("The Kingdom F already has a Ruler.");
return;
}
if (FClaims.Contains(player))
{
player.SendError("You have already submitted your claim to the Kingdom F");
return;
}
bool hasClaim = false;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests)
{
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
if (crestGuildname == player.GetGuild().Name)
{
hasClaim = true;
}
}
if (hasClaim == false)
{
player.SendError("You have no claim to the Kingdom F.");
return;
}
bonuses = bonuses + player.GetGuild().Members().MemberCount();
if (player.GetGuild().OwnerId == player.Id)
{
bonuses = bonuses + 3;
}
for (int i = 0; i <= bonuses; i++)
{
FClaims.Add(player);
}
if (FFirstClaim == true)
{
FFirstClaim = false;
timer.In(600, () => KingdomsList.GetAt<Kingdom>(5).Ruler = DetermineRuler(FClaims));
timer.Once(605, () => FClaims.Clear());
timer.Once(610, () => FFirstClaim = true);
timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).SendNews("You are now the Ruler of the Kingdom F. Long may you reign.", Severity.Urgent));
timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).DisplayName + " is the new Ruler of F.", Server.ClientPlayers, Severity.Urgent));
}
}
}
[ChatCommand("renounce")]
void RenounceKingdom(Player player, string command, string[] args)
{
var kingdom = args[0].ToLower();
if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(0).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).SendNews("You are no longer the Ruler of the Kingdom A.");
KingdomsList.GetAt<Kingdom>(0).Ruler = 0;
}
}
if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(1).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).SendNews("You are no longer the Ruler of the Kingdom B.");
KingdomsList.GetAt<Kingdom>(1).Ruler = 0;
}
}
if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(2).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).SendNews("You are no longer the Ruler of the Kingdom C.");
KingdomsList.GetAt<Kingdom>(2).Ruler = 0;
}
}
if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(3).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).SendNews("You are no longer the Ruler of the Kingdom D.");
KingdomsList.GetAt<Kingdom>(3).Ruler = 0;
}
}
if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(4).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).SendNews("You are no longer the Ruler of the Kingdom E.");
KingdomsList.GetAt<Kingdom>(4).Ruler = 0;
}
}
if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
{
if (player.Id == KingdomsList.GetAt<Kingdom>(5).Ruler)
{
Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).SendNews("You are no longer the Ruler of the Kingdom F.");
KingdomsList.GetAt<Kingdom>(5).Ruler = 0;
}
}
}
[ChatCommand("kingdomAdd")]
void AddCrestToKingdom(Player player, string command, string[] args)
{
if (!player.HasPermission("admin"))
{
return;
}
uint crestId;
try
{
uint.TryParse(args[1], out crestId);
}
catch
{
player.SendError("Could not Parse CrestId (string args[1]) to uint.");
return;
}
var kingdom = args[0].ToLower();
if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
{
KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom A.");
}
if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
{
KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom B.");
}
if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
{
KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom C.");
}
if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
{
KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom D.");
}
if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
{
KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom E.");
}
if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
{
KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests.Add(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom F.");
}
SaveLists();
}
[ChatCommand("kingdomRemove")]
void RemoveCrestFromKingdom(Player player, string command, string[] args)
{
if (!player.HasPermission("admin"))
{
return;
}
uint crestId;
try
{
uint.TryParse(args[1], out crestId);
}
catch
{
player.SendError("Could not Parse CrestId (string args[1]) to uint.");
return;
}
var kingdom = args[0].ToLower();
if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
{
KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom A.");
}
if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
{
KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom B.");
}
if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
{
KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom C.");
}
if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
{
KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom D.");
}
if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
{
KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom E.");
}
if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
{
KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests.Remove(crestId);
string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom F.");
}
SaveLists();
}
#endregion
ulong DetermineRuler (List<Player> KingdomClaims)
{
Player potentialNewRuler = null;
KingdomClaims.Shuffle<Player>();
KingdomClaims.FastShuffle<Player>();
KingdomClaims.Shuffle<Player>();
bool potentialNewRulerIsOnline = false;
while (!potentialNewRulerIsOnline)
{
potentialNewRuler = KingdomClaims.GetRandom<Player>();
potentialNewRulerIsOnline = potentialNewRuler.IsOnlineAccount;
}
ulong newRulerId = potentialNewRuler.Id;
bool newRulerIsMale = Server.GetPlayerById(newRulerId).GetCharacterGender();
if (!Server.GetPlayerById(newRulerId).HasPermission("admin"))
{
if (newRulerIsMale)
{
Server.Permissions.Load();
Server.Permissions.AddUser(Server.GetPlayerById(newRulerId).Name);
Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).AddGroup(Server.Permissions.GetGroup("king"));
Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).MakePrimaryGroup(Server.Permissions.GetGroup("king"));
Server.Permissions.Save();
}
else if (!newRulerIsMale)
{
Server.Permissions.Load();
Server.Permissions.AddUser(Server.GetPlayerById(newRulerId).Name);
Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).AddGroup(Server.Permissions.GetGroup("queen"));
Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).MakePrimaryGroup(Server.Permissions.GetGroup("queen"));
Server.Permissions.Save();
}
}
IPlayer server = covalence.Players.FindPlayerById("9999999999");
server.Command("permissions reload");
timer.Once(5, () => SaveLists());
return newRulerId;
}
void OnEntityDeath(EntityDeathEvent ede)
{
if (!ede.Entity.IsPlayer && ede.Entity.name.Contains("Crest"))
{
for (int i = 0; i <= 5; i++)
{
int guildCrestsInKingdom = 0;
foreach (uint crestId in KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests)
{
if (SocialAPI.Get<CrestScheme>().GetCrest(crestId).Position == ede.Entity.Position)
{
KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Remove(crestId);
}
if (ede.Entity.Owner.GetGuild().Name == SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName)
{
guildCrestsInKingdom++;
}
}
if (guildCrestsInKingdom == 0 && ede.Entity.Owner.GetGuild().Name == Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).GetGuild().Name)
{
Server.Permissions.Load();
Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("king");
Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("queen");
KingdomsList.GetAt<Kingdom>(i).Ruler = 0;
Server.Permissions.Save();
IPlayer server = covalence.Players.FindPlayerById("9999999999");
server.Command("permissions reload");
}
}
}
}
}
}
Thanks in advance.