C#:
using Rust;
using UnityEngine;
using Oxide.Core.Libraries;
using System.Collections;
using System.Linq;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine.Networking;
using System.Text.RegularExpressions;
using System.Globalization;
using System;
namespace Oxide.Plugins {
[Info("XDStatistics", "Sempai#3239", "2.3.3")]
[Description("Multifunctional statistics for your server!")]
class XDStatistics : RustPlugin {
private void SaveDataIgnoreList() => Interface.Oxide.DataFileSystem.WriteObject("XDStatistics/IgnorePlayers", IgnoreReservedPlayer);
private string GetImage(string shortname, ulong skin = 0) => (string)ImageLibrary?.Call("GetImage", shortname, skin);
private void SendImage(BasePlayer player, string imageName, ulong imageId = 0) => ImageLibrary?.Call("SendImage", player, imageName, imageId);
private void LoadData() => Players = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, PlayerInfo>>("XDStatistics/StatsUser");
public static Dictionary<String, String> KeyImages = new Dictionary<string, string>() {
{
"1", "https://i.ibb.co/cD6gHhT/1.png"
}
, {
"2", "https://i.ibb.co/xY2P00h/2.png"
}
, {
"3", "https://i.ibb.co/rvttQ2V/3.png"
}
, {
"4", "https://i.ibb.co/sbZW9r7/4.png"
}
, {
"5", "https://i.ibb.co/vzwS5xJ/5.png"
}
, {
"6", "https://i.ibb.co/QvHFDLh/6.png"
}
, {
"7", "https://i.ibb.co/Gf6rdrP/7.png"
}
, {
"8", "https://i.ibb.co/rGxcvtn/8.png"
}
, {
"9", "https://i.ibb.co/bNfPM93/9.png"
}
, {
"10", "https://i.ibb.co/qyS5fYj/10.png"
}
, {
"11", "https://i.ibb.co/hyr3nDm/11.png"
}
, {
"12", "https://i.ibb.co/Xk6P3W6/12.png"
}
, {
"13", "https://i.ibb.co/K9BTZ77/13.png"
}
, {
"14", "https://i.ibb.co/RptKqfK/14.png"
}
, {
"15", "https://i.ibb.co/z73GKWC/15.png"
}
, {
"16", "https://i.ibb.co/mB4JJbQ/16.png"
}
, {
"17", "https://i.ibb.co/RcKr3jf/17.png"
}
, {
"18", "https://i.ibb.co/mhbW5LY/18.png"
}
, {
"19", "https://i.ibb.co/3v4f7f6/19.png"
}
, {
"20", "https://i.ibb.co/dDsDHNS/20.png"
}
}
;
private class Field {
public Field(string name, string value, bool inline) {
Name = name;
Value = value;
Inline = inline;
}
[JsonProperty("name")]
public string Name {
get;
set;
}
[JsonProperty("value")]
public string Value {
get;
set;
}
[JsonProperty("inline")]
public bool Inline {
get;
set;
}
}
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["STAT_TOP_FIVE_KILL"]
= "Top 5 <color=#4286f4>Killers</color>\n{0}</size>", ["STAT_TOP_FIVE_KILL_NPC"] = "Top 5 <color=#4286f4>NPC killers</color>\n{0}</size>", ["STAT_TOP_FIVE_FARM"] = "Top 5 <color=#4286f4>Farmers</color>\n{0}</size>", ["STAT_TOP_FIVE_EXPLOSION"] = "Top 5 <color=#4286f4>Explosions</color>\n{0}</size>", ["STAT_TOP_FIVE_TIMEPLAYED"] = "Top 5 <color=#4286f4>Most Time Played</color>\n{0}</size>", ["STAT_TOP_FIVE_BUILDINGS"] = "Top 5 <color=#4286f4>Builders</color>\n{0}</size>", ["STAT_TOP_FIVE_SCORE"] = "Top 5 <color=#4286f4>Most points</color>\n{0}</size>", ["STAT_TOP_FIVE_FERMER"] = "Top 5 <color=#4286f4>Farmers</color>\n{0}</size>", ["STAT_USER_TOTAL_GATHERED"] = "Total Gathered:", ["STAT_USER_TOTAL_EXPLODED"] = "Total Explosions:", ["STAT_USER_TOTAL_GROWED"] = "Total Farmed:", ["STAT_UI_MY_STAT"] = "My Statistics", ["STAT_UI_TOP_TEN"] = "Top 10 Players", ["STAT_UI_SEARCH"] = "Search", ["STAT_UI_INFO"] = "Player Information {0}", ["STAT_UI_ACTIVITY"] = "Activity", ["STAT_UI_ACTIVITY_TODAY"] = "Today: {0}", ["STAT_UI_ACTIVITY_TOTAL"] = "All Time: {0}", ["STAT_UI_SETTINGS"] = "Settings", ["STAT_UI_PLACE_TOP"] = "Place On Top: {0}", ["STAT_UI_SCORE"] = "Score: {0}", ["STAT_UI_PVP"] = "PvP Statistics", ["STAT_UI_FAVORITE_WEAPON"] = "Favorite Weapon", ["STAT_UI_PVP_KILLS"] = "Kills", ["STAT_UI_PVP_KILLS_NPC"] = "Kills NPC", ["STAT_UI_PVP_DEATH"] = "Deaths", ["STAT_UI_PVP_KDR"] = "K/D", ["STAT_UI_FAVORITE_WEAPON_KILLS"] = "Kills: {0}\nHits: {1}", ["STAT_UI_FAVORITE_WEAPON_NOT_DATA"] = "Data is still being calculated..", ["STAT_UI_OTHER_STAT"] = "Other Statistics", ["STAT_UI_HIDE_STAT"] = "Public Profile", ["STAT_UI_CONFIRM"] = "Are You Sure?", ["STAT_UI_CONFIRM_YES"] = "Yes", ["STAT_UI_CONFIRM_NO"] = "No", ["STAT_UI_RESET_STAT"] = "Reset Statistics", ["STAT_UI_CRATE_OPEN"] = "Crates Opened: {0}", ["STAT_UI_BARREL_KILL"] = "Barrels Destroyed: {0}", ["STAT_UI_ANIMAL_KILL"] = "Animal Kills: {0}", ["STAT_UI_HELI_KILL"] = "Helicopter Kills: {0}", ["STAT_UI_BRADLEY_KILL"] = "Bradley Kills: {0}", ["STAT_UI_NPC_KILL"] = "NPC Kills: {0}", ["STAT_UI_BTN_MORE"] = "Show More", ["STAT_UI_CATEGORY_GATHER"] = "Gather", ["STAT_UI_CATEGORY_EXPLOSED"] = "Explosions", ["STAT_UI_CATEGORY_PLANT"] = "Farming", ["STAT_UI_CATEGORY_TOP_KILLER"] = "Top 10 Killers", ["STAT_UI_CATEGORY_TOP_KILLER_ANIMALS"] = "Top 10 Animal Killers", ["STAT_UI_CATEGORY_TOP_NPCKILLER"] = "Top 10 NPC Killers", ["STAT_UI_CATEGORY_TOP_TIME"] = "Top 10 Most Time Played", ["STAT_UI_CATEGORY_TOP_GATHER"] = "Top 10 Gatherers", ["STAT_UI_CATEGORY_TOP_SCORE"] = "Top 10 Most Score", ["STAT_UI_CATEGORY_TOP_EXPLOSED"] = "Top 10 Explosions", ["STAT_PRINT_WIPE"] = "Wipe Detected.Data was successfully cleared!", ["STAT_CMD_1"] = "No Permission!!", ["STAT_CMD_2"] = "Usage: stat.ignore <add/remove> <Steam ID|Name>", ["STAT_CMD_3"] = "The specified playername could not be found.Please use their SteamID.", ["STAT_CMD_4"] = "Found several players with similar names: {0}", ["STAT_CMD_5"] = "Player not found!", ["STAT_CMD_6"] = "Player {0} is already ignored", ["STAT_CMD_7"] = "You have successfully added a player {0} to the ignore list", ["STAT_CMD_8"] = "The player {0} is not in the ignore list", ["STAT_CMD_9"] = "You have successfully removed the player {0} from the ignore list", ["STAT_CMD_10"] = "Player {0} successfully credited {1} score", ["STAT_CMD_11"] = "Player {0} successfully removed {1} score", ["STAT_ADMIN_HIDE_STAT"] = "You've been added to the ignore list.You will not have access to the statistics.If this is an error, Please contact the Administrator!", ["STAT_TOP_PLAYER_WIPE_SCORE"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>HIGHEST SCORE</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_TIME"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>MOST TIME PLAYED</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_EXP"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>MOST EXPLOSIONS</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_FARM"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>MOST CROPS FARMED</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_KILL"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>MOST KILLS</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_KILL_NPC"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>NPC Killer</color>\nYou received a well deserved Reward!", ["STAT_TOP_PLAYER_WIPE_KILL_ANIMAL"] = "Congratulations!\nYou successfully held the {0} position in the previous wipe in the category <color=#4286f4>ANIMAL Killer</color>\nYou received a well deserved Reward!", ["STAT_TOP_VK_SCORE"] = "Топ {0} игрока по очкам\n {1}", ["STAT_TOP_VK_KILLER"] = "Топ {0} игрока по убийствам\n {1}", ["STAT_TOP_VK_TIME"] = "Топ {0} игрока по онлайну\n {1}", ["STAT_TOP_VK_FARM"] = "Топ {0} игрока по фарму\n {1}", ["STAT_TOP_VK_RAID"] = "Топ {0} игрока по рейдам\n {1}", ["STAT_TOP_VK_KILLER_NPC"] = "Топ {0} игрока по убийствам NPC\n {1}", ["STAT_TOP_VK_KILLER_ANIMAL"] = "Топ {0} игрока по убийствам животных\n {1}",
}
, this);
lang.RegisterMessages(new Dictionary<string, string> {
["STAT_TOP_FIVE_KILL"]
= "Топ 5 <color=#4286f4>киллеры</color>\n{0}</size>", ["STAT_TOP_FIVE_KILL_NPC"] = "Топ 5 <color=#4286f4>убийцы NPC</color>\n{0}</size>", ["STAT_TOP_FIVE_FARM"] = "Топ 5 <color=#4286f4>фармеры</color>\n{0}</size>", ["STAT_TOP_FIVE_EXPLOSION"] = "Топ 5 <color=#4286f4>рейдеры</color>\n{0}</size>", ["STAT_TOP_FIVE_TIMEPLAYED"] = "Топ 5 <color=#4286f4>долгожителей</color>\n{0}</size>", ["STAT_TOP_FIVE_BUILDINGS"] = "Топ 5 <color=#4286f4>строители</color>\n{0}</size>", ["STAT_TOP_FIVE_SCORE"] = "Топ 5 по <color=#4286f4>очкам</color>\n{0}</size>", ["STAT_TOP_FIVE_FERMER"] = "Топ 5 <color=#4286f4>фермеров</color>\n{0}</size>", ["STAT_USER_TOTAL_GATHERED"] = "Всего добыто:", ["STAT_USER_TOTAL_EXPLODED"] = "Всего взорвано:", ["STAT_USER_TOTAL_GROWED"] = "Всего выращено:", ["STAT_UI_MY_STAT"] = "Моя Статистика", ["STAT_UI_TOP_TEN"] = "Топ 10 игроков", ["STAT_UI_SEARCH"] = "Поиск", ["STAT_UI_INFO"] = "Информация о профиле {0}", ["STAT_UI_ACTIVITY"] = "Активность", ["STAT_UI_ACTIVITY_TODAY"] = "Сегодня: {0}", ["STAT_UI_ACTIVITY_TOTAL"] = "За все время: {0}", ["STAT_UI_SETTINGS"] = "Настройки", ["STAT_UI_PLACE_TOP"] = "Место в топе: {0}", ["STAT_UI_SCORE"] = "SCORE: {0}", ["STAT_UI_PVP"] = "PVP статистика", ["STAT_UI_FAVORITE_WEAPON"] = "Фаворитное оружие", ["STAT_UI_PVP_KILLS"] = "Убийств", ["STAT_UI_PVP_KILLS_NPC"] = "Убийств NPC", ["STAT_UI_PVP_DEATH"] = "Смертей", ["STAT_UI_PVP_KDR"] = "K/D", ["STAT_UI_FAVORITE_WEAPON_KILLS"] = "Убийств: {0}\nПопаданий: {1}", ["STAT_UI_FAVORITE_WEAPON_NOT_DATA"] = "Данные еще собираются...", ["STAT_UI_OTHER_STAT"] = "Другая статистика", ["STAT_UI_HIDE_STAT"] = "Общедоступный профиль", ["STAT_UI_CONFIRM"] = "Вы уверены ?", ["STAT_UI_CONFIRM_YES"] = "Да", ["STAT_UI_CONFIRM_NO"] = "Нет", ["STAT_UI_RESET_STAT"] = "Обнулить статистику", ["STAT_UI_CRATE_OPEN"] = "Открыто ящиков: {0}", ["STAT_UI_BARREL_KILL"] = "Разбито бочек: {0}", ["STAT_UI_ANIMAL_KILL"] = "Убито животных: {0}", ["STAT_UI_HELI_KILL"] = "Сбито вертолетов: {0}", ["STAT_UI_BRADLEY_KILL"] = "Танков уничтожено: {0}", ["STAT_UI_NPC_KILL"] = "Убито NPC: {0}", ["STAT_UI_BTN_MORE"] = "Показать еще", ["STAT_UI_CATEGORY_GATHER"] = "Добыча", ["STAT_UI_CATEGORY_EXPLOSED"] = "Взрывчатка", ["STAT_UI_CATEGORY_PLANT"] = "Фермерство", ["STAT_UI_CATEGORY_TOP_KILLER"] = "Топ 10 киллеров", ["STAT_UI_CATEGORY_TOP_KILLER_ANIMALS"] = "Топ 10 убийц животных", ["STAT_UI_CATEGORY_TOP_NPCKILLER"] = "Топ 10 убийц npc", ["STAT_UI_CATEGORY_TOP_TIME"] = "Топ 10 по онлайну", ["STAT_UI_CATEGORY_TOP_GATHER"] = "Топ 10 фармил", ["STAT_UI_CATEGORY_TOP_SCORE"] = "Топ 10 по очкам", ["STAT_UI_CATEGORY_TOP_EXPLOSED"] = "Топ 10 рейдеров", ["STAT_PRINT_WIPE"] = "Произошел вайп.Данные успешно удалены!", ["STAT_CMD_1"] = "Недостаточно прав!", ["STAT_CMD_2"] = "Используйте: stat.ignore <add/remove> <Steam ID|Имя>", ["STAT_CMD_3"] = "Указанный игрок не найден.Для более точного поиска укажите его SteamID.", ["STAT_CMD_4"] = "Найдено несколько игроков с похожим именем: {0}", ["STAT_CMD_5"] = "Игрок не найден!", ["STAT_CMD_6"] = "Игрок {0} уже игнорируется", ["STAT_CMD_7"] = "Вы успешно добавили игрока {0} в игнор лист", ["STAT_CMD_8"] = "Игрока {0} нет в списке игнорируемых", ["STAT_CMD_9"] = "Вы успешно убрали игрока {0} из игнор листа", ["STAT_CMD_10"] = "Игроку {0} успешно зачислено {1} очков", ["STAT_CMD_11"] = "Игроку {0} успешно снято {1} очков", ["STAT_ADMIN_HIDE_STAT"] = "Вы добавлены в игнор лист.У вас нет доступа к статистики, если это ошибка, свяжитесь с администратором!", ["STAT_TOP_PLAYER_WIPE_SCORE"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>SCORE</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_TIME"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Долгожитель</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_EXP"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Рейдер</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_FARM"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Добытчик</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_KILL"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Киллер</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_KILL_NPC"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Убийца нпс</color>\nВы заслужено получаете награду!", ["STAT_TOP_PLAYER_WIPE_KILL_ANIMAL"] = "Поздравляю!\nВ прошлом вайпе вы успешно удерживали {0} позицию в категории <color=#4286f4>Убийца животных</color>\nВы заслужено получаете награду!", ["STAT_TOP_VK_SCORE"] = "Топ {0} игрока по очкам\n {1}", ["STAT_TOP_VK_KILLER"] = "Топ {0} игрока по убийствам\n {1}", ["STAT_TOP_VK_TIME"] = "Топ {0} игрока по онлайну\n {1}", ["STAT_TOP_VK_FARM"] = "Топ {0} игрока по фарму\n {1}", ["STAT_TOP_VK_RAID"] = "Топ {0} игрока по рейдам\n {1}", ["STAT_TOP_VK_KILLER_NPC"] = "Топ {0} игрока по убийствам NPC\n {1}", ["STAT_TOP_VK_KILLER_ANIMAL"] = "Топ {0} игрока по убийствам животных\n {1}",
}
, this, "ru");
}
public static StringBuilder sb;
private enum CatType {
score, killer, time, farm, raid, killerNPC, killerAnimal
}
private void OnPlayerConnected(BasePlayer player) {
if (!IgnoreReservedPlayer.ContainsKey(player.userID)) {
var dataPlayer = PlayerInfo.Find(player.userID);
dataPlayer.Name = CleanString(player.displayName);
if (dataPlayer.playedTime.DayNumber != DateTime.Now.ToShortDateString()) {
dataPlayer.playedTime.PlayedToday = 0;
dataPlayer.playedTime.DayNumber = DateTime.Now.ToShortDateString();
}
}
if (PrizePlayerData.ContainsKey(player.userID)) SendMsgRewardWipe(player);
SteamAvatarAdd(player.UserIDString);
}
private void CloseLayer(BasePlayer player) {
CuiHelper.DestroyUi(player, UI_USER_STAT);
CuiHelper.DestroyUi(player, UI_SEARCH_USER);
CuiHelper.DestroyUi(player, UI_TOP_TEN_USER);
}
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) {
try {
if (entity == null || info == null) return;
BasePlayer player = null;
if (entity is BaseHelicopter) {
uint id = entity.net.ID;
if (!_heliattacker.ContainsKey(id)) return;
player = BasePlayer.FindByID(_heliattacker[id]);
if (player == null) return;
PlayerInfo Playerstat = PlayerInfo.Find(player.userID);
Playerstat.pVP.HeliKill++;
Playerstat.Score += _config.settingsScore.HeliScore;
_heliattacker.Remove(id);
return;
}
if (info.InitiatorPlayer != null) player = info.InitiatorPlayer;
if (player == null || !player.userID.IsSteamId()) return;
PlayerInfo Playerstat2 = PlayerInfo.Find(player.userID);
if (entity is ScientistNPC) {
Playerstat2.pVP.KillsNpc++;
Playerstat2.Score += _config.settingsScore.NpcScore;
if (_config.settings.npsDeathUse) WeaponProgressAdd(Playerstat2, info, true);
return;
}
if (entity is BaseAnimalNPC) {
Playerstat2.otherStat.AnimalsKill++;
Playerstat2.Score += _config.settingsScore.AnimalScore;
return;
}
if (entity is BradleyAPC) {
Playerstat2.pVP.BradleyKill++;
Playerstat2.Score += _config.settingsScore.BradleyScore;
return;
}
}
catch (NullReferenceException ex) {
}
}
private void OnDispenserBonus(ResourceDispenser dispenser, BaseEntity entity, Item item) {
BasePlayer player = entity.ToPlayer();
if (player == null) return;
ProgressAdd(player, item.info.shortname, item.amount, true);
}
public static string CleanString(string str, string sub = "") {
if (str == null) return null;
StringBuilder sb = null;
for (int i = 0; i < str.Length; i++) {
char ch = str[i];
if (char.IsSurrogate(ch)) {
if (sb == null) sb = new StringBuilder(str, 0, i, str.Length);
sb.Append(sub);
if (i + 1 < str.Length && char.IsHighSurrogate(ch) && char.IsLowSurrogate(str[i + 1])) i++;
}
else if (sb != null) sb.Append(ch);
}
return sb == null ? str : sb.ToString();
}
private void DiscordPrintTopFive() {
var data = GetRandomTopPlayer();
SendDiscordMessage(Regex.Replace(lang.GetMessage(data.Item1, this), "<.*?>|{.*?}", string.Empty), new List<string> {
data.Item2
}
, false);
timer.Once(_config.discordMessage.discordSendTopTime, DiscordPrintTopFive);
}
private List<int> AlowedSeedId = new List<int>() {
1548091822, 1771755747, 1112162468, 1367190888, 858486327, -1962971928, -2086926071, -567909622, 1272194103, 854447607, 1660145984, 1783512007, -858312878
}
;
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
BasePlayer player = entity.ToPlayer();
if (player == null) return;
ProgressAdd(player, item.info.shortname, item.amount);
}
private bool IsDuel(ulong userID) {
if (Battles) return (bool)Battles?.Call("IsPlayerOnBattle", userID);
else if (Duel) return (bool)Duel?.Call("IsPlayerOnActiveDuel", BasePlayer.FindByID(userID));
else return false;
}
private void OnItemCraftFinished(ItemCraftTask task, Item item) {
PlayerInfo Player = PlayerInfo.Find(task.owner.userID);
Player.otherStat.AllCraft += item.amount;
Player.Score += _config.settingsScore.craftScore;
}
private void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("XDStatistics/StatsUser", Players);
private readonly Regex _avatarRegex = new Regex(@"<avatarFull><!\[CDATA\[(.*)\]\]></avatarFull>", RegexOptions.Compiled);
Int32 GetTopScore(ulong userid) {
Int32 Top = 1;
var RaitingNumber = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.Score);
foreach (var Data in RaitingNumber) {
if (Data.Key == userid) break;
Top++;
}
return Top;
}
public const string UI_INTERFACE = "INTERFACE_STATS";
void OnItemPickup(Item item, BasePlayer player) {
if (item == null || item.skin != 2352567) return;
item.skin = 0;
if (item.info.shortname == "scrap") ProgressAdd(player, item.info.shortname, item.amount);
}
private IEnumerator ParseTopUserForPrize() {
PrizePlayerData.Clear();
List<CatType> catTypes = new List<CatType> {
CatType.score, CatType.killer, CatType.time, CatType.farm, CatType.raid, CatType.killerNPC, CatType.killerAnimal
}
;
foreach (var cat in catTypes) {
switch (cat) {
case CatType.score : {
int countReward = _config.settingsPrize.prizeScore.Count;
if (countReward != 0) {
var score = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.Score).Take(countReward);
int top = 1;
foreach (var item in score) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = (int)item.Value.Score, top = top
}
);
_config.settingsPrize.prizeScore.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.killer : {
int countReward = _config.settingsPrize.prizeKiller.Count;
if (countReward != 0) {
var killer = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.pVP.Kills).Take(countReward);
int top = 1;
foreach (var item in killer) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = (int)item.Value.pVP.Kills, top = top
}
);
_config.settingsPrize.prizeKiller.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.time : {
int countReward = _config.settingsPrize.prizeTime.Count;
if (countReward != 0) {
var time = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.playedTime.PlayedForWipe).Take(countReward);
int top = 1;
foreach (var item in time) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = (int)item.Value.playedTime.PlayedForWipe, top = top
}
);
_config.settingsPrize.prizeTime.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.farm : {
int countReward = _config.settingsPrize.prizeFarm.Count;
if (countReward != 0) {
var farm = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.gather.AllGathered).Take(countReward);
int top = 1;
foreach (var item in farm) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = item.Value.gather.AllGathered, top = top
}
);
_config.settingsPrize.prizeFarm.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.raid : {
int countReward = _config.settingsPrize.prizeRaid.Count;
if (countReward != 0) {
var raid = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.explosion.AllExplosionUsed).Take(countReward);
int top = 1;
foreach (var item in raid) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = item.Value.explosion.AllExplosionUsed, top = top
}
);
_config.settingsPrize.prizeRaid.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.killerNPC : {
int countReward = _config.settingsPrize.prizeNPCKiller.Count;
if (countReward != 0) {
var killerNpc = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.pVP.KillsNpc).Take(countReward);
int top = 1;
foreach (var item in killerNpc) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = item.Value.pVP.KillsNpc, top = top
}
);
_config.settingsPrize.prizeNPCKiller.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
case CatType.killerAnimal : {
int countReward = _config.settingsPrize.prizeAnimalKiller.Count;
if (countReward != 0) {
var killerAnimal = Players.Where(x => !_config.settings.ignoreList.Contains(x.Key)).OrderByDescending(x => x.Value.otherStat.AnimalsKill).Take(countReward);
int top = 1;
foreach (var item in killerAnimal) {
if (!PrizePlayerData.ContainsKey(item.Key)) {
PrizePlayerData.Add(item.Key, new List<PrizePlayer>());
}
var player = PrizePlayerData[item.Key];
player.Add(new PrizePlayer {
catType = cat, Name = item.Value.Name, value = item.Value.otherStat.AnimalsKill, top = top
}
);
_config.settingsPrize.prizeAnimalKiller.Find(x => x.top == top)?.GiftPrizePlayer(item.Key.ToString());
top++;
yield return CoroutineEx.waitForSeconds(0.02f);
}
}
break;
}
default : break;
}
}
rewardPlayerCoroutine = null;
SaveDataPrize();
if (_config.settings.wipeData) {
PlayerInfo.ClearDataWipe();
NextTick(() => {
SaveData();
SaveDataIgnoreList();
}
);
PrintWarning(GetLang("STAT_PRINT_WIPE"));
}
}
private void OnPlayerAttack(BasePlayer attacker, HitInfo hitinfo) {
if (hitinfo == null || attacker == null || hitinfo.HitEntity == null || !attacker.IsConnected) return;
if ((hitinfo.HitEntity is ScientistNPC && _config.settings.npsDeathUse) || (hitinfo.HitEntity is BasePlayer && (hitinfo.HitEntity as BasePlayer).userID.IsSteamId())) {
if (hitinfo.HitEntity == attacker) return;
PlayerInfo PlayerstatInitiator = PlayerInfo.Find(attacker.userID);
WeaponProgressAdd(PlayerstatInitiator, hitinfo);
PlayerstatInitiator.pVP.Shots++;
if (hitinfo.isHeadshot) PlayerstatInitiator.pVP.Headshots++;
}
}
private void OnExplosiveThrown(BasePlayer player, BaseEntity entity, ThrownWeapon item) {
if (player == null || item == null) return;
ExplosionProgressAdd(player, entity);
}
private class DiscordMessage {
public DiscordMessage(string content, params Embed[] embeds) {
Content = content;
Embeds = embeds.ToList();
}
[JsonProperty("content")]
public string Content {
get;
set;
}
[JsonProperty("embeds")]
public List<Embed> Embeds {
get;
set;
}
public string ToJson() {
return JsonConvert.SerializeObject(this);
}
}
private void CategoryStatUser(BasePlayer player, ulong target = 0, int cat = 0) {
var container = new CuiElementContainer();
PlayerInfo statInfo = PlayerInfo.Find(target == 0 ? player.userID : target);
var list = GetCategory(statInfo, cat);
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = "0.58 0.57 0.61 0.43"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"151.69 {181.04 - ((list.Count - 1) * 50.7)}", OffsetMax = $"153.21 225.49"
}
}
, UI_USER_STAT_INFO, "STAT_LINE");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = "0.58 0.57 0.61 1"
}
, RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = $"-0.7 {-23.3 - ((list.Count - 1) * 30.7)}", OffsetMax = "0.7 0.17"
}
}
, "STAT_LINE", "STAT_LINE_CHILD");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-146.988 -71.4", OffsetMax = "146.388 -53.16"
}
}
, UI_USER_STAT_INFO, "MENU_USER_STAT");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "0.312 -9.12", OffsetMax = "84.704 9.12"
}
, Button = {
Command = $"UI_HandlerStat changeCategory {target} 0", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("STAT_UI_CATEGORY_GATHER", player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter,
}
}
, "MENU_USER_STAT", "Panel_5655");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = cat == 0 ? "0.2 0.6 0.12 0.64" : "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-42.347 0", OffsetMax = "42.196 1.8"
}
}
, "Panel_5655", "Panel_8052");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-61.983 -9.12", OffsetMax = "31.232 9.12"
}
, Button = {
Command = $"UI_HandlerStat changeCategory {target} 1", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("STAT_UI_CATEGORY_EXPLOSED", player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter,
}
}
, "MENU_USER_STAT", "Panel_56551");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = cat == 1 ? "0.2 0.6 0.12 0.64" : "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-46.608 0", OffsetMax = "46.608 1.8"
}
}
, "Panel_56551", "Panel_8052");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = "-115.459 -9.12", OffsetMax = "0.001 9.12"
}
, Button = {
Command = $"UI_HandlerStat changeCategory {target} 2", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("STAT_UI_CATEGORY_PLANT", player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter,
}
}
, "MENU_USER_STAT", "Panel_56553");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = cat == 2 ? "0.2 0.6 0.12 0.64" : "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-57.73 0", OffsetMax = "57.73 1.8"
}
}
, "Panel_56553", "Panel_8052");
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-146.991 -124.12", OffsetMax = "146.4 226.03"
}
}
, "USER_STAT_INFO", "MAIN_LIST_STAT_USER");
int y = 0;
string userLang = lang.GetLanguage(player.UserIDString);
foreach (var item in list) {
if (_config.settingsScore.blackListed.Contains(item.Key)) continue;
float fade = 0.15f * y;
string itemName = string.Empty;
if (_itemName.ContainsKey(item.Key)) {
itemName = userLang == "ru" ? _itemName[item.Key].ru : _itemName[item.Key].en;
}
container.Add(new CuiElement {
Name = "STAT_USER_LINE", Parent = "MAIN_LIST_STAT_USER", Components = {
new CuiRawImageComponent {
Color = "1 1 1 0.03", Png = item.Key == "all" ? ImageUi.GetImage("10") : ImageUi.GetImage("9"), FadeIn = fade
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = $"-146.118 {-44.9 - (y * 50.7)}", OffsetMax = $"146.6 {-0.7 - (y * 50.7)}"
}
}
}
);
string name = cat == 0 ? item.Value.ToString("0,0", CultureInfo.InvariantCulture) : item.Value.ToString();
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "26.03 -10.5", OffsetMax = "126.03 12.5"
}
, Text = {
Text = name, Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleRight, Color = "0.8 0.8 0.8 1", FadeIn = fade
}
}
, "STAT_USER_LINE", "STAT_USER_AMOUNT");
if (item.Key == "all") {
string langGet = cat == 0 ? "STAT_USER_TOTAL_GATHERED" : cat == 1 ? "STAT_USER_TOTAL_EXPLODED" : "STAT_USER_TOTAL_GROWED";
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-128 -10.5", OffsetMax = "50 12.5"
}
, Text = {
Text = GetLang(langGet, player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = "1 1 1 1", FadeIn = fade
}
}
, "STAT_USER_LINE", "ALL_TOTAL");
}
else {
container.Add(new CuiElement {
Name = "IMAGE_ITEM", Parent = "STAT_USER_LINE", Components = {
new CuiRawImageComponent {
Color = "1 1 1 1", Png = GetImage(item.Key + 50), FadeIn = fade
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-128 -17.5", OffsetMax = "-93 17.5"
}
}
}
);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-73.17 -10.5", OffsetMax = "50 12.5"
}
, Text = {
Text = itemName, Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleLeft, Color = "0.8 0.8 0.8 1", FadeIn = fade
}
}
, "STAT_USER_LINE");
}
y++;
}
CuiHelper.DestroyUi(player, "MENU_USER_STAT");
CuiHelper.DestroyUi(player, "MAIN_LIST_STAT_USER");
CuiHelper.DestroyUi(player, "STAT_LINE");
CuiHelper.AddUi(player, container);
}
private void SendDiscordMessage(string title, List<string> embeds, bool inline = false) {
Embed embed = new Embed();
foreach (var item in embeds) {
embed.AddField(title, item, inline, _config.discordMessage.colorLines.GetRandom());
}
webrequest.Enqueue(_config.discordMessage.weebHook, new DiscordMessage(_config.discordMessage.message, embed).ToJson(), (code, response) => {
}
, this, RequestMethod.POST, new Dictionary<string, string> {
{
"Content-Type", "application/json"
}
}
);
}
private bool AddImage(string url, string shortname, ulong skin = 0) => (bool)ImageLibrary?.Call("AddImage", url, shortname, skin);
private void OnGrowableGathered(GrowableEntity plant, Item item, BasePlayer player) {
if (AlowedSeedId.Contains(item.info.itemid)) {
NextTick(() => {
PlayerInfo Playerstat = PlayerInfo.Find(player.userID);
if (!Playerstat.harvesting.HarvestingList.ContainsKey(item.info.shortname)) {
Playerstat.harvesting.HarvestingList.Add(item.info.shortname, item.amount);
}
else {
Playerstat.harvesting.HarvestingList[item.info.shortname] += item.amount;
}
Playerstat.harvesting.AllHarvesting += item.amount;
Playerstat.Score += _config.settingsScore.PlantScore;
}
);
}
}
private bool HasImage(string imageName, ulong imageId = 0) => (bool)ImageLibrary.Call("HasImage", imageName, imageId);
private void ProgressAdd(BasePlayer player, string shortname, int count, bool scoreGive = false) {
PlayerInfo Playerstat = PlayerInfo.Find(player.userID);
if (_config.settingsScore.blackListed.Contains(shortname)) return;
switch (shortname) {
case "wood" : {
Playerstat.gather.GatheredTotal[shortname] += count;
Playerstat.gather.AllGathered += count;
if (scoreGive) Playerstat.Score += _config.settingsScore.GatherScore[shortname];
break;
}
case "stones" : {
Playerstat.gather.GatheredTotal[shortname] += count;
Playerstat.gather.AllGathered += count;
if (scoreGive) Playerstat.Score += _config.settingsScore.GatherScore[shortname];
break;
}
case "metal.ore" : case "metal.fragments" : {
Playerstat.gather.GatheredTotal["metal.ore"] += count;
Playerstat.gather.AllGathered += count;
if (scoreGive) Playerstat.Score += _config.settingsScore.GatherScore["metal.ore"];
break;
}
case "sulfur.ore" : case "sulfur" : {
Playerstat.gather.GatheredTotal["sulfur.ore"] += count;
Playerstat.gather.AllGathered += count;
if (scoreGive) Playerstat.Score += _config.settingsScore.GatherScore["sulfur.ore"];
break;
}
case "hq.metal.ore" : case "metal.refined" : {
Playerstat.gather.GatheredTotal["hq.metal.ore"] += count;
Playerstat.gather.AllGathered += count;
if (scoreGive) Playerstat.Score += _config.settingsScore.GatherScore["hq.metal.ore"];
break;
}
case "scrap" : {
Playerstat.gather.GatheredTotal[shortname] += count;
Playerstat.gather.AllGathered += count;
Playerstat.Score += _config.settingsScore.ScrapScore;
break;
}
}
}
private class PlayerInfo {
public string Name = string.Empty;
public bool HidedStatistics = false;
internal string GetPlayerName(ulong steamId) => string.IsNullOrWhiteSpace(Name) ? _.covalence.Players.FindPlayerById(steamId.ToString())?.Name ?? "UNKNOWN" : Name;
public float Score = 0;
public Harvesting harvesting = new Harvesting();
public OtherStat otherStat = new OtherStat();
public Explosion explosion = new Explosion();
public Gather gather = new Gather();
public Weapon weapon = new Weapon();
public PVP pVP = new PVP();
public PlayedTime playedTime = new PlayedTime();
internal class PlayedTime {
public string DayNumber = DateTime.Now.ToShortDateString();
public int PlayedForWipe = 0;
public int PlayedToday = 0;
}
internal class Harvesting {
public Dictionary<string, int> HarvestingList = new Dictionary<string, int>();
public int AllHarvesting = 0;
}
internal class OtherStat {
public int CrateOpen = 0;
public int BarrelDeath = 0;
public int AllCraft = 0;
public int BuildingCrate = 0;
public int AnimalsKill = 0;
}
internal class Explosion {
public Dictionary<string, int> ExplosionUsed = new Dictionary<string, int>() {
["explosive.timed"]
= 0, ["explosive.satchel"] = 0, ["grenade.beancan"] = 0, ["grenade.f1"] = 0, ["ammo.rocket.basic"] = 0, ["ammo.rocket.hv"] = 0, ["ammo.rocket.fire"] = 0, ["ammo.rifle.explosive"] = 0
}
// ... [Code preview truncated due to length. Full source in attached file] ...