C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
// #define TESTING
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Plugins.CraftsExtensionMethods;
using Rust;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Oxide.Plugins
{
[Info("Crafts", "Mevent", "2.10.11")]
public class Crafts : RustPlugin
{
#region Fields
[PluginReference] private Plugin
ImageLibrary = null,
SpawnModularCar = null,
Notify = null,
UINotify = null,
LangAPI = null;
private static Crafts _instance;
private bool _enabledImageLibrary;
private const string Layer = "UI.Crafts";
private const string EditLayer = "UI.Crafts.Edit";
private const string PermEdit = "crafts.edit";
private const string PermSetWb = "crafts.setworkbench";
private const string PermBypass = "crafts.bypass";
private List<CraftConf> _crafts = new List<CraftConf>();
private readonly List<RecyclerComponent> _recyclers = new List<RecyclerComponent>();
private readonly List<CarController> _cars = new List<CarController>();
private readonly List<BasePlayer> _openedUi = new List<BasePlayer>();
private readonly Dictionary<string, List<KeyValuePair<int, string>>> _itemsCategories =
new Dictionary<string, List<KeyValuePair<int, string>>>();
private readonly List<SafeZoneComponent> _safeZones = new List<SafeZoneComponent>();
private enum WorkbenchLevel
{
None = 0,
One = 1,
Two = 2,
Three = 3
}
private enum CraftType
{
Command,
Vehicle,
Item,
Recycler,
ModularCar
}
private readonly Dictionary<int, ItemForCraft> _itemsById = new Dictionary<int, ItemForCraft>();
private readonly Dictionary<int, CraftConf> _craftsById = new Dictionary<int, CraftConf>();
private readonly Dictionary<BasePlayer, Dictionary<string, object>> _craftEditing =
new Dictionary<BasePlayer, Dictionary<string, object>>();
private readonly Dictionary<BasePlayer, Dictionary<string, object>> _itemEditing =
new Dictionary<BasePlayer, Dictionary<string, object>>();
private readonly Dictionary<ulong, CustomWorkbenchConf> _openedCustomWb =
new Dictionary<ulong, CustomWorkbenchConf>();
#endregion
#region Config
private static Configuration _config;
private class Configuration
{
[JsonProperty(PropertyName = "Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] Commands = {"craft", "crafts"};
[JsonProperty(PropertyName = "Close UI when reusing a command?")]
public bool CloseReusing = false;
[JsonProperty(PropertyName = "Work with Notify?")]
public bool UseNotify = true;
[JsonProperty(PropertyName = "Work with LangAPI?")]
public bool UseLangAPI = true;
[JsonProperty(PropertyName = "Permission (ex: crafts.use)")]
public string Permission = string.Empty;
[JsonProperty(PropertyName = "Economy")]
public EconomyConf Economy = new EconomyConf
{
Show = false,
Type = EconomyConf.EconomyType.Plugin,
AddHook = "Deposit",
BalanceHook = "Balance",
RemoveHook = "Withdraw",
Plug = "Economics",
ShortName = "scrap",
DisplayName = string.Empty,
Skin = 0
};
[JsonProperty(PropertyName = "Categories", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<Category> Categories = new List<Category>
{
new Category
{
Enabled = true,
Permission = string.Empty,
Title = "Vehicles",
Color = new IColor("#161617", 100),
Crafts = new List<CraftConf>
{
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/mqYTq4P/image.png",
Title = "Minicopter",
Description = "Fast air transport",
CmdToGive = "givecopter",
Permission = "crafts.all",
DisplayName = "Minicopter",
ShortName = "electric.flasherlight",
Amount = 1,
SkinID = 2080145158,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/minicopter/minicopter.entity.prefab",
Level = WorkbenchLevel.One,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Fast air transport",
["fr"] = "Transport aérien rapide"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/tmsNRcB/newkopter.png",
Title = "Attack Helicopter",
Description = "Fast air transport",
CmdToGive = "giveattackhelicopter",
Permission = "crafts.all",
DisplayName = "Attack Helicopter",
ShortName = "electric.flasherlight",
Amount = 1,
SkinID = 3043024177,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/attackhelicopter/attackhelicopter.entity.prefab",
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Fast air transport",
["fr"] = "Transport aérien rapide"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/LJdqQ6z/image.png",
Description = "Slow water transport",
Title = "Row Boat",
CmdToGive = "giverowboat",
Permission = "crafts.all",
DisplayName = "Row Boat",
ShortName = "coffin.storage",
Amount = 1,
SkinID = 2080150023,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/boats/rowboat/rowboat.prefab",
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Slow water transport",
["fr"] = "Transport lent de l'eau"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/HpkTsBZ/image.png",
Description = "Slow water transport",
Title = "RHIB",
CmdToGive = "giverhibboat",
Permission = "crafts.all",
DisplayName = "RHIB",
ShortName = "electric.sirenlight",
Amount = 1,
SkinID = 2080150770,
Type = CraftType.Vehicle,
GiveCommand = string.Empty,
Prefab = "assets/content/vehicles/boats/rhib/rhib.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Slow water transport",
["fr"] = "Transport lent de l'eau"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/gr64fDx/image.png",
Title = "Hot Air Balloon",
Description = "Slow air transport",
CmdToGive = "givehotair",
Permission = "crafts.all",
DisplayName = "Hot Air Balloon",
ShortName = "box.repair.bench",
Amount = 1,
SkinID = 2080152635,
Type = CraftType.Vehicle,
GiveCommand = string.Empty,
Prefab = "assets/prefabs/deployable/hot air balloon/hotairballoon.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Slow air transport",
["fr"] = "Lenteur du transport aérien"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/nzXCNws/image.png",
Title = "Transport Helicopter",
Description = "Fast air transport",
CmdToGive = "givescrapheli",
Permission = "crafts.all",
DisplayName = "Transport Helicopter",
ShortName = "electric.flasherlight",
Amount = 1,
SkinID = 2080154394,
Type = CraftType.Vehicle,
GiveCommand = string.Empty,
Prefab = "assets/content/vehicles/scrap heli carrier/scraptransporthelicopter.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Fast air transport",
["fr"] = "Transport aérien rapide"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/gdcVNwr/image.png",
Title = "Snowmobile",
Description = "Conquers snow biomes",
CmdToGive = "givesnowmobile",
Permission = "crafts.all",
DisplayName = "Snowmobile",
ShortName = "electric.flasherlight",
Amount = 1,
SkinID = 2747934628,
Type = CraftType.Vehicle,
GiveCommand = string.Empty,
Prefab = "assets/content/vehicles/snowmobiles/snowmobile.prefab",
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = false,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Conquers snow biomes",
["fr"] = "À la conquête des biomes enneigés"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/jWC9Mrd/image.png",
Title = "Submarine Solo",
Description = "Fast underwater transport",
CmdToGive = "givesolosubmarine",
Permission = "crafts.all",
DisplayName = "Submarine Solo",
ShortName = "barricade.sandbags",
Amount = 1,
SkinID = 3043043385,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/submarine/submarinesolo.entity.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Fast underwater transport",
["fr"] = "Transport subaquatique rapide"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/qYNQhTJ/image.png",
Title = "Submarine Duo",
Description = "Fast underwater transport",
CmdToGive = "giveduosubmarine",
Permission = "crafts.all",
DisplayName = "Submarine Duo",
ShortName = "barricade.sandbags",
Amount = 1,
SkinID = 3043043217,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/submarine/submarineduo.entity.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Fast underwater transport",
["fr"] = "Transport subaquatique rapide"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/80hKRcm/tugboat.png",
Title = "Tugboat",
Description = "Slow water transport",
CmdToGive = "givetugboat",
Permission = "crafts.all",
DisplayName = "Tugboat",
ShortName = "barricade.sandbags",
Amount = 1,
SkinID = 3043043727,
Type = CraftType.Vehicle,
Prefab = "assets/content/vehicles/boats/tugboat/tugboat.prefab",
Level = WorkbenchLevel.Three,
UseDistance = true,
Distance = 1.5f,
GiveCommand = string.Empty,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = true,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "Slow water transport",
["fr"] = "Transport lent de l'eau"
}
}
}
}
},
new Category
{
Enabled = true,
Permission = string.Empty,
Title = "Cars",
Color = new IColor("#161617", 100),
Crafts = new List<CraftConf>
{
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/MG4N1cs/image.png",
Title = "Sedan",
Description = "5KM/H",
CmdToGive = "givesedan",
Permission = "crafts.all",
DisplayName = "Car",
ShortName = "woodcross",
Amount = 1,
SkinID = 2080151780,
Type = CraftType.Vehicle,
GiveCommand = string.Empty,
Prefab = "assets/content/vehicles/sedan_a/sedantest.entity.prefab",
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = false,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "5KM/H",
["fr"] = "5KM/H"
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/nwsDTbW/image.png",
Title = "Ferrari",
Description = "25KM/H",
CmdToGive = "givemod1",
Permission = "crafts.all",
DisplayName = "Car",
ShortName = "electric.flasherlight",
Amount = 1,
SkinID = 2244308598,
Type = CraftType.ModularCar,
Prefab = string.Empty,
GiveCommand = string.Empty,
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = false,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = "25KM/H",
["fr"] = "25KM/H"
}
}
}
}
},
new Category
{
Enabled = true,
Permission = string.Empty,
Title = "Misc",
Color = new IColor("#161617", 100),
Crafts = new List<CraftConf>
{
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/mHRkk5P/image.png",
Title = "Home Recycler",
Description = string.Empty,
CmdToGive = "giverecycler",
Permission = "crafts.all",
DisplayName = "Home Recycler",
ShortName = "research.table",
Amount = 1,
SkinID = 2186833264,
Type = CraftType.Recycler,
Prefab = "assets/bundled/prefabs/static/recycler_static.prefab",
GiveCommand = string.Empty,
Level = WorkbenchLevel.Two,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = false,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = string.Empty,
["fr"] = string.Empty
}
}
},
new CraftConf
{
Enabled = true,
Image = "https://i.ibb.co/024076x/image.png",
Title = string.Empty,
Description = string.Empty,
CmdToGive = "givelr300",
Permission = "crafts.all",
DisplayName = string.Empty,
ShortName = "rifle.lr300",
Amount = 1,
SkinID = 0,
Type = CraftType.Item,
Prefab = string.Empty,
GiveCommand = string.Empty,
Level = WorkbenchLevel.None,
UseDistance = true,
Distance = 1.5f,
Ground = true,
Structure = true,
Items = new List<ItemForCraft>
{
new ItemForCraft(string.Empty, "gears", 5, 0),
new ItemForCraft(string.Empty, "roadsigns", 5, 0),
new ItemForCraft(string.Empty, "metal.fragments", 2000, 0)
},
Modular = new ModularCarConf
{
CodeLock = true,
KeyLock = false,
EnginePartsTier = 2,
FreshWaterAmount = 0,
FuelAmount = 140,
Modules = new[]
{
"vehicle.1mod.engine",
"vehicle.1mod.cockpit.armored",
"vehicle.1mod.cockpit.armored"
}
},
Cooldown = 0,
MultipleCraft = false,
MaxAmount = 0,
Craft = true,
Sale = false,
Cost = 100,
SetOwnerID = false,
CustomizeRotationOnSpawning = false,
CraftMenuDescription = new Localization
{
Enabled = false,
Messages = new Dictionary<string, string>
{
["en"] = string.Empty,
["fr"] = string.Empty
}
}
}
}
}
};
[JsonProperty(PropertyName = "Workbenches Setting",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<WorkbenchLevel, IColor> Workbenches =
new Dictionary<WorkbenchLevel, IColor>
{
[WorkbenchLevel.None] = new IColor("#FFFFFF", 00),
[WorkbenchLevel.One] = new IColor("#74884A", 100),
[WorkbenchLevel.Two] = new IColor("#B19F56", 100),
[WorkbenchLevel.Three] = new IColor("#B43D3D", 100)
};
[JsonProperty(PropertyName = "Recycler Settings")]
public RecyclerConfig Recycler = new RecyclerConfig
{
Enabled = true,
UseSpeed = true,
Speed = 5f,
Radius = 7.5f,
Text = "<size=19>RECYCLER</size>\n<size=15>{0}/{1}</size>",
Color = "#C5D0E6",
Delay = 0.75f,
Available = true,
Owner = true,
Amounts = new[]
{0.9f, 0, 0, 0, 0, 0.5f, 0, 0, 0, 0.9f, 0.5f, 0.5f, 0, 1, 1, 0.5f, 0, 0, 0, 0, 0, 1, 1},
Scale = 0.5f,
DDraw = true,
Building = true,
Destroy = new RecyclerDestroy
{
CheckGround = true,
Item = true,
Effects = new List<string>
{
"assets/bundled/prefabs/fx/item_break.prefab",
"assets/bundled/prefabs/fx/impacts/stab/rock/stab_rock_01.prefab"
}
}
};
[JsonProperty(PropertyName = "Car Settings")]
public CarConfig Car = new CarConfig
{
ActiveItems = new ActiveItemOptions
{
Disable = true,
BlackList = new[]
{
"explosive.timed", "rocket.launcher", "surveycharge", "explosive.satchel"
}
},
Radius = 7.5f,
Text = "<size=15>{0}/{1}</size>",
Color = "#C5D0E6",
Delay = 0.75f
};
[JsonProperty(PropertyName = "Custom Workbench Stations (Entity ID - settings)",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<ulong, CustomWorkbenchConf> CustomWorkbench =
new Dictionary<ulong, CustomWorkbenchConf>
{
[123343941] = new CustomWorkbenchConf
{
Categories = new List<string>
{
"Cars", "Misc"
},
SafeZone = true,
SafeZoneRadius = 5,
WorkBench = new Dictionary<string, int>
{
["crafts.default"] = 0,
["crafts.premium"] = 3
}
}
};
[JsonProperty(PropertyName = "UI Settings")]
public UserInterface UI = new UserInterface
{
CatWidth = 90,
CatMargin = 5,
CatHeight = 25,
CraftWidth = 125,
CraftHeight = 125,
CraftMargin = 10,
CraftYIndent = -115,
CraftStrings = 2,
CraftAmountOnString = 5,
CategoriesAmountOnPage = 7,
PageSize = 25,
PageSelectedSize = 40,
PagesMargin = 5,
Color1 = new IColor("#0E0E10", 100),
Color2 = new IColor("#161617", 100),
Color3 = new IColor("#FFFFFF", 100),
Color4 = new IColor("#4B68FF", 100),
Color5 = new IColor("#74884A", 100),
Color6 = new IColor("#CD4632", 100),
Color7 = new IColor("#595651", 100),
Color8 = new IColor("#4B68FF", 70),
Color9 = new IColor("#0E0E10", 98),
Color10 = new IColor("#4B68FF", 50),
Color11 = new IColor("#FF4B4B", 100),
BackgroundImage = string.Empty,
CloseAfterCraft = true,
CraftMenuSettings = new UserInterface.CraftMenu
{
ItemWidth = 40,
ItemHeight = 165,
ItemMargin = 105,
MaxItemsOnString = 7,
ItemUpIndent = 285,
Description = new PanelSettings
{
AnchorMin = "0.5 0",
AnchorMax = "0.5 0",
OffsetMin = "-200 50",
OffsetMax = "200 130",
FontSize = 14,
Align = TextAnchor.MiddleCenter,
Color = new IColor("#FFFFFF", 100),
Font = "robotocondensed-bold.ttf",
BackgroundColor = new IColor("#0E0E10", 100)
}
}
};
public VersionNumber Version;
}
private class Localization
{
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Text (language - text)",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, string> Messages = new Dictionary<string, string>();
public string GetMessage(BasePlayer player = null)
{
if (Messages.Count == 0)
throw new Exception("The use of localization is enabled, but there are no messages!");
var userLang = "en";
if (player != null) userLang = _instance.lang.GetLanguage(player.UserIDString);
string message;
if (Messages.TryGetValue(userLang, out message))
return message;
if (Messages.TryGetValue("en", out message))
return message;
return Messages.ElementAt(0).Value;
}
}
private class EconomyConf
{
public enum EconomyType
{
Plugin,
Item
}
[JsonProperty(PropertyName = "Show Balance")]
public bool Show;
[JsonProperty(PropertyName = "Type (Plugin/Item)")] [JsonConverter(typeof(StringEnumConverter))]
public EconomyType Type;
[JsonProperty(PropertyName = "Plugin name")]
public string Plug;
[JsonProperty(PropertyName = "Balance add hook")]
public string AddHook;
[JsonProperty(PropertyName = "Balance remove hook")]
public string RemoveHook;
[JsonProperty(PropertyName = "Balance show hook")]
public string BalanceHook;
[JsonProperty(PropertyName = "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = "Display Name (empty - default)")]
public string DisplayName;
[JsonProperty(PropertyName = "Skin")] public ulong Skin;
public double ShowBalance(BasePlayer player)
{
switch (Type)
{
case EconomyType.Plugin:
{
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return 0;
return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.userID)), 2);
}
case EconomyType.Item:
{
return ItemCount(player.inventory.AllItems(), ShortName, Skin);
}
default:
return 0;
}
}
public void AddBalance(BasePlayer player, double amount)
{
switch (Type)
{
case EconomyType.Plugin:
{
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return;
switch (Plug)
{
case "BankSystem":
case "ServerRewards":
case "IQEconomic":
plugin.Call(AddHook, player.userID, (int) amount);
break;
default:
plugin.Call(AddHook, player.userID, amount);
break;
}
break;
}
case EconomyType.Item:
{
var am = (int) amount;
var item = ToItem(am);
if (item == null) return;
player.GiveItem(item);
break;
}
}
}
public bool RemoveBalance(BasePlayer player, double amount)
{
switch (Type)
{
case EconomyType.Plugin:
{
if (ShowBalance(player) < amount) return false;
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return false;
switch (Plug)
{
case "BankSystem":
case "ServerRewards":
case "IQEconomic":
plugin.Call(RemoveHook, player.userID, (int) amount);
break;
default:
plugin.Call(RemoveHook, player.userID, amount);
break;
}
return true;
}
case EconomyType.Item:
{
var playerItems = player.inventory.AllItems();
var am = (int) amount;
if (ItemCount(playerItems, ShortName, Skin) < am) return false;
Take(playerItems, ShortName, Skin, am);
return true;
}
default:
return false;
}
}
public bool Transfer(BasePlayer player, BasePlayer targetPlayer, double amount)
{
if (!RemoveBalance(player, amount))
return false;
AddBalance(targetPlayer, amount);
return true;
}
private Item ToItem(int amount)
{
var item = ItemManager.CreateByName(ShortName, amount, Skin);
if (item == null)
{
Debug.LogError($"Error creating item with ShortName: '{ShortName}'");
return null;
}
if (!string.IsNullOrEmpty(DisplayName)) item.name = DisplayName;
return item;
}
}
private class CustomWorkbenchConf
{
[JsonProperty(PropertyName = "Categories (Titles) [* - all]",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> Categories;
[JsonProperty(PropertyName = "Use safe zone")]
public bool SafeZone;
[JsonProperty(PropertyName = "Safe Zone Radius")]
public float SafeZoneRadius;
[JsonProperty(PropertyName = "WorkBench Level", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, int> WorkBench = new Dictionary<string, int>
{
["crafts.default"] = 0,
["crafts.premium"] = 0
};
public WorkbenchLevel GetWorkBenchLevel(BasePlayer player)
{
var result = 0;
foreach (var check in WorkBench)
if (!string.IsNullOrEmpty(check.Key) &&
_instance.permission.UserHasPermission(
player.UserIDString, check.Key)
&& check.Value > result)
result = check.Value;
return (WorkbenchLevel) result;
}
}
private class UserInterface
{
[JsonProperty(PropertyName = "Category Width")]
public float CatWidth;
[JsonProperty(PropertyName = "Category Height")]
public float CatHeight;
[JsonProperty(PropertyName = "Category Margin")]
public float CatMargin;
[JsonProperty(PropertyName = "Craft Width")]
public float CraftWidth;
[JsonProperty(PropertyName = "Craft Height")]
public float CraftHeight;
[JsonProperty(PropertyName = "Craft Margin")]
public float CraftMargin;
[JsonProperty(PropertyName = "Craft Y Indent")]
public float CraftYIndent;
[JsonProperty(PropertyName = "Craft Amount On String")]
public int CraftAmountOnString;
[JsonProperty(PropertyName = "Categories Amount On Page")]
public int CategoriesAmountOnPage;
[JsonProperty(PropertyName = "Craft Strings")]
public int CraftStrings;
[JsonProperty(PropertyName = "Page Size")]
public float PageSize;
[JsonProperty(PropertyName = "Page Selected Size")]
public float PageSelectedSize;
[JsonProperty(PropertyName = "Pages Margin")]
public float PagesMargin;
[JsonProperty(PropertyName = "Color 1")]
public IColor Color1;
[JsonProperty(PropertyName = "Color 2")]
public IColor Color2;
[JsonProperty(PropertyName = "Color 3")]
public IColor Color3;
[JsonProperty(PropertyName = "Color 4")]
public IColor Color4;
[JsonProperty(PropertyName = "Color 5")]
public IColor Color5;
[JsonProperty(PropertyName = "Color 6")]
public IColor Color6;
[JsonProperty(PropertyName = "Color 7")]
public IColor Color7;
[JsonProperty(PropertyName = "Color 8")]
public IColor Color8;
[JsonProperty(PropertyName = "Color 9")]
public IColor Color9;
[JsonProperty(PropertyName = "Color 10")]
public IColor Color10;
[JsonProperty(PropertyName = "Color 11")]
public IColor Color11;
[JsonProperty(PropertyName = "Background Image")]
public string BackgroundImage;
[JsonProperty(PropertyName = "Close after craft?")]
public bool CloseAfterCraft;
[JsonProperty(PropertyName = "Craft Menu")]
public CraftMenu CraftMenuSettings;
public class CraftMenu
{
[JsonProperty(PropertyName = "Item Width")]
public float ItemWidth;
[JsonProperty(PropertyName = "Item Height")]
public float ItemHeight;
[JsonProperty(PropertyName = "Item Margin")]
public float ItemMargin;
[JsonProperty(PropertyName = "Max Items On String")]
public int MaxItemsOnString;
[JsonProperty(PropertyName = "Item Up Indent")]
public float ItemUpIndent;
[JsonProperty(PropertyName = "Description")]
public PanelSettings Description;
}
}
private class InterfacePosition
{
public string AnchorMin;
public string AnchorMax;
public string OffsetMin;
public string OffsetMax;
}
private class LabelSettings : InterfacePosition
{
[JsonProperty(PropertyName = "FontSize")]
public int FontSize;
[JsonProperty(PropertyName = "Align")] [JsonConverter(typeof(StringEnumConverter))]
public TextAnchor Align;
[JsonProperty(PropertyName = "Color")] public IColor Color;
[JsonProperty(PropertyName = "Font")] public string Font;
}
private class PanelSettings : LabelSettings
{
[JsonProperty(PropertyName = "Background Color")]
public IColor BackgroundColor;
}
private class Category
{
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Permission (ex: crafts.vip)")]
public string Permission;
[JsonProperty(PropertyName = "Title")] public string Title;
[JsonProperty(PropertyName = "Background color")]
public IColor Color;
[JsonProperty(PropertyName = "Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<CraftConf> Crafts;
}
private class CraftConf
{
[JsonProperty(PropertyName = "ID")] public int ID;
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Image")] public string Image;
[JsonProperty(PropertyName = "Title")] public string Title;
[JsonProperty(PropertyName = "Description")]
public string Description;
[JsonProperty(PropertyName = "Command (to give an item)")]
public string CmdToGive;
[JsonProperty(PropertyName = "Permission (ex: crafts.vip)")]
public string Permission;
[JsonProperty(PropertyName = "Display Name")]
public string DisplayName;
[JsonProperty(PropertyName = "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = "Amount")]
public int Amount;
[JsonProperty(PropertyName = "Skin")] public ulong SkinID;
[JsonProperty(PropertyName = "Type (Item/Command/Vehicle/Recycler)")]
[JsonConverter(typeof(StringEnumConverter))]
public CraftType Type;
[JsonProperty(PropertyName = "Prefab")]
public string Prefab;
[JsonProperty(PropertyName = "Command on give")]
public string GiveCommand;
[JsonProperty(PropertyName = "Workbench Level")]
public WorkbenchLevel Level;
[JsonProperty(PropertyName = "Distance Check")]
public bool UseDistance;
[JsonProperty(PropertyName = "Distance")]
public float Distance;
[JsonProperty(PropertyName = "Place the ground")]
public bool Ground;
[JsonProperty(PropertyName = "Place the structure")]
public bool Structure;
[JsonProperty(PropertyName = "Items For Craft",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ItemForCraft> Items;
[JsonProperty(PropertyName = "For Modular Car")]
public ModularCarConf Modular;
[JsonProperty(PropertyName = "Cooldown")]
public float Cooldown;
[JsonProperty(PropertyName = "Multiple Craft")]
public bool MultipleCraft;
[JsonProperty(PropertyName = "Maximum number of crafts")]
public int MaxAmount;
[JsonProperty(PropertyName = "Enable Craft?")]
public bool Craft;
[JsonProperty(PropertyName = "Enable Sales?")]
public bool Sale;
[JsonProperty(PropertyName = "Cost")] public float Cost;
[JsonProperty(PropertyName = "Set OwnerID for child containers?")]
public bool SetOwnerID;
[JsonProperty(PropertyName = "Need to customize the rotation when spawning?")]
public bool CustomizeRotationOnSpawning;
[JsonProperty(PropertyName = "Description settings (in the craft menu)")]
public Localization CraftMenuDescription;
[JsonIgnore] private int _itemId = -1;
[JsonIgnore]
public int itemId
{
get
{
if (_itemId == -1)
_itemId = ItemManager.FindItemDefinition(ShortName)?.itemid ?? -1;
return _itemId;
}
}
[JsonIgnore]
public int PUBLIC_ID
{
get
{
while (ID == 0)
{
var val = Random.Range(int.MinValue, int.MaxValue);
if (_instance._craftsById.ContainsKey(val)) continue;
ID = val;
}
return ID;
}
}
[JsonIgnore] private string _publicTitle;
[JsonIgnore]
public string PublicTitle
{
get
{
if (string.IsNullOrEmpty(_publicTitle))
_publicTitle = GetName();
return _publicTitle;
}
}
private string GetName()
{
if (!string.IsNullOrEmpty(Title))
return Title;
if (!string.IsNullOrEmpty(DisplayName))
return DisplayName;
var def = ItemManager.FindItemDefinition(ShortName);
if (!string.IsNullOrEmpty(ShortName) && def != null)
return def.displayName.translated;
return string.Empty;
}
public Item ToItem()
{
var newItem = ItemManager.CreateByName(ShortName, Amount, SkinID);
if (newItem == null)
{
Debug.LogError($"Error creating item with ShortName: '{ShortName}'");
return null;
}
if (!string.IsNullOrEmpty(DisplayName)) newItem.name = DisplayName;
return newItem;
}
public void Give(BasePlayer player)
{
if (player == null) return;
var item = ToItem();
if (item == null) return;
player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
}
public void Spawn(BasePlayer player, Vector3 pos, Quaternion rot)
{
switch (Type)
{
case CraftType.ModularCar:
{
_instance?.SpawnModularCar?.Call("API_SpawnPresetCar", player, Modular.Get());
break;
}
case CraftType.Vehicle:
{
var entity = GameManager.server.CreateEntity(Prefab, pos,
CustomizeRotationOnSpawning
? Quaternion.Euler(0, player.GetNetworkRotation().eulerAngles.y - 90, 0)
: rot);
if (entity == null) return;
entity.skinID = SkinID;
entity.OwnerID = player.userID;
entity.Spawn();
if (SetOwnerID)
foreach (var container in entity.GetComponentsInChildren<StorageContainer>())
container.OwnerID = player.userID;
break;
}
default:
{
var entity = GameManager.server.CreateEntity(Prefab, pos, rot);
if (entity == null) return;
entity.skinID = SkinID;
entity.OwnerID = player.userID;
entity.Spawn();
if (SetOwnerID)
foreach (var container in entity.GetComponentsInChildren<StorageContainer>())
container.OwnerID = player.userID;
break;
}
}
}
public Dictionary<string, object> ToDictionary()
{
return new Dictionary<string, object>
{
["Generated"] = false,
["Enabled"] = Enabled,
["Image"] = Image,
["Title"] = Title,
["Description"] = Description,
["CmdToGive"] = CmdToGive,
["Permission"] = Permission,
["DisplayName"] = DisplayName,
["ShortName"] = ShortName,
["Amount"] = Amount,
["SkinID"] = SkinID,
["Type"] = Type,
["Prefab"] = Prefab,
["GiveCommand"] = GiveCommand,
["Level"] = Level,
["UseDistance"] = UseDistance,
["Distance"] = Distance,
["Ground"] = Ground,
["Structure"] = Structure,
["Items"] = Items,
["Craft"] = Craft,
["Sales"] = Sale,
["Cost"] = Cost
};
}
public void UpdateCooldown(BasePlayer player)
{
PlayerCooldown.GetOrAdd(player.userID)?.Add(this);
}
public bool HasCooldown(BasePlayer player, out int timeLeft)
{
timeLeft = 0;
if (Cooldown <= 0)
return false;
var data = PlayerCooldown.GetOrAdd(player.userID);
if (data == null) return false;
timeLeft = data.GetCooldown(this);
return timeLeft > 0;
}
}
private class IColor
{
[JsonProperty(PropertyName = "HEX")] public string Hex;
[JsonProperty(PropertyName = "Opacity (0 - 100)")]
public float Alpha;
public string Get()
{
if (string.IsNullOrEmpty(Hex)) Hex = "#FFFFFF";
var str = Hex.Trim('#');
if (str.Length != 6) throw new Exception(Hex);
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
}
public IColor(string hex, float alpha)
{
Hex = hex;
Alpha = alpha;
}
}
private class ItemForCraft
{
[JsonProperty(PropertyName = "Image")] public string Image;
[JsonProperty(PropertyName = "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = "Amount")]
public int Amount;
[JsonProperty(PropertyName = "Skin")] public ulong SkinID;
[JsonProperty(PropertyN
// ... [Code preview truncated due to length. Full source in attached file] ...