C#:
using System;
using Random = System.Random;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Rust;
using Facepunch;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Collections;
using System.Globalization;
namespace Oxide.Plugins {
[Info("MeteorFall", "https://topplugin.ru/", "1.1.5")]
class MeteorFall : RustPlugin {
[PluginReference]
Plugin EcoMap, RustMap, LustyMap, Map;
private PluginConfig config;
private class PluginConfig {
[JsonProperty("Общие Настройки")]
public Options _Options {
get;
set;
}
public class Options {
[JsonProperty("Отключать стандартную радиацию?")]
public bool OffStandartRad {
get;
set;
}
[JsonProperty("Включить автозапуск ивента?")]
public bool EnableAutomaticEvents {
get;
set;
}
[JsonProperty("Настройка автозапуска")]
public Timers EventTimers {
get;
set;
}
[JsonProperty("Сообщать о начале ивента в чат?")]
public bool NotifyEvent {
get;
set;
}
[JsonProperty("Включить эффект тряски земли от падения метеорита?")]
public bool Earthquake {
get;
set;
}
[JsonProperty("Минимальное количество игроков для запуска ивента")]
public int MinPlayer {
get;
set;
}
}
[JsonProperty("Настройки UI")]
public UiSettings uiSettings {
get;
set;
}
public class UiSettings {
[JsonProperty("Включить UI?")]
public bool useUi {
get;
set;
}
[JsonProperty("Ссылка на картинку")]
public string IconImage {
get;
set;
}
[JsonProperty("Положение UI")]
public UiTransform uiTransform {
get;
set;
}
public class UiTransform {
[JsonProperty("Координата Х Мин")]
public string AnchorXMin {
get;
set;
}
[JsonProperty("Координата Х Мax")]
public string AnchorXMax {
get;
set;
}
[JsonProperty("Координата Y Мин")]
public string AnchorYMin {
get;
set;
}
[JsonProperty("Координата Y Мax")]
public string AnchorYMax {
get;
set;
}
}
}
[JsonProperty("Настройки радиации")]
public Radiations _Radiations {
get;
set;
}
public class Radiations {
[JsonProperty("Радиус зоны")]
public float Radius {
get;
set;
}
[JsonProperty("Сила радиации")]
public float Strange {
get;
set;
}
}
public class Timers {
[JsonProperty("Интервал ивента (Минуты) (Если выключен рандом)")]
public int EventInterval {
get;
set;
}
[JsonProperty("Включить рандомное время?")]
public bool UseRandomTimer {
get;
set;
}
[JsonProperty("Минимальный интервал (Минуты)")]
public int RandomTimerMin {
get;
set;
}
[JsonProperty("Максимальный интервал (Минуты)")]
public int RandomTimerMax {
get;
set;
}
}
[JsonProperty("Настройка ивента")]
public Intensity Settings {
get;
set;
}
public class Intensity {
[JsonProperty("Шанс распространения огня от малого метеорита")]
public int FireRocketChance {
get;
set;
}
[JsonProperty("Радиус на котором проходит метеоритопад")]
public float Radius {
get;
set;
}
[JsonProperty("Количество падающих метеоритов (малых)")]
public int RocketAmount {
get;
set;
}
[JsonProperty("Длительность падения малых метеоритов")]
public int Duration {
get;
set;
}
[JsonProperty("Множитель урона от попадания по Enemy")]
public float DamageMultiplier {
get;
set;
}
[JsonProperty("Настройка выпадающих ресурсов после попадания метеорита по земле")]
public Drop ItemDropControl {
get;
set;
}
public class Drop {
[JsonProperty("Включить дроп ресурсов после метеорита?")]
public bool EnableItemDrop {
get;
set;
}
[JsonProperty("Настройка выпадаемых ресурсов")]
public ItemDrops[] ItemsToDrop {
get;
set;
}
}
[JsonProperty("Количество NPC возле главного метеорита")]
public int NpcAmount {
get;
set;
}
[JsonProperty("Включить спавн NPC возле метеорита?")]
public bool NpcSpawn {
get;
set;
}
[JsonProperty("Количество HP у ученых")]
public float NpcHealth {
get;
set;
}
[JsonProperty("Время которое будет остывать метеорит (Минуты)")]
public float FireTime {
get;
set;
}
[JsonProperty("Время через которое метеорит исчезнет после остывания (Минуты)")]
public float DespawnTime {
get;
set;
}
}
[JsonProperty("Настройки метеорита")]
public MeteorSetting meteorSetting {
get;
set;
}
public class MeteorSetting {
[JsonProperty("Время до падения метеорита")]
public int MeteorTime {
get;
set;
}
[JsonProperty("Шанс спавна малого метеорита (от 2 до 4х камней)(0 - отключить)")]
public float SmalMeteor {
get;
set;
}
[JsonProperty("Шанс спавна среднего метеорита (от 3 до 6х камней)(0 - отключить)")]
public float MinorMeteor {
get;
set;
}
[JsonProperty("Шанс спавна большого метеорита (от 4 до 7х камней)(0 - отключить)")]
public float MajorMeteor {
get;
set;
}
[JsonProperty("Шанс того, что метеорит будет радиоактивен (0-отключить)")]
public float RadChacnce {
get;
set;
}
[JsonProperty("Запускать волну радиации после приземления если метеорит радиоактивный?")]
public bool RadWave {
get;
set;
}
[JsonProperty("Шанс появления Серы")]
public float sulfurpercent {
get;
set;
}
[JsonProperty("Шанс появления Метала")]
public float metalpercent {
get;
set;
}
}
[JsonProperty("Настройки API SeedEvent")]
public ApiSetting apiSetting {
get;
set;
}
public class ApiSetting {
[JsonProperty("Использовать SeedEvent?")]
public bool ApiEnable {
get;
set;
}
[JsonProperty("Шанс дропа семян")]
public float SeddChance {
get;
set;
}
}
}
protected override void LoadDefaultConfig() {
config = new PluginConfig() {
_Options = new PluginConfig.Options {
OffStandartRad = false, EnableAutomaticEvents = true, MinPlayer = 5, EventTimers = new PluginConfig.Timers {
EventInterval = 60, UseRandomTimer = true, RandomTimerMin = 20, RandomTimerMax = 30
}
, NotifyEvent = true, Earthquake = true,
}
, uiSettings = new PluginConfig.UiSettings {
useUi = true, IconImage = "https://i.imgur.com/1PSiC85.png", uiTransform = new PluginConfig.UiSettings.UiTransform {
AnchorXMax = "0.6414062", AnchorXMin = "0.34375", AnchorYMax = "0.2083333", AnchorYMin = "0.1097223"
}
}
, _Radiations = new PluginConfig.Radiations {
Radius = 10f, Strange = 5f,
}
, Settings = new PluginConfig.Intensity {
Duration = 180, FireRocketChance = 20, Radius = 50, RocketAmount = 90, DamageMultiplier = 0.4f, NpcAmount = 5, NpcSpawn = false, NpcHealth = 300f, FireTime = 5, DespawnTime = 10, ItemDropControl = new PluginConfig.Intensity.Drop {
EnableItemDrop = true, ItemsToDrop = new ItemDrops[] {
new ItemDrops {
Maximum = 150, Minimum = 80, Shortname = "stones"
}
, new ItemDrops {
Maximum = 100, Minimum = 50, Shortname = "metal.ore"
}
, new ItemDrops {
Maximum = 90, Minimum = 40, Shortname = "sulfur"
}
,
}
}
}
, meteorSetting = new PluginConfig.MeteorSetting {
MeteorTime = 30, SmalMeteor = 33f, MinorMeteor = 33, MajorMeteor = 34, RadChacnce = 70, RadWave = true, sulfurpercent = 60, metalpercent = 25
}
, apiSetting = new PluginConfig.ApiSetting {
ApiEnable = false, SeddChance = 100f
}
}
;
}
protected override void LoadConfig() {
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
}
protected override void SaveConfig() {
Config.WriteObject(config);
}
class ItemDrops {
public string Shortname;
public int Minimum;
public int Maximum;
}
static MeteorFall ins;
private bool rads;
void OnServerInitialized() {
ins = this;
LoadConfig();
LoadMessages();
StartEventTimer();
InitFileManager();
ServerMgr.Instance.StartCoroutine(LoadImages());
}
private void OnServerRadiation() {
var allobjects = UnityEngine.Object.FindObjectsOfType<TriggerRadiation>();
for (int i = 0; i < allobjects.Length; i++) {
UnityEngine.Object.Destroy(allobjects[i]);
}
}
void Unload() {
var objects = UnityEngine.Object.FindObjectsOfType<ItemCarrier>();
if (objects != null) foreach (var gameObj in objects) UnityEngine.Object.Destroy(gameObj);
Despawn();
if (EventTimer != null) EventTimer.Destroy();
foreach (var check in radiationZone) UnityEngine.Object.Destroy(check);
radiationZone.Clear();
if (!rads) ConVar.Server.radiation = false;
if (mapMarker != null && !mapMarker.IsDestroyed) mapMarker.Kill();
if (MarkerT != null && !MarkerT.IsDestroyed) MarkerT.Kill();
}
private Timer EventTimer, AlertTimer;
private float launchStraightness = 2.0f;
private float launchHeight = 150f;
private float MapSize() => TerrainMeta.Size.x / 2;
private float projectileSpeed = 250f;
private float gravityModifier = 0.2f;
private float detonationTime = 60f;
class ItemCarrier : MonoBehaviour {
private ItemDrops[] carriedItems = null;
private float multiplier;
public void SetCarriedItems(ItemDrops[] carriedItems) => this.carriedItems = carriedItems;
public void SetDropMultiplier(float multiplier) => this.multiplier = 1.0f;
private void OnDestroy() {
if (carriedItems == null) return;
int amount;
for (int i = 0; i < carriedItems.Length; i++) {
if ((amount = (int)(UnityEngine.Random.Range(carriedItems[i].Minimum, carriedItems[i].Maximum) * 1.0f)) > 0) ItemManager.CreateByName(carriedItems[i].Shortname, amount).Drop(gameObject.transform.position, Vector3.up);
}
}
}
private void StartEventTimer() {
if (config._Options.EnableAutomaticEvents) {
if (config._Options.EventTimers.UseRandomTimer) {
var random = UnityEngine.Random.Range(config._Options.EventTimers.RandomTimerMin, config._Options.EventTimers.RandomTimerMax);
EventTimer = timer.Once(random * 60, () => StartRandomOnMap());
}
else EventTimer = timer.Once(config._Options.EventTimers.EventInterval * 60, () => StartRandomOnMap());
}
}
private void StopTimer() {
if (rockettimer != null) rockettimer?.Destroy();
if (AlertTimer != null) AlertTimer?.Destroy();
if (EventTimer != null) EventTimer?.Destroy();
if (npcTimer != null) timer.Destroy(ref npcTimer);
npcTimer?.Destroy();
if (mystimer != null) mystimer?.Destroy();
if (mystimer1 != null) mystimer1?.Destroy();
if (mystimer2 != null) mystimer2?.Destroy();
if (mystimer3 != null) mystimer3?.Destroy();
if (mystimer4 != null) mystimer4?.Destroy();
if (mystimer5 != null) mystimer5?.Destroy();
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
}
private void StartRandomOnMap() {
if (config._Options.NotifyEvent) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("incoming", pl.userID));
}
mystimer2 = timer.In(10f, () => CollisionAtm());
}
private Timer rockettimer, effecttimer, timerfireball;
List<uint> MeteorList = new List<uint>();
List<uint> MeteorFound = new List<uint>();
List<uint> NpcList = new List<uint>();
List<uint> FireBall = new List<uint>();
public List<string> prefabOsn = new List<string>() {
"assets/bundled/prefabs/autospawn/resource/ores/stone-ore.prefab", "assets/bundled/prefabs/autospawn/resource/ores/metal-ore.prefab", "assets/bundled/prefabs/autospawn/resource/ores/sulfur-ore.prefab"
}
;
Quaternion qTo;
BaseEntity met;
private Timer mystimer, mystimer3, mystimer4, mystimer5;
private Timer mystimer1;
private Timer mystimer2;
void CollisionAtm() {
PrintWarning($"Event Started!!!!!!!!!");
if (BasePlayer.activePlayerList.Count < config._Options.MinPlayer) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("EventCancel", pl.userID));
StartEventTimer();
return;
}
if (!ConVar.Server.radiation) {
rads = false;
if (config._Options.OffStandartRad) OnServerRadiation();
ConVar.Server.radiation = true;
}
else rads = true;
mystimer2 = timer.Once(10f, () => {
if (config._Options.NotifyEvent) foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("InAtm", pl.userID));
}
);
var callAt = GetEventPosition();
int coldown = config.meteorSetting.MeteorTime >= 5 ? config.meteorSetting.MeteorTime : 5;
mystimer1 = mystimer = timer.Repeat(1.1f, coldown, () => {
if (coldown == 1) {
timer.In(1f, () => StartRainOfFire(callAt));
}
if (coldown <= 5 && coldown != 0) {
if (config._Options.NotifyEvent) foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("Dropped", pl.userID).Replace("{cooldown}", $"{coldown}"));
}
if (coldown >= 0) {
foreach (var player in BasePlayer.activePlayerList) DrawUI(player, $"Метеорит упадет через: {FormatTime(TimeSpan.FromSeconds(coldown))}");
coldown--;
}
if (coldown <= 0) {
mystimer1.Destroy();
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
}
}
);
}
Vector3 spawnpos;
private Vector3 MeteorSpawnPos() {
return spawnpos;
}
private void StartRainOfFire(Vector3 origin) {
float radius = config.Settings.Radius;
int numberOfRockets = config.Settings.RocketAmount;
float duration = config.Settings.Duration;
bool dropsItems = config.Settings.ItemDropControl.EnableItemDrop;
ItemDrops[] itemDrops = config.Settings.ItemDropControl.ItemsToDrop;
float intervals = duration / numberOfRockets;
rockettimer = timer.Repeat(intervals, numberOfRockets, () => RandomRocket(origin, radius));
Random rnd = new Random();
var location = origin;
location.y = GetGroundPosition(location);
float posy;
float posx;
float posz;
string pref = "assets/bundled/prefabs/autospawn/resource/ores/stone-ore.prefab";
int meteorcount = 0;
if (UnityEngine.Random.Range(0f, 100f) <= config.meteorSetting.MajorMeteor) {
meteorcount = UnityEngine.Random.Range(4, 7);
timer.In(2f, () => {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("MajorMeteor", pl.userID));
}
);
}
else if (UnityEngine.Random.Range(0f, 100f) <= config.meteorSetting.MinorMeteor) {
meteorcount = UnityEngine.Random.Range(3, 6);
timer.In(2f, () => {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("MinorMeteor", pl.userID));
}
);
}
else {
meteorcount = UnityEngine.Random.Range(2, 4);
timer.In(2f, () => {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("SmalMeteor", pl.userID));
}
);
}
for (int i = 0; i < (meteorcount > 2 ? meteorcount : 2);
i++) {
qTo = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-150, -50), 0));
if (i == 0) {
if (UnityEngine.Random.Range(0, 100) < config.meteorSetting.sulfurpercent) pref = "assets/bundled/prefabs/autospawn/resource/ores/sulfur-ore.prefab";
else if (UnityEngine.Random.Range(0, 100) < config.meteorSetting.metalpercent) pref = "assets/bundled/prefabs/autospawn/resource/ores/metal-ore.prefab";
met = GameManager.server.CreateEntity(pref, location, qTo, true);
var reply = 1;
EcoMap?.Call("AddMapMarker", "meteor", false, 0.0300f, met.transform, "Метеорит");
RustMap?.Call("AddTemporaryMarker", "meteor", false, 0.05f, 0.95f, met.transform, "Метеорит");
LustyMap?.Call("AddMarker", location.x, location.z, "Метеорит", "https://i.imgur.com/BFCdsOx.png");
Map?.Call("ApiAddPointUrl", "https://i.imgur.com/BFCdsOx.png", "Метеорит", met.transform.position);
CreatePrivateMap(met.transform.position);
if (reply == 0) {
}
met.Spawn();
MeteorList.Add(met.net.ID);
MeteorFound.Add(met.net.ID);
spawnpos = met.transform.position;
}
else {
if (UnityEngine.Random.Range(0, 100) < config.meteorSetting.sulfurpercent) pref = "assets/bundled/prefabs/autospawn/resource/ores/sulfur-ore.prefab";
else if (UnityEngine.Random.Range(0, 100) < config.meteorSetting.metalpercent) pref = "assets/bundled/prefabs/autospawn/resource/ores/metal-ore.prefab";
posy = i - (i - UnityEngine.Random.Range(0.3f, 0.6f));
posx = i - (i - UnityEngine.Random.Range(-1f, +1f));
posz = i - (i - UnityEngine.Random.Range(-1f, +1f));
location.y = location.y + posy;
location.x = location.x + posx;
met = GameManager.server.CreateEntity(pref, (Vector3)location, qTo, true);
met.Spawn();
MeteorList.Add(met.net.ID);
MeteorFound.Add(met.net.ID);
}
}
AlertTimer = timer.In(10f, () => {
if (config._Options.NotifyEvent) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("colding", pl.userID).Replace("{time}", $"{FormatTime(TimeSpan.FromSeconds(config.Settings.FireTime * 60))}"));
}
}
);
mystimer3 = timer.In(20f, () => {
if (config._Options.NotifyEvent) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("Warning", pl.userID).Replace("{radius}", $"{config.Settings.Radius}"));
}
}
);
int cooldown2 = Convert.ToInt32((config.Settings.FireTime * 60) + 10);
mystimer4 = timer.Repeat(1f, cooldown2, () => {
if (cooldown2 == 1) {
ColdMeteorite();
}
if (1 < cooldown2 && cooldown2 <= config.Settings.FireTime * 60) foreach (var player in BasePlayer.activePlayerList) DrawUI(player, $"Метеорит остынет через: {FormatTime(TimeSpan.FromSeconds(cooldown2))}");
if (cooldown2 != 0) cooldown2--;
}
);
CreateFireBall(location, new Vector3(0, 2, 0));
CreateFireBall(location, new Vector3(2, 0, 0));
CreateFireBall(location, new Vector3(-2, 0, 0));
CreateFireBall(location, new Vector3(0, 0, 2));
CreateFireBall(location, new Vector3(0, 0, -2));
Effect.server.Run("assets/prefabs/npc/m2bradley/effects/bradley_explosion.prefab", location);
Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/heli_explosion.prefab", location);
timer.Once(1f, () => {
Effect.server.Run("assets/prefabs/npc/m2bradley/effects/bradley_explosion.prefab", location);
Effect.server.Run("assets/prefabs/npc/patrol helicopter/effects/heli_explosion.prefab", location);
}
);
if (config._Options.Earthquake) foreach (var pl in BasePlayer.activePlayerList) Screen(pl);
var radchance = UnityEngine.Random.Range(0f, 100f);
if (radchance < config.meteorSetting.RadChacnce) {
if (config.meteorSetting.RadWave) CrateWave();
CreateZone(location);
}
if (config.Settings.NpcSpawn) CreateNpc(location, config.Settings.NpcAmount);
}
private MapMarkerGenericRadius mapMarker;
private VendingMachineMapMarker MarkerT;
private UnityEngine.Color ConvertToColor(string color) {
if (color.StartsWith("#")) color = color.Substring(1);
int red = int.Parse(color.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(color.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(color.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return new UnityEngine.Color((float)red / 255, (float)green / 255, (float)blue / 255);
}
private void CreatePrivateMap(Vector3 pos) {
mapMarker = (MapMarkerGenericRadius)GameManager.server.CreateEntity("assets/prefabs/tools/map/genericradiusmarker.prefab", pos, new Quaternion());
MarkerT = GameManager.server.CreateEntity("assets/prefabs/deployable/vendingmachine/vending_mapmarker.prefab", pos).GetComponent<VendingMachineMapMarker>();
mapMarker.enableSaving = false;
MarkerT.markerShopName = "<size=18>Метеорит</size>";
MarkerT.enableSaving = false;
MarkerT.Spawn();
MarkerT.enabled = false;
mapMarker.Spawn();
mapMarker.radius = 0.2f;
mapMarker.alpha = 1f;
UnityEngine.Color color = ConvertToColor("#932e1d");
UnityEngine.Color color2 = new UnityEngine.Color(0, 0, 0, 0);
mapMarker.color1 = color;
mapMarker.color2 = color2;
mapMarker.SendUpdate();
}
List<string> prefabscreen = new List<string>() {
"assets/prefabs/weapons/bone knife/effects/strike_screenshake.prefab", "assets/prefabs/weapons/hatchet/effects/strike_screenshake.prefab", "assets/prefabs/weapons/pickaxe/effects/strike_screenshake.prefab", "assets/prefabs/weapons/salvaged_axe/effects/strike_screenshake.prefab", "assets/bundled/prefabs/fx/screen_jump.prefab"
}
;
Random rnd = new Random();
void Screen(BasePlayer pl) {
effecttimer = timer.Repeat(0.2f, 21, () => {
string screanp = prefabscreen[rnd.Next(prefabscreen.Count)];
Effect.server.Run(screanp, pl.transform.position);
}
);
}
private void ColdMeteorite() {
timerfireball?.Destroy();
foreach (var check in FireBall) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) BaseNetworkable.serverEntities.Find(check).Kill();
}
FireBall.Clear();
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
if (config._Options.NotifyEvent) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("coldingFinish", pl.userID));
}
AlertTimer = timer.Once(60f, () => {
if (config._Options.NotifyEvent) {
foreach (var pl in BasePlayer.activePlayerList) SendToChat(pl, GetMsg("Despawn", pl.userID).Replace("{time}", $"{FormatTime(TimeSpan.FromSeconds(config.Settings.DespawnTime * 60))}"));
}
}
);
int desptime = Convert.ToInt32((config.Settings.DespawnTime * 60) + 60f);
mystimer5 = timer.Every(1f, () => {
if (MeteorFound.Count > 0) {
if (desptime == 1) {
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
Despawn();
}
if (1 < desptime && desptime <= config.Settings.DespawnTime * 60) {
foreach (var player in BasePlayer.activePlayerList) DrawUI(player, $"Метеорит исчезнет через: {FormatTime(TimeSpan.FromSeconds(desptime))}");
}
if (desptime != 0) desptime--;
}
else {
if (mystimer5 != null) timer.Destroy(ref mystimer5);
mystimer5?.Destroy();
}
}
);
}
Dictionary<Scientist, Vector3> npcPos = new Dictionary<Scientist, Vector3>();
private void CreateNpc(Vector3 position, int amount = 0) {
for (int i = 0; i < amount; i++) {
var pos = RandomCircle(position, 10);
Scientist scientist = GameManager.server.CreateEntity("assets/prefabs/npc/scientist/scientist.prefab", pos) as Scientist;
scientist.Spawn();
npcPos.Add(scientist, pos);
}
ToSpawnPoint();
}
private Timer npcTimer;
void ToSpawnPoint() {
npcTimer = timer.Every(5f, () => {
foreach (var npc in npcPos.Keys.ToList()) if (npc != null && npcPos.ContainsKey(npc) && npc?.AttackTarget == null) npc?.SetDestination(npcPos[npc]);
}
);
}
private void CreateFireBall(Vector3 position, Vector3 additional) {
FireBall fireball_ = null;
fireball_ = GameManager.server.CreateEntity("assets/bundled/prefabs/oilfireballsmall.prefab", position + additional) as FireBall;
fireball_.lifeTimeMin = config.Settings.FireTime * 60 + 10;
fireball_.lifeTimeMax = config.Settings.FireTime * 60 + 10;
fireball_.Spawn();
FireBall.Add(fireball_.net.ID);
}
void OnEntitySpawned(BaseNetworkable entity) {
if (entity is NPCPlayer) NpcList.Add(entity.net.ID);
}
private void Despawn() {
foreach (var check in MeteorList) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) BaseNetworkable.serverEntities.Find(check).Kill();
}
foreach (var check in NpcList) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) BaseNetworkable.serverEntities.Find(check).Kill();
}
foreach (var check in FireBall) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) BaseNetworkable.serverEntities.Find(check).Kill();
}
foreach (var check in radiationZone) if (check != null) UnityEngine.Object.Destroy(check);
radiationZone.Clear();
MeteorList.Clear();
MeteorFound.Clear();
FireBall.Clear();
NpcList.Clear();
StopTimer();
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
EcoMap?.Call("RemoveMapMarker", "Метеорит");
RustMap?.Call("RemoveTemporaryMarkerByName", "Метеорит");
LustyMap?.Call("RemoveMarker", "Метеорит");
Map?.Call("ApiRemovePointUrl", "https://i.imgur.com/BFCdsOx.png", "Метеорит", met.transform.position);
if (mapMarker != null && !mapMarker.IsDestroyed) mapMarker.Kill();
if (MarkerT != null && !MarkerT.IsDestroyed) MarkerT.Kill();
timer.In(10f, () => StartEventTimer());
PrintWarning($"Event Stoped!!!!!!!!!!");
}
private void RandomRocket(Vector3 origin, float radius) {
bool isFireRocket = false;
Vector2 rand = UnityEngine.Random.insideUnitCircle;
Vector3 offset = new Vector3(rand.x * radius, 0, rand.y * radius);
Random rnd = new Random();
Vector3 direction = (Vector3.up * -launchStraightness + Vector3.right).normalized;
Vector3 launchPos = origin + offset - direction * launchHeight;
if (UnityEngine.Random.Range(1, config.Settings.FireRocketChance) == 1) isFireRocket = true;
BaseEntity rocket = CreateRocket(launchPos, direction, isFireRocket);
if (config.Settings.ItemDropControl.EnableItemDrop) {
var comp = rocket.gameObject.AddComponent<ItemCarrier>();
comp.SetCarriedItems(config.Settings.ItemDropControl.ItemsToDrop);
comp.SetDropMultiplier(1.0f);
}
}
private BaseEntity CreateRocket(Vector3 startPoint, Vector3 direction, bool isFireRocket) {
ItemDefinition projectileItem;
if (isFireRocket) projectileItem = GetFireRocket();
else projectileItem = GetRocket();
ItemModProjectile component = projectileItem.GetComponent<ItemModProjectile>();
BaseEntity entity = GameManager.server.CreateEntity(component.projectileObject.resourcePath, startPoint, new Quaternion(), true);
TimedExplosive timedExplosive = entity.GetComponent<TimedExplosive>();
ServerProjectile serverProjectile = entity.GetComponent<ServerProjectile>();
serverProjectile.gravityModifier = gravityModifier;
serverProjectile.speed = projectileSpeed;
timedExplosive.timerAmountMin = detonationTime;
timedExplosive.timerAmountMax = detonationTime;
ScaleAllDamage(timedExplosive.damageTypes, config.Settings.DamageMultiplier);
entity.SendMessage("InitializeVelocity", (object)(direction * 30f));
entity.Spawn();
return entity;
}
private void ScaleAllDamage(List<DamageTypeEntry> damageTypes, float scale) {
for (int i = 0; i < damageTypes.Count; i++) damageTypes[i].amount *= scale;
}
private ItemDefinition GetRocket() => ItemManager.FindItemDefinition("ammo.rocket.hv");
private ItemDefinition GetFireRocket() => ItemManager.FindItemDefinition("ammo.rocket.fire");
[ConsoleCommand("meteor")]
void ConsoleStart(ConsoleSystem.Arg args) {
if (args.Connection != null) if (!args.IsConnectionAdmin) return;
if (args.Args == null || args.Args.Length < 0) {
Puts("MeteorFall by EcoSmile (RustPlugin.ru)\nКоманды:\n\tmeteor start - Ручной запуск ивента\n\tmeteor stop - Остановить текущий запущенный ивент");
return;
}
switch (args.Args[0]) {
case "start" : foreach (var check in MeteorList) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) {
PrintWarning("Ивент MeteorFall уже запущен, используйте: meteor stop");
return;
}
}
Despawn();
PrintWarning("Вы запустили Ивент MeteorFall в ручном режиме");
StartRandomOnMap();
break;
case "stop" : StopTimer();
Despawn();
PrintWarning("Ивент MeteorFall остановлен");
break;
}
}
[ChatCommand("meteor")]
void ChatCmdControll(BasePlayer player, string command, string[] args, ulong playerid = 1) {
if (player == null) return;
if (!player.IsAdmin) return;
if (args == null || args.Length <= 0) {
SendToChat(player, GetMsg("CmdHelp", player.userID));
return;
}
switch (args[0]) {
case "start" : foreach (var check in MeteorList) {
if (BaseNetworkable.serverEntities.Find(check) != null && !BaseNetworkable.serverEntities.Find(check).IsDestroyed) {
SendToChat(player, GetMsg("CmdEventCurrent", player.userID));
return;
}
}
if (EventTimer != null) EventTimer.Destroy();
SendToChat(player, GetMsg("CmdEventStart", player.userID));
StartRandomOnMap();
break;
case "stop" : StopTimer();
Despawn();
SendToChat(player, GetMsg("CmdEventStop", player.userID));
break;
}
}
[PluginReference]
Plugin SeedEvent;
void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
if (player == null) return;
var ID = dispenser.GetComponent<BaseEntity>().net.ID;
if (ID != 0 && MeteorFound.Contains(ID)) {
if (config.apiSetting.ApiEnable) {
var Chance = UnityEngine.Random.Range(0f, 100f);
if (Chance < config.apiSetting.SeddChance) {
SeedEvent?.Call("GiveSeeds", player);
return;
}
}
}
}
void OnEntityKill(BaseNetworkable entity) {
if (entity == null) return;
if (entity.net == null) return;
if (MeteorFound.Contains(entity.net.ID)) {
if (MeteorFound.Count == 1) {
StopTimer();
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, "CuiElementMt");
EcoMap?.Call("RemoveMapMarker", "Метеорит");
RustMap?.Call("RemoveTemporaryMarkerByName", "Метеорит");
LustyMap?.Call("RemoveMarker", "Метеорит");
Map?.Call("ApiRemovePointUrl", "https://i.imgur.com/BFCdsOx.png", "Метеорит", met?.transform.position);
if (mapMarker != null && !mapMarker.IsDestroyed) mapMarker?.Kill();
if (MarkerT != null && !MarkerT.IsDestroyed) MarkerT?.Kill();
MeteorFound.Clear();
return;
}
MeteorFound.Remove(entity.net.ID);
}
}
void DrawUI(BasePlayer player, string msg) {
if (!config.uiSettings.useUi) return;
if (!string.IsNullOrEmpty(config.uiSettings.uiTransform.AnchorXMax) && !string.IsNullOrEmpty(config.uiSettings.uiTransform.AnchorYMax) && !string.IsNullOrEmpty(config.uiSettings.uiTransform.AnchorXMin) && !string.IsNullOrEmpty(config.uiSettings.uiTransform.AnchorYMin)) {
string anchormax_ = $"{config.uiSettings.uiTransform.AnchorXMax} {config.uiSettings.uiTransform.AnchorYMax}";
string anchormin_ = $"{config.uiSettings.uiTransform.AnchorXMin} {config.uiSettings.uiTransform.AnchorYMin}";
CuiHelper.DestroyUi(player, "CuiElementMt");
CuiHelper.AddUi(player, ui.Replace("{anchormax}", anchormax_).Replace("{anchormin}", anchormin_).Replace("{Icon}", Images).Replace("{Text}", msg));
}
else {
string anchormax_ = "0.6414062 0.2083333";
string anchormin_ = "0.34375 0.1097223";
CuiHelper.DestroyUi(player, "CuiElementMt");
CuiHelper.AddUi(player, ui.Replace("{anchormax}", anchormax_).Replace("{anchormin}", anchormin_).Replace("{Icon}", Images).Replace("{Text}", msg));
}
}
string ui = "[{\"name\":\"CuiElementMt\",\"parent\":\"Hud\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"color\":\"0 0 0 0.2394277\",\"sprite\":\"assets/content/textures/generic/fulltransparent.tga\"},{\"type\":\"RectTransform\",\"anchormin\":\"{anchormin}\",\"anchormax\":\"{anchormax}\",\"offsetmin\":\"0 0\",\"offsetmax\":\"1 1\"}]},{\"name\":\"CuiElement\",\"parent\":\"CuiElementMt\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"color\":\"0 0 0 0.434163\",\"sprite\":\"assets/content/textures/generic/fulltransparent.tga\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.007874042 0.09859085\",\"anchormax\":\"0.1758531 0.915493\",\"offsetmin\":\"0 0\",\"offsetmax\":\"1 1\"}]},{\"name\":\"CuiElement\",\"parent\":\"CuiElementMt\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"png\":\"{Icon}\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.01049873 0.07042181\",\"anchormax\":\"0.1758531 0.915493\",\"offsetmin\":\"0 0\",\"offsetmax\":\"1 1\"}]},{\"name\":\"CuiElement\",\"parent\":\"CuiElementMt\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"color\":\"0 0 0 0.3316553\",\"sprite\":\"assets/content/textures/generic/fulltransparent.tga\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.2020998 0.1236111\",\"anchormax\":\"0.9658796 0.8450704\",\"offsetmin\":\"0 0\",\"offsetmax\":\"1 1\"}]},{\"name\":\"CuiElement\",\"parent\":\"CuiElementMt\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{Text}\",\"align\":\"MiddleCenter\"},{\"type\":\"UnityEngine.UI.Outline\",\"color\":\"0.7238988 0.3568805 0.1592568 1\",\"distance\":\"1 -1\"},{\"type\":\"RectTransform\",\"anchormin\":\"0.2047244 0.1236111\",\"anchormax\":\"0.9580055 0.8309858\",\"offsetmin\":\"0 0\",\"offsetmax\":\"1 1\"}]}]";
bool init;
private GameObject FileManagerObject;
private FileManager m_FileManager;
private string Images;
IEnumerator LoadImages() {
if (!string.IsNullOrEmpty(config.uiSettings.IconImage)) {
Images = config.uiSettings.IconImage;
yield return m_FileManager.StartCoroutine(m_FileManager.LoadFile(Images, Images));
Images = m_FileManager.GetPng(Images);
}
else {
Images = "https://i.imgur.com/1PSiC85.png";
yield return m_FileManager.StartCoroutine(m_FileManager.LoadFile(Images, Images));
Images = m_FileManager.GetPng(Images);
}
}
void InitFileManager() {
FileManagerObject = new GameObject("FileManagerObject");
m_FileManager = FileManagerObject.AddComponent<FileManager>();
}
class FileManager : MonoBehaviour {
int loaded = 0;
int needed = 0;
public bool IsFinished => needed == loaded;
const ulong MaxActiveLoads = 10;
Dictionary<string, FileInfo> files = new Dictionary<string, FileInfo>();
private class FileInfo {
public string Url;
public string Png;
}
public string GetPng(string name) => files[name].Png;
public IEnumerator LoadFile(string name, string url, int size = -1) {
if (files.ContainsKey(name) && files[name].Url == url && !string.IsNullOrEmpty(files[name].Png)) yield break;
files[name] = new FileInfo() {
Url = url
}
;
needed++;
yield return StartCoroutine(LoadImageCoroutine(name, url, size));
}
IEnumerator LoadImageCoroutine(string name, string url, int size = -1) {
using (WWW www = new WWW(url)) {
yield return www;
if (string.IsNullOrEmpty(www.error)) {
var bytes = size == -1 ? www.bytes : Resize(www.bytes, size);
var entityId = CommunityEntity.ServerInstance.net.ID;
var crc32 = FileStorage.server.Store(bytes, FileStorage.Type.png, entityId).ToString();
files[name].Png = crc32;
}
}
ins.init = true;
loaded++;
}
static byte[] Resize(byte[] bytes, int size) {
Image img = (Bitmap)(new ImageConverter().ConvertFrom(bytes));
Bitmap cutPiece = new Bitmap(size, size);
System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(cutPiece);
graphic.DrawImage(img, new Rectangle(0, 0, size, size), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
graphic.Dispose();
MemoryStream ms = new MemoryStream();
cutPiece.Save(ms, ImageFormat.Jpeg);
return ms.ToArray();
}
}
private List<RadiationZone> radiationZone = new List<RadiationZone>();
private class RadiationZone : MonoBehaviour {
private TriggerRadiation rads;
public float radius;
public float amount;
private void Awake() {
gameObject.layer = (int)Rust.Layer.Reserved1;
enabled = false;
}
private void OnDestroy() => Destroy(gameObject);
public void DestroyZone() {
try {
Destroy(this);
}
catch (Exception ex) {
ins.LogToFile("MeteorLog", $"Инфа о ошибке DestroyZone: {ex.Message} {Environment.NewLine} {ex.StackTrace}", ins, true);
}
}
public void InitializeRadiationZone(Vector3 position, float radius, float amount) {
this.radius = radius;
this.amount = amount;
transform.position = position;
transform.rotation = new Quaternion();
UpdateCollider();
rads = gameObject.AddComponent<TriggerRadiation>();
rads.RadiationAmountOverride = amount;
/*rads.radiationSize = radius;
// ... [Code preview truncated due to length. Full source in attached file] ...