C#:
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using Rust.Ai;
using Oxide.Core.Plugins;
using UnityEngine;
using WebSocketSharp;
namespace Oxide.Plugins {
[Info("UProfile", "TopPlugin.ru", "0.0.1")]
public class UProfile : RustPlugin {
#region Classes
private class Profile {
public string DisplayName;
public ulong UserID;
public int Kills;
public int Deathes;
public int Plus = 1;
public int Minus = 1;
public string LastCheck = string.Empty;
public Dictionary<string, int> FarmStats = new Dictionary<string, int>();
public List<ulong> Voices = new List<ulong>();
public Profile() {
}
public Profile(BasePlayer player) {
DisplayName = player.displayName;
UserID = player.userID;
}
}
private class DataBase {
public Dictionary<ulong, Profile> Profiles = new Dictionary<ulong, Profile>();
public Profile GetUser(BasePlayer player) {
if (!Profiles.ContainsKey(player.userID)) Profiles.Add(player.userID, new Profile(player));
return Profiles[player.userID];
}
public static DataBase LoadData() {
if (Interface.Oxide.DataFileSystem.ExistsDatafile("UProfile")) return Interface.Oxide.DataFileSystem.ReadObject<DataBase>("UProfile");
return new DataBase();
}
public void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("UProfile", this);
}
#endregion
#region Variables
private static UProfile _;
private static DataBase Base = DataBase.LoadData();
[PluginReference]
private Plugin ImageLibrary;
#endregion
#region Commands
[ConsoleCommand("UI_UProfile")]
private void CmdConsoleHandler(ConsoleSystem.Arg args) {
var player = args.Player();
if (!player || !args.HasArgs(1)) return;
var info = Base.GetUser(player);
switch (args.Args[0].ToLower()) {
case "page" : {
int page = 0;
if (!args.HasArgs(2) || !int.TryParse(args.Args[1], out page)) return;
if (page < 0) return;
InitializeSearch(player, page);
break;
}
case "choose" : {
ulong targetId = 0;
if (!args.HasArgs(2) || !ulong.TryParse(args.Args[1], out targetId)) return;
var target = BasePlayer.FindByID(targetId);
if (target == null) {
target = BasePlayer.FindSleeping(targetId);
if (target == null) return;
}
InitializeProfile(player, Base.GetUser(target));
break;
}
case "rep" : {
ulong targetId = 0;
if (!args.HasArgs(2) || !ulong.TryParse(args.Args[1], out targetId)) return;
var target = BasePlayer.FindByID(targetId);
if (target == null) {
target = BasePlayer.FindSleeping(targetId);
if (target == null) return;
}
var targetInfo = Base.GetUser(target);
if (targetInfo.Voices.Contains(player.userID)) return;
if (args.Args[2] == "+") targetInfo.Plus++;
else targetInfo.Minus++;
targetInfo.Voices.Add(player.userID);
InitializeProfile(player, targetInfo);
break;
}
}
}
[ChatCommand("profile")]
private void CmdChatProfile(BasePlayer player, string command, string[] args) {
if (args.Length == 0) {
InitializeSearch(player);
return;
}
var targetInfo = args[0];
var target = BasePlayer.activePlayerList.FirstOrDefault(p => p.displayName.ToLower().Contains(targetInfo.ToLower()));
if (target == null) {
target = BasePlayer.sleepingPlayerList.FirstOrDefault(p => p.displayName.ToLower().Contains(targetInfo.ToLower()));
if (target == null) {
player.ChatMessage($"Игрок с таким именем <color=orange>не найден</color>!");
return;
}
}
var targetProfile = Base.GetUser(target);
if (permission.UserHasPermission(player.UserIDString, "uprofile.moderator")) {
if (args.Length == 2) {
targetProfile.LastCheck = DateTime.Now.ToShortDateString();
player.ChatMessage($"Проверка <color=orange>засчитана</color>");
return;
}
}
InitializeProfile(player, targetProfile);
}
#endregion
#region Hooks
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
var player = entity as BasePlayer;
if (player == null) return;
var info = Base.GetUser(player);
if (!info.FarmStats.ContainsKey(item.info.shortname)) info.FarmStats.Add(item.info.shortname, 0);
info.FarmStats[item.info.shortname] += item.amount;
}
private void OnPlayerDie(BasePlayer player, HitInfo info) {
if (player.UserIDString.Length != 17 || info == null) return;
Base.GetUser(player).Deathes++;
if (info.InitiatorPlayer?.userID != player.userID && info.InitiatorPlayer != null && info.InitiatorPlayer?.UserIDString.Length == 17) Base.GetUser(info.InitiatorPlayer).Kills++;
}
#endregion
#region Initialization
private void OnServerInitialized() {
permission.RegisterPermission("uprofile.moderator", this);
timer.Every(30, Base.SaveData);
}
private void OnSave() => Base.SaveData();
private void Unload() => Base.SaveData();
#endregion
#region Interface
private static string Layer = "UI_ProfileLayerNaguoh";
private void InitializeSearch(BasePlayer player, int page = 0) {
CuiHelper.DestroyUi(player, Layer);
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel() {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0"
}
}
, "Overlay", Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 1", Material = "assets/content/ui/uibackgroundblur-notice.mat", Close = Layer, Command = "closemenu"
}
, Text = {
Text = ""
}
}
, Layer);
var list = BasePlayer.activePlayerList.ToList();
list.AddRange(BasePlayer.sleepingPlayerList.ToList());
list = list.Skip(page * 32).Take(32).ToList();
if (list.Count == 0 && page > 0) {
InitializeSearch(player);
return;
}
float dropPosition = 140;
float marginPosition = -350;
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"380 -60", OffsetMax = "420 60"
}
, Button = {
Color = "0 0 0 0", Command = $"UI_UProfile page {page + 1}"
}
, Text = {
Text = ">", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 80, Color = "1 1 1 0.8"
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"-420 -60", OffsetMax = "-380 60"
}
, Button = {
Color = "0 0 0 0", Command = $"UI_UProfile page {page - 1}"
}
, Text = {
Text = "<", Align = TextAnchor.MiddleRight, Font = "robotocondensed-bold.ttf", FontSize = 80, Color = page == 0 ? "1 1 1 0.2" : "1 1 1 0.8"
}
}
, Layer);
foreach (var check in list) {
string color = "1 1 1 0.5";
if (player.userID == check.userID) {
color = "1 1 1 0.2";
}
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5", OffsetMin = $"{marginPosition} {dropPosition - 35}", OffsetMax = $"{marginPosition + 172.5f} {dropPosition}"
}
, Button = {
Color = color, Command = $"UI_UProfile choose {check.userID}"
}
, Text = {
Text = check.displayName, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 18
}
}
, Layer);
marginPosition += 175.7f;
if (marginPosition >= 300) {
marginPosition = -350;
dropPosition -= 38.3f;
}
}
for (int i = list.Count; i < 32; i++) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5", OffsetMin = $"{marginPosition} {dropPosition - 35}", OffsetMax = $"{marginPosition + 172.5f} {dropPosition}"
}
, Button = {
Color = "1 1 1 0.2",
}
, Text = {
Text = "", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 18
}
}
, Layer);
marginPosition += 175.7f;
if (marginPosition >= 300) {
marginPosition = -350;
dropPosition -= 38.3f;
}
}
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5", OffsetMin = $"-350 -210", OffsetMax = $"350 -170"
}
, Button = {
Color = "1 1 1 0.5", Command = $"UI_UProfile choose {player.userID}"
}
, Text = {
Text = "ПРОСМОТРЕТЬ СВОЙ ЛИЧНЫЙ ПРОФИЛЬ", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 22
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.5 0.5", AnchorMax = $"0.5 0.5", OffsetMin = $"-350 147", OffsetMax = $"350 187"
}
, Button = {
Color = "1 1 1 0.5", Command = $""
}
, Text = {
Text = "ВЫБЕРИТЕ ИГРОКА, ЧЕЙ ПРОФИЛЬ ВЫ ХОТИТЕ ПРОСМОТРЕТЬ", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 22, Color = "1 1 1 1"
}
}
, Layer);
CuiHelper.AddUi(player, container);
}
private void InitializeProfile(BasePlayer player, Profile profile) {
CuiHelper.DestroyUi(player, Layer);
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel() {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0"
}
}
, "Overlay", Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 1", Material = "assets/content/ui/uibackgroundblur-notice.mat", Close = Layer, Command = "closemenu"
}
, Text = {
Text = ""
}
}
, Layer);
container.Add(new CuiElement {
Name = Layer + ".A", Parent = Layer, Components = {
new CuiRawImageComponent() {
Png = (string) ImageLibrary.Call("GetImage", profile.UserID.ToString())
}
, new CuiRectTransformComponent() {
AnchorMin = "0.5 0.7", AnchorMax = "0.5 0.7", OffsetMin = $"-100 -75", OffsetMax = $"100 125"
}
, new CuiOutlineComponent {
Distance = "2 2", Color = "0 0 0 0.5", UseGraphicAlpha = true
}
}
}
);
string text = $"<color=red>X</color> ИГРОК ЕЩЁ НЕ ПРОВЕРЕН <color=red>X</color>";
if (!profile.LastCheck.IsNullOrEmpty()) text = $"<color=green>✔</color> ИГРОК ПРОВЕРЕН {profile.LastCheck} <color=green>✔</color>";
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "-500 225", OffsetMax = "500 10000"
}
, Text = {
Text = text, Align = TextAnchor.LowerCenter, Font = "robotocondensed-bold.ttf", FontSize = 22
}
}
, Layer + ".A");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "-500 -50", OffsetMax = "500 0"
}
, Text = {
Text = profile.DisplayName + " - РАЗРАБОТЧИК ПЛАГИНОВ", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-bold.ttf", FontSize = 22
}
}
, Layer + ".A");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "-500 -100", OffsetMax = "500 0"
}
, Text = {
Text = profile.UserID.ToString(), Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 18, Color = "1 1 1 0.4"
}
}
, Layer + ".A");
int total = profile.Plus + profile.Minus;
float dimension = (float) profile.Plus / total;
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.5 0.2", AnchorMax = "0.5 0.2", OffsetMin = $"-200 -20", OffsetMax = "200 10"
}
, Image = {
Color = "1 1 1 0.2",
}
}
, Layer, Layer + ".R");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = $"{dimension} 1", OffsetMin = $"0 0", OffsetMax = "0 0"
}
, Button = {
Color = "0.6 1 0.6 0.8", Command = $"UI_UProfile rep {profile.UserID} +"
}
, Text = {
Text = $"{(dimension * 100):F0}%", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 18
}
}
, Layer + ".R");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 4", OffsetMax = "0 50"
}
, Text = {
Text = $"Репутация пользователя на основе\n отзывов <b>других игроков</b>, вы можете оставить свой отзыв", Align = TextAnchor.LowerCenter, Font = "robotocondensed-regular.ttf", FontSize = 16, Color = "1 1 1 0.4"
}
}
, Layer + ".R");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0", OffsetMin = "0 -50", OffsetMax = "0 -2"
}
, Text = {
Text = profile.Voices.Contains(player.userID) ? "Вы уже оставляли отзыв о пользователе" : $"Нажмите на <b>красное</b> / <b>зеленое</b> поле", Align = TextAnchor.UpperCenter, Font = "robotocondensed-regular.ttf", FontSize = 16, Color = "1 1 1 0.4"
}
}
, Layer + ".R");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.4", AnchorMax = "0.5 0.4", OffsetMin = "-200 -50", OffsetMax = "200 65"
}
, Text = {
Text = $"<b>ТЕКУЩИЙ РАНГ</b>\n" + $"<size=18>ОБЫЧНЫЙ ИГРОК</size>", Align = TextAnchor.UpperCenter, Font = "robotocondensed-regular.ttf", FontSize = 24, Color = "1 1 1 0.8"
}
}
, Layer);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.32", AnchorMax = "0.5 0.32", OffsetMin = "-200 15", OffsetMax = "200 55"
}
, Text = {
Text = $"ОБЩАЯ СТАТИСТИКА", Align = TextAnchor.UpperCenter, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "1 1 1 0.8"
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.32", AnchorMax = "0.5 0.32", OffsetMin = $"-175 -20", OffsetMax = $"-5 20"
}
, Button = {
Color = "1 1 1 0.2"
}
, Text = {
Text = $"<b>K/D</b>: {(((float) profile.Kills + 1) / ((float) profile.Deathes + 1)):F2}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 22
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0.32", AnchorMax = "0.5 0.32", OffsetMin = $"5 -20", OffsetMax = $"175 20"
}
, Button = {
Color = "1 1 1 0.2"
}
, Text = {
Text = $"<b>FARM</b>: x{profile.FarmStats.Sum(p => p.Value)}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 22
}
}
, Layer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"{dimension} 0", AnchorMax = $"1 1", OffsetMin = $"0 0", OffsetMax = "0 0"
}
, Button = {
Color = "1 0.6 0.6 0.8", Command = $"UI_UProfile rep {profile.UserID} -"
}
, Text = {
Text = $"{((1 - dimension) * 100):F0}%", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 18
}
}
, Layer + ".R");
CuiHelper.AddUi(player, container);
}
#endregion
}
}