C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Text;
using System.Linq;
using UnityEngine;
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using Oxide.Core;
namespace Oxide.Plugins {
[Info("Factions", "Absolut", "3.5.0", ResourceId = 1919)]
class Factions : RustPlugin {
#region Fields
[PluginReference]
Plugin EventManager;
[PluginReference]
Plugin Economics;
[PluginReference]
Plugin ServerRewards;
[PluginReference]
Plugin Kits;
[PluginReference]
Plugin LustyMap;
[PluginReference]
Plugin ZoneManager;
[PluginReference]
Plugin ZoneDomes;
[PluginReference]
Plugin ActiveCSZone;
private bool UseFactions;
private bool TaxBoxFullNotification;
private int BZPrepTime = 99;
ushort bZID = 0;
int GlobalTime = 0;
static FieldInfo buildingPrivlidges;
FactionSavedPlayerData playerData;
private DynamicConfigFile PlayerData;
PlayerSavedInventories invData;
private DynamicConfigFile InvData;
FactionStatistics factionData;
private DynamicConfigFile FactionData;
private List<ushort> activeBoxes = new List<ushort>();
private List<ulong> UnsureWaiting = new List<ulong>();
private List<ulong> MenuState = new List<ulong>();
private List<ulong> ButtonState = new List<ulong>();
private List<ulong> ImmunityList = new List<ulong>();
private List<ulong> OpenMemberStatus = new List<ulong>();
private Dictionary<ulong, FactionDesigner> ActiveCreations = new Dictionary<ulong, FactionDesigner>();
private Dictionary<ulong, FactionDesigner> ActiveEditors = new Dictionary<ulong, FactionDesigner>();
private Dictionary<ulong, SpawnDesigner> SpawnCreation = new Dictionary<ulong, SpawnDesigner>();
private Dictionary<ushort, target> FactionInvites = new Dictionary<ushort, target>();
private Dictionary<ushort, target> FactionKicks = new Dictionary<ushort, target>();
private Dictionary<ushort, target> LeaderPromotes = new Dictionary<ushort, target>();
private Dictionary<int, TradeProcessing> TradeAssignments = new Dictionary<int, TradeProcessing>();
private Dictionary<int, TradeProcessing> TradeRemoval = new Dictionary<int, TradeProcessing>();
private Dictionary<ulong, List<string>> OpenUI = new Dictionary<ulong, List<string>>();
private Dictionary<int, Monuments> MonumentLocations = new Dictionary<int, Monuments>();
private List<BaseEntity> bzBuildings = new List<BaseEntity>();
private Dictionary<ulong, PlayerCond> Condition = new Dictionary<ulong, PlayerCond>();
private Dictionary<ushort, string> BattleZones = new Dictionary<ushort, string>();
private Dictionary<ulong, BattleZonePlayer> BZPlayers = new Dictionary<ulong, BattleZonePlayer>();
private Dictionary<ushort, float> BZTimes;
private Dictionary<ushort, Timer> BZTimers;
private Dictionary<ulong, Timer> BZKillTimers;
private List<ulong> SpawnTimers;
/// Turrets///
private readonly string turretPrefab = "assets/prefabs/npc/autoturret/autoturret_deployed.prefab";
private uint turretPrefabId;
Dictionary<ulong, List<AutoTurret>> bzTurrets = new Dictionary<ulong, List<AutoTurret>>();
FieldInfo bulletDamageField = typeof(AutoTurret).GetField("bulletDamage", (BindingFlags.Instance | BindingFlags.NonPublic));
FieldInfo healthField = typeof(BaseCombatEntity).GetField("_health", (BindingFlags.Instance | BindingFlags.NonPublic));
FieldInfo maxHealthField = typeof(BaseCombatEntity).GetField("_maxHealth", (BindingFlags.Instance | BindingFlags.NonPublic));
static string UIMain = "UIMain";
static string FactionsUIPanel = "FactionsUIPanel";
static string UIEntry = "UIEntry";
static string BattleZoneTimer = "BattleZoneTimer";
static string SpawnTimerUI = "SpawnTimerUI";
#endregion
#region Hooks
void Loaded() {
PlayerData = Interface.Oxide.DataFileSystem.GetFile("factions_playerdata");
InvData = Interface.Oxide.DataFileSystem.GetFile("factions_invdata");
FactionData = Interface.Oxide.DataFileSystem.GetFile("factions_factiondata");
buildingPrivlidges = typeof(BasePlayer).GetField("buildingPrivlidges", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));
lang.RegisterMessages(messages, this);
BZTimers = new Dictionary<ushort, Timer>();
BZKillTimers = new Dictionary<ulong, Timer>();
BZTimes = new Dictionary<ushort, float>();
SpawnTimers = new List<ulong>();
FindMonuments();
}
void Unload() {
activeBoxes.Clear();
SpawnCreation.Clear();
FactionKicks.Clear();
LeaderPromotes.Clear();
TradeAssignments.Clear();
TradeRemoval.Clear();
FactionInvites.Clear();
SpawnTimers.Clear();
MonumentLocations.Clear();
foreach (BasePlayer p in BasePlayer.activePlayerList) {
DestroyPlayer(p);
}
if (BattleZones.Count > 0) EndBZ(bZID, "Unloaded");
UseFactions = false;
SaveData();
}
void OnServerInitialized() {
LoadVariables();
LoadData();
if (configData.Use_TokensReward) {
try {
EventManager.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"EventManager is missing.Unloading {Name} as it will not work without EventManager.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_ServerRewardsReward) {
try {
ServerRewards.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"ServerRewards is missing.Unloading {Name} as it will not work without ServerRewards.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_EconomicsReward) {
try {
Economics.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"Economics is missing.Unloading {Name} as it will not work without Economics.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_Kits) {
try {
Kits.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"Kits is missing.Unloading {Name} as it will not work without Kits.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_FactionZones) {
try {
ZoneManager.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"ZoneManager is missing.Unloading {Name} as it will not work without ZoneManager.Check Option: FactionZones.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_BattleZones) {
try {
ZoneManager.Call("isLoaded", null);
}
catch (Exception) {
PrintWarning($"ZoneManager is missing.Unloading {Name} as it will not work without ZoneManager.Check Option: BattleZones.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_FactionLeaderByRank) {
if (configData.Use_FactionLeaderByTime == true || configData.Use_FactionLeaderByAdmin == true) {
PrintWarning($"You have more then (1) Use_FactionLeaderBy setting as true.Unloading {Name} as it will not work properly.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_FactionLeaderByAdmin) {
if (configData.Use_FactionLeaderByRank == true || configData.Use_FactionLeaderByTime == true) {
PrintWarning($"You have more then (1) Use_FactionLeaderBy setting as true.Unloading {Name} as it will not work properly.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
if (configData.Use_FactionLeaderByTime) {
if (configData.Use_FactionLeaderByRank == true || configData.Use_FactionLeaderByAdmin == true) {
PrintWarning($"You have more then (1) Use_FactionLeaderBy setting as true.Unloading {Name} as it will not work properly.");
Interface.Oxide.UnloadPlugin(Name);
return;
}
}
foreach (BasePlayer p in BasePlayer.activePlayerList) {
OnPlayerInit(p);
}
GlobalTime = 0;
InfoLoop();
timer.Once(configData.Save_Interval * 60, () => SaveLoop());
timer.Once(1 * 60, () => ChangeGlobalTime());
timer.Once(30, () => RefreshOpenMemberStatus());
timer.Once(900 * 60, () => CheckLeaderTime());
SaveData();
}
void OnEntityBuilt(Planner planner, GameObject gameobject) {
if (gameobject.GetComponent<BaseEntity>() != null) {
if (bZID != 0) {
var entityowner = gameobject.GetComponent<BaseEntity>().OwnerID;
if (BZPlayers.ContainsKey(entityowner)) if (BZPlayers[entityowner].died == false && BZPlayers[entityowner].entered == true) {
var position = (Vector3)GetZoneLocation(BattleZones[bZID]);
var radius = (float)GetZoneRadius(BattleZones[bZID]);
var distance = Vector3.Distance(gameobject.transform.position, position);
if (distance <= radius) {
bzBuildings.Add(gameobject.GetComponent<BaseEntity>());
}
}
}
}
}
private void OnPlayerInit(BasePlayer player) {
if (player != null) {
if (UseFactions) {
Bindings(player);
RefreshTicker(player);
if (player.IsSleeping()) {
timer.Once(5, () => {
player.EndSleeping();
SendMSG(player, lang.GetMessage("FactionsInfo", this));
if (FactionMemberCheck(player)) {
playerData.playerFactions[player.userID].Name = $"{player.displayName}";
SendPuts(string.Format(lang.GetMessage("PlayerReturns", this, player.UserIDString), player.displayName));
InitPlayerTime(player);
AuthorizePlayerOnTurrets(player);
if (bZID != 0) if (!BZPlayers.ContainsKey(player.userID)) BZButton(player, bZID);
}
if (!FactionMemberCheck(player)) {
if (!playerData.playerFactions.ContainsKey(player.userID)) {
playerData.playerFactions.Add(player.userID, new FactionPlayerData {
Name = $"{player.displayName}", trade = Trade.None, level = 1, FactionMemberTime = 0, rank = Rank.Recruit
}
);
Kits?.Call("GiveKit", player, configData.StarterKit);
SendPuts(string.Format(lang.GetMessage("PlayerNew", this, player.UserIDString), player.displayName));
}
{
SetFaction(player);
return;
}
}
}
);
}
else {
if (FactionMemberCheck(player)) {
playerData.playerFactions[player.userID].Name = $"{player.displayName}";
InitPlayerTime(player);
AuthorizePlayerOnTurrets(player);
if (bZID != 0) if (!BZPlayers.ContainsKey(player.userID)) BZButton(player, bZID);
}
if (!FactionMemberCheck(player)) {
if (!playerData.playerFactions.ContainsKey(player.userID)) {
playerData.playerFactions.Add(player.userID, new FactionPlayerData {
Name = $"{player.displayName}", trade = Trade.None, level = 1, FactionMemberTime = 0, rank = Rank.Recruit
}
);
Kits?.Call("GiveKit", player, configData.StarterKit);
SendPuts(string.Format(lang.GetMessage("PlayerNew", this, player.UserIDString), player.displayName));
}
{
SetFaction(player);
return;
}
}
}
}
}
}
private void OnPlayerRespawned(BasePlayer player) {
if (UseFactions) {
if (FactionMemberCheck(player)) {
var faction = GetPlayerFaction(player);
RefreshTicker(player);
if (OpenMemberStatus.Contains(player.userID)) FactionMemberStatus(player);
if (!isCSPlayer(player)) {
if (playerData.playerFactions[player.userID].SavedInventory == true) {
RestoreBZPlayer(player);
}
else if (configData.Use_Kits) GiveFactionKit(player, faction);
if (bZID != 0) if (!BZPlayers.ContainsKey(player.userID)) BZButton(player, bZID);
else if (BZPlayers[player.userID].entered == true) {
BZPlayers[player.userID].died = true;
BZPlayers[player.userID].oob = false;
if (BZKillTimers.ContainsKey(player.userID)) {
BZKillTimers[player.userID].Destroy();
BZKillTimers.Remove(player.userID);
}
CuiHelper.DestroyUi(player, BattleZoneTimer);
}
SpawnButtons(player, faction);
timer.Once(30, () => {
CuiHelper.DestroyUi(player, PanelSpawnButtons);
}
);
}
}
else OnPlayerInit(player);
}
}
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) {
try {
if (UseFactions) {
var attacker = hitInfo.Initiator.ToPlayer();
if (!FactionMemberCheck(attacker)) return;
if (GetFactionType(attacker) == FactionType.FFA) return;
if (configData.Use_Ranks) {
int attackerRank = (int)GetPlayerRank(attacker);
float dmgMod = (attackerRank * configData.RankBonus + 100) / 100;
hitInfo.damageTypes.ScaleAll(dmgMod);
}
if (entity is BasePlayer && hitInfo.Initiator is BasePlayer) {
if (entity as BasePlayer == null || hitInfo == null) return;
var victim = entity.ToPlayer();
if (BZPlayers.ContainsKey(attacker.userID)) if (BZPlayers[attacker.userID].died == false && BZPlayers[attacker.userID].entered == true) if (!BZPlayers.ContainsKey(victim.userID)) {
SendMSG(attacker, string.Format(lang.GetMessage("VictimNotinBZ", this)));
return;
}
if (BZPlayers.ContainsKey(victim.userID)) if (BZPlayers[victim.userID].died == false && BZPlayers[victim.userID].entered == true) if (!BZPlayers.ContainsKey(attacker.userID)) {
SendMSG(attacker, string.Format(lang.GetMessage("AttackerNotinBZ", this)));
return;
}
if (ImmunityList.Contains(attacker.userID) || ImmunityList.Contains(victim.userID)) {
hitInfo.damageTypes.ScaleAll(0);
try {
SendMSG(attacker, string.Format(lang.GetMessage("CurrentlyImmuneAttacker", this)));
}
catch {
}
try {
SendMSG(victim, string.Format(lang.GetMessage("CurrentlyImmuneVictim", this)));
}
catch {
}
return;
}
if (!configData.FFDisabled) return;
if (GetFactionType(victim) == FactionType.FFA) return;
if (EventManager) {
object isPlaying = EventManager?.Call("isPlaying", new object[] {
attacker
}
);
if (isPlaying is bool) if ((bool)isPlaying) return;
}
if (ActiveCSZone) {
if (isCSPlayer(attacker)) return;
}
if (victim != attacker) {
if ((FactionMemberCheck(attacker)) && (FactionMemberCheck(victim))) {
if (configData.Use_RevoltChallenge) {
if ((playerData.playerFactions[attacker.userID].ChallengeStatus) && (playerData.playerFactions[victim.userID].ChallengeStatus)) return;
}
if (!SameFactionCheck(attacker, victim.userID)) return;
{
hitInfo.damageTypes.ScaleAll(configData.FF_DamageScale);
SendMSG(attacker, string.Format(lang.GetMessage("FFs", this, attacker.UserIDString), victim.displayName));
}
}
}
}
///Player Structure Check
else if (entity is BaseEntity && hitInfo.Initiator is BasePlayer) {
if (!configData.BuildingProtectionEnabled) return;
var OwnerID = entity.OwnerID;
if (!FactionMemberCheck(attacker)) return;
if (attacker.userID == OwnerID) return;
if (!SameFactionCheck(attacker, OwnerID)) return;
if (OwnerID != 0) {
{
if (EventManager) {
object isPlaying = EventManager?.Call("isPlaying", new object[] {
attacker
}
);
if (isPlaying is bool) if ((bool)isPlaying) return;
}
if (configData.Use_RevoltChallenge) {
if ((playerData.playerFactions[attacker.userID].ChallengeStatus) && (playerData.playerFactions[OwnerID].ChallengeStatus)) return;
}
//if (AuthorizedTC(attacker)) return;
hitInfo.damageTypes.ScaleAll(0);
SendMSG(attacker, string.Format(lang.GetMessage("FFBuildings", this, attacker.UserIDString), playerData.playerFactions[OwnerID].Name));
}
}
}
}
}
catch (Exception) {
}
}
private void OnEntityDeath(BaseEntity entity, HitInfo hitInfo) {
if (UseFactions) {
try {
if (entity is AutoTurret) {
var userid = entity.OwnerID;
BasePlayer owner = BasePlayer.FindByID(userid);
if (InBZ(owner)) {
if (bzTurrets.ContainsKey(userid)) if (bzTurrets[userid].Contains(entity.GetComponent<AutoTurret>())) bzTurrets[userid].Remove(entity.GetComponent<AutoTurret>());
Item item = BuildItem("autoturret", 1);
GiveItem(owner, item, "");
return;
}
else if (playerData.playerFactions[userid].factionTurrets.Contains(entity.GetComponent<AutoTurret>())) playerData.playerFactions[userid].factionTurrets.Remove(entity.GetComponent<AutoTurret>());
return;
}
if (entity is StorageContainer) {
Vector3 ContPosition = entity.transform.position;
foreach (var box in factionData.Boxes) {
BasePlayer factionleader = BasePlayer.FindByID(factionData.leader[box.Key]);
if (ContPosition.x == box.Value.x && ContPosition.y == box.Value.y && ContPosition.z == box.Value.z) {
factionData.Boxes.Remove(box.Key);
if (BasePlayer.activePlayerList.Contains(factionleader)) SendMSG(factionleader, lang.GetMessage("TaxBoxDestroyed", this));
}
}
return;
}
var attacker = hitInfo.Initiator.ToPlayer() as BasePlayer;
var victim = entity.ToPlayer();
if (InBZ(victim)) {
if (bzTurrets.ContainsKey(victim.userID)) {
foreach (var autoturret in bzTurrets[victim.userID]) autoturret.DieInstantly();
bzTurrets[victim.userID].Clear();
}
if (BZPlayers.ContainsKey(victim.userID)) {
BZPlayers[victim.userID].died = true;
}
if (BZPlayers[victim.userID].owner == true) EndBZ(GetPlayerFaction(victim), "LeaderDeath");
else BZAttackerCheck();
}
if (GetFactionType(attacker) == FactionType.FFA) return;
if (GetFactionType(victim) == FactionType.FFA) return;
if (!FactionMemberCheck(attacker) || !FactionMemberCheck(victim)) return;
var victimfaction = GetPlayerFaction(victim);
if (entity is BasePlayer && hitInfo.Initiator is BasePlayer) {
if (entity as BasePlayer == null || hitInfo == null) return;
if (victim.userID != attacker.userID) {
var attackerFaction = GetPlayerFaction(attacker);
if (!SameFactionCheck(attacker, victim.userID)) {
if (EventManager) {
object isPlaying = EventManager?.Call("isPlaying", new object[] {
attacker
}
);
if (isPlaying is bool) if ((bool)isPlaying) return;
}
if (ActiveCSZone) {
if (isCSPlayer(attacker)) return;
}
if (configData.Use_FactionKillIncentives) {
factionData.Factions[attackerFaction].Kills += 1;
SaveData();
foreach (BasePlayer p in BasePlayer.activePlayerList) RefreshTicker(p);
if (factionData.Factions[attackerFaction].Kills >= configData.KillLimit) {
var fname = factionData.Factions[attackerFaction].Name;
SendPuts(string.Format(lang.GetMessage("KillLimitReached", this), fname));
foreach (var entry in playerData.playerFactions) {
if (entry.Value.faction == attackerFaction) {
var reward = "";
if (configData.Use_EconomicsReward) {
Economics.Call("DepositS", attacker.userID.ToString(), configData.FactionKillsRewardEconomics);
reward = $"{configData.FactionKillsRewardEconomics.ToString()} Economics!";
}
if (configData.Use_TokensReward) {
EventManager.Call("AddTokens", attacker.userID.ToString(), configData.FactionKillsRewardTokens);
reward = $"{configData.FactionKillsRewardTokens.ToString()} Tokens!";
}
if (configData.Use_ServerRewardsReward) {
ServerRewards?.Call("AddPoints", attacker.userID.ToString(), configData.FactionKillsRewardServerRewards);
reward = $"{configData.FactionKillsRewardServerRewards.ToString()} Reward Points!";
}
SendPuts(string.Format(lang.GetMessage("KillLimitReward", this), reward));
}
}
SendPuts(string.Format(lang.GetMessage("KillTickerReset", this)));
timer.Once(300, () => ResetTicker());
}
}
playerData.playerFactions[attacker.userID].Kills += 1;
if (configData.Use_Ranks) {
var currentrank = playerData.playerFactions[attacker.userID].rank;
if (currentrank != Rank.SharpShooter) {
playerData.playerFactions[attacker.userID].Kills += 1;
SaveData();
if (GetPlayerKills(attacker) >= configData.RankRequirement * (int)currentrank) {
playerData.playerFactions[attacker.userID].rank = currentrank + 1;
playerData.playerFactions[attacker.userID].Kills = 0;
SaveData();
RankAdvancement(attacker);
}
}
CheckLeaderRank(attacker);
}
SendDeathNote(attacker, victim, GetPlayerFaction(attacker));
if (configData.Use_EconomicsReward) {
Economics.Call("DepositS", attacker.userID.ToString(), configData.KillAmountEconomics);
SendMSG(attacker, string.Format(lang.GetMessage("Payment", this, attacker.UserIDString), configData.KillAmountEconomics, "Currency"));
}
if (configData.Use_TokensReward) {
EventManager.Call("AddTokens", attacker.userID.ToString(), configData.KillAmountTokens);
SendMSG(attacker, string.Format(lang.GetMessage("Payment", this, attacker.UserIDString), configData.KillAmountTokens, "Tokens"));
}
if (configData.Use_ServerRewardsReward) {
ServerRewards?.Call("AddPoints", attacker.userID.ToString(), configData.KillAmountServerRewards);
SendMSG(attacker, string.Format(lang.GetMessage("Payment", this, attacker.UserIDString), configData.KillAmountServerRewards, "Reward Points"));
}
}
else if (configData.Use_RevoltChallenge) {
if (factionData.ActiveChallenges.ContainsKey(victim.userID) && factionData.ActiveChallenges.ContainsKey(attacker.userID)) {
if (configData.Use_Ranks) {
var currentrank = playerData.playerFactions[attacker.userID].rank;
if (currentrank != Rank.SharpShooter) {
//Puts("Trying Rank");
playerData.playerFactions[attacker.userID].Kills += 1;
SaveData();
if (GetPlayerKills(attacker) >= configData.RankRequirement * (int)currentrank) {
playerData.playerFactions[attacker.userID].rank = currentrank + 1;
playerData.playerFactions[attacker.userID].Kills = 0;
SaveData();
RankAdvancement(attacker);
}
}
}
if (isleader(attacker)) //Leader wins, Challenger is removed from faction.{
SendPuts(string.Format(lang.GetMessage("ChallengerLost", this, attacker.UserIDString), victim.displayName));
UnassignPlayerFromFaction(victim.userID);
if (configData.Use_FactionLeaderByRank) {
playerData.playerFactions[victim.userID].rank = Rank.Recruit;
if (BasePlayer.activePlayerList.Contains(victim)) SendMSG(victim, string.Format(lang.GetMessage("ChallengeLostRank", this)));
}
if (configData.Use_FactionLeaderByTime) {
playerData.playerFactions[victim.userID].time = GlobalTime;
playerData.playerFactions[victim.userID].FactionMemberTime = 0;
if (BasePlayer.activePlayerList.Contains(victim)) SendMSG(victim, string.Format(lang.GetMessage("ChallengeLostTime", this)));
}
}
else if (isleader(victim)) //Challenger wins, Leader playtime set to 0 or Rank set to Recruit or leader just removed.{
SendPuts(string.Format(lang.GetMessage("LeaderLost", this, attacker.UserIDString), attacker.displayName));
if (configData.Use_FactionLeaderByRank) {
playerData.playerFactions[victim.userID].rank = Rank.Recruit;
if (BasePlayer.activePlayerList.Contains(victim)) SendMSG(victim, string.Format(lang.GetMessage("ChallengeLostRank", this)));
}
if (configData.Use_FactionLeaderByTime) {
playerData.playerFactions[victim.userID].time = GlobalTime;
playerData.playerFactions[victim.userID].FactionMemberTime = 0;
if (BasePlayer.activePlayerList.Contains(victim)) SendMSG(victim, string.Format(lang.GetMessage("ChallengeLostTime", this)));
}
if (configData.Use_FactionLeaderByAdmin) {
factionData.leader.Remove(victimfaction);
factionData.Factions[victimfaction].tax = 0;
if (factionData.Boxes.ContainsKey(victimfaction)) factionData.Boxes.Remove(victimfaction);
if (BasePlayer.activePlayerList.Contains(victim)) SendMSG(victim, string.Format(lang.GetMessage("ChallengeLostLeader", this)));
BroadcastFaction(victim, string.Format(lang.GetMessage("ChallengeNewLeader", this), attacker.displayName, victim.displayName));
factionData.leader[attackerFaction] = attacker.userID;
}
}
//Remove Challenge Stuff
factionData.ActiveChallenges.Remove(victim.userID);
factionData.ActiveChallenges.Remove(attacker.userID);
FactionDamage(attacker);
FactionDamage(victim);
SaveData();
CheckLeaderTime();
CheckLeaderRank(attacker);
}
}
}
}
}
catch (Exception) {
}
}
}
private void OnPlayerDisconnected(BasePlayer player) {
DestroyPlayer(player);
SendPuts(string.Format(lang.GetMessage("PlayerLeft", this, player.UserIDString), player.displayName));
}
void DestroyPlayer(BasePlayer player) {
if (player == null) return;
CuiHelper.DestroyUi(player, SpawnTimerUI);
player.Command("bind n \"\"");
player.Command("bind p \"\"");
DestroyAll(player);
if (OpenMemberStatus.Contains(player.userID)) OpenMemberStatus.Remove(player.userID);
if (!FactionMemberCheck(player)) return;
var faction = GetPlayerFaction(player);
if (configData.Use_FactionLeaderByTime) {
SaveTimeData(player);
playerData.playerFactions[player.userID].time = 0;
}
if (isleader(player)) {
if (activeBoxes.Contains(faction)) activeBoxes.Remove(faction);
}
}
private object OnPlayerChat(ConsoleSystem.Arg arg) {
var player = arg.connection.player as BasePlayer;
if (player == null) return null;
bool isCreatingFaction = false;
bool isEditingFaction = false;
bool isSpawn = false;
FactionDesigner Creator = new FactionDesigner();
Faction Faction = new Faction();
SpawnDesigner Designer = new SpawnDesigner();
Coords spawn = new Coords();
if (ActiveEditors.ContainsKey(player.userID)) {
isEditingFaction = true;
Creator = ActiveEditors[player.userID];
Faction = Creator.Entry;
}
else if (ActiveCreations.ContainsKey(player.userID)) {
isCreatingFaction = true;
Creator = ActiveCreations[player.userID];
Faction = Creator.Entry;
}
else if (SpawnCreation.ContainsKey(player.userID)) {
isSpawn = true;
Designer = SpawnCreation[player.userID];
spawn = Designer.Entry;
}
if (isSpawn) {
var args = string.Join(" ", arg.Args);
if (args.Contains("quit")) {
ExitSpawnCreation(player, isSpawn);
return true;
}
if (args.Contains("save spawn")) {
SaveSpawn(player, isSpawn);
return true;
}
switch (Designer.partNum) {
case 0 : spawn.Name = string.Join(" ", arg.Args);
CreationHelp(player, 10);
return true;
}
}
if (isEditingFaction || isCreatingFaction) {
var args = string.Join(" ", arg.Args);
if (args.Contains("quit")) {
QuitFactionCreation(player, isCreatingFaction);
return true;
}
if (args.Contains("save faction")) {
SaveFaction(player, isCreatingFaction);
return true;
}
switch (Creator.partNum) {
case 0 : foreach (var faction in factionData.Factions) if (faction.Value.Name.Contains(string.Join(" ", arg.Args))) {
SendMSG(player, string.Format(lang.GetMessage("FactionNameExists", this), args));
return true;
}
Faction.Name = string.Join(" ", arg.Args);
Creator.partNum++;
SendMSG(player, string.Format(lang.GetMessage("CreatorFactionName", this), args));
if (isCreatingFaction) CreationHelp(player, 1);
else CreationHelp(player, 20);
return true;
case 1 : Faction.LeaderTitle = string.Join(" ", arg.Args);
SendMSG(player, string.Format(lang.GetMessage("CreatorLeaderTitle", this), args));
Creator.partNum++;
if (isCreatingFaction) CreationHelp(player, 2);
else CreationHelp(player, 20);
return true;
case 2 : Faction.group = string.Join(" ", arg.Args);
SendMSG(player, string.Format(lang.GetMessage("CreatorFactionGroup", this), args));
ConsoleSystem.Run.Server.Normal($"group add {Faction.group}");
Creator.partNum++;
if (isCreatingFaction) CreationHelp(player, 20);
return true;
}
}
if (EventManager) {
object isPlaying = EventManager?.Call("isPlaying", new object[] {
player
}
);
if (isPlaying is bool) if ((bool)isPlaying) return null;
}
if (ActiveCSZone) {
if (isCSPlayer(player)) return null;
}
if (UseFactions) if (configData.Use_FactionChatControl) {
string message = arg.GetString(0, "text");
string color = "";
if (FactionMemberCheck(player)) {
color = factionData.Factions[GetPlayerFaction(player)].ChatColor;
if (configData.Use_FactionNamesonChat) {
color += "[" + factionData.Factions[GetPlayerFaction(player)].Name + "] ";
}
if (configData.Use_ChatTitles) {
if (isleader(player) && isAuth(player)) {
string formatMsg = color + "[ADMIN][LEADER] " + player.displayName + "</color> : " + message;
Broadcast(formatMsg, player.userID.ToString());
}
else if (isAuth(player)) {
string formatMsg = color + "[ADMIN] " + player.displayName + "</color> : " + message;
Broadcast(formatMsg, player.userID.ToString());
}
else if (isleader(player)) {
string formatMsg = color + "[LEADER] " + player.displayName + "</color> : " + message;
Broadcast(formatMsg, player.userID.ToString());
}
else {
string formatMsg = color + player.displayName + "</color> : " + message;
Broadcast(formatMsg, player.userID.ToString());
}
return false;
}
else {
string formatMsg = color + player.displayName + "</color> : " + message;
Broadcast(formatMsg, player.userID.ToString());
}
return false;
}
}
return null;
}
void OnLootEntity(BasePlayer player, object lootable) {
if (!configData.Use_Taxes) return;
BaseEntity container = lootable as BaseEntity;
if ((player == null) || (container == null) || (!isleader(player))) return;
{
var faction = GetPlayerFaction(player);
var coords = container.transform.localPosition;
if (!activeBoxes.Contains(faction)) {
if (GetTaxContainer(faction) == container) {
SendMSG(player, lang.GetMessage("TaxBox", this));
return;
}
return;
}
if (container.OwnerID == player.userID || SameFactionCheck(player, container.OwnerID)) {
if (container.PrefabName == "assets/prefabs/deployable/large wood storage/box.wooden.large.prefab" || container.PrefabName == "assets/prefabs/deployable/woodenbox/woodbox_deployed.prefab") {
if (!hasTaxBox(faction)) {
activeBoxes.Remove(faction);
factionData.Boxes.Add(faction, new Coords {
x = coords.x, y = coords.y, z = coords.z
}
);
SendMSG(player, lang.GetMessage("NewTaxBox", this));
SendMSG(player, lang.GetMessage("TaxBoxDeActivated", this));
SaveData();
return;
}
else {
activeBoxes.Remove(faction);
factionData.Boxes.Remove(faction);
factionData.Boxes.Add(faction, new Coords {
x = coords.x, y = coords.y, z = coords.z
}
);
SendMSG(player, lang.GetMessage("NewTaxBox", this));
SendMSG(player, lang.GetMessage("TaxBoxDeActivated", this));
SaveData();
return;
}
}
SendMSG(player, lang.GetMessage("TaxBoxError", this));
return;
}
SendMSG(player, lang.GetMessage("TaxBoxOwnerError", this));
return;
}
}
void OnPlantGather(PlantEntity Plant, Item item, BasePlayer player) {
if (!FactionMemberCheck(player)) return;
if (configData.Use_Trades) {
if (playerData.playerFactions[player.userID].trade == Trade.Forager) {
int level = Convert.ToInt32(playerData.playerFactions[player.userID].level);
double bonus = Convert.ToInt32(Math.Round(configData.LevelBonus * level));
int bonusamount = Convert.ToInt32(Math.Round((bonus * item.amount) / 100));
item.amount = item.amount + bonusamount;
playerData.playerFactions[player.userID].Gathered += item.amount;
SaveData();
var currentlevel = playerData.playerFactions[player.userID].level;
if (GetPlayerGathered(player) >= (configData.LevelRequirement * currentlevel)) {
if (currentlevel != configData.MaxLevel) {
playerData.playerFactions[player.userID].level += 1;
playerData.playerFactions[player.userID].Gathered = 0;
SaveData();
LevelAdvancement(player);
}
}
}
}
if (!configData.Use_Taxes) return;
{
var faction = GetPlayerFaction(player);
if (isleader(player)) return;
if (!factionData.leader.ContainsKey(faction)) return;
var factionleaderid = factionData.leader[faction];
BasePlayer factionleader = BasePlayer.FindByID(factionleaderid);
var taxrate = factionData.Factions[faction].tax;
StorageContainer TaxContainer = GetTaxContainer(faction);
if (TaxContainer == null) return;
int Tax = Convert.ToInt32(Math.Round((item.amount * taxrate) / 100));
item.amount = item.amount - Tax;
if (!TaxContainer.inventory.IsFull()) {
ItemDefinition ToAdd = ItemManager.FindItemDefinition(item.info.itemid);
if (ToAdd != null) {
TaxContainer.inventory.AddItem(ToAdd, Tax);
}
}
else if (BasePlayer.activePlayerList.Contains(factionleader)) if (!TaxBoxFullNotification) {
SendMSG(player, lang.GetMessage("TaxBoxFull", this));
SetBoxFullNotification();
return;
}
}
}
void OnCollectiblePickup(Item item, BasePlayer player) {
if (!FactionMemberCheck(player)) return;
if (configData.Use_Trades) {
if (playerData.playerFactions[player.userID].trade == Trade.Forager) {
int level = Convert.ToInt32(playerData.playerFactions[player.userID].level);
double bonus = Convert.ToInt32(Math.Round(configData.LevelBonus * level));
int bonusamount = Convert.ToInt32(Math.Round((bonus * item.amount) / 100));
item.amount = item.amount + bonusamount;
playerData.playerFactions[player.userID].Gathered += item.amount;
SaveData();
var currentlevel = playerData.playerFactions[player.userID].level;
if (GetPlayerGathered(player) >= (configData.LevelRequirement * currentlevel)) {
if (currentlevel != configData.MaxLevel) {
playerData.playerFactions[player.userID].level += 1;
playerData.playerFactions[player.userID].Gathered = 0;
SaveData();
LevelAdvancement(player);
}
}
}
}
if (!configData.Use_Taxes) return;
{
if (isleader(player)) return;
var faction = GetPlayerFaction(player);
if (!factionData.leader.ContainsKey(faction)) return;
var factionleaderid = factionData.leader[faction];
BasePlayer factionleader = BasePlayer.FindByID(factionleaderid);
var taxrate = factionData.Factions[faction].tax;
StorageContainer TaxContainer = GetTaxContainer(faction)
// ... [Code preview truncated due to length. Full source in attached file] ...