C#:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using WebSocketSharp;
using Random = UnityEngine.Random;
namespace Oxide.Plugins {
[Info("MultiEvents", "by.kamAp", "1.39.0")]
public class MultiEvents : RustPlugin {
#region Fields
[PluginReference]
private Plugin Duel, ImageLibrary;
private const string Layer = "UI.MultiEvents";
private int time;
private BasePlayer winner;
private BasePlayer runner;
private readonly List<string> Winners = new List<string>();
private bool hasStarted;
private string nowEvent;
private Dictionary<BasePlayer, float> PlayersTop = new Dictionary<BasePlayer, float>();
private readonly List<LootContainer> LookingLoot = new List<LootContainer>();
private static MultiEvents _instance;
private static Vector3 EventPosition;
private static FoundationDrop cEvent;
private MonumentInfo beginning_mission;
private MonumentInfo end_mission;
private readonly Dictionary<int, RadZone> RadiationZones = new Dictionary<int, RadZone>();
private static readonly int playerLayer = LayerMask.GetMask("Player (Server)");
private Action aStartEvent;
private Action EventRepeating;
public enum ItemTypes {
Item, Command
}
private readonly List<Downgrader> Downgraders = new List<Downgrader>();
private readonly List<SCmarker> SCmarkers = new List<SCmarker>();
private readonly List<RadZone> Zones = new List<RadZone>();
#endregion
#region Config
private static Configuration _config;
private class Configuration {
[JsonProperty("Использовать автоматический запуск ивентов?")]
public bool useTimer = true;
[JsonProperty("Задержка между эвентами")]
public int Delay = 3600;
[JsonProperty("Отклонение от стандартного времени (рандомное время)")]
public int RandomTime = 900;
[JsonProperty("Максимальная длина никнейма")]
public int NameLenght = 16;
[JsonProperty("Эвенты доступные для игроков", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> EnabledEvents = new List<string> {
"KingMountain", "CollectionResources", "HuntAnimal", "HelicopterPet", "LookingLoot", "SpecialCargo", "FoundationDrop"
}
;
[JsonProperty("Право на запуск ивента")]
public string perm_admin = "multievents.admin";
[JsonProperty("Команда открытия склада")]
public string cmdStorage = "storage";
[JsonProperty("Включить оповещение о получении награды?")]
public bool EnableRewardAlert = true;
[JsonProperty("Настройка эвента ЛЮБИМЧИК ВЕРТОЛЁТА")]
public EventSettings HelicopterPet = new EventSettings {
MinPlayers = 4, TimeDelay = 300, ImageUrl = "https://i.imgur.com/owDanC1.png", ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента ОХОТА НА ЖИВОТНЫХ")]
public HuntAnimalSettings HuntAnimal = new HuntAnimalSettings {
MinPlayers = 4, TimeDelay = 300, ImageUrl = "https://i.imgur.com/9gTw3kN.png", Chicken = 1, Wolf = 4, Boar = 4, Deer = 4, Horse = 4, Bear = 10, ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
, new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
, new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента КОРОЛЬ ГОРЫ")]
public KingMountainSettings KingMountain = new KingMountainSettings {
checkDuels = true, checkHotair = true, checkMinicopter = true, checkScrapheli = true, checkBuilding = true, MinPlayers = 4, TimeDelay = 300, ImageUrl = "https://i.imgur.com/dLWgxg7.png", ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента СБОР РЕСУРСОВ")]
public CollectionResourcesSettings CollectionResources = new CollectionResourcesSettings {
MinPlayers = 4, TimeDelay = 300, ImageUrl = "https://i.imgur.com/FggJeaH.png", ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, BlockItems = new List<string> {
"jackhammer", "chainsaw"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
, new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
, new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента В ПОИСКАХ ЛУТА")]
public LookingLootSettings LookingLoot = new LookingLootSettings {
MinPlayers = 4, TimeDelay = 300, ImageUrl = "https://i.imgur.com/4ZOIs33.png", Barrels = new List<string> {
"assets/bundled/prefabs/autospawn/resource/loot/loot-barrel-1.prefab", "assets/bundled/prefabs/autospawn/resource/loot/loot-barrel-2.prefab", "assets/bundled/prefabs/radtown/loot_barrel_1.prefab", "assets/bundled/prefabs/radtown/loot_barrel_2.prefab", "assets/bundled/prefabs/radtown/oil_barrel.prefab"
}
, ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента ДОСТАВКА ОСОБОГО ГРУЗА")]
public SpecialCargoSettings SpecialCargo = new SpecialCargoSettings {
tpBlock = true, MarkerName = "ОСОБЫЙ ГРУЗ", MinPlayers = 4, TimeDelay = 1800, ImageUrl = "https://i.imgur.com/Dp9bMSl.png", timeNewRunner = 6, timeStart = 4, blockMonuments = new List<string> {
"oilrig", "cave", "power_sub"
}
, ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
}
;
[JsonProperty("Настройка эвента ПАДАЮЩИЕ ПЛАТФОРМЫ")]
public FoundationDropSettings FoundationDrop = new FoundationDropSettings {
AwardItems = new List<Loot> {
new Loot {
itemenabled = true, cashenabled = true, items = new List<List<Items>> {
new List<Items> {
new Items {
Type = ItemTypes.Item, Item = new ItemConfClass {
ShortName = "autoturret", SkinID = 0, minAmount = 1, maxAmount = 1
}
, DisplayName = string.Empty, Command = string.Empty, ImageURL = string.Empty
}
, new Items {
Type = ItemTypes.Command, Item = new ItemConfClass {
SkinID = 0, ShortName = string.Empty, minAmount = 1, maxAmount = 1
}
, Command = "addgroup %steamid% vip 1d", DisplayName = "VIP на 1 день", ImageURL = "https://i.imgur.com/GuJUyLH.png"
}
}
}
, cash = new Cash {
function = "Deposit", plugin = "Economics", amount = 400
}
}
}
, MinPlayers = 4, TimeDelay = 1800, ImageUrl = "https://i.imgur.com/B4DCBs2.png", ArenaSize = 10, DelayDestroy = 5f, WaitTime = 60, IntensityRadiation = 10f, DisableDefaultRadiation = false, ui = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -305", oMax = "-5 -5"
}
, infoUI = new Interface {
color = "0.024 0.016 0.17 0.7", oMin = "-225 -100", oMax = "-5 -5"
}
, CanTrade = true, CanBackpack = true, UseTruePVE = true, commands = new List<string> {
"bp", "backpack", "skin", "skinbox", "rec", "tpa", "tpr", "sethome", "home", "kit", "remove"
}
}
;
}
public class Interface {
[JsonProperty("Цвет фона")]
public string color;
[JsonProperty("Offset Min")]
public string oMin;
[JsonProperty("Offset Max")]
public string oMax;
}
public class EventSettings {
[JsonProperty("Настройка интерфейса ивента")]
public Interface ui;
[JsonProperty("Сколько игроков требуется для начала эвента?")]
public int MinPlayers;
[JsonProperty("Время продолжительности эвента (в секундах)")]
public int TimeDelay;
[JsonProperty("Ссылка на картинку")]
public string ImageUrl;
[JsonProperty("Настройка приза для победителя", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<Loot> AwardItems;
}
public class HuntAnimalSettings : EventSettings {
[JsonProperty("Сколько очков даётся за курицу?")]
public int Chicken;
[JsonProperty("Сколько очков даётся за волка?")]
public int Wolf;
[JsonProperty("Сколько очков даётся за кабана?")]
public int Boar;
[JsonProperty("Сколько очков даётся за оленя?")]
public int Deer;
[JsonProperty("Сколько очков даётся за лошадь?")]
public int Horse;
[JsonProperty("Сколько очков даётся за медведя?")]
public int Bear;
}
public class CollectionResourcesSettings : EventSettings {
[JsonProperty("Список предметов, добыча при помощи которых не учитывается", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> BlockItems;
}
public class KingMountainSettings : EventSettings {
[JsonProperty("Блокировать людей на дуэдли (Duels)")]
public bool checkDuels;
[JsonProperty("Блокировать людей в миникоптере")]
public bool checkMinicopter;
[JsonProperty("Блокировать людей в скрап вертолёте")]
public bool checkScrapheli;
[JsonProperty("Блокировать людей в воздушномшаре")]
public bool checkHotair;
[JsonProperty("Блокировать людей в билде (когда игрок авторизован в шкафу)")]
public bool checkBuilding;
}
public class LookingLootSettings : EventSettings {
[JsonProperty("Лутание каких бочек считаются в эвенте?", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> Barrels;
}
public class SpecialCargoSettings : EventSettings {
[JsonProperty("Время показа уведомления о запуске ивента")]
public float timeStart;
[JsonProperty("Время показа уведомления об объявлении бегущего")]
public float timeNewRunner;
[JsonProperty("Название маркера для карты")]
public string MarkerName;
[JsonProperty("Блокировать телепортацию для бегущего?")]
public bool tpBlock;
[JsonProperty("Запрещённые монументы для игры", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blockMonuments;
}
public class FoundationDropSettings : EventSettings {
[JsonProperty("Настройка интерфейса с информацией о количестве игроков и блоков")]
public Interface infoUI;
[JsonProperty("Размер арены в квадратах")]
public int ArenaSize;
[JsonProperty("Интвервал между удалениями блоков")]
public float DelayDestroy;
[JsonProperty("Время ожидания игроков с момента объявления ивента")]
public int WaitTime;
[JsonProperty("Интенсивность созданой радиации")]
public float IntensityRadiation;
[JsonProperty("Отключить стандартную радиацию на РТ (Это нужно в случае если у Вас отключена радиация, плагин включит её обратно но уберёт на РТ)")]
public bool DisableDefaultRadiation;
[JsonProperty(PropertyName = "Заблокировать трейд?")]
public bool CanTrade;
[JsonProperty(PropertyName = "Заблокировать backpack?")]
public bool CanBackpack;
[JsonProperty(PropertyName = "Включить работу с True PVE?")]
public bool UseTruePVE;
[JsonProperty("Заблокированные команды", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> commands;
}
public class Loot {
[JsonProperty("Выдавать предмет?")]
public bool itemenabled;
[JsonProperty("Выдавать баланс?")]
public bool cashenabled;
[JsonProperty("Настройка предмета", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<List<Items>> items;
[JsonProperty("Настройка баланса")]
public Cash cash;
}
public class ItemConfClass : ItemClass {
[JsonProperty(PropertyName = "Минимальное количество предмета")]
public int minAmount;
[JsonProperty(PropertyName = "Максимальное количество предмета")]
public int maxAmount;
}
public class Items {
[JsonProperty(PropertyName = "Тип предмета")]
[JsonConverter(typeof(StringEnumConverter))]
public ItemTypes Type;
[JsonProperty(PropertyName = "Предмет")]
public ItemConfClass Item;
[JsonProperty(PropertyName = "Команда")]
public string Command;
[JsonProperty(PropertyName = "Отображаемое имя (если ковычки - дефолт из игры)")]
public string DisplayName;
[JsonProperty(PropertyName = "Картинка (если пусто - по шортнейму)")]
public string ImageURL;
public DataItem ToDataItem() {
return new DataItem {
Type = Type, item = new ItemClass {
ShortName = Item.ShortName, SkinID = Item.SkinID
}
, Command = Command, DisplayName = DisplayName, Amount = Type == ItemTypes.Item ? Random.Range(Item.minAmount, Item.maxAmount) : 1, ImageURL = ImageURL
}
;
}
}
public class Cash {
[JsonProperty("Название функции для вызова")]
public string function;
[JsonProperty("Название плагина")]
public string plugin;
[JsonProperty("Количество денег")]
public int amount;
}
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
SaveConfig();
}
catch {
PrintError("Your configuration file contains an error.Using default configuration values.");
LoadDefaultConfig();
}
}
protected override void SaveConfig() {
Config.WriteObject(_config);
}
protected override void LoadDefaultConfig() {
_config = new Configuration();
}
#endregion
#region Data
private static PluginData _data;
private void SaveData() {
Core.Interface.Oxide.DataFileSystem.WriteObject(Name, _data);
}
private void LoadData() {
try {
_data = Core.Interface.Oxide.DataFileSystem.ReadObject<PluginData>(Name);
}
catch (Exception e) {
PrintError(e.ToString());
}
if (_data == null) _data = new PluginData();
}
private class PluginData {
[JsonProperty(PropertyName = "Players Data", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<ulong, List<DataItem>> PlayersData = new Dictionary<ulong, List<DataItem>>();
}
public class DataItem {
[JsonProperty(PropertyName = "Тип предмета")]
public ItemTypes Type;
[JsonProperty(PropertyName = "Предмет")]
public ItemClass item;
[JsonProperty(PropertyName = "Команда")]
public string Command;
[JsonProperty(PropertyName = "Отображаемое имя (если ковычки - дефолт из игры)")]
public string DisplayName;
[JsonProperty(PropertyName = "Количество")]
public int Amount;
[JsonProperty(PropertyName = "Картинка (если пусто - по шортнейму)")]
public string ImageURL;
public Item ToItem() {
var newItem = ItemManager.CreateByName(item.ShortName, Amount, item.SkinID);
if (newItem == null) {
_instance?.PrintError($"Error creating item with shortname '{item.ShortName}'");
return null;
}
if (!string.IsNullOrEmpty(DisplayName)) newItem.name = DisplayName;
return newItem;
}
public void GiveCmd(BasePlayer player) {
var command = Command.Replace("\n", "|").Replace("%steamid%", player.UserIDString, StringComparison.OrdinalIgnoreCase).Replace("%username%", player.displayName, StringComparison.OrdinalIgnoreCase);
_instance?.Server.Command(command);
}
}
public class ItemClass {
[JsonProperty(PropertyName = "Короткое название предмета")]
public string ShortName;
[JsonProperty(PropertyName = "Skin ID предмета")]
public ulong SkinID;
}
#endregion
#region Initialization
private void OnServerInitialized() {
LoadData();
PrintWarning(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
PrintWarning($" {Name} v{Version} loading");
if (!ImageLibrary) {
PrintError(" Install plugin: 'ImageLibrary'");
Core.Interface.Oxide.UnloadPlugin(Title);
return;
}
PrintWarning(" Plugin loaded - OK");
PrintWarning(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
if (_config.useTimer) {
aStartEvent = () => StartEvent(_config.EnabledEvents.GetRandom());
InvokeHandler.Instance.InvokeRandomized(aStartEvent, _config.Delay, _config.Delay, _config.RandomTime);
}
cmd.AddChatCommand(_config.cmdStorage, this, nameof(CmdChatOpenStorage));
AddCovalenceCommand("event", nameof(CmdEventConsole));
if (!permission.PermissionExists(_config.perm_admin, this)) permission.RegisterPermission(_config.perm_admin, this);
#region ImageLibrary
ImageLibrary.Call("AddImage", _config.CollectionResources.ImageUrl, "CollectionResources");
ImageLibrary.Call("AddImage", _config.FoundationDrop.ImageUrl, "FoundationDrop");
ImageLibrary.Call("AddImage", _config.HelicopterPet.ImageUrl, "HelicopterPet");
ImageLibrary.Call("AddImage", _config.HuntAnimal.ImageUrl, "HuntAnimal");
ImageLibrary.Call("AddImage", _config.KingMountain.ImageUrl, "KingMountain");
ImageLibrary.Call("AddImage", _config.LookingLoot.ImageUrl, "LookingLoot");
ImageLibrary.Call("AddImage", _config.SpecialCargo.ImageUrl, "SpecialCargo");
ImageLibrary.Call("AddImage", "https://i.imgur.com/Okt1BMH.png", "ME_Background_image");
ImageLibrary.Call("AddImage", "https://i.imgur.com/DpLldC8.png", "ME_Logo_image");
foreach (var img in _config.CollectionResources.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.FoundationDrop.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.HelicopterPet.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.HuntAnimal.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.KingMountain.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.LookingLoot.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _config.SpecialCargo.AwardItems.SelectMany(p => p.items).SelectMany(p => p)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
foreach (var img in _data.PlayersData.SelectMany(p => p.Value)) if (!string.IsNullOrEmpty(img.ImageURL)) ImageLibrary.Call("AddImage", img.ImageURL, img.ImageURL);
#endregion
#region FoundationDrop
var entityList = BaseNetworkable.serverEntities.entityList.Values;
for (var i = 0; i < entityList.Count; i++) {
var entity = entityList[i] as BuildingBlock;
if (entity == null || entity.IsDestroyed || entity.OwnerID != 98596) continue;
entity.Kill();
}
#endregion
_instance = this;
}
private void Init() {
Unsubscribe(nameof(OnCollectiblePickup));
Unsubscribe(nameof(OnGrowableGather));
Unsubscribe(nameof(OnDispenserBonus));
Unsubscribe(nameof(OnDispenserGather));
Unsubscribe(nameof(OnEntityDeath));
Unsubscribe(nameof(OnLootEntity));
Unsubscribe(nameof(OnPlayerDeath));
Unsubscribe(nameof(OnEntityKill));
Unsubscribe(nameof(ClearTeleport));
Unsubscribe(nameof(OnPlayerDisconnected));
Unsubscribe(nameof(DropFoundation));
Unsubscribe(nameof(OnUserCommand));
Unsubscribe(nameof(OnServerCommand));
Unsubscribe(nameof(OnPlayerLand));
Unsubscribe(nameof(OnRunPlayerMetabolism));
Unsubscribe(nameof(CanTeleport));
Unsubscribe(nameof(CanTrade));
Unsubscribe(nameof(CanBackpack));
Unsubscribe(nameof(CanEntityTakeDamage));
}
private void OnServerSave() {
SaveData();
}
private void Unload() {
SaveData();
InvokeHandler.Instance.CancelInvoke(aStartEvent);
InvokeHandler.Instance.CancelInvoke(EventRepeating);
InvokeHandler.Instance.CancelInvoke(DestroyEvent);
if (hasStarted) try {
DestroyEvent();
}
catch (NullReferenceException) {
foreach (var player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, Layer);
CuiHelper.DestroyUi(player, Layer + ".Notification");
CuiHelper.DestroyUi(player, Layer + ".SpecialCargo");
CuiHelper.DestroyUi(player, Layer + ".FoundationDrop.Play");
}
foreach (var entity in BaseNetworkable.serverEntities.OfType<BuildingBlock>()) {
if (entity == null || entity.IsDestroyed || entity.OwnerID != 98596) continue;
entity.Kill();
}
Downgraders.ToList().ForEach(component => {
if (component != null) component.Kill();
}
);
SCmarkers.ToList().ForEach(component => {
if (component != null) component.Kill();
}
);
Zones.ToList().ForEach(component => {
if (component != null) component.Kill();
}
);
}
_instance = null;
cEvent = null;
_config = null;
_data = null;
}
#endregion
#region Functions
private void StartEvent(string type, BasePlayer target = null) {
InvokeHandler.Instance.CancelInvoke(EventRepeating);
InvokeHandler.Instance.CancelInvoke(DestroyEvent);
if (hasStarted || !string.IsNullOrEmpty(nowEvent)) {
DestroyEvent();
return;
}
if (Core.Interface.CallHook("OnEventStart", type, target) != null) return;
nowEvent = type;
PlayersTop = new Dictionary<BasePlayer, float>();
switch (type) {
case "KingMountain" : {
if (BasePlayer.activePlayerList.Count < _config.KingMountain.MinPlayers && target == null) {
nowEvent = null;
return;
}
foreach (var player in BasePlayer.activePlayerList) TopUI(player, "all", GetMessage(type, player.UserIDString), oMin : _config.KingMountain.ui.oMin, oMax : _config.KingMountain.ui.oMax, color : _config.KingMountain.ui.color);
time = _config.KingMountain.TimeDelay;
EventRepeating = () => {
var list = PlayersTop.OrderByDescending(p => p.Value).Take(8).ToList();
foreach (var player in BasePlayer.activePlayerList) {
if (player == null || player.IsNpc) continue;
TopUI(player, "refresh", list : list);
if (player.GetMounted() || player.IsFlying || _config.KingMountain.checkBuilding && player.IsBuildingAuthed() || _config.KingMountain.checkDuels && IsDuelPlayer(player) || _config.KingMountain.checkScrapheli && player.GetComponentInParent<ScrapTransportHelicopter>() != null || _config.KingMountain.checkMinicopter && player.GetComponentInParent<MiniCopter>() != null || _config.KingMountain.checkHotair && player.GetComponentInParent<HotAirBalloon>() != null) continue;
if (PlayersTop.ContainsKey(player)) PlayersTop[player] = player.transform.position.y;
else PlayersTop.Add(player, player.transform.position.y);
}
time--;
}
;
InvokeHandler.Instance.InvokeRepeating(EventRepeating, 0, 1);
InvokeHandler.Instance.Invoke(DestroyEvent, _config.KingMountain.TimeDelay + 1);
}
break;
case "CollectionResources" : {
if (BasePlayer.activePlayerList.Count < _config.CollectionResources.MinPlayers && target == null) {
nowEvent = null;
return;
}
Subscribe(nameof(OnCollectiblePickup));
Subscribe(nameof(OnGrowableGather));
Subscribe(nameof(OnDispenserBonus));
Subscribe(nameof(OnDispenserGather));
foreach (var player in BasePlayer.activePlayerList) TopUI(player, "all", GetMessage(type, player.UserIDString), oMin : _config.CollectionResources.ui.oMin, oMax : _config.CollectionResources.ui.oMax, color : _config.CollectionResources.ui.color);
time = _config.CollectionResources.TimeDelay;
EventRepeating = () => {
var list = PlayersTop.O
// ... [Code preview truncated due to length. Full source in attached file] ...