C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Rust;
using System.Collections.Generic;
using System;
using System.Text;
using UnityEngine;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries;
using Oxide.Core.Configuration;
using System.Linq;
using Oxide.Game.Rust.Cui;
using System.Reflection;
namespace Oxide.Plugins {
[Info("PlayerRanks", "Steenamaroo", "1.4.1", ResourceId = 2359)]
class PlayerRanks : RustPlugin {
[PluginReference]
Plugin Clans, Friends, EventManager, PlaytimeTracker, Economics;
#region RustIO
private Library lib;
private MethodInfo isInstalled;
private MethodInfo hasFriend;
bool IsInstalled() {
return (lib != null) && (bool)isInstalled.Invoke(lib, new object[] {
}
);
}
bool HasFriend(string playerId, string friendId) {
return (lib != null) && (bool)hasFriend.Invoke(lib, new object[] {
playerId, friendId
}
);
}
#endregion
Dictionary<uint, Dictionary<ulong, float>> BradleyAttackers = new Dictionary<uint, Dictionary<ulong, float>>();
Dictionary<uint, Dictionary<ulong, int>> HeliAttackers = new Dictionary<uint, Dictionary<ulong, int>>();
Dictionary<ulong, WoundedData> woundedData = new Dictionary<ulong, WoundedData>();
bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
private Dictionary<string, bool> allowedCats = new Dictionary<string, bool>();
List<ulong> airdrops = new List<ulong>();
const string permAllowed = "playerranks.allowed";
List<string> Broadcast = new List<string>();
List<ulong> MenuOpen = new List<ulong>();
bool catsOnOff;
Timer broadcastTimer;
public class DataStorage {
public Dictionary<ulong, PRDATA> PlayerRankData = new Dictionary<ulong, PRDATA>();
public Dictionary<DateTime, Dictionary<string, LeaderBoardData>> leaderBoards = new Dictionary<DateTime, Dictionary<string, LeaderBoardData>>();
}
public class LeaderBoardData {
public ulong UserID;
public string UserName;
public double Score;
}
public class PRDATA {
public object GetValue(String category) {
if (category == "PVPKills") return PVPKills;
if (category == "PVPDistance") return PVPDistance;
if (category == "PVEKills") return PVEKills;
if (category == "PVEDistance") return PVEDistance;
if (category == "NPCKills") return NPCKills;
if (category == "NPCDistance") return NPCDistance;
if (category == "SleepersKilled") return SleepersKilled;
if (category == "HeadShots") return HeadShots;
if (category == "Deaths") return Deaths;
if (category == "Suicides") return Suicides;
if (category == "KDR") return KDR;
if (category == "SDR") return SDR;
if (category == "SkullsCrushed") return SkullsCrushed;
if (category == "TimesWounded") return TimesWounded;
if (category == "TimesHealed") return TimesHealed;
if (category == "HeliHits") return HeliHits;
if (category == "HeliKills") return HeliKills;
if (category == "APCHits") return APCHits;
if (category == "APCKills") return APCKills;
if (category == "BarrelsDestroyed") return BarrelsDestroyed;
if (category == "ExplosivesThrown") return ExplosivesThrown;
if (category == "ArrowsFired") return ArrowsFired;
if (category == "BulletsFired") return BulletsFired;
if (category == "RocketsLaunched") return RocketsLaunched;
if (category == "WeaponTrapsDestroyed") return WeaponTrapsDestroyed;
if (category == "DropsLooted") return DropsLooted;
if (category == "StructuresBuilt") return StructuresBuilt;
if (category == "StructuresDemolished") return StructuresDemolished;
if (category == "ItemsDeployed") return ItemsDeployed;
if (category == "ItemsCrafted") return ItemsCrafted;
if (category == "EntitiesRepaired") return EntitiesRepaired;
if (category == "ResourcesGathered") return ResourcesGathered;
if (category == "StructuresUpgraded") return StructuresUpgraded;
return "Not Found";
}
public bool Admin;
public ulong UserID;
public string Name;
public string TimePlayed = "0";
public string Status = "offline";
public int Economics;
public DateTime ActiveDate = DateTime.UtcNow;
public int PVPKills;
public double PVPDistance;
public int PVEKills;
public double PVEDistance;
public int NPCKills;
public double NPCDistance;
public int SleepersKilled;
public int HeadShots;
public int Deaths;
public int Suicides;
public double KDR;
public double SDR;
public int SkullsCrushed;
public int TimesWounded;
public int TimesHealed;
public int HeliHits;
public int HeliKills;
public int APCHits;
public int APCKills;
public int BarrelsDestroyed;
public int ExplosivesThrown;
public int ArrowsFired;
public int BulletsFired;
public int RocketsLaunched;
public int WeaponTrapsDestroyed;
public int DropsLooted;
//intense options
public int StructuresBuilt;
public int StructuresDemolished;
public int ItemsDeployed;
public int ItemsCrafted;
public int EntitiesRepaired;
public int ResourcesGathered;
public int StructuresUpgraded;
}
class WoundedData {
public float distance;
public ulong attackerId;
}
DataStorage data;
private DynamicConfigFile PRData;
void Loaded() {
SetUp();
lang.RegisterMessages(messages, this);
permission.RegisterPermission(permAllowed, this);
cmd.AddChatCommand($"{conf.Options.chatCommandAlias}", this, "CmdTarget");
CheckDependencies();
Sql_conn = Sql.OpenDb(conf.MySQL.sql_host, conf.MySQL.sql_port, conf.MySQL.sql_db, conf.MySQL.sql_user, conf.MySQL.sql_pass + ";CharSet=utf8mb4", this);
}
void Unload() {
Sql_conn.Con.Dispose();
foreach (BasePlayer current in BasePlayer.activePlayerList) if (MenuOpen.Contains(current.userID)) {
CuiHelper.DestroyUi(current, "ranksgui");
MenuOpen.Remove(current.userID);
}
SaveData(false);
}
void OnPlayerDisconnected(BasePlayer player) {
data.PlayerRankData[player.userID].Status = "offline";
if (MenuOpen.Contains(player.userID)) {
CuiHelper.DestroyUi(player, "ranksgui");
MenuOpen.Remove(player.userID);
}
}
void SetUp() {
PRData = Interface.Oxide.DataFileSystem.GetFile("PlayerRanks");
LoadData();
LoadConfigVariables();
foreach (var entry in data.PlayerRankData) entry.Value.Status = "offline";
foreach (BasePlayer player in BasePlayer.activePlayerList) OnPlayerInit(player);
timer.Every(conf.Options.saveTimer * 60, () => {
SaveData(true);
Puts("Player Ranks Local Database Was Saved.");
}
);
UpdateCategories();
SetUpBroadcast();
}
void SetUpBroadcast() {
if (conf.Options.useTimedTopList) {
if (broadcastTimer != null) broadcastTimer.Destroy();
Broadcast.Clear();
foreach (var cat in allowedCats) {
if (allowedCats[cat.Key] == true) Broadcast.Add(cat.Key);
}
if (Broadcast.Count != 0) BroadcastLooper(0);
}
}
void BroadcastLooper(int counter) {
var time = 10f;
if (BroadcastMethod(Broadcast[counter])) time = conf.Options.TimedTopListTimer * 60;
counter++;
if (counter == Broadcast.Count) counter = 0;
broadcastTimer = timer.Once(time, () => BroadcastLooper(counter));
}
void UpdateCategories() {
allowedCats.Clear();
allowedCats.Add("PVPKills", conf.Categories.usepvpkills);
allowedCats.Add("PVPDistance", conf.Categories.usepvpdistance);
allowedCats.Add("PVEKills", conf.Categories.usepvekills);
allowedCats.Add("PVEDistance", conf.Categories.usepvedistance);
allowedCats.Add("NPCKills", conf.Categories.usenpckills);
allowedCats.Add("NPCDistance", conf.Categories.usenpcdistance);
allowedCats.Add("SleepersKilled", conf.Categories.usesleeperskilled);
allowedCats.Add("HeadShots", conf.Categories.useheadshots);
allowedCats.Add("Deaths", conf.Categories.usedeaths);
allowedCats.Add("Suicides", conf.Categories.usesuicides);
allowedCats.Add("KDR", conf.Categories.usekdr);
allowedCats.Add("SDR", conf.Categories.usesdr);
allowedCats.Add("SkullsCrushed", conf.Categories.useskullscrushed);
allowedCats.Add("TimesWounded", conf.Categories.usetimeswounded);
allowedCats.Add("TimesHealed", conf.Categories.usetimeshealed);
allowedCats.Add("HeliHits", conf.Categories.usehelihits);
allowedCats.Add("HeliKills", conf.Categories.usehelikills);
allowedCats.Add("APCHits", conf.Categories.useapchits);
allowedCats.Add("APCKills", conf.Categories.useapckills);
allowedCats.Add("BarrelsDestroyed", conf.Categories.usebarrelsdestroyed);
allowedCats.Add("ExplosivesThrown", conf.Categories.useexplosivesthrown);
allowedCats.Add("ArrowsFired", conf.Categories.usearrowsfired);
allowedCats.Add("BulletsFired", conf.Categories.usebulletsfired);
allowedCats.Add("RocketsLaunched", conf.Categories.userocketslaunched);
allowedCats.Add("WeaponTrapsDestroyed", conf.Categories.useweapontrapsdestroyed);
allowedCats.Add("DropsLooted", conf.Categories.usedropslooted);
if (conf.Options.useIntenseOptions) {
allowedCats.Add("StructuresBuilt", conf.Categories.usestructuresbuilt);
allowedCats.Add("StructuresDemolished", conf.Categories.usestructuresdemolished);
allowedCats.Add("ItemsDeployed", conf.Categories.useitemsdeployed);
allowedCats.Add("ItemsCrafted", conf.Categories.useitemscrafted);
allowedCats.Add("EntitiesRepaired", conf.Categories.useentitiesrepaired);
allowedCats.Add("ResourcesGathered", conf.Categories.useresourcesgathered);
allowedCats.Add("StructuresUpgraded", conf.Categories.usestructuresupgraded);
}
}
void CheckDependencies() {
//warn if enabled and missing
if (Friends == null) if (conf.Options.useFriendsAPI && conf.Options.useFriendsAPI) PrintWarning("{0}: {1}", Title, "FriendsAPI is not installed and will not be used.");
if (Clans == null && conf.Options.useClans) PrintWarning("{0}: {1}", Title, "Clans is not installed and will not be used.");
lib = Interface.GetMod().GetLibrary<Library>("RustIO");
if (lib == null || (isInstalled = lib.GetFunction("IsInstalled")) == null || (hasFriend = lib.GetFunction("HasFriend")) == null) {
lib = null;
if (conf.Options.useRustIO) PrintWarning("{0}: {1}", Title, "Rust:IO is not installed and will not be used.");
}
//just warn if missing
if (PlaytimeTracker == null) PrintWarning("{0}: {1}", Title, "PlayTime Tracker is not installed and will not be used.");
if (Economics == null) PrintWarning("{0}: {1}", Title, "Economics is not installed and will not be used.");
}
void OnPlayerInit(BasePlayer player) {
if (ServerUsers.Is(player.userID, ServerUsers.UserGroup.Banned)) if (data.PlayerRankData.ContainsKey(player.userID)) {
data.PlayerRankData.Remove(player.userID);
SaveData(true);
return;
}
if (MenuOpen.Contains(player.userID)) {
MenuOpen.Remove(player.userID);
CuiHelper.DestroyUi(player, "ranksgui");
}
if (!data.PlayerRankData.ContainsKey(player.userID)) {
data.PlayerRankData.Add(player.userID, new PRDATA() {
Admin = IsAuth(player), UserID = player.userID, Name = player.displayName, TimePlayed = "0", Status = "online", ActiveDate = DateTime.UtcNow, Economics = 0, PVPKills = 0, PVPDistance = 0.0, PVEKills = 0, PVEDistance = 0.0, NPCKills = 0, NPCDistance = 0.0, SleepersKilled = 0, HeadShots = 0, Deaths = 0, Suicides = 0, KDR = 0, SDR = 0, SkullsCrushed = 0, TimesHealed = 0, TimesWounded = 0, HeliHits = 0, HeliKills = 0, APCHits = 0, APCKills = 0, BarrelsDestroyed = 0, ExplosivesThrown = 0, ArrowsFired = 0, BulletsFired = 0, RocketsLaunched = 0, WeaponTrapsDestroyed = 0, DropsLooted = 0, //intense options
StructuresBuilt = 0, StructuresDemolished = 0, ItemsDeployed = 0, ItemsCrafted = 0, EntitiesRepaired = 0, ResourcesGathered = 0, StructuresUpgraded = 0,
}
);
}
else UpdatePlayer(player);
}
void UpdatePlayer(BasePlayer player) {
var path = data.PlayerRankData[player.userID];
var time = PlaytimeTracker?.Call("GetPlayTime", player.UserIDString);
var playTime = (time != null) ? GetPlaytimeClock((double)time) : null;
path.Admin = IsAuth(player);
path.Name = player.displayName;
path.Status = "online";
path.ActiveDate = DateTime.UtcNow;
if (Economics) path.Economics = Convert.ToInt32(Economics?.Call("Balance", player.userID));
path.TimePlayed = (!string.IsNullOrEmpty(playTime)) ? playTime : string.Empty;
}
void OnPlayerBanned(string name, ulong id, string address, string reason)=>data.PlayerRankData.Remove(id);
private string GetPlaytimeClock(double time) {
TimeSpan dateDifference = TimeSpan.FromSeconds((float)time);
var days = dateDifference.Days;
var hours = dateDifference.Hours;
hours += (days * 24);
var mins = dateDifference.Minutes;
var secs = dateDifference.Seconds;
return string.Format("{0:00}:{1:00}:{2:00}", hours, mins, secs);
}
void OnEntityTakeDamage(BaseEntity entity, HitInfo hitinfo) {
if (hitinfo.Initiator == null || !(hitinfo.Initiator is BasePlayer)) return;
var player = hitinfo.Initiator as BasePlayer;
DamageType type = hitinfo.damageTypes.GetMajorityDamageType();
float amount = hitinfo.damageTypes.Total();
if (conf.Options.blockEvents) if (CheckEvents(player))return;
if (entity is BaseHelicopter) {
if (!HeliAttackers.ContainsKey(entity.net.ID)) HeliAttackers.Add(entity.net.ID, new Dictionary<ulong, int>());
if (!HeliAttackers[entity.net.ID].ContainsKey(player.userID)) HeliAttackers[entity.net.ID].Add(player.userID, 1);
else {
HeliAttackers[entity.net.ID][player.userID]++;
ProcessHeliHits(player);
}
}
if (entity is BradleyAPC) {
if (type.ToString() == "Bullet") {
ProcessAPCHits(player);
//plain bullets count as hits, but not towards majority damage
return;
}
if (!BradleyAttackers.ContainsKey(entity.net.ID)) //explosive ammo does get this far, because two damage types are processed.BradleyAttackers.Add(entity.net.ID, new Dictionary<ulong, float>());
if (!BradleyAttackers[entity.net.ID].ContainsKey(player.userID)) BradleyAttackers[entity.net.ID].Add(player.userID, amount);
else {
BradleyAttackers[entity.net.ID][player.userID] = BradleyAttackers[entity.net.ID][player.userID] + amount;
ProcessAPCHits(player);
}
}
if (entity is BasePlayer) if (hitinfo.isHeadshot && !FriendCheck(player, entity as BasePlayer)) ProcessHeadShot(player);
}
ulong GetMajorityAttacker(uint id) {
ulong majorityPlayer = 0U;
if (HeliAttackers.ContainsKey(id)) {
Dictionary<ulong, int> majority = HeliAttackers[id].OrderByDescending(pair => pair.Value).Take(1).ToDictionary(pair => pair.Key, pair => pair.Value);
foreach (var name in majority) {
majorityPlayer = name.Key;
}
}
if (BradleyAttackers.ContainsKey(id)) {
Dictionary<ulong, float> majority = BradleyAttackers[id].OrderByDescending(pair => pair.Value).Take(1).ToDictionary(pair => pair.Key, pair => pair.Value);
foreach (var name in majority) {
majorityPlayer = name.Key;
}
}
return majorityPlayer;
}
void OnEntityDeath(BaseEntity entity, HitInfo hitinfo) {
if (entity.name.Contains("corpse")) return;
var victim = entity as BasePlayer;
if (hitinfo?.Initiator == null && entity is BasePlayer) {
if (woundedData.ContainsKey(victim.userID)) {
BasePlayer attacker = BasePlayer.FindByID(woundedData[victim.userID].attackerId);
if (conf.Options.blockEvents) if (CheckEvents(attacker))return;
var distance = woundedData[victim.userID].distance;
if (!victim.userID.IsSteamId() || victim is NPCPlayer || victim is HTNPlayer) {
if (attacker != null) {
if (data.PlayerRankData.ContainsKey(attacker.userID)) data.PlayerRankData[attacker.userID].NPCKills++;
if (distance > data.PlayerRankData[attacker.userID].NPCDistance) data.PlayerRankData[attacker.userID].NPCDistance = Math.Round(distance, 2);
//process method not called, because distance is from record
}
return;
}
if (victim.userID.IsSteamId()) {
ProcessDeath(victim);
if (attacker != null) {
if (data.PlayerRankData.ContainsKey(attacker.userID)) data.PlayerRankData[attacker.userID].PVPKills++;
if (distance > data.PlayerRankData[attacker.userID].PVPDistance) data.PlayerRankData[attacker.userID].PVPDistance = Math.Round(distance, 2);
}
return;
}
woundedData.Remove(victim.userID);
}
String [] stringArray = {
"Cold", "Drowned", "Heat", "Suicide", "Generic", "Posion", "Radiation", "Thirst", "Hunger", "Fall"
}
;
if (stringArray.Any(victim.lastDamage.ToString().Contains)) ProcessSuicide(victim);
ProcessDeath(victim);
return;
}
if (entity is BaseHelicopter) {
BasePlayer player = null;
player = BasePlayer.FindByID(GetMajorityAttacker(entity.net.ID));
if (player != null) {
ProcessHeliKills(player);
HeliAttackers.Remove(entity.net.ID);
}
return;
}
if (entity is BradleyAPC) {
BasePlayer player;
var BradleyID = entity.net.ID;
player = BasePlayer.FindByID(GetMajorityAttacker(BradleyID));
if (player != null) {
ProcessAPCKills(player);
BradleyAttackers.Remove(BradleyID);
}
return;
}
if (hitinfo?.Initiator is BasePlayer) {
var player = hitinfo.Initiator as BasePlayer;
if (player.userID.IsSteamId() && !(player is NPCPlayer) && !(player is HTNPlayer)) {
if (entity.name.Contains("agents/")) ProcessPVEKill(player, entity);
else if (entity.name.Contains("barrel")) ProcessBarrelsDestroyed(player);
else if (!(entity is BasePlayer) && entity.name.Contains("turret")) ProcessWeaponTrapsDestroyed(player);
else if (entity.name.Contains("guntrap")) ProcessWeaponTrapsDestroyed(player);
else if (victim is BasePlayer && !victim.userID.IsSteamId()) ProcessNPCKills(player, victim);
else if (victim is BasePlayer && (victim is NPCPlayer || victim is HTNPlayer)) ProcessNPCKills(player, victim);
else if (victim is BasePlayer && victim.userID.IsSteamId()) {
ProcessDeath(victim);
if (hitinfo.Initiator != entity) ProcessPVPKill(player, victim);
if (victim.IsSleeping()) ProcessSleepersKilled(player, victim);
if (hitinfo.Initiator == entity) ProcessSuicide(player);
}
return;
}
}
if (victim == null) return;
if (victim is BasePlayer && !(victim is NPCPlayer) && !(victim is HTNPlayer)) ProcessDeath(victim);
if (woundedData.ContainsKey(victim.userID)) woundedData.Remove(victim.userID);
return;
}
void OnExplosiveThrown(BasePlayer player, BaseEntity entity, Item item) {
if (!(player.GetActiveItem().info.displayName.english == "Supply Signal")) ProcessExplosivesThrown(player);
}
void OnWeaponFired(BaseProjectile projectile, BasePlayer player, ItemModProjectile mod) {
if (mod.ToString().Contains("arrow")) ProcessArrowsFired(player);
if (mod.ToString().Contains("ammo")) ProcessBulletsFired(player);
}
void OnRocketLaunched(BasePlayer player)=>ProcessRocketsLaunched(player);
void OnEntityBuilt(Planner plan, GameObject objectBlock) {
if (conf.Options.useIntenseOptions) {
BasePlayer player = plan.GetOwnerPlayer();
if (player.GetActiveItem().info.displayName.english == "Building Plan") ProcessStructuresBuilt(player);
else ProcessItemsDeployed(player);
}
}
void OnStructureDemolish(BaseCombatEntity entity, BasePlayer player)=>ProcessStructuresDemolished(player);
void OnItemCraft(ItemCraftTask item) {
if (conf.Options.useIntenseOptions) {
BasePlayer crafter = item.owner;
if (crafter != null) ProcessItemsCrafted(crafter);
}
}
void OnStructureRepair(BaseCombatEntity entity, BasePlayer player) {
float before = 0, after = 0;
if (conf.Options.useIntenseOptions) {
if (entity.health != null) {
before = entity.health;
timer.Once(0.1f, ()=> {
after = entity.health;
if (!Mathf.Approximately(before, after)) ProcessEntitiesRepaired(player);
}
);
}
}
}
void OnHealingItemUse(HeldEntity item, BasePlayer target)=>ProcessTimesHealed(target);
void OnItemUse(Item item) {
BasePlayer player = item?.GetOwnerPlayer();
if (item.GetOwnerPlayer() == null) return;
if (player != null && item.info.displayName.english == "Large Medkit") ProcessTimesHealed(player);
if (item.info.shortname != "skull.human") return;
//credit redBDGR
string skullName = null;
if (item.name != null) skullName = item.name.Substring(10, item.name.Length - 11);
else return;
if (!player.displayName.Contains($"{skullName}")) //.contains is for [God] - UserID would be better here
ProcessSkullsCrushed(player);
}
void CanBeWounded(BasePlayer player, HitInfo hitInfo) {
if (player == null || hitInfo == null) return;
if (!(player.userID.IsSteamId()) || player is NPCPlayer || player is HTNPlayer) return;
var attacker = hitInfo.InitiatorPlayer;
if (attacker != null) {
if (attacker == player || IsFriend(attacker.userID, player.userID) || IsClanmate(attacker.userID, player.userID)) return;
woundedData[player.userID] = new WoundedData {
distance = Vector3.Distance(player.transform.position, attacker.transform.position), attackerId = attacker.userID
}
;
{
NextTick(() => {
if (player.IsWounded()) ProcessTimesWounded(player);
}
);
}
}
}
void OnPlayerRecover(BasePlayer player) {
if (woundedData.ContainsKey(player.userID)) woundedData.Remove(player.userID);
}
void OnStructureUpgrade(BaseCombatEntity entity, BasePlayer player, BuildingGrade.Enum grade)=>ProcessStructuresUpgraded(player);
void OnCollectiblePickup(Item item, BasePlayer player) {
if (conf.Options.useIntenseOptions) ProcessResourcesGathered(player, item.amount);
}
void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
if (conf.Options.useIntenseOptions) {
BasePlayer player = entity?.ToPlayer();
ProcessResourcesGathered(player, item.amount);
}
}
void OnEntitySpawned(BaseEntity entity) {
if (entity.name.Contains("supply_drop")) airdrops.Add(entity.net.ID);
}
void OnLootEntity(BasePlayer player, BaseEntity entity) {
if (airdrops.Contains(entity.net.ID)) {
airdrops.Remove(entity.net.ID);
ProcessDropsLooted(player);
}
}
#region processes
bool ProcessChecks(BasePlayer player) {
if(!conf.Options.statCollection) return false;
if (conf.Options.blockEvents) if (CheckEvents(player))return false;
return data.PlayerRankData.ContainsKey(player.userID);
}
bool FriendCheck(BasePlayer player, BasePlayer victim) {
if (victim != null) {
if (conf.Options.useClans && IsClanmate(player.userID, victim.userID)) return true;
if (conf.Options.useFriendsAPI && IsFriend(player.userID, victim.userID)) return true;
if (conf.Options.useRustIO && HasFriend(player.userID.ToString(), victim.userID.ToString())) return true;
}
return false;
}
void ProcessPVPKill(BasePlayer player, BasePlayer victim) {
if (FriendCheck(player, victim)) return;
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].PVPKills++;
if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVPDistance) data.PlayerRankData[player.userID].PVPDistance = Math.Round(victim.Distance(player.transform.position), 2);
if ((data.PlayerRankData[player.userID].Deaths) > 0) {
var KDR = Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
}
else data.PlayerRankData[player.userID].KDR = (data.PlayerRankData[player.userID].PVPKills);
}
}
void ProcessPVEKill(BasePlayer player, BaseEntity victim) {
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].PVEKills++;
if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVEDistance) data.PlayerRankData[player.userID].PVEDistance = Math.Round(victim.Distance(player.transform.position), 2);
}
}
void ProcessNPCKills(BasePlayer player, BaseEntity victim) {
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].NPCKills++;
if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].NPCDistance) data.PlayerRankData[player.userID].NPCDistance = Math.Round(victim.Distance(player.transform.position), 2);
}
}
void ProcessSleepersKilled(BasePlayer player, BaseEntity victim) {
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].SleepersKilled++;
if (victim.Distance(player.transform.position) > data.PlayerRankData[player.userID].PVPDistance) data.PlayerRankData[player.userID].PVPDistance = Math.Round(victim.Distance(player.transform.position), 2);
}
}
void ProcessHeadShot(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].HeadShots++;
}
void ProcessDeath(BasePlayer player) {
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].Deaths++;
var SDR = Convert.ToDouble(data.PlayerRankData[player.userID].Suicides) / (data.PlayerRankData[player.userID].Deaths);
data.PlayerRankData[player.userID].SDR = Math.Round(SDR, 2);
var KDR = Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
}
}
void ProcessSuicide(BasePlayer player) {
if (ProcessChecks(player)) {
data.PlayerRankData[player.userID].Suicides++;
if ((data.PlayerRankData[player.userID].Deaths) > 0) {
var SDR = Convert.ToDouble(data.PlayerRankData[player.userID].Suicides) / (data.PlayerRankData[player.userID].Deaths);
data.PlayerRankData[player.userID].SDR = Math.Round(SDR, 2);
var KDR = Convert.ToDouble(data.PlayerRankData[player.userID].PVPKills) / (data.PlayerRankData[player.userID].Deaths);
data.PlayerRankData[player.userID].KDR = Math.Round(KDR, 2);
}
else {
data.PlayerRankData[player.userID].SDR = (data.PlayerRankData[player.userID].Suicides);
data.PlayerRankData[player.userID].KDR = (data.PlayerRankData[player.userID].PVPKills);
}
}
}
void ProcessSkullsCrushed(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].SkullsCrushed++;
}
void ProcessTimesWounded(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].TimesWounded++;
}
void ProcessTimesHealed(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].TimesHealed++;
}
void ProcessHeliHits(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].HeliHits++;
}
void ProcessHeliKills(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].HeliKills++;
}
void ProcessAPCHits(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].APCHits++;
}
void ProcessAPCKills(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].APCKills++;
}
void ProcessBarrelsDestroyed(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].BarrelsDestroyed++;
}
void ProcessExplosivesThrown(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].ExplosivesThrown++;
}
void ProcessArrowsFired(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].ArrowsFired++;
}
void ProcessBulletsFired(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].BulletsFired++;
}
void ProcessRocketsLaunched(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].RocketsLaunched++;
}
void ProcessWeaponTrapsDestroyed(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].WeaponTrapsDestroyed++;
}
void ProcessDropsLooted(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].DropsLooted++;
}
void ProcessStructuresBuilt(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].StructuresBuilt++;
}
void ProcessStructuresDemolished(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].StructuresDemolished++;
}
void ProcessItemsDeployed(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].ItemsDeployed++;
}
void ProcessItemsCrafted(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].ItemsCrafted++;
}
void ProcessEntitiesRepaired(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].EntitiesRepaired++;
}
void ProcessResourcesGathered(BasePlayer player, int amount = 0) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].ResourcesGathered+=amount;
}
void ProcessStructuresUpgraded(BasePlayer player) {
if (ProcessChecks(player)) data.PlayerRankData[player.userID].StructuresUpgraded++;
}
void BroadcastToAll(string msg, string keyword) => PrintToChat(conf.GUI.fontColor1 + keyword + " </color>" + conf.GUI.fontColor2 + msg + "</color>");
bool IsClanmate(ulong playerId, ulong friendId) {
if (!Clans || !conf.Options.useClans) return false;
object playerTag = Clans?.Call("GetClanOf", playerId);
object friendTag = Clans?.Call("GetClanOf", friendId);
if (playerTag is string && friendTag is string) if (playerTag == friendTag) return true;
return false;
}
bool IsFriend(ulong playerID, ulong friendID) {
if (!Friends || !conf.Options.useFriendsAPI) return false;
bool isFriend = (bool)Friends?.Call("IsFriend", playerID, friendID);
return isFriend;
}
bool CheckEvents(BasePlayer player) {
object isPlaying = EventManager?.Call("isPlaying", new object[] {
player
}
);
if (isPlaying is bool) if ((bool)isPlaying) return true;
return false;
}
#endregion
void PersonalAndCategoryUI(BasePlayer player, string personalStatsCat, string personalStatsVal, string pageTitle) {
string guiString = String.Format("0.1 0.1 0.1 {0}", conf.GUI.guitransparency);
var elements = new CuiElementContainer();
var buttonColour = conf.GUI.buttonColour;
var mainName = elements.Add(new CuiPanel {
Image = {
Color = guiString
}
, RectTransform = {
AnchorMin = "0.1 0.12", AnchorMax = "0.9 0.98"
}
, CursorEnabled = true, FadeOut = 0.1f
}
, "Overlay", "ranksgui");
elements.Add(new CuiElement {
Parent = "ranksgui", Components = {
new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
}
);
elements.Add(new CuiButton {
Button = {
Command = $"CallPersonalStatsUI true", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.03 0.95", AnchorMax = "0.22 0.98"
}
, Text = {
Text = lang.GetMessage("mystats", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = $"CallLeaderBoardUI true", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.27 0.95", AnchorMax = "0.47 0.98"
}
, Text = {
Text = lang.GetMessage("leaderboard", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = $"CallCategoriesUI", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.53 0.95", AnchorMax = "0.72 0.98"
}
, Text = {
Text = lang.GetMessage("categories", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
if (HasPermission(player.UserIDString, permAllowed)) elements.Add(new CuiButton {
Button = {
Command = $"CallAdminUI", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.77 0.95", AnchorMax = "0.97 0.98"
}
, Text = {
Text = lang.GetMessage("admin", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiLabel {
Text = {
Text = pageTitle, FontSize = 20, Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = "0 0.88", AnchorMax = "1 0.92"
}
}
, mainName);
elements.Add(new CuiLabel {
Text = {
Text = personalStatsCat, FontSize = 12, Align = TextAnchor.MiddleRight
}
, RectTransform = {
AnchorMin = "0.1 0.10", AnchorMax = "0.48 0.88"
}
}
, mainName);
elements.Add(new CuiLabel {
Text = {
Text = personalStatsVal, FontSize = 12, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = "0.52 0.10", AnchorMax = "0.9 0.88"
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = "Close", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.082"
}
, Text = {
Text = lang.GetMessage("close", this, player.UserIDString), FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, mainName);
CuiHelper.AddUi(player, elements);
}
void CategoriesUI(BasePlayer player, string pageTitle) {
string guiString = String.Format("0.1 0.1 0.1 {0}", conf.GUI.guitransparency);
var elements = new CuiElementContainer();
var buttonColour = conf.GUI.buttonColour;
var mainName = elements.Add(new CuiPanel {
Image = {
Color = guiString
}
, RectTransform = {
AnchorMin = "0.1 0.12", AnchorMax = "0.9 0.98"
}
, CursorEnabled = true, FadeOut = 0.1f
}
, "Overlay", "ranksgui");
elements.Add(new CuiElement {
Parent = "ranksgui", Components = {
new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
}
);
elements.Add(new CuiButton {
Button = {
Command = $"CallPersonalStatsUI true", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.03 0.95", AnchorMax = "0.22 0.98"
}
, Text = {
Text = lang.GetMessage("mystats", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = $"CallLeaderBoardUI true", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.27 0.95", AnchorMax = "0.47 0.98"
}
, Text = {
Text = lang.GetMessage("leaderboard", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = null, Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.53 0.95", AnchorMax = "0.72 0.98"
}
, Text = {
Text = lang.GetMessage("categories", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
if (HasPermission(player.UserIDString, permAllowed)) elements.Add(new CuiButton {
Button = {
Command = $"CallAdminUI false", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.77 0.95", AnchorMax = "0.97 0.98"
}
, Text = {
Text = lang.GetMessage("admin", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
var buttonTop = 0.853;
var buttonBottom = 0.873;
foreach (var cat in allowedCats) {
if (cat.Value == true) {
elements.Add(new CuiButton {
Button = {
Command = $"GetCategory {cat.Key}", Color = "0.7 0.32 0.17 0.0"
}
, RectTransform = {
AnchorMin = $"0.3 {buttonTop}", AnchorMax = $"0.7 {buttonBottom}"
}
, Text = {
Text = lang.GetMessage(cat.Key, this), FontSize = 12, Align = TextAnchor.MiddleCenter
}
}
, mainName);
buttonTop = buttonTop - 0.021;
buttonBottom = buttonBottom - 0.021;
}
}
elements.Add(new CuiLabel {
Text = {
Text = pageTitle, FontSize = 20, Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = "0 0.88", AnchorMax = "1 0.92"
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = "Close", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.4 0.02", AnchorMax = "0.6 0.082"
}
, Text = {
Text = lang.GetMessage("close", this, player.UserIDString), FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, mainName);
CuiHelper.AddUi(player, elements);
}
void LeaderBoardUI(BasePlayer player, string leaderBoardCat, string leaderBoardName, string leaderBoardScore, string pageTitle) {
string guiString = String.Format("0.1 0.1 0.1 {0}", conf.GUI.guitransparency);
var elements = new CuiElementContainer();
var buttonColour = conf.GUI.buttonColour;
var mainName = elements.Add(new CuiPanel {
Image = {
Color = guiString
}
, RectTransform = {
AnchorMin = "0.1 0.12", AnchorMax = "0.9 0.98"
}
, CursorEnabled = true, FadeOut = 0.1f
}
, "Overlay", "ranksgui");
elements.Add(new CuiElement {
Parent = "ranksgui", Components = {
new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
}
);
elements.Add(new CuiButton {
Button = {
Command = $"CallPersonalStatsUI true", Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.03 0.95", AnchorMax = "0.22 0.98"
}
, Text = {
Text = lang.GetMessage("mystats", this, player.UserIDString), FontSize = 16, Align = TextAnchor.MiddleCenter
}
}
, mainName);
elements.Add(new CuiButton {
Button = {
Command = null, Color = buttonColour
}
, RectTransform = {
AnchorMin = "0.27 0.9
// ... [Code preview truncated due to length. Full source in attached file] ...