C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins {
[Info("Lights On", "mspeedie", "2.2.1")]
[Description("Toggle lights on/off either as configured or by name.")]
// big thank you to FastBurn for helping fix Fluid Splitters and adding Flashing Lights and Siren Lights
// big thank you to Meeh for the help with the boomboxes
public class LightsOn : CovalencePlugin //RustPlugin
{
[PluginReference]
Plugin ZoneManager;
const string perm_lightson = "lightson.allowed";
private bool NightToggleactive = false;
private bool nightcross24 = false;
private bool config_changed = false;
private Timer Sweeptimer;
private List<string> zones_with_lights = new List<string>();
readonly DynamicConfigFile zdataFile = Interface.Oxide.DataFileSystem.GetFile("LightsOn-Zones");
ItemDefinition fuel = ItemManager.FindItemDefinition("lowgradefuel");
private Dictionary<string, int> IOPowerAmt = new Dictionary<string, int>();
// strings to compare to check object names
//const string autoturret_name = "autoturret";
//const string microphonestand_name = "microphonestand"; // this generates a signal and does not require power
const string bbq_camper_name = "bbq.campermodule";
const string bbq_name = "bbq";
const string boombox_name = "boombox";
const string campfire_name = "campfire";
const string carvablepumpkin_name = "carvable.pumpkin";
const string cctv_name = "cctv";
const string ceilinglight_name = "ceilinglight";
const string chandelier_name = "electric.chandelier";
const string chineselantern2_name = "chineselantern_white";
const string chineselantern_name = "chineselantern";
const string computerstation_name = "computerstation.ioent";
const string cookingworkbench_bbq_name = "cookingworkbench.bbq";
const string cookingworkbench_name = "cookingworkbench";
const string cursedcauldron_name = "cursedcauldron";
const string deluxe_lights2_name = "xmas.advanced.lights";
// it is not always consistent in name
const string deluxe_lightstring_name = "xmas.lightstring.advanced";
// it is not always consistent in name
const string electric_furnace_name = "electricfurnace";
const string fairylight_name = "electric.fairylights";
const string firepit_name = "skull_fire_pit";
const string fireplace_name = "fireplace";
const string flasherlight_name = "electric.flasherlight";
const string fluidswitch_name = "fluidswitch";
const string fluorescentlight_name = "electric.fluorescentlight";
const string fluorescentlightceiling_name = "electric.fluorescentlight.ceiling";
const string fogmachine_name = "fogmachine";
const string fridge_name = "fridge";
const string furnace_large_name = "furnace.large";
const string furnace_name = "furnace";
const string gamesroom_minifridge_name = "gamesroom.minifridge";
const string hatcandle_name = "hat.candle";
const string hatminer_name = "hat.miner";
const string heater_name = "electrical.heater";
const string hobobarrel_p_name = "hobobarrel";
const string hobobarrel_s_name = "hobobarrel_static";
const string hopper_name = "hopper";
const string igniter_name = "igniter";
const string industrial_combiner_name = "industrialcombiner";
const string industrial_conveyor_name = "industrialconveyor";
const string industrial_crafter_name = "industrialcrafter";
const string industrial_electric_furnace_name = "industrial_electric_furnace";
const string industrial_splitter_name = "industrialsplitter";
const string industrial_wall_lamp_blue_name = "industrial.wall.lamp.blue";
const string industrial_wall_lamp_green_name = "industrial.wall.lamp.green";
const string industrial_wall_lamp_name = "industrial.wall.lamp";
const string industrial_wall_lamp_red_name = "industrial.wall.lamp.red";
const string jackolantern_angry_name = "jackolantern.angry";
const string jackolantern_happy_name = "jackolantern.happy";
const string jukebox_name = "jukebox";
const string lantern_name = "lantern";
const string large_candleset_name = "largecandleset";
const string laserdetector_name = "laserdetector";
const string laserlight_name = "laserlight";
const string legacyfurnace_name = "legacy_furnace";
const string lightupframe_large_name = "lightupframe.ioent.large";
const string lightupframe_small_name = "lightupframe.ioent.small";
const string lightupframe_standing_name = "lightupframe.ioent.standing";
const string lightupframe_xl_name = "lightupframe.ioent.xl";
const string lightupframe_xxl_name = "lightupframe.ioent.xxl";
const string minifridge_name = "minifridge";
const string mining_pumpjack_name = "mining.pumpjack";
const string mining_pumpjack_static_name = "pumpjack";
const string mining_quarry_name = "mining_quarry";
const string mining_quarry_static_name = "miningquarry";
const string mixingtable_name = "mixingtable";
const string paintabletarget_reactive_name = "paintabletarget.reactive";
const string powered_water_purifier_name = "poweredwaterpurifier";
const string ptzcamera_name = "ptz_cctv";
const string reactive_target_name = "reactivetarget";
const string refinery_small_name = "refinery_small";
// no clue why this one is inconsistent so we have it twice
const string rfbroadcaster_name = "rfbroadcaster";
const string rfreceiver_name = "rfreceiver";
const string sam_site_name = "sam_site_turret";
const string searchlight_name = "searchlight";
const string sign_name = "sign";
// we have a procedure to find all the specific sign names and below
const string sign_neon_125x125_name = "sign.neon.125x125";
const string sign_neon_125x215_animated_name = "sign.neon.125x215.animated";
const string sign_neon_125x215_name = "sign.neon.125x215";
const string sign_neon_xl_animated_name = "sign.neon.xl.animated";
const string sign_neon_xl_name = "sign.neon.xl";
const string simplelight_name = "simplelight";
const string sirenlight_name = "electric.sirenlight";
const string small_candleset_name = "smallcandleset";
const string small_refinery_name = "small_refinery";
// no clue why this one is inconsistent so we have it twice
const string smart_alarm_name = "smartalarm";
const string smart_switch_name = "smartswitch";
const string snowmachine_name = "snowmachine";
const string spookyspeaker_name = "spookyspeaker";
const string spotlight_name = "electric.spotlight";
const string storage_monitor_name = "storagemonitor";
const string stringlight_name = "electric.bulbstringlights";
const string strobelight_name = "strobelight";
const string tablelamp_name = "electric.tablelamp";
const string telephone_name = "telephone";
const string teslacoil_name = "teslacoil";
const string torch_holder_name = "torchdeployablelightsource";
const string tripod_name = "electric.spotlight.tripod";
const string tunalight_name = "tunalight";
const string twitch_sign_name = "neonsigntr";
const string vehiclelift_name = "electrical.modularcarlift";
const string wallcabinet_name = "electric.wallcabinet";
const string water_purifier_name = "waterpurifier";
const string waterpump_name = "water.pump";
const string weaponsrack_double_light_name = "weaponracklightdouble";
const string weaponsrack_light_name = "weaponracklight";
#region Configuration
private Configuration config;
public class Configuration {
[JsonProperty(PropertyName = "Hats do not use fuel (a-always d-day n-night i-ignore)")]
public string Hats {
get;
set;
}
= "a";
//[JsonProperty(PropertyName = "Auto Turrets (a-always d-day n-night i-ignore)")]
//public string AutoTurrets { get; set; } = "i";
[JsonProperty(PropertyName = "BBQs (a-always d-day n-night i-ignore)")]
public string BBQs {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Boom Boxes (a-always d-day n-night i-ignore)")]
public string BoomBoxes {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Campfires (a-always d-day n-night i-ignore)")]
public string Campfires {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Candles (a-always d-day n-night i-ignore)")]
public string Candles {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Cauldrons (a-always d-day n-night i-ignore)")]
public string Cauldrons {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "CCTVs (a-always d-day n-night i-ignore)")]
public string CCTVs {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Ceiling Lights (a-always d-day n-night i-ignore)")]
public string CeilingLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Chandeliers (a-always d-day n-night i-ignore)")]
public string Chandeliers {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Cooking Workbench (a-always d-day n-night i-ignore)")]
public string CookingWorkbenchs {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Computer Stations (a-always d-day n-night i-ignore)")]
public string ComputerStations {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Deluxe Light Strings (a-always d-day n-night i-ignore)")]
public string DeluxeLightstrings {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Electric Furnaces (a-always d-day n-night i-ignore)")]
public string ElectricFurnaces {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "FairyLights (a-always d-day n-night i-ignore)")]
public string FairyLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Fireplaces (a-always d-day n-night i-ignore)")]
public string Fireplaces {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Fire Pits (a-always d-day n-night i-ignore)")]
public string FirePits {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Flasher Lights (a-always d-day n-night i-ignore)")]
public string FlasherLights {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "FluidSwitches (a-always d-day n-night i-ignore)")]
public string FluidSwitches {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Fog Machines (a-always d-day n-night i-ignore)")]
public string FogMachines {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Fluorescent Lights (a-always d-day n-night i-ignore)")]
public string FluorescentLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Fridge (a-always d-day n-night i-ignore)")]
public string Fridges {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Furnaces (a-always d-day n-night i-ignore)")]
public string Furnaces {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Hobo Barrels Static (a-always d-day n-night i-ignore)")]
public string SHoboBarrels {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Player Hobo Barrels (a-always d-day n-night i-ignore)")]
public string PHoboBarrels {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Heaters (a-always d-day n-night i-ignore)")]
public string Heaters {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Hopper (a-always d-day n-night i-ignore)")]
public string Hoppers {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Industrial Combiners (a-always d-day n-night i-ignore)")]
public string IndustrialCombiners {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Industrial Conveyors (a-always d-day n-night i-ignore)")]
public string IndustrialConveyors {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Industrial Crafters(a-always d-day n-night i-ignore)")]
public string IndustrialCrafters {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Industrial Splitters (a-always d-day n-night i-ignore)")]
public string IndustrialSplitters {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Industrial Wall Lamp (a-always d-day n-night i-ignore)")]
public string IndustrialWallLamps {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Igniters (a-always d-day n-night i-ignore)")]
public string Igniters {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Jukeboxes (a-always d-day n-night i-ignore)")]
public string Jukeboxes {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Lanterns (a-always d-day n-night i-ignore)")]
public string Lanterns {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "LaserDetectors (a-always d-day n-night i-ignore)")]
public string LaserDetectors {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "LaserLights (a-always d-day n-night i-ignore)")]
public string LaserLights {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "Light Up Frames (a-always d-day n-night i-ignore)")]
public string Lightups {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Mining Quarries (a-always d-day n-night i-ignore)")]
public string MiningQuarries {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Mixing Tables (a-always d-day n-night i-ignore)")]
public string MixingTables {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "PTZ Camera (a-always d-day n-night i-ignore)")]
public string PTZCameras {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Pump Jacks (a-always d-day n-night i-ignore)")]
public string PumpJacks {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Reactive Targets (a-always d-day n-night i-ignore)")]
public string ReactiveTargets {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "RF Broadcasters (a-always d-day n-night i-ignore)")]
public string RFBroadcasters {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "RF Receivers (a-always d-day n-night i-ignore)")]
public string RFReceivers {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Refineries (a-always d-day n-night i-ignore)")]
public string Refineries {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "SAM Sites (a-always d-day n-night i-ignore)")]
public string SamSites {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Search Lights (a-always d-day n-night i-ignore)")]
public string SearchLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Signs (a-always d-day n-night i-ignore)")]
public string Signs {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Simple Lights (a-always d-day n-night i-ignore)")]
public string SimpleLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Siren Lights (a-always d-day n-night i-ignore)")]
public string SirenLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Smart Alarms (a-always d-day n-night i-ignore)")]
public string SmartAlarms {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Smart Switches (a-always d-day n-night i-ignore)")]
public string SmartSwitches {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "SnowMachines (a-always d-day n-night i-ignore)")]
public string SnowMachines {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "SpookySpeakers (a-always d-day n-night i-ignore)")]
public string Speakers {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "SpotLights (a-always d-day n-night i-ignore)")]
public string SpotLights {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "StringLights (a-always d-day n-night i-ignore)")]
public string StringLights {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Storage Monitor (a-always d-day n-night i-ignore)")]
public string StorageMonitors {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Strobe Lights (a-always d-day n-night i-ignore)")]
public string StrobeLights {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "TableLamps (a-always d-day n-night i-ignore)")]
public string TableLamps {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Telephones (a-always d-day n-night i-ignore)")]
public string Telephones {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Tesla Coils (a-always d-day n-night i-ignore)")]
public string TeslaCoils {
get;
set;
}
= "i";
[JsonProperty(PropertyName = "VehicleLifts (a-always d-day n-night i-ignore)")]
public string VehicleLifts {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Wall Cabinet (a-always d-day n-night i-ignore)")]
public string WallCabinets {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Water Pumps (a-always d-day n-night i-ignore)")]
public string WaterPumps {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Water Purifiers (powered and unpowered) (a-always d-day n-night i-ignore)")]
public string WaterPurifiers {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Weapons Racks (a-always d-day n-night i-ignore)")]
public string WeaponsRacks {
get;
set;
}
= "a";
[JsonProperty(PropertyName = "Protect BBQs (true/false)")]
public bool ProtectBBQs {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Protect Campfires (true/false)")]
public bool ProtectCampfires {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Protect Cauldrons (true/false)")]
public bool ProtectCauldrons {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Protect Fire Pits (true/false)")]
public bool ProtectFirePits {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Protect Fireplaces (true/false)")]
public bool ProtectFireplaces {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Protect Furnaces (true/false)")]
public bool ProtectFurnaces {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Protect Hobo Barrels (true/false)")]
public bool ProtectHoboBarrels {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Protect Mixing Tables (true/false)")]
public bool ProtectMixingTables {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Protect Refineries (true/false)")]
public bool ProtectRefineries {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Keep running if more than one fuel present (true/false)")]
public bool KeepRunningIfFuel {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Console Output (true/false)")]
public bool ConsoleMsg {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Check Frequency (in seconds)")]
public int CheckFrequency {
get;
set;
}
= 300;
[JsonProperty(PropertyName = "Dusk Time (HH in a 24 hour clock)")]
public float DuskTime {
get;
set;
}
= 17.5f;
[JsonProperty(PropertyName = "Dawn Time (HH in a 24 hour clock)")]
public float DawnTime {
get;
set;
}
= 09.0f;
[JsonProperty(PropertyName = "Use Zone Manager Plugin")]
public bool UseZoneManagerPlugin {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Alter Unowned Entities")]
public bool AlterUnowned {
get;
set;
}
= false;
[JsonProperty(PropertyName = "BoomBox Power")]
public int BoomBoxPower {
get;
set;
}
= 200;
[JsonProperty(PropertyName = "Christmas Lights Power")]
public int XmasLightsPower {
get;
set;
}
= 200;
[JsonProperty(PropertyName = "Laser Detector Power")]
public int LaserDetectorPower {
get;
set;
}
= 2;
[JsonProperty(PropertyName = "Player Can Toggle non-lights (true/false)")]
public bool PlayerToggleAll {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Furnace InstaCook (true/false)")]
public bool FurnaceInstaCook {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Campfire InstaCook (true/false)")]
public bool CampfireInstaCook {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Hobo Barrel InstaCook (true/false)")]
public bool HoboInstaCook {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Fireplace InstaCook (true/false)")]
public bool FireplaceInstaCook {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Cooking/Mixing Table Instant (true/false)")]
public bool MixingInstant {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Smelting and Cooking NoFuelRequired (true/false)")]
public bool InstaNoFuelRequired {
get;
set;
}
= false;
//[JsonProperty(PropertyName = "Microphone Stand Power")]
//public int MicrophoneStandPower { get; set; } = 200;
[JsonProperty(PropertyName = "Boom boxes On (true/false)")]
public bool BoomBoxOn {
get;
set;
}
= true;
public string ToJson() => JsonConvert.SerializeObject(this);
public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
}
protected override void LoadDefaultConfig() => config = new Configuration();
protected override void LoadConfig() {
// Set power amounts
// If needed this can be moved to config
//IOPowerAmt.Add("autoturret", 10);
// we call clear incase LoadConfig gets called more than once or after load
IOPowerAmt.Clear();
IOPowerAmt.Add("boombox", 200);
IOPowerAmt.Add("cctv", 5);
IOPowerAmt.Add("ceilinglight", 2);
IOPowerAmt.Add("computerstation.ioent", 10);
IOPowerAmt.Add("electric.bulbstringlights", 2);
IOPowerAmt.Add("electric.chandelier", 2);
IOPowerAmt.Add("electric.fairylights", 2);
IOPowerAmt.Add("electric.flasherlight", 1);
IOPowerAmt.Add("electric.fluorescentlight", 2);
IOPowerAmt.Add("electric.fluorescentlight.ceiling", 2);
IOPowerAmt.Add("electric.sirenlight", 1);
IOPowerAmt.Add("electric.spotlight", 2);
IOPowerAmt.Add("electric.spotlight.tripod", 2);
IOPowerAmt.Add("electric.tablelamp", 2);
IOPowerAmt.Add("electric.wallcabinet", 1);
IOPowerAmt.Add("electric_furnace", 2);
IOPowerAmt.Add("electrical.heater", 3);
IOPowerAmt.Add("electrical.modularcarlift", 5);
IOPowerAmt.Add("fluidswitch", 1);
IOPowerAmt.Add("fogmachine", 1);
IOPowerAmt.Add("fridge", 6);
IOPowerAmt.Add("gamesroom.minifridge", 6);
IOPowerAmt.Add("hopper", 2);
IOPowerAmt.Add("igniter", 2);
IOPowerAmt.Add("industrial.wall.lamp", 2);
IOPowerAmt.Add("industrial.wall.lamp.blue", 2);
IOPowerAmt.Add("industrial.wall.lamp.green", 2);
IOPowerAmt.Add("industrial.wall.lamp.red", 2);
IOPowerAmt.Add("industrial.electric.furnace", 2);
IOPowerAmt.Add("industrialcombiner", 2);
IOPowerAmt.Add("industrialconveyor", 2);
IOPowerAmt.Add("industrialcrafter", 2);
IOPowerAmt.Add("industrialsplitter", 2);
IOPowerAmt.Add("jukebox", 2);
IOPowerAmt.Add("laserlight", 1);
IOPowerAmt.Add("lightupframe.ioent.large", 1);
IOPowerAmt.Add("lightupframe.ioent.small", 1);
IOPowerAmt.Add("lightupframe.ioent.standing", 1);
IOPowerAmt.Add("lightupframe.ioent.xl", 1);
IOPowerAmt.Add("lightupframe.ioent.xxl", 1);
IOPowerAmt.Add("minifridge", 6);
IOPowerAmt.Add("neonsigntr", 15);
IOPowerAmt.Add("paintabletarget.reactive", 2);
IOPowerAmt.Add("poweredwaterpurifier", 5);
IOPowerAmt.Add("ptz_cctv", 10);
IOPowerAmt.Add("reactivetarget", 1);
IOPowerAmt.Add("rfbroadcaster", 1);
IOPowerAmt.Add("rfreceiver", 1);
IOPowerAmt.Add("sam_site_turret", 25);
IOPowerAmt.Add("searchlight", 10);
IOPowerAmt.Add("sign.neon.125x125", 4);
IOPowerAmt.Add("sign.neon.125x215", 6);
IOPowerAmt.Add("sign.neon.125x215.animated", 10);
IOPowerAmt.Add("sign.neon.xl", 8);
IOPowerAmt.Add("sign.neon.xl.animated", 15);
IOPowerAmt.Add("simplelight", 2);
IOPowerAmt.Add("smartalarm", 1);
IOPowerAmt.Add("smartswitch", 1);
IOPowerAmt.Add("snowmachine", 1);
IOPowerAmt.Add("storagemonitor", 1);
IOPowerAmt.Add("strobelight", 1);
IOPowerAmt.Add("telephone", 2);
IOPowerAmt.Add("teslacoil", 34);
IOPowerAmt.Add("water.pump", 5);
IOPowerAmt.Add("waterpurifier", 5);
IOPowerAmt.Add("weaponracklight", 1);
IOPowerAmt.Add("weaponracklightdouble", 1);
IOPowerAmt.Add("xmas.lightstring.advanced", 200);
//IOPowerAmt.Add("microphonestand", 200);
// added to deal with inconsistent names
IOPowerAmt.Add("xmas.advanced.lights", 200);
try {
base.LoadConfig();
config = Config.ReadObject<Configuration>();
if (config == null) {
throw new JsonException();
}
if (!config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys)) {
LogWarning($"Configuration appears to be outdated; updating and saving");
SaveConfig();
}
}
catch {
LogWarning($"Configuration file {Name}.json is invalid; using defaults");
LoadDefaultConfig();
}
// set the dictionary to be in synch
IOPowerAmt["boombox"] = config.BoomBoxPower;
IOPowerAmt["xmas.lightstring.advanced"] = config.XmasLightsPower;
IOPowerAmt["xmas.advanced.lights"] = config.XmasLightsPower;
IOPowerAmt["laserdetector"] = config.LaserDetectorPower;
//IOPowerAmt["microphonestand"] = config.MicrophoneStandPower;
CheckConfig();
}
protected override void SaveConfig() {
LogWarning($"Configuration changes saved to {Name}.json");
Config.WriteObject(config, true);
}
#endregion Configuration
string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
// if the id is null most likely it is a console command, thus use Puts
private void message_player(IPlayer player , string prefix, string message_name, string string_message) {
if (player.Id != null) {
try {
player.Message(String.Concat(String.Concat(Lang(prefix) , Lang(message_name, player.Id)) , string_message));
}
catch {
LogWarning(String.Concat(String.Concat(Lang(prefix) , Lang(message_name), string_message)));
}
}
else {
LogWarning(String.Concat(String.Concat(Lang(prefix) , Lang(message_name), string_message)));
}
}
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["bad check frequency"]
= "Check frequency must be between 10 and 600", ["bad check frequency2"] = "Check frequency must be between 60 and 6000", ["bad prefab"] = "Bad Prefab Name, not found: ", ["bad dusk time"] = "Dusk time must be between 0 and 24", ["bad dawn time"] = "Dawn time must be between 0 and 24", ["Coninstacook"] = "Cook anything only supported when InstaCook is true", ["dawn=dusk"] = "Dawn can't be the same value as dusk", ["dawn"] = "Lights going off. Next lights on at ", ["default"] = "Loading default config for LightsOn", ["dusk"] = "Lights coming on. Ending at ", ["Empty Zone"] = @"Empty Zone name in your oxide\data\LightsOn-Zones.json", ["Foninstacook"] = "No Fuel Requirement only supported when InstaCook is true", ["lights off"] = "Lights Off", ["lights on"] = "Lights On", ["lights check"] = "Lights processing based on settings", ["nopermission"] = "You do not have permission to use that command.", ["No Zone"] = @"Use Zone Manager set but no zones in oxide\data\LightsOn-Zones.json", ["invalid state"] = "Please select one (and only one of a, d, n, or i)[a-always d-day n-night i-ignore] for {0}", ["prefix"] = "LightsOn: ", ["state"] = "unknown state: please use on or off", ["syntax"] = @"syntax: Lights State (check/on/off) Optional: prefabshortname (part of the prefab name) to change their state, use all to force all lights' state", ["zone"] = "Zone Manager requested but not found loaded"
}
, this);
}
protected void CheckConfig() {
// used to validate config settings
List<string> ValidConfigChoices = new List<string> {
"a", "d", "i", "n"
}
;
config_changed = false;
// check data is ok because people can make mistakes
if (config.DuskTime < 0f || config.DuskTime > 24f) {
Puts(Lang("bad dusk time (outside of 0 to 24)"));
config.DuskTime = 17f;
config_changed = true;
}
if (config.DawnTime < 0f || config.DawnTime > 24f) {
Puts(Lang("bad dawn time (outside of 0 to 24)"));
config.DawnTime = 9f;
config_changed = true;
}
if (config.DawnTime == config.DuskTime) {
Puts(Lang("dawn can't be equal to dusk"));
config.DawnTime = 9f;
config.DuskTime = 17f;
config_changed = true;
}
if (config.CheckFrequency < 30 || config.CheckFrequency > 3600) {
Puts(Lang("bad check frequency (too small or too large)"));
config.CheckFrequency = 300;
config_changed = true;
}
// determine correct light timing logic
if (config.DuskTime > config.DawnTime) nightcross24 = true;
else nightcross24 = false;
if (config.BBQs == null || config.BBQs.Length != 1 || !ValidConfigChoices.Contains(config.BBQs)) {
Puts(Lang("invalid state", null, "BBQs"));
config.BBQs = "a";
config_changed = true;
}
if (config.BoomBoxes == null || config.BoomBoxes.Length != 1 || !ValidConfigChoices.Contains(config.BoomBoxes)) {
Puts(Lang("invalid state", null, "BoomBoxes"));
config.BoomBoxes = "a";
config_changed = true;
}
//if (config.MicrophoneStands == null || config.MicrophoneStands.Length != 1 || !ValidConfigChoices.Contains(config.MicrophoneStands))
//{
// Puts(Lang("invalid state",null,"MicrophoneStands"));
// config.MicrophoneStands = "a";
// config_changed = true;
//}
if (config.PTZCameras == null || config.PTZCameras.Length != 1 || !ValidConfigChoices.Contains(config.PTZCameras)) {
Puts(Lang("invalid state", null, "PTZCameras"));
config.PTZCameras = "a";
config_changed = true;
}
if (config.CCTVs == null || config.CCTVs.Length != 1 || !ValidConfigChoices.Contains(config.CCTVs)) {
Puts(Lang("invalid state", null, "CCTVs"));
config.CCTVs = "a";
config_changed = true;
}
if (config.Campfires == null || config.Campfires.Length != 1 || !ValidConfigChoices.Contains(config.Campfires)) {
Puts(Lang("invalid state", null, "Campfires"));
config.Campfires = "a";
config_changed = true;
}
if (config.Candles == null || config.Candles.Length != 1 || !ValidConfigChoices.Contains(config.Candles)) {
Puts(Lang("invalid state", null, "Candles"));
config.Candles = "a";
config_changed = true;
}
if (config.Cauldrons == null || config.Cauldrons.Length != 1 || !ValidConfigChoices.Contains(config.Cauldrons)) {
Puts(Lang("invalid state", null, "Cauldrons"));
config.Cauldrons = "a";
config_changed = true;
}
if (config.CeilingLights == null || config.CeilingLights.Length != 1 || !ValidConfigChoices.Contains(config.CeilingLights)) {
Puts(Lang("invalid state", null, "CeilingLights"));
config.CeilingLights = "a";
config_changed = true;
}
if (config.ComputerStations == null || config.ComputerStations.Length != 1 || !ValidConfigChoices.Contains(config.ComputerStations)) {
Puts(Lang("invalid state", null, "ComputerStations"));
config.ComputerStations = "a";
config_changed = true;
}
if (config.DeluxeLightstrings == null || config.DeluxeLightstrings.Length != 1 || !ValidConfigChoices.Contains(config.DeluxeLightstrings)) {
Puts(Lang("invalid state", null, "DeluxeLightstrings"));
config.DeluxeLightstrings = "a";
config_changed = true;
}
if (config.FirePits == null || config.FirePits.Length != 1 || !ValidConfigChoices.Contains(config.FirePits)) {
Puts(Lang("invalid state", null, "FirePits"));
config.FirePits = "a";
config_changed = true;
}
if (config.Fireplaces == null || config.Fireplaces.Length != 1 || !ValidConfigChoices.Contains(config.Fireplaces)) {
Puts(Lang("invalid state", null, "Fireplaces"));
config.Fireplaces = "a";
config_changed = true;
}
if (config.FlasherLights == null || config.FlasherLights.Length != 1 || !ValidConfigChoices.Contains(config.FlasherLights)) {
Puts(Lang("invalid state", null, "FlasherLights"));
config.FlasherLights = "a";
config_changed = true;
}
if (config.FluidSwitches == null || config.FluidSwitches.Length != 1 || !ValidConfigChoices.Contains(config.FluidSwitches)) {
Puts(Lang("invalid state", null, "FluidSwitches"));
config.FluidSwitches = "a";
config_changed = true;
}
if (config.FogMachines == null || config.FogMachines.Length != 1 || !ValidConfigChoices.Contains(config.FogMachines)) {
Puts(Lang("invalid state", null, "FogMachines"));
config.FogMachines = "a";
config_changed = true;
}
if (config.Furnaces == null || config.Furnaces.Length != 1 || !ValidConfigChoices.Contains(config.Furnaces)) {
Puts(Lang("invalid state", null, "Furnaces"));
config.Furnaces = "a";
config_changed = true;
}
if (config.Hats == null || config.Hats.Length != 1 || !ValidConfigChoices.Contains(config.Hats)) {
Puts(Lang("invalid state", null, "Hats"));
config.Hats = "a";
config_changed = true;
}
if (config.Heaters == null || config.Heaters.Length != 1 || !ValidConfigChoices.Contains(config.Heaters)) {
Puts(Lang("invalid state", null, "Heaters"));
config.Heaters = "a";
config_changed = true;
}
if (config.PHoboBarrels == null || config.PHoboBarrels.Length != 1 || !ValidConfigChoices.Contains(config.PHoboBarrels)) {
Puts(Lang("invalid state", null, "Player HoboBarrels"));
config.PHoboBarrels = "a";
config_changed = true;
}
if (config.SHoboBarrels == null || config.SHoboBarrels.Length != 1 || !ValidConfigChoices.Contains(config.SHoboBarrels)) {
Puts(Lang("invalid state", null, "Static HoboBarrels"));
config.SHoboBarrels = "a";
config_changed = true;
}
if (config.Igniters == null || config.Igniters.Length != 1 || !ValidConfigChoices.Contains(config.Igniters)) {
Puts(Lang("invalid state", null, "Igniters"));
config.Igniters = "a";
config_changed = true;
}
if (config.Jukeboxes == null || config.Jukeboxes.Length != 1 || !ValidConfigChoices.Contains(config.Jukeboxes)) {
Puts(Lang("invalid state", null, "Jukeboxes"));
config.Jukeboxes = "a";
config_changed = true;
}
if (config.Lanterns == null || config.Lanterns.Length != 1 || !ValidConfigChoices.Contains(config.Lanterns)) {
Puts(Lang("invalid state", null, "Lanterns"));
config.Lanterns = "a";
config_changed = true;
}
if (config.LaserDetectors == null || config.LaserDetectors.Length != 1 || !ValidConfigChoices.Contains(config.LaserDetectors)) {
Puts(Lang("invalid state", null, "LaserDetectors"));
config.LaserDetectors = "i";
config_changed = true;
}
if (config.LaserLights == null || config.LaserLights.Length != 1 || !ValidConfigChoices.Contains(config.LaserLights)) {
Puts(Lang("invalid state", null, "LaserLights"));
config.LaserLights = "i";
config_changed = true;
}
if (config.Lightups == null || config.Lightups.Length != 1 || !ValidConfigChoices.Contains(config.Lightups)) {
Puts(Lang("invalid state", null, "Lightups"));
config.Lightups = "i";
config_changed = true;
}
if (config.MixingTables == null || config.MixingTables.Length != 1 || !ValidConfigChoices.Contains(config.MixingTables)) {
Puts(Lang("invalid state", null, "MixingTables"));
config.MixingTables = "a";
config_changed = true;
}
if (config.RFBroadcasters == null || config.RFBroadcasters.Length != 1 || !ValidConfigChoices.Contains(config.RFBroadcasters)) {
Puts(Lang("invalid state", null, "RFBroadcasters"));
config.RFBroadcasters = "a";
config_changed = true;
}
if (config.RFReceivers == null || config.RFReceivers.Length != 1 || !ValidConfigChoices.Contains(config.RFReceivers)) {
Puts(Lang("invalid state", null, "RFReceivers"));
config.RFReceivers = "a";
config_changed = true;
}
if (config.ReactiveTargets == null || config.ReactiveTargets.Length != 1 || !ValidConfigChoices.Contains(config.ReactiveTargets)) {
Puts(Lang("invalid state", null, "ReactiveTargets"));
config.ReactiveTargets = "a";
config_changed = true;
}
if (config.Refineries == null || config.Refineries.Length != 1 || !ValidConfigChoices.Contains(config.Refineries)) {
Puts(Lang("invalid state", null, "Refineries"));
config.Refineries = "a";
config_changed = true;
}
if (config.SamSites == null || config.SamSites.Length != 1 || !ValidConfigChoices.Contains(config.SamSites)) {
Puts(Lang("invalid state", null, "SamSites"));
config.SamSites = "a";
config_changed = true;
}
if (config.SearchLights == null || config.SearchLights.Length != 1 || !ValidConfigChoices.Contains(config.SearchLights)) {
Puts(Lang("invalid state", null, "SearchLights"));
// ... [Code preview truncated due to length. Full source in attached file] ...