C#:
using System;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("CheckCupboard", "Nimant", "1.0.1")]
public class CheckCupboard : RustPlugin
{
[ConsoleCommand("cupboard.owner")]
private void ConsCommandCheckCupOwner(ConsoleSystem.Arg arg)
{
if (arg == null) return;
var player = arg.Player();
var param = arg.Args.Length > 0 ? arg.Args[0] : "";
if (string.IsNullOrEmpty(param))
{
Print(player, "Использование: cupboard.owner <steamID>");
return;
}
var cups = BaseNetworkable.serverEntities.OfType<BuildingPrivlidge>().Where(x=>x.OwnerID == (ulong)Convert.ToInt64(param));
bool wasIn = false;
if (cups?.Count()>0)
Print(player, "\n");
foreach(var cup in cups)
{
Print(player, string.Format("<color=white>Шкаф в квадрате {0}, содержит игроков:</color>", GetGrid(cup.transform.position)));
foreach(var user in cup.authorizedPlayers)
Print(player, $"{user.userid}");
Print(player, "\n");
wasIn = true;
}
if (!wasIn)
Print(player, "Данный игрок не создавал ни одного шкафа.");
}
[ConsoleCommand("cupboard.auth")]
private void ConsCommandCheckCupAuth(ConsoleSystem.Arg arg)
{
if (arg == null) return;
var player = arg.Player();
var param = arg.Args.Length > 0 ? arg.Args[0] : "";
if (string.IsNullOrEmpty(param))
{
Print(player, "Использование: cupboard.auth <steamID>");
return;
}
var cups = BaseNetworkable.serverEntities.OfType<BuildingPrivlidge>().Where(y=> y.authorizedPlayers.Exists(x=>x.userid == (ulong)Convert.ToInt64(param)));
bool wasIn = false;
if (cups?.Count()>0)
Print(player, "\n");
foreach(var cup in cups)
{
Puts(cup.transform.position.ToString());
Print(player, string.Format($"<color=white>Шкаф в квадрате {GetGrid(cup.transform.position)}, содержит игроков:</color>"));
foreach(var user in cup.authorizedPlayers)
{
Print(player, $"{user.userid}");
}
Print(player, "\n");
wasIn = true;
}
if (!wasIn)
Print(player, "Данный игрок не зарегистрирован ни в одном шкафу.");
}
private string GetCluster(Vector3 pos)
{
string[] args = new string[] { $"{pos.x}", $"{pos.y}", $"{pos.z}" };
return $"{(char)((int)Math.Truncate((World.Size/2f+Convert.ToSingle(args[0]))/150f)+65)}{(int)Math.Truncate((World.Size/2f-Convert.ToSingle(args[2]))/150f)}";
}
private static string GetGrid(Vector3 pos) {
char letter = 'A';
var x = Mathf.Floor((pos.x+(ConVar.Server.worldsize/2)) / 146.3f)%26;
var z = (Mathf.Floor(ConVar.Server.worldsize/146.3f)-1)-Mathf.Floor((pos.z+(ConVar.Server.worldsize/2)) / 146.3f);
letter = (char)(((int)letter)+x);
return $"{letter}{z}";
}
private void Print(BasePlayer player, string text)
{
if (player != null)
{
Puts(text);
PrintToConsole(player, text);
}
else
{
Puts(text.Replace("<color=white>", "").Replace("</color>", ""));
Puts(text.Replace("<color=white>", "").Replace("</color>", ""));
}
}
}
}