C#:
using System.Linq;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System;
using Oxide.Core;
using Newtonsoft.Json;
using System.Collections;
using Oxide.Core.Plugins;
using System.Collections.Generic;
namespace Oxide.Plugins {
[Info("XBuildingSkinMenu", "Monster", "1.1.9")]
class XBuildingSkinMenu : RustPlugin {
private BuildingSkinConfig config;
private void OnPluginLoaded(Plugin name) {
if(name.Title == "XSkinMenu") _blacklist = XSkinMenu?.Call<List<ulong>>("API_GetBlacklist") ?? _blacklist;
if(name.Title == "IQGradeRemove") NextTick(() => _isRepairToGrade = IQGradeRemove?.Call<bool>("API_IS_REPAIR_TO_GRADE") ?? false);
}
internal class Data {
[JsonProperty(LanguageEnglish ? "Change the skin of a building block with a hammer" : "Изменять скин строительного блока киянкой")]
public bool HChange;
[JsonProperty(LanguageEnglish ? "Change the skin of a wallpaper with a hammer" : "Изменять скин обоев киянкой")]
public bool WHChange;
[JsonProperty(LanguageEnglish ? "Selected color" : "Выбранный цвет")]
public uint ColourID;
[JsonProperty(LanguageEnglish ? "Skins for buildings" : "Скины на постройки")]
public Dictionary<string, ulong> BuildingSkins = new Dictionary<string, ulong>();
public Dictionary<string, ulong> WallpaperSkins = new Dictionary<string, ulong>();
}
private void OnPluginUnloaded(Plugin name) {
if(name.Title == "XSkinMenu") _blacklist.Clear();
if(name.Title == "IQGradeRemove") _isRepairToGrade = false;
}
private void OnUserPermissionRevoked(string id, string permName) => ResetPlayerSkins(id);
private void OnEntityKill(BuildingPrivlidge entity) {
ulong netID = entity.net.ID.Value;
if(_coroutine_list.ContainsKey(netID)) {
ServerMgr.Instance.StopCoroutine(_coroutine_list[netID]);
_coroutine_list.Remove(netID);
}
if(_coroutine_listEnt.ContainsKey(netID)) {
ServerMgr.Instance.StopCoroutine(_coroutine_listEnt[netID]);
_coroutine_listEnt.Remove(netID);
}
}
private Dictionary<ulong, Coroutine> _coroutine_list = new Dictionary<ulong, Coroutine>();
private void OnLootEntity(BasePlayer player, BuildingPrivlidge entity) {
if(config.Setting.HouseOwner && player.userID != entity.OwnerID) return;
if(permission.UserHasPermission(player.UserIDString, permUse) && !_coroutine_list.ContainsKey(entity.net.ID.Value)) {
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = config.GUI.AnchorMinB1, AnchorMax = config.GUI.AnchorMaxB1, OffsetMin = config.GUI.OffsetMinB1, OffsetMax = config.GUI.OffsetMaxB1
}
, Button = {
Color = config.GUI.ButtonColorCup, Command = "set_skin_building block", Close = ".SetSkinBUTTON"
}
, Text = {
Text = ""
}
}
, "Overlay", ".SetSkinBUTTON", ".SetSkinBUTTON");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = lang.GetMessage("SETSKIN", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 10, Color = config.GUI.TButtonColorCup
}
}
, ".SetSkinBUTTON");
CuiHelper.AddUi(player, container);
}
if(config.Setting.UseXSM && permission.UserHasPermission(player.UserIDString, permEnt) && !_coroutine_listEnt.ContainsKey(entity.net.ID.Value)) {
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = config.GUI.AnchorMinB2, AnchorMax = config.GUI.AnchorMaxB2, OffsetMin = config.GUI.OffsetMinB2, OffsetMax = config.GUI.OffsetMaxB2
}
, Button = {
Color = config.GUI.ButtonColorCup, Command = "set_skin_building entity", Close = ".SetSkinEntBUTTON"
}
, Text = {
Text = ""
}
}
, "Overlay", ".SetSkinEntBUTTON", ".SetSkinEntBUTTON");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = lang.GetMessage("SETSKIN_ENT", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 10, Color = config.GUI.TButtonColorCup
}
}
, ".SetSkinEntBUTTON");
CuiHelper.AddUi(player, container);
}
}
[ConsoleCommand("xskinmenu_open")]
private void ccmdXSkinMenuOpen(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player != null) XSkinMenu?.Call("cmdOpenGUI", player, null, null);
}
private ulong GetBuildingSkin(BasePlayer player, BuildingGrade.Enum grade) => StoredData.ContainsKey(player.userID) && StoredData[player.userID].BuildingSkins.ContainsKey(grade.ToString()) ? StoredData[player.userID].BuildingSkins[grade.ToString()] : 0;
private uint GetShippingContainerBlockColourForPlayer(BasePlayer player) {
int infoInt = player.GetInfoInt("client.SelectedShippingContainerBlockColour", 0);
if (infoInt >= 0) return (uint)infoInt;
return (uint)0;
}
[ConsoleCommand("skin_build_colour")]
private void ccmdSetColour(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args.Args == null || !permission.UserHasPermission(player.UserIDString, permUse)) return;
if(Cooldowns.ContainsKey(player)) if(Cooldowns[player].Subtract(DateTime.Now).TotalSeconds >= 0) return;
Cooldowns[player] = DateTime.Now.AddSeconds(1.0f);
if(args.Args.Length >= 1) {
uint colourID;
uint.TryParse(args.Args[0], out colourID);
if(_colours.ContainsKey(colourID) || colourID == 0) {
SetShippingContainerBlockColourForPlayer(player, colourID);
StoredData[player.userID].ColourID = colourID;
ColourGUI(player);
EffectNetwork.Send(new Effect("assets/prefabs/deployable/repair bench/effects/skinchange_spraypaint.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
}
}
private void OnServerInitialized() {
PrintWarning("\n-----------------------------\n" + " Author - Monster\n" + " VK - vk.com/idannopol\n" + " Discord - Monster#4837\n" + " Config - v.66719\n" + "-----------------------------");
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
if(!ImageLibrary) {
PrintError(LanguageEnglish ? "You don't have the plugin installed - ImageLibrary!" : "У вас не установлен плагин - ImageLibrary!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
if(config.Setting.UseXSM && !XSkinMenu) {
PrintError(LanguageEnglish ? "You don't have the plugin installed - XSkinMenu!" : "У вас не установлен плагин - XSkinMenu!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
if(config.Setting.UseXSM && XSkinMenu) if(new Version(XSkinMenu.Version.ToString()) < new Version("1.4.1")) {
PrintError(LanguageEnglish ? "XSkinMenu plugin version must be 1.4.1 and higher!" : "Версия плагина XSkinMenu должна быть 1.4.1 и выше!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
foreach(string command in config.Setting.BSkinCommandList) cmd.AddChatCommand(command, this, cmdOpenGUIB);
ImageLibrary.Call("AddImage", "https://i.ibb.co/5kMf0fH/000.png", $"B_IMG_Random");
foreach(var building in config.Setting.BuildingSkins) foreach(var skinID in building.Value) {
ImageLibrary.Call("AddImage", skinID.Value.ImageURL, $"B_IMG_{building.Key + skinID.Key}");
if(skinID.Value.Permission != "" && !permission.PermissionExists(skinID.Value.Permission, this)) permission.RegisterPermission(skinID.Value.Permission, this);
}
InitializeLang();
permission.RegisterPermission(permUse, this);
permission.RegisterPermission(permEnt, this);
foreach(var item in ItemManager.GetItemDefinitions()) {
var prefab = item.GetComponent<ItemModDeployable>()?.entityPrefab?.resourcePath;
if(string.IsNullOrEmpty(prefab)) continue;
var shortPrefabName = Utility.GetFileNameWithoutExtension(prefab);
if(!string.IsNullOrEmpty(shortPrefabName) && !_shortnamesEntity.ContainsKey(shortPrefabName)) _shortnamesEntity.Add(shortPrefabName, item.shortname);
}
NextTick(() => {
BgMainLayer = config.GUI.BColor0 != "0 0 0 0" || config.GUI.CloseUI ? ".BgBgBSkinGUI" : ".BgBSkinGUI";
_blacklist = XSkinMenu?.Call<List<ulong>>("API_GetBlacklist") ?? _blacklist;
_isRepairToGrade = IQGradeRemove?.Call<bool>("API_IS_REPAIR_TO_GRADE") ?? false;
}
);
}
private void EffectsRun(Vector3 position) {
Effect.server.Run("assets/prefabs/deployable/repair bench/effects/skinchange_spraypaint.prefab", position);
Effect.server.Run("assets/prefabs/tools/spraycan/reskineffect.prefab", position);
}
private readonly List<string> _grades = new List<string> {
"Twigs", "Wood", "Stone", "Metal", "TopTier"
}
;
protected override void LoadDefaultConfig() => config = BuildingSkinConfig.GetNewConfiguration();
private readonly Dictionary<uint, string> _colours = new Dictionary<uint, string> {
[1]
= "0.38 0.56 0.74 1", [2] = "0.45 0.71 0.35 1", [3] = "0.57 0.29 0.83 1", [4] = "0.42 0.16 0.11 1", [5] = "0.82 0.46 0.13 1", [6] = "0.87 0.87 0.87 1", [7] = "0.20 0.20 0.18 1", [8] = "0.40 0.33 0.28 1", [9] = "0.20 0.22 0.33 1", [10] = "0.24 0.35 0.20 1", [11] = "0.73 0.29 0.18 1", [12] = "0.78 0.53 0.39 1", [13] = "0.86 0.66 0.22 1", [14] = "0.34 0.33 0.31 1", [15] = "0.21 0.34 0.37 1", [16] = "0.66 0.61 0.56 1"
}
;
private void SaveData(BasePlayer player) => Interface.Oxide.DataFileSystem.WriteObject($"XDataSystem/XBuildingSkinMenu/{player.userID}", StoredData[player.userID]);
private const string permUse = "xbuildingskinmenu.use";
[ConsoleCommand("set_skin_building")]
private void ccmdSetSkinBuilding(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
BaseEntity entity = player?.inventory?.loot?.entitySource;
if(entity == null || args.Args == null || args.Args.Length == 0 || !(entity is BuildingPrivlidge)) return;
if(config.Setting.HouseOwner && player.userID != entity.OwnerID) return;
switch(args.Args[0]) {
case "block" : {
if(permission.UserHasPermission(player.UserIDString, permUse)) {
if(_coroutine_list.ContainsKey(entity.net.ID.Value)) {
SendReply(player, string.Format(lang.GetMessage("PAINT_ACTIVE", this, player.UserIDString), entity.net.ID.Value));
return;
}
_coroutine_list[entity.net.ID.Value] = ServerMgr.Instance.StartCoroutine(SetBuildingSkins(player, entity));
EffectNetwork.Send(new Effect("assets/prefabs/misc/halloween/lootbag/effects/loot_bag_upgrade.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
break;
}
case "entity" : {
if(config.Setting.UseXSM && permission.UserHasPermission(player.UserIDString, permEnt)) {
if(_coroutine_listEnt.ContainsKey(entity.net.ID.Value)) {
SendReply(player, string.Format(lang.GetMessage("PAINT_ENT_ACTIVE", this, player.UserIDString), entity.net.ID.Value));
return;
}
_coroutine_listEnt[entity.net.ID.Value] = ServerMgr.Instance.StartCoroutine(SetEntitySkins(player, entity));
EffectNetwork.Send(new Effect("assets/prefabs/misc/halloween/lootbag/effects/loot_bag_upgrade.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
break;
}
}
}
private void OnPlayerDisconnected(BasePlayer player) {
if(StoredData.ContainsKey(player.userID)) {
SaveData(player);
StoredData.Remove(player.userID);
}
}
private string BgMainLayer;
private void GUI(BasePlayer player) {
CuiElementContainer container = new CuiElementContainer();
bool xsmLoad = XSkinMenu;
if(config.GUI.BColor0 != "0 0 0 0" || config.GUI.CloseUI) {
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = config.GUI.BColor0, Material = config.GUI.BMaterial0
}
}
, "Overlay", ".BgBgBSkinGUI", ".BgBgBSkinGUI");
if(config.GUI.CloseUI) container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Close = ".BgBgBSkinGUI"
}
, Text = {
Text = ""
}
}
, ".BgBgBSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-210 -147.5", OffsetMax = "210 262.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/icons/greyout.mat"
}
}
, ".BgBgBSkinGUI", ".BgBSkinGUI");
}
else container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-210 -147.5", OffsetMax = "210 262.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/icons/greyout.mat"
}
}
, "Overlay", ".BgBSkinGUI", ".BgBSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
, Image = {
Color = config.GUI.BColor2
}
}
, ".BgBSkinGUI", ".BSkinGUI");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-32.5 -32.5", OffsetMax = "-5 -5"
}
, Button = {
Color = config.GUI.IconColor, Sprite = "assets/icons/close.png", Close = BgMainLayer
}
, Text = {
Text = ""
}
}
, ".BSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-42.5 -42.5", OffsetMax = "-37.5 0"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".BSkinGUI");
if(xsmLoad) {
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "5 -32.5", OffsetMax = "32.5 -5"
}
, Button = {
Color = config.GUI.IconColor, Sprite = "assets/icons/clothing.png", Command = "xskinmenu_open", Close = BgMainLayer
}
, Text = {
Text = ""
}
}
, ".BSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "37.5 -42.5", OffsetMax = "42.5 0"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".BSkinGUI");
}
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = xsmLoad ? "-122.5 162.5" : "-165 162.5", OffsetMax = "122.5 200"
}
, Text = {
Text = lang.GetMessage("TITLE", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = xsmLoad ? 13 : 15, Color = "1 1 1 0.75011085"
}
}
, ".BSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 157.5", OffsetMax = "0 162.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".BSkinGUI");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "0 -162.5", OffsetMax = "0 -157.5"
}
, Image = {
Color = config.GUI.BColor1, Material = "assets/content/ui/uibackgroundblur.mat"
}
}
, ".BSkinGUI");
CuiHelper.AddUi(player, container);
ButtonGUI(player);
BuildingSkinGUI(player);
ColourGUI(player);
}
private Dictionary<ulong, Coroutine> _coroutine_listEnt = new Dictionary<ulong, Coroutine>();
private void OnUserGroupRemoved(string id, string groupName) => ResetPlayerSkins(id);
private void cmdOpenGUIB(BasePlayer player, string command, string[] args) {
if(permission.UserHasPermission(player.UserIDString, permUse)) GUI(player);
else SendReply(player, lang.GetMessage("NOPERM", this, player.UserIDString));
}
private const bool LanguageEnglish = false;
private void OnLootEntityEnd(BasePlayer player, BuildingPrivlidge entity) {
CuiHelper.DestroyUi(player, ".SetSkinBUTTON");
CuiHelper.DestroyUi(player, ".SetSkinEntBUTTON");
}
private void SetShippingContainerBlockColourForPlayer(BasePlayer player, uint color) => player.SetInfo("client.SelectedShippingContainerBlockColour", color.ToString());
private void ButtonGUI(BasePlayer player) {
CuiElementContainer container = new CuiElementContainer();
Data player_data = StoredData[player.userID];
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "1 0.5", OffsetMin = "5 -195", OffsetMax = "-5 -167.5"
}
, Image = {
Color = "0 0 0 0"
}
}
, ".BSkinGUI", ".ButtonChange", ".ButtonChange");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "0.5 1", OffsetMin = "0 0", OffsetMax = "-2.5 0"
}
, Button = {
Color = player_data.HChange ? config.GUI.ButtonColorHOn : config.GUI.ButtonColorHOff, Command = "skin_build hammer"
}
, Text = {
Text = ""
}
}
, ".ButtonChange", ".BHChange");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "2 2", OffsetMax = "-2 -2"
}
, Text = {
Text = lang.GetMessage(player_data.HChange ? "HAMMER_ON" : "HAMMER_OFF", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 9, Font = "robotocondensed-regular.ttf", Color = player_data.HChange ? config.GUI.TButtonColorHOn : config.GUI.TButtonColorHOff
}
}
, ".BHChange");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "1 1", OffsetMin = "2.5 0", OffsetMax = "0 0"
}
, Button = {
Color = player_data.WHChange ? config.GUI.ButtonColorHOn : config.GUI.ButtonColorHOff, Command = "skin_build whammer"
}
, Text = {
Text = ""
}
}
, ".ButtonChange", ".WHChange");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "2 2", OffsetMax = "-2 -2"
}
, Text = {
Text = lang.GetMessage(player_data.WHChange ? "W_HAMMER_ON" : "W_HAMMER_OFF", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 9, Font = "robotocondensed-regular.ttf", Color = player_data.WHChange ? config.GUI.TButtonColorHOn : config.GUI.TButtonColorHOff
}
}
, ".WHChange");
CuiHelper.AddUi(player, container);
}
private void ResetPlayerSkins(string id) {
ulong userID = Convert.ToUInt64(id);
if(StoredData.ContainsKey(userID)) {
if(permission.UserHasPermission(id, permUse)) {
var cfg = config.Setting.BuildingSkins;
foreach(var skin in StoredData[userID].BuildingSkins.ToDictionary(k => k.Key, v => v.Value)) {
if(cfg.ContainsKey(skin.Key) && cfg[skin.Key].ContainsKey(skin.Value)) if(cfg[skin.Key][skin.Value].Permission != "" && !permission.UserHasPermission(id, cfg[skin.Key][skin.Value].Permission)) StoredData[userID].BuildingSkins[skin.Key] = 0;
if(cfg.ContainsKey(skin.Key)) {
if(!cfg[skin.Key].ContainsKey(skin.Value)) StoredData[userID].BuildingSkins[skin.Key] = 0;
}
else StoredData[userID].BuildingSkins.Remove(skin.Key);
}
}
else StoredData[userID].BuildingSkins = config.Setting.DefaultBuildingSkins.ToDictionary(k => k.Key, v => v.Value);
}
}
private static Dictionary<string, Dictionary<ulong, BSkins>> _buildingSkins = new Dictionary<string, Dictionary<ulong, BSkins>> {
["Twigs"]
= new Dictionary<ulong, BSkins> {
[0]
= new BSkins("https://i.ibb.co/xsPpBq7/000.png", "")
}
, ["Wood"] = new Dictionary<ulong, BSkins> {
[0]
= new BSkins("https://i.ibb.co/xGSyFy3/111.png", ""), [2] = new BSkins("https://i.ibb.co/JcS3LrT/101010.png", "xbuildingskinmenu.default"), [10232] = new BSkins("https://i.ibb.co/X5ww3T5/888.png", "xbuildingskinmenu.default")
}
, ["Stone"] = new Dictionary<ulong, BSkins> {
[0]
= new BSkins("https://i.ibb.co/st1DGc8/222.png", ""), [10220] = new BSkins("https://i.ibb.co/zZCHpRm/333.png", "xbuildingskinmenu.default"), [10223] = new BSkins("https://i.ibb.co/x1Bhvhq/777.png", "xbuildingskinmenu.default"), [10225] = new BSkins("https://i.ibb.co/kX2cnCz/999.png", "xbuildingskinmenu.default")
}
, ["Metal"] = new Dictionary<ulong, BSkins> {
[0]
= new BSkins("https://i.ibb.co/1v9YM5h/444.png", ""), [10221] = new BSkins("https://i.ibb.co/sHgDH6V/666.png", "xbuildingskinmenu.default")
}
, ["TopTier"] = new Dictionary<ulong, BSkins> {
[0]
= new BSkins("https://i.ibb.co/hd37DWH/555.png", "")
}
}
;
private object OnStructureUpgrade(BuildingBlock block, BasePlayer player, BuildingGrade.Enum grade, ulong skin) {
if(player == null || block == null || skin != 0) return null;
if(permission.UserHasPermission(player.UserIDString, permUse) && !PlayerIsRaidBlocked(player)) {
string g = grade.ToString();
if(StoredData[player.userID].BuildingSkins.ContainsKey(g)) {
if(block.SecondsSinceAttacked <= 30f) return true;
if(_isRepairToGrade && IQGradeRemove && block.health < block.MaxHealth()) return true;
if(block.grade == grade && block.skinID != 0) return null;
ulong skinID = StoredData[player.userID].BuildingSkins[g];
NextTick(() => {
if(block != null && block.skinID != skinID) {
uint color = GetShippingContainerBlockColourForPlayer(player);
block.ChangeGradeAndSkin(block.grade, skinID, false, true);
if(g == "Metal" && color != 0 && (skinID == 10221 || skinID == 15063726)) block.SetCustomColour(color);
}
}
);
}
}
return null;
}
private ulong GetBuildingSkin(BasePlayer player, string grade) => StoredData.ContainsKey(player.userID) && StoredData[player.userID].BuildingSkins.ContainsKey(grade) ? StoredData[player.userID].BuildingSkins[grade] : 0;
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<BuildingSkinConfig>();
}
catch {
PrintWarning(LanguageEnglish ? "Configuration read error! Creating a default configuration!" : "Ошибка чтения конфигурации! Создание дефолтной конфигурации!");
LoadDefaultConfig();
}
if(config.Setting.BSkinCommandList == null || config.Setting.BSkinCommandList.Count == 0) config.Setting.BSkinCommandList = new List<string> {
"bskin"
}
;
if(config.Setting.AutoAddSkins) foreach(var block in _buildingSkins) {
if(!config.Setting.BuildingSkins.ContainsKey(block.Key)) config.Setting.BuildingSkins.Add(block.Key, new Dictionary<ulong, BSkins>());
foreach(var skin in block.Value) if(!config.Setting.BuildingSkins[block.Key].ContainsKey(skin.Key)) config.Setting.BuildingSkins[block.Key].Add(skin.Key, new BSkins(skin.Value.ImageURL, skin.Value.Permission));
}
if(config.Setting.BuildingSkins.ContainsKey("Wood")) config.Setting.BuildingSkins["Wood"].Remove(10226);
foreach(string grade in _grades) if(!config.Setting.DefaultBuildingSkins.ContainsKey(grade)) config.Setting.DefaultBuildingSkins.Add(grade, 0);
config.Setting.BuildingSkins = config.Setting.BuildingSkins.OrderBy(x => _grades.IndexOf(x.Key)).ToDictionary(x => x.Key, x => x.Value);
SaveConfig();
}
private void LoadData(BasePlayer player) {
var Data = Interface.Oxide.DataFileSystem.ReadObject<Data>($"XDataSystem/XBuildingSkinMenu/{player.userID}");
StoredData[player.userID] = Data ?? new Data();
if(StoredData[player.userID].BuildingSkins == null) StoredData[player.userID].BuildingSkins = new Dictionary<string, ulong>();
if(StoredData[player.userID].BuildingSkins.Count == 0 || StoredData[player.userID].BuildingSkins.Count < config.Setting.BuildingSkins.Count) {
var dbs = config.Setting.DefaultBuildingSkins;
foreach(string grade in _grades) StoredData[player.userID].BuildingSkins[grade] = dbs.ContainsKey(grade) ? dbs[grade] : 0;
}
SetShippingContainerBlockColourForPlayer(player, StoredData[player.userID].ColourID);
ResetPlayerSkins(player.UserIDString);
if(StoredData[player.userID].WallpaperSkins == null) StoredData[player.userID].WallpaperSkins = new Dictionary<string, ulong>();
foreach(var block in _buildingSkins) foreach(var skinID in block.Value) {
string key = block.Key + skinID.Key;
if(!StoredData[player.userID].WallpaperSkins.ContainsKey(key)) StoredData[player.userID].WallpaperSkins.Add(key, 0);
}
}
private class BSkins {
public string ImageURL;
public string Permission;
public BSkins(string imageurl, string permission) {
ImageURL = imageurl;
Permission = permission;
}
}
private const string permEnt = "xbuildingskinmenu.entity";
private readonly Dictionary<string, string> _shortnamesEntity = new Dictionary<string, string>();
private class BuildingSkinConfig {
internal class GeneralSetting {
[JsonProperty(LanguageEnglish ? "Automatically add actual skins of building blocks to the configuration" : "Автоматически добавлять актуальные скины строительных блоков в конфигурацию")]
public bool AutoAddSkins;
[JsonProperty(LanguageEnglish ? "Only the owner of the cupboard can start painting the house" : "Только владелец шкафа может начать покраску дома")]
public bool HouseOwner;
[JsonProperty(LanguageEnglish ? "Use effects when painting home" : "Использовать эффекты при покраске дома")]
public bool UseEffect;
[JsonProperty(LanguageEnglish ? "Use effects when painting items/constructions in the house" : "Использовать эффекты при покраске предметов/конструкций в доме")]
public bool UseEffectE;
[JsonProperty(LanguageEnglish ? "Use effects when painting building blocks by hitting a hammer" : "Использовать эффекты при покраске строительного блоки ударом киянки")]
public bool UseEffectH;
[JsonProperty(LanguageEnglish ? "Enable painting of items/constructions in the house using player skins from the XSkinMenu plugin" : "Включить покраску предметов/конструкций в доме используя скины игроков из плагина XSkinMenu")]
public bool UseXSM;
[JsonProperty(LanguageEnglish ? "Skins for buildings" : "Скины на постройки")]
public Dictionary<string, Dictionary<ulong, BSkins>> BuildingSkins;
[JsonProperty(LanguageEnglish ? "Default skins for new players" : "Скины по умолчанию для новых игроков")]
public Dictionary<string, ulong> DefaultBuildingSkins;
[JsonProperty(LanguageEnglish ? "List of commands to open the menu" : "Список команд для открытия меню")]
public List<string> BSkinCommandList;
}
internal class GUISetting {
[JsonProperty(LanguageEnglish ? "Close the menu by tapping on an empty area of the screen" : "Закрыть меню нажатием на пустую область экрана")]
public bool CloseUI;
[JsonProperty(LanguageEnglish ? "Material_background_0" : "Материал_фон_0")]
public string BMaterial0;
[JsonProperty(LanguageEnglish ? "Color_background_0" : "Цвет_фон_0")]
public string BColor0;
[JsonProperty(LanguageEnglish ? "Color_background_1" : "Цвет_фон_1")]
public string BColor1;
[JsonProperty(LanguageEnglish ? "Color_background_2" : "Цвет_фон_2")]
public string BColor2;
[JsonProperty(LanguageEnglish ? "Skin background color" : "Цвет заднего фона скинов")]
public string BlockColor;
[JsonProperty(LanguageEnglish ? "Background color of the selected skin" : "Цвет заднего фона выбранного скина")]
public string ActiveBlockColor;
[JsonProperty(LanguageEnglish ? "Close button (icon) color" : "Цвет кнопки (иконки) закрыть")]
public string IconColor;
[JsonProperty(LanguageEnglish ? "Color of buttons in cupboard" : "Цвет кнопок в шкафу")]
public string ButtonColorCup;
[JsonProperty(LanguageEnglish ? "Button text color in cupboard" : "Цвет текста кнопок в шкафу")]
public string TButtonColorCup;
[JsonProperty(LanguageEnglish ? "Hammer button color - On" : "Цвет кнопки вкл киянки")]
public string ButtonColorHOn;
[JsonProperty(LanguageEnglish ? "Hammer button text color - On" : "Цвет текста кнопки вкл киянки")]
public string TButtonColorHOn;
[JsonProperty(LanguageEnglish ? "Hammer button color - Off" : "Цвет кнопки выкл киянки")]
public string ButtonColorHOff;
[JsonProperty(LanguageEnglish ? "Hammer button text color - Off" : "Цвет текста кнопки выкл киянки")]
public string TButtonColorHOff;
[JsonProperty(LanguageEnglish ? "AnchorMin - button 1" : "AnchorMin - кнопка 1")]
public string AnchorMinB1;
[JsonProperty(LanguageEnglish ? "AnchorMax - button 1" : "AnchorMax - кнопка 1")]
public string AnchorMaxB1;
[JsonProperty(LanguageEnglish ? "OffsetMin - button 1" : "OffsetMin - кнопка 1")]
public string OffsetMinB1;
[JsonProperty(LanguageEnglish ? "OffsetMax - button 1" : "OffsetMax - кнопка 1")]
public string OffsetMaxB1;
[JsonProperty(LanguageEnglish ? "AnchorMin - button 2" : "AnchorMin - кнопка 2")]
public string AnchorMinB2;
[JsonProperty(LanguageEnglish ? "AnchorMax - button 2" : "AnchorMax - кнопка 2")]
public string AnchorMaxB2;
[JsonProperty(LanguageEnglish ? "OffsetMin - button 2" : "OffsetMin - кнопка 2")]
public string OffsetMinB2;
[JsonProperty(LanguageEnglish ? "OffsetMax - button 2" : "OffsetMax - кнопка 2")]
public string OffsetMaxB2;
}
[JsonProperty(LanguageEnglish ? "General setting" : "Общие настройки")]
public GeneralSetting Setting = new GeneralSetting();
[JsonProperty(LanguageEnglish ? "GUI setting" : "Настройки GUI")]
public GUISetting GUI = new GUISetting();
public static BuildingSkinConfig GetNewConfiguration() {
return new BuildingSkinConfig {
Setting = new GeneralSetting {
AutoAddSkins = true, HouseOwner = false, UseEffect = true, UseEffectE = true, UseEffectH = false, UseXSM = false, BuildingSkins = _buildingSkins.ToDictionary(k => k.Key, v => v.Value), DefaultBuildingSkins = new Dictionary<string, ulong> {
["Twigs"]
= 0, ["Wood"] = 0, ["Stone"] = 0, ["Metal"] = 0, ["TopTier"] = 0
}
, BSkinCommandList = new List<string> {
"bskin"
}
}
, GUI = new GUISetting {
CloseUI = false, BMaterial0 = "assets/icons/greyout.mat", BColor0 = "0 0 0 0", BColor1 = "0.517 0.521 0.509 0.95", BColor2 = "0.217 0.221 0.209 0.95", BlockColor = "0.517 0.521 0.509 0.5", ActiveBlockColor = "0.53 0.77 0.35 0.8", IconColor = "1 1 1 0.75", ButtonColorCup = "0.35 0.45 0.25 1", TButtonColorCup = "0.75 0.95 0.41 1", ButtonColorHOn = "0.35 0.45 0.25 1", TButtonColorHOn = "0.75 0.95 0.41 1", ButtonColorHOff = "0.65 0.29 0.24 1", TButtonColorHOff = "0.92 0.79 0.76 1", AnchorMinB1 = "0.5 0", AnchorMaxB1 = "0.5 0", OffsetMinB1 = "395 621.5", OffsetMaxB1 = "572.5 641.5", AnchorMinB2 = "0.5 0", AnchorMaxB2 = "0.5 0", OffsetMinB2 = "395 646.5", OffsetMaxB2 = "572.5 666.5"
}
}
;
}
}
private void OnPlayerConnected(BasePlayer player) {
if(player.IsReceivingSnapshot) {
NextTick(() => OnPlayerConnected(player));
return;
}
LoadData(player);
}
[PluginReference]
private Plugin ImageLibrary, XSkinMenu, IQGradeRemove, RaidBlock, NoEscape;
private bool PlayerIsRaidBlocked(BasePlayer player) => Convert.ToBoolean(RaidBlock?.Call("IsRaidBlocked", player)) || Convert.ToBoolean(NoEscape?.Call("IsRaidBlocked", player));
[ConsoleCommand("skin_build")]
private void ccmdSetBuildingSkin(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if(player == null || args.Args == null || !permission.UserHasPermission(player.UserIDString, permUse)) return;
if(Cooldowns.ContainsKey(player)) if(Cooldowns[player].Subtract(DateTime.Now).TotalSeconds >= 0) return;
Cooldowns[player] = DateTime.Now.AddSeconds(1.0f);
if(args.Args.Length == 1) {
switch(args.GetString(0)) {
case "hammer" : {
StoredData[player.userID].HChange = !StoredData[player.userID].HChange;
break;
}
case "whammer" : {
StoredData[player.userID].WHChange = !StoredData[player.userID].WHChange;
break;
}
}
ButtonGUI(player);
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
return;
}
if(args.Args.Length >= 2) {
string key = args.Args[0];
if(config.Setting.BuildingSkins.ContainsKey(key) && StoredData[player.userID].BuildingSkins.ContainsKey(key)) {
ulong skinID;
ulong.TryParse(args.Args[1], out skinID);
if(config.Setting.BuildingSkins[key].ContainsKey(skinID) && (config.Setting.BuildingSkins[key][skinID].Permission == "" || permission.UserHasPermission(player.UserIDString, config.Setting.BuildingSkins[key][skinID].Permission))) {
StoredData[player.userID].BuildingSkins[key] = skinID;
SaveData(player);
BuildingSkinGUI(player);
EffectNetwork.Send(new Effect("assets/prefabs/deployable/repair bench/effects/skinchange_spraypaint.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
}
}
}
private void InitializeLang() {
lang.RegisterMessages(new Dictionary<string, string> {
["TITLE"]
= "COOL SERVER SKINS MENU", ["NOPERM"] = "No permissions!", ["SETSKIN"] = "PAINT THE HOUSE", ["SETSKIN_ENT"] = "PAINTING ITEMS IN THE HOUSE", ["PAINT_ACTIVE"] = "House <color=#fc9090>#{0}</color> is already being painted!", ["PAINT_ENT_ACTIVE"] = "Items/Constructions in the house <color=#fc9090>#{0}</color> is already being painted!", ["PAINT_START"] = "House <color=#9bfc90>#{0}</color> painting started.", ["PAINT_ENT_START"] = "Painting of items/constructions in house <color=#9bfc90>#{0}</color> has started.", ["PAINT_END"] = "House <color=#9bfc90>#{0}</color> painting completed.\n<size=12>Painted <color=#9bfc90>{1}</color> building blocks.</size>", ["PAINT_ENT_END"] = "Painting of items/constructions in house <color=#9bfc90>#{0}</color> completed.\n<size=12>Painted <color=#9bfc90>{1}</color> items/constructions.</size>", ["HAMMER_ON"] = "PAINTING BUILDING BLOCKS WITH A HAMMER - ON", ["HAMMER_OFF"] = "PAINTING BUILDING BLOCKS WITH A HAMMER - OFF", ["W_HAMMER_ON"] = "PAINTING WALLPAPERS WITH A HAMMER - ON", ["W_HAMMER_OFF"] = "PAINTING WALLPAPERS WITH A HAMMER - OFF"
}
, this);
lang.RegisterMessages(new Dictionary<string, string> {
["TITLE"]
= "МЕНЮ СКИНОВ КРУТОГО СЕРВЕРА", ["NOPERM"] = "Недостаточно прав!", ["SETSKIN"] = "ПОКРАСИТЬ ДОМ", ["SETSKIN_ENT"] = "ПОКРАСИТЬ ПРЕДМЕТЫ В ДОМЕ", ["PAINT_ACTIVE"] = "Дом <color=#fc9090>#{0}</color> уже красят!", ["PAINT_ENT_ACTIVE"] = "Предметы/Конструкции в доме <color=#fc9090>#{0}</color> уже красят!", ["PAINT_START"] = "Покраска дома <color=#9bfc90>#{0}</color> началась.", ["PAINT_ENT_START"] = "Покраска предметов/конструкций в доме <color=#9bfc90>#{0}</color> началась.", ["PAINT_END"] = "Покраска дома <color=#9bfc90>#{0}</color> завершена.\n<size=12>Покрашено <color=#9bfc90>{1}</color> строительных блоков.</size>", ["PAINT_ENT_END"] = "Покраска предметов/конструкций в доме <color=#9bfc90>#{0}</color> завершена.\n<size=12>Покрашено <color=#9bfc90>{1}</color> предметов/конструкций.</size>", ["HAMMER_ON"] = "ПОКРАСКА СТРОИТЕЛЬНЫХ БЛОКОВ КИЯНКОЙ - ВКЛ", ["HAMMER_OFF"] = "ПОКРАСКА СТРОИТЕЛЬНЫХ БЛОКОВ КИЯНКОЙ - ВЫКЛ", ["W_HAMMER_ON"] = "ПОКРАСКА ОБОЕВ КИЯНКОЙ - ВКЛ", ["W_HAMMER_OFF"] = "ПОКРАСКА ОБОЕВ КИЯНКОЙ - ВЫКЛ"
}
, this, "ru");
lang.RegisterMessages(new Dictionary<string, string> {
["TITLE"]
= "МЕНЮ СКІНІВ КРУТОГО СЕРВЕРУ", ["NOPERM"] = "Недостатньо прав!", ["SETSKIN"] = "ПОФАРБУВАТИ БУДИНОК", ["SETSKIN_ENT"] = "ПОФАРБУВАТИ ПРЕДМЕТИ У БУДИНКУ", ["PAINT_ACTIVE"] = "Будинок <color=#fc9090>#{0}</color> вже фарбують!", ["PAINT_ENT_ACTIVE"] = "Предмети/Конструкції у будинку <color=#fc9090>#{0}</color> вже фарбують!", ["PAINT_START"] = "Фарбування будинку <color=#9bfc90>#{0}</color> розпочалося.", ["PAINT_ENT_START"] = "Фарбування предметів/конструкцій у будинку <color=#9bfc90>#{0}</color> розпочалося.", ["PAINT_END"] = "Фарбування будинку <color=#9bfc90>#{0}</color> завершено.\n<size=12>Пофарбовано <color=#9bfc90>{1}</color> будівельних блоків.</size>", ["PAINT_ENT_END"] = "Фарбування предметів/конструкцій у будинку <color=#9bfc90>#{0}</color> завершено.\n<size=12>Пофарбовано <color=#9bfc90>{1}</color> предметів/конструкцій.</size>", ["HAMMER_ON"] = "ФАРБУВАННЯ БУДІВЕЛЬНИХ БЛОКІВ КИЯНКОЮ - УВІМК", ["HAMMER_OFF"] = "ФАРБУВАННЯ БУДІВЕЛЬНИХ БЛОКІВ КИЯНКОЮ - ВИМК", ["W_HAMMER_ON"] = "ФАРБУВАННЯ ШПАЛЕР КИЯНКОЮ - УВІМК", ["W_HAMMER_OFF"] = "ФАРБУВАННЯ ШПАЛЕР КИЯНКОЮ - ВИМК"
}
, this, "uk");
lang.RegisterMessages(new Dictionary<string, string> {
["TITLE"]
= "NOMBRE DEL SERVIDOR", ["NOPERM"] = "¡No tienes permisos!", ["SETSKIN"] = "PINTA LA CASA", ["SETSKIN_ENT"] = "ARTÍCULOS DE PINTURA EN CASA", ["PAINT_ACTIVE"] = "¡La casa <color=#fc9090>#{0}</color> ya se está pintando!", ["PAINT_ENT_ACTIVE"] = "¡Ya se están pintando los artículos/construcciones de la casa <color=#fc9090>#{0}</color>!", ["PAINT_START"] = "Comenzó la pintura de la casa <color=#9bfc90>#{0}</color>.", ["PAINT_ENT_START"] = "Se ha iniciado la pintura de artículos/construcciones en la casa <color=#9bfc90>#{0}</color>.", ["PAINT_END"] = "Pintura de la casa <color=#9bfc90>#{0}</color> completada.\n<size=12>Pintado <color=#9bfc90>{1}</color> bloques de construcción.</size>", ["PAINT_ENT_END"] = "Pintura de artículos/construcciones en la casa <color=#9bfc90>#{0}</color> completada.\n<size=12>Pintado <color=#9bfc90>{1}</color> artículos/construcciones.</size>", ["HAMMER_ON"] = "PINTAR BLOQUES DE CONSTRUCCIÓN CON UN MARTILLO - ON", ["HAMMER_OFF"] = "PINTAR BLOQUES DE CONSTRUCCIÓN CON UN MARTILLO - OFF", ["W_HAMMER_ON"] = "PINTAR PAPELES PINTADOS CON UN MARTILLO - ON", ["W_HAMMER_OFF"] = "PINTAR PAPELES PINTADOS CON UN MARTILLO - OFF"
}
, this, "es-ES");
}
private void OnHammerHit(BasePlayer player, HitInfo info) {
BuildingBlock block = info?.HitEntity as BuildingBlock;
if(player == null || block == null || !player.CanBuild() || !permission.UserHasPermission(player.UserIDString, permUse)) return;
if(config.Setting.HouseOwner && block.GetBuildingPrivilege()?.OwnerID != player.userID) return;
var player_data = StoredData[player.userID];
string g = block.grade.ToString();
if(player_data.BuildingSkins.ContainsKey(g)) {
if(player_data.HChange) {
uint colourID = GetShippingContainerBlockColourForPlayer(player);
ulong skinID = player_data.BuildingSkins[g];
if(block.skinID != skinID) {
block.ChangeGradeAndSkin(block.grade, skinID, false, true);
if(g == "Metal" && colourID != 0 && (skinID == 10221 || skinID == 15063726)) block.SetCustomColour(colourID);
if(config.Setting.UseEffectH) EffectsRun(block.transform.position);
}
else {
if(g == "Metal" && (skinID == 10221 || skinID == 15063726)) if(block.customColour != colourID) {
if(colourID == 0) block.SetCustomColour(block.currentSkin.GetStartingDetailColour(0));
else block.SetCustomColour(colourID);
if(config.Setting.UseEffectH) EffectsRun(block.transform.position);
}
}
}
if(player_data.WHChange && block.wallpaperHealth > 0f) {
ulong wallpaperSkin = player_data.WallpaperSkins[g + block.skinID];
if(block.wallpaperID != wallpaperSkin) block.SetWallpaper(wall
// ... [Code preview truncated due to length. Full source in attached file] ...