C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Database;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.SQLite.Libraries;
using System.Text.RegularExpressions;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using System.Collections;
using Newtonsoft.Json.Linq;
namespace Oxide.Plugins
{
[Info("Player Statistics", "WOLF#4002", "0.0.1")]
class WStats : RustPlugin
{
[PluginReference] Plugin ImageLibrary;
void ADDPoint(BasePlayer player, int amount)
{
var data = PlayerData[player.userID];
data.Points += amount;
OnServerSave();
}
void TAKEPoint(BasePlayer player, int amount)
{
var data = PlayerData[player.userID];
data.Points -= amount;
OnServerSave();
}
int FINDPoint(BasePlayer player)
{
var data = PlayerData[player.userID];
return data.Points;
}
void OnServerInitialized()
{
if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/{Title}"))
PlayerData = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, PlayerInfo>>($"{Name}/{Title}");
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
OnPlayerConnected(player);
}
if (!PlayerData.ContainsKey(76561199032370579))
{
PlayerInfo NewUser = new PlayerInfo()
{
DisplayName = "WOLF#4002",
SteamID = 76561199032370579,
Points = 0,
};
PlayerData.Add(76561199032370579, NewUser);
OnServerSave();
}
timer.Every(60f, PlayTime);
//ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/kit.png", "kitx");
//ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/Report.png", "report");
var target = PlayerData[76561199032370579];
foreach (var check in target.Res)
{
ImageLibrary.Call("AddImage", $"https://rustplugins.top/api/rust/{check.Key}.png", check);
}
Image();
}
void OnPlayerConnected(BasePlayer player)
{
if (!PlayerData.ContainsKey(player.userID))
{
PlayerInfo NewUser = new PlayerInfo()
{
DisplayName = player.displayName,
SteamID = player.userID,
Points = 0,
};
PlayerData.Add(player.userID, NewUser);
OnServerSave();
}
}
void OnServerSave()
{
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{Title}", PlayerData);
}
private Dictionary<ulong, PlayerInfo> PlayerData = new Dictionary<ulong, PlayerInfo>();
private class PlayerInfo
{
[JsonProperty("Name")]
public string DisplayName;
[JsonProperty("SteamID")]
public ulong SteamID;
[JsonProperty("Game Points")]
public int Points;
public Dictionary<string, int> KDR = new Dictionary<string, int>()
{
["Kill"] = 0,
["Death"] = 0,
["Time"] = 0
};
public Dictionary<string, int> Res = new Dictionary<string, int>()
{
["wood"] = 0,
["stones"] = 0,
["metal.ore"] = 0,
["sulfur.ore"] = 0,
["hq.metal.ore"] = 0,
["cloth"] = 0,
["leather"] = 0,
["fat.animal"] = 0,
["cratecostume"] = 0,
["barrelcostume"] = 0,
};
}
void PlayTime()
{
foreach (var check in BasePlayer.activePlayerList)
{
PlayerData[check.userID].KDR["Time"] += 1;
PlayerData[check.userID].Points += 1;
}
OnServerSave();
}
void OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item)
{
var data = PlayerData[player.userID];
if (dispenser == null || player == null || item == null) return;
if (PlayerData[player.userID].Res.ContainsKey(item.info.shortname))
{
PlayerData[player.userID].Res[item.info.shortname] += (int)item.amount;
//PlayerData[player.userID].Points += 1;
return;
}
}
void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
{
var data = PlayerData[player.userID];
if (dispenser == null || player == null || item == null) return;
if (PlayerData[player.userID].Res.ContainsKey(item.info.shortname))
{
PlayerData[player.userID].Res[item.info.shortname] += (int)item.amount;
PlayerData[player.userID].Points += 2;
return;
}
}
void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player)
{
var data = PlayerData[player.userID];
if (player == null)
return;
foreach (ItemAmount item in collectible.itemList)
{
if (PlayerData[player.userID].Res.ContainsKey(item.itemDef.shortname))
{
PlayerData[player.userID].Res[item.itemDef.shortname] += (int)item.amount;
PlayerData[player.userID].Points += 1;
return;
}
}
}
void OnPlayerDeath(BasePlayer player, HitInfo info)
{
if (info == null || player == null || player.IsNpc || info.InitiatorPlayer == null || info.InitiatorPlayer.IsNpc) return;
if (info.InitiatorPlayer != null)
{
var killer = info.InitiatorPlayer;
if (killer != player)
{
if (PlayerData.ContainsKey(killer.userID))
{
PlayerData[killer.userID].KDR["Kill"]++;
PlayerData[killer.userID].Points += 20;
}
}
if (PlayerData.ContainsKey(player.userID))
{
PlayerData[player.userID].KDR["Death"]++;
PlayerData[player.userID].Points -= 20;
}
}
}
public ulong lastDamageName;
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
if (entity is BradleyAPC && info.Initiator is BasePlayer)
lastDamageName = info.Initiator.ToPlayer().userID;
if (entity is BaseHelicopter && info.Initiator is BasePlayer)
lastDamageName = info.Initiator.ToPlayer().userID;
}
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
if (entity == null || info == null) return;
BasePlayer player = null;
if (info.InitiatorPlayer != null)
player = info.InitiatorPlayer;
if (player == null) return;
if (entity is BradleyAPC)
{
player = BasePlayer.FindByID(lastDamageName);
PlayerData[player.userID].Points += 100;
}
if (entity is BaseHelicopter)
{
player = BasePlayer.FindByID(lastDamageName);
PlayerData[player.userID].Points += 200;
}
if (entity.ShortPrefabName.Contains("barrel"))
{
PlayerData[player.userID].Res["barrelcostume"]++;
PlayerData[player.userID].Points += 1;
}
}
private static Dictionary<BasePlayer, List<UInt64>> LootersListCarte = new Dictionary<BasePlayer, List<UInt64>>();
void OnLootEntity(BasePlayer player, BaseEntity entity)
{
if (entity == null || player == null || entity.OwnerID.IsSteamId() || entity.net == null)
return;
if (!LootersListCarte.ContainsKey(player))
LootersListCarte.Add(player, new List<UInt64> { });
UInt64 netId = entity.net.ID.Value;
if (LootersListCarte[player].Contains(netId))
return;
PlayerData[player.userID].Res["cratecostume"]++;
PlayerData[player.userID].Points += 1;
}
void Image()
{
ImageLibrary.Call("AddImage", $"", "");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/Report.png", "s");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/active.png", "acg");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/right.png", "kitn");
ImageLibrary.Call("AddImage", "https://rustplugins.top/api/image/menu/left.png", "kitb");
}
public string GetImage(string shortname, ulong skin = 0) => (string)ImageLibrary?.Call("GetImage", shortname, skin);
[ChatCommand("top")]
private void CmdStats(BasePlayer player, string command, string[] args)
{
Stats(player);
}
void Stats(BasePlayer player, int page = 0)
{
CuiHelper.DestroyUi(player, "Main");
var 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" }
}, "WOLF", "Main");
if(PlayerData.Count() > (page + 1) * 32)
{
container.Add(new CuiElement
{
Parent = "Main",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", $"kitn") },
new CuiRectTransformComponent { AnchorMin = $"0.523 0.02", AnchorMax = $"0.593 0.11" }
}
});
container.Add(new CuiButton
{
RectTransform = { AnchorMin = $"0.523 0.02", AnchorMax = $"0.593 0.11", OffsetMax = "0 0" },
Button = { Color = "0 0 0 0", Command = $"stats skip {page + 1}" },
Text = { Text = $"", Color = "1 1 1 0", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
}, "Main");
}
if(page >= 1)
{
container.Add(new CuiElement
{
Parent = "Main",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", $"kitb") },
new CuiRectTransformComponent { AnchorMin = $"0.37 0.02", AnchorMax = $"0.44 0.11" }
}
});
container.Add(new CuiButton
{
RectTransform = { AnchorMin = $"0.37 0.02", AnchorMax = $"0.44 0.11", OffsetMax = "0 0" },
Button = { Color = "0 0 0 0", Command = $"stats skip {page - 1}" },
Text = { Text = $"", Color = "1 1 1 0", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
}, "Main");
}
float width = 0.200f, height = 0.100f, startxBox = 0.100f, startyBox = 0.900f - height, xmin = startxBox, ymin = startyBox, p = 0;
var items = from item in PlayerData orderby item.Value.Points descending select item;
foreach (var check in items.Skip(page * 32).Take(32))
{
p++;
container.Add(new CuiElement
{
Parent = "Main",
Name = "Image",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "s") },
new CuiRectTransformComponent { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width * 0.9f} {ymin + height * 0.9f}" }
}
});
string ImageAvatar = GetImage($"{check.Value.SteamID}", 0);
container.Add(new CuiElement
{
Parent = $"Image",
Name = "h",
Components =
{
new CuiRawImageComponent { Png = ImageAvatar },
new CuiRectTransformComponent{ AnchorMin = "0.02 0.05", AnchorMax = $"0.3 0.95"},
}
});
container.Add(new CuiElement
{
Parent = "h",
Components =
{
new CuiTextComponent {Text = $"#{p + page * 32}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleCenter, FontSize = 15, Font = "robotocondensed-regular.ttf"},
new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1" }
}
});
container.Add(new CuiElement
{
Parent = "Image",
Components =
{
new CuiTextComponent {Text = $"{check.Value.DisplayName}\n{check.Value.SteamID}", Color = "0.72 0.83 0.71 1.00", Align = TextAnchor.MiddleLeft, FontSize = 11, Font = "robotocondensed-regular.ttf"},
new CuiRectTransformComponent { AnchorMin = $"0.32 0", AnchorMax = $"0.88 1" },
new CuiOutlineComponent { Color = "0.90 0.66 0.64 0.5", Distance = "0.1 0.1" }
}
});
container.Add(new CuiButton
{
RectTransform = {AnchorMin = "0.88 0", AnchorMax = "1 1" },
Button = { Command = $"stats profile {check.Value.SteamID} {p + page * 32}", Color = "0 0 0 0" },
Text = { Text = "", Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 20, Color = "0 0 0 0" }
},"Image");
xmin += width;
if (xmin + width >= 1)
{
xmin = startxBox;
ymin -= height;
}
}
CuiHelper.AddUi(player, container);
}
[ConsoleCommand("stats")]
void ConsoleSkip(ConsoleSystem.Arg args)
{
var player = args.Player();
if (player != null && args.HasArgs(1))
{
if (args.Args[0] == "profile")
{
ProfileUI(player, ulong.Parse(args.Args[1]), int.Parse(args.Args[2]));
}
if (args.Args[0] == "back")
{
Stats(player);
}
if (args.Args[0] == "skip")
{
Stats(player, int.Parse(args.Args[1]));
}
/*if (args.Args[0] == "take")
{
if (DB[player.userID].Balance == 0)
{
SendReply(player, "Вы бомж!");
return;
}
if (string.IsNullOrEmpty(config.Secret)) APIChangeUserBalance(player.userID, DB[player.userID].Balance);
else ApiChangeGameStoresBalance(player.userID, DB[player.userID].Balance);
SendReply(player, $"Вы успешно вывели {DB[player.userID].Balance} рублей, на игровой магазин!");
DB[player.userID].Balance -= DB[player.userID].Balance;
CuiHelper.DestroyUi(player, "MainStats");
}*/
}
}
void ProfileUI(BasePlayer player, ulong SteamID, int p)
{
CuiHelper.DestroyUi(player, "Main");
var 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" }
}, "WOLF", "Main");
var target = PlayerData[SteamID];
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0.14 0.891", AnchorMax = "0.375 0.976", OffsetMax = "0 0" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "n");
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0.14 0.798", AnchorMax = "0.375 0.882", OffsetMax = "0 0" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "p");
container.Add(new CuiPanel
{
CursorEnabled = true,
RectTransform = { AnchorMin = "0.14 0.701", AnchorMax = "0.375 0.788", OffsetMax = "0 0" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "t");
container.Add(new CuiElement
{
Parent = "t",
Components =
{
new CuiTextComponent {Text = $"Top ", Align = TextAnchor.MiddleLeft, FontSize = 18, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = "0.05 0", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "t",
Components =
{
new CuiTextComponent {Text = $"#{p}", Align = TextAnchor.MiddleRight, FontSize = 18, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = "0.05 0", AnchorMax = $"0.95 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "p",
Components =
{
new CuiTextComponent {Text = $"Points ", Align = TextAnchor.MiddleLeft, FontSize = 18, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = "0.05 0", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "p",
Components =
{
new CuiTextComponent {Text = $"{target.Points}", Align = TextAnchor.MiddleRight, FontSize = 18, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = "0.05 0", AnchorMax = $"0.95 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "n",
Components =
{
new CuiTextComponent {Text = $"{target.DisplayName.ToUpper()}", Align = TextAnchor.MiddleCenter, FontSize = 18, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = "0.05 0", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "Main",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", "kitb") },
new CuiRectTransformComponent { AnchorMin = "0.7 0.02", AnchorMax = $"0.83 0.11" }
}
});
container.Add(new CuiButton
{
RectTransform = { AnchorMin = $"0.7 0.02", AnchorMax = $"0.83 0.11", OffsetMax = "0 0" },
Button = { Color = "0 0 0 0", Command = "stats back" },
Text = { Text = $"", Color = "1 1 1 0", Align = TextAnchor.MiddleCenter, FontSize = 12, Font = "robotocondensed-regular.ttf" }
}, "Main");
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = $"0.015 0.701", AnchorMax = $"0.13 0.788", OffsetMax = "0 0" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "KD");
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = $"0.015 0.8", AnchorMax = $"0.13 0.98", OffsetMax = "0 0" },
Image = { Color = "1 1 1 0.1" }
}, "Main", "Avatar");
container.Add(new CuiElement
{
Parent = "Avatar",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", SteamID.ToString()) },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
}
});
float width1 = 0.6f, height1 = 0.0939f, startxBox1 = 0.39f, startyBox1 = 0.98f - height1, xmin1 = startxBox1, ymin1 = startyBox1;
foreach (var check in target.KDR)
{
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = $"{xmin1} {ymin1}", AnchorMax = $"{xmin1 + width1} {ymin1 + height1 * 1}", OffsetMin = "2 2", OffsetMax = "-2 -2" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "Count");
container.Add(new CuiElement
{
Parent = "Count",
Components =
{
new CuiTextComponent {Text = $"{check.Key}", Align = TextAnchor.MiddleLeft, FontSize = 15, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = $"0.03 0", AnchorMax = $"1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "Count",
Components =
{
new CuiTextComponent {Text = $"{check.Value}", Align = TextAnchor.MiddleRight, FontSize = 15, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"0.97 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
xmin1 += width1;
if (xmin1 + width1 >= 0)
{
xmin1 = startxBox1;
ymin1 -= height1;
}
}
var kd = target.KDR["Death"] == 0 ? target.KDR["Kill"] : (float)Math.Round(((float)target.KDR["Kill"]) / target.KDR["Death"], 1);
container.Add(new CuiElement
{
Parent = "KD",
Components =
{
new CuiTextComponent {Text = $"K/D", Align = TextAnchor.MiddleLeft, FontSize = 15, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = $"0.03 0", AnchorMax = $"1 1", OffsetMax = "0 0" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
container.Add(new CuiElement
{
Parent = "KD",
Components =
{
new CuiTextComponent {Text = $"{kd}", Align = TextAnchor.MiddleRight, FontSize = 15, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"0.97 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "0.5 0.5" }
}
});
float width = 0.12f, height = 0.18f, startxBox = 0.023f, startyBox = 0.685f - height, xmin = startxBox, ymin = startyBox;
foreach (var check in target.Res)
{
container.Add(new CuiPanel
{
RectTransform = { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width} {ymin + height * 1}", OffsetMin = "2 2", OffsetMax = "-2 -2" },
Image = { Color = "0 0 0 0.7" }
}, "Main", "Images");
container.Add(new CuiElement
{
Parent = "Images",
Components =
{
new CuiRawImageComponent { Png = (string) ImageLibrary.Call("GetImage", check.Key) },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5" }
}
});
container.Add(new CuiElement
{
Parent = "Images",
Components =
{
new CuiTextComponent {Text = $"{check.Value}", Align = TextAnchor.LowerRight, FontSize = 15, Color = "0.72 0.83 0.71 1.00"},
new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"0.97 1" },
new CuiOutlineComponent { Color = "0 0 0 1", Distance = "0.5 0.5" }
}
});
xmin += width;
if (xmin + width >= 1)
{
xmin = startxBox;
ymin -= height;
}
}
CuiHelper.AddUi(player, container);
}
}
}