C#:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Configuration;
using UnityEngine;
using Network;
using Facepunch;
using Facepunch.Extend;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
namespace Oxide.Plugins {
[Info("UpLifted", "Skuli Dropek", "1.2.17", ResourceId = 110)]
[Description("Куплено на Oxide-Russia.ru")]
internal class UpLifted : RustPlugin {
[PluginReference]
private Plugin Clans, Friends;
private static UpLifted UpL;
private bool initialized;
private bool Changed;
private bool hasFullyLoaded;
private double lastHour;
private static bool isDayTime;
private int versionMajor;
private int versionMinor;
private bool _newConfig = false;
private static Dictionary<string, bool> adminAccessEnabled = new Dictionary<string, bool>();
private static Dictionary<string, bool> adminLiftEntkill = new Dictionary<string, bool>();
private static Dictionary<uint, Elevator> crossReference;
private Dictionary<ulong, Elevator> playerStartups;
private List<string> permissionGroups = new List<string>();
private List<ConsoleSystem.Command> aclVars;
private static WaitForFixedUpdate waitFFU = new WaitForFixedUpdate();
private static WaitForEndOfFrame waitFOF = new WaitForEndOfFrame();
private static string cabinControlUI = "CabinControlUI";
private static string cabinDestroyUI = "CabinDestroyUI";
private static string cabinSettingsUI = "CabinSettingsUI";
private static string cabinPlacementUI = "CabinPlacementUI";
private static string cabinSharingUI = "CabinSharingUI";
private Dictionary<string, object> permissionBlock = new Dictionary<string, object>();
private Dictionary<string, object> playerPermissionMatrix = new Dictionary<string, object> {
{
"MaxLiftPerUser", new object[] {
-1, 1, 2, "The number of lifts a player can create"
}
}
, {
"MaxMoveSpeed", new object[] {
5, 1, 3, "The maximum speed being available to choose"
}
}
, {
"MaxPlacementFloor", new object[] {
-1, 2, 3, "The last floor a player can place a lift on"
}
}
, {
"MaxFloorRange", new object[] {
15, 3, 7, "The from-to-range a player can place a lift"
}
}
, {
"MaxFloorLevel", new object[] {
-1, 5, 10, "The last floor a player can place a lift to"
}
}
, {
"FuelConsumePerFloor", new object[] {
1, 5, 3, "The amount of consumed fuel per moved floor"
}
}
, {
"FuelStorageItemSlots", new object[] {
6, 1, 3, "The available slots for the central fuel storage"
}
}
, {
"FuelStorageStackSize", new object[] {
0, 500, 1000, "The stacksize limit for the central fuel storage"
}
}
, {
"DoorSkin", new object[] {
1276338615uL, 1276338615uL, 1276338615uL, "The default skin for new placements"
}
}
, {
"BuildCostMultiplier", new object[] {
1.0f, 2.0f, 1.5f, "The buildcost multiplier for build and remove"
}
}
, {
"EnableBuildCost", new object[] {
false, true, true, "Enable or disable buildcosts for a player"
}
}
, {
"EnableFuelUsage", new object[] {
false, true, true, "Enable or disable fuel usage for a player"
}
}
, {
"CanCreate", new object[] {
true, false, true, "Needed option to allow the placement of lifts"
}
}
, {
"CanReskin", new object[] {
true, false, true, "Needed option to allow door reskinning"
}
}
, {
"CanPlaceOnFloor", new object[] {
true, false, false, "Needed option to place on floors also"
}
}
, {
"AccessVipShare", new object[] {
true, false, false, "Needed option to allow access to VIP shares"
}
}
, {
"BaseComfort", new object[] {
100, 0, 25, "The cabin's enabled comfort level from 0 to 100"
}
}
, {
"BaseTemperature", new object[] {
34, 0, 17, "The cabin's enabled temperature level from 34 to 0"
}
}
,
}
;
private object GetConfig(string menu, string datavalue, object defaultValue) {
Dictionary<string, object> data = Config[menu] as Dictionary<string, object>;
if (data == null) {
data = new Dictionary<string, object>();
Config[menu] = data;
Changed = true;
}
object value;
if (!data.TryGetValue(datavalue, out value)) {
value = defaultValue;
data[datavalue] = value;
Changed = true;
}
return value;
}
protected override void LoadDefaultConfig() {
_newConfig = true;
Config.Clear();
LoadVariables();
}
private string msg(string key, string id = null) {
return lang.GetMessage(key, this, id);
}
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
{
"Couldn't use the RemoverTool on a Lift installation", "Couldn't use the RemoverTool on a Lift installation"
}
, {
"Couldn't add a home inside a Lift installation", "Couldn't add a home inside a Lift installation"
}
, {
"Entkill disabled for Lifts.Toggle this by: ", "Entkill disabled for Lifts.Toggle this by: "
}
, {
"No build or place access inside a Lift installation", "No build or place access inside a Lift installation"
}
, {
"You are not permitted for this command", "You are not permitted for this command"
}
, {
"You are building blocked on that position", "You are building blocked on that position"
}
, {
"You cannot place on deployed objects", "You cannot place on deployed objects"
}
, {
"You do not own this foundation", "You do not own this foundation"
}
, {
"You cannot place anymore on this level", "You cannot place anymore on this level"
}
, {
"You reached your placement limit!", "You reached your placement limit!"
}
, {
"The foundation needs to be at least of grade Stone", "The foundation needs to be at least of grade Stone"
}
, {
"You cannot build under the terrain/caves/cliffs", "You cannot build under the terrain/caves/cliffs"
}
, {
"Too close by another installed lift", "Too close by another installed lift"
}
, {
"You can place on foundations only", "You can place on foundations only"
}
, {
"Choose the planned Lift size", "Choose the planned Lift size"
}
, {
"Choose where to pre-place doors", "Choose where to pre-place doors"
}
, {
"You reached your placement limit", "You reached your placement limit"
}
, {
"Lift admin access enabled", "Lift admin access enabled"
}
, {
"Lift admin access disabled", "Lift admin access disabled"
}
, {
"Lift admin entkill enabled", "Lift admin entkill enabled"
}
, {
"Lift admin entkill disabled", "Lift admin entkill disabled"
}
, {
"This lift was sucessfully reset", "<size=%id%></size>This lift was sucessfully reset"
}
, {
"Nothing valid to reset was found", "Nothing valid to reset was found"
}
, {
"The new lift failed for some reason.Please try from a lower floor", "The new lift failed for some reason.Please try from a lower floor"
}
, {
"Do Placement", "Do Placement"
}
, {
"Do Place (Upward Overwrite)", "Do Place (Upward Overwrite)"
}
, {
"Cancel Action", "Cancel Action"
}
, {
"Cancel", "Cancel"
}
, {
"Tear down\nLift", "Tear down\nLift"
}
, {
"Full Remove", "Full Remove"
}
, {
"Keep Building", "Keep Building"
}
, {
"Operating\nPanel", "Operating\nPanel"
}
, {
"Lighting", "Lighting"
}
, {
"Move Speed", "Move Speed"
}
, {
"Floor OnHold", "Floor OnHold"
}
, {
"Idle Close", "Idle Close"
}
, {
"Power State", "Power State"
}
, {
"Clan Share", "Clan Share"
}
, {
"FriendShare", "FriendShare"
}
, {
"Door Skin", "Door Skin"
}
, {
"Update", "Update"
}
, {
"Bad", "Bad"
}
, {
"Good", "Good"
}
, {
"FoC", "FoC"
}
, {
"Door", "Door"
}
, {
"Floor", "Floor"
}
, {
"Current", "Current"
}
, {
"Static", "Static"
}
, {
"Share Mode", "Share Mode"
}
, {
"Floor Sharing\nOptions", "Floor Sharing\nOptions"
}
, {
"Switch\nAll Floors", "Switch\nAll Floors"
}
, {
"Reset\nAll Floors", "Reset\nAll Floors"
}
, {
"Settings\nPanel", "Settings\nPanel"
}
, {
"PowerState.Internal", "Internal"
}
, {
"PowerState.TC", "TC"
}
, {
"PowerState.FoC", "FoC"
}
, {
"CabinLightMode.Dynamic", "Dynamic"
}
, {
"CabinLightMode.AlwaysOn", "AlwaysOn"
}
, {
"CabinLightMode.Disabled", "Disabled"
}
, {
"ShareMode.None", "None"
}
, {
"ShareMode.Clan", "Clan"
}
, {
"ShareMode.Friends", "Friends"
}
, {
"ShareMode.Full", "Full"
}
, {
"ShareMode.Public", "Public"
}
, {
"FloorShare.Public", "Public"
}
, {
"FloorShare.Full", "Full"
}
, {
"FloorShare.Friends", "Friends"
}
, {
"FloorShare.Clan", "Clan"
}
, {
"FloorShare.Excluded", "Excluded"
}
, {
"FloorShare.Hidden", "Hidden"
}
, {
"FloorShare.HiddenVIP", "HiddenVIP"
}
,
}
, this);
}
private bool loadOverrideCorrupted;
private string createChatCommand;
private string helpChatCommand;
private string pluginPrefix;
private string prefixColor;
private string prefixFormat;
private int buildingGrade = 3;
private static string knockEffectGuid;
private int lastStableFloor;
private static bool enableClanShare;
private static bool enableFriendShare;
private static bool clansEnabled;
private static bool friendsEnabled;
private bool sharingPlugins;
private bool enableEntIdKillProtection;
private bool enableRemoverToolProtection;
private bool enableSetHomeDeny;
private static bool isGroundBlockVulnerable;
private static bool doorDestructionKillsLiftCabin;
private static bool sleepWatchEnabled;
private static float sleepWatchDelay;
private static float sleepWatchInterval;
private static bool sleepWatchMoveDown;
private static bool preventPlacementInCaves;
private static bool preventPlacementAboveDeployables;
private bool admAccessSwitchable;
private bool admSwitchEnabledAtLogin;
private string admAccessToggleCmd;
private int admAccessAuthLevel;
private string admAccessPermission;
private int defaultMoveSpeed;
private List<object> admPseudoPerms = new List<object>();
private List<string> pseudoPerms = new List<string>();
private void LoadVariables() {
versionMinor = Convert.ToInt32(GetConfig("Debug", "VersionMinor", -1));
if (!_newConfig && versionMinor < 1) {
Config.Save(Manager.ConfigPath + string.Format("\\{0}_OLD.json", Name));
PrintWarning("Created a copy of the old config");
Config.Clear();
Config["Debug", "VersionMinor"] = Version.Minor;
Config["Debug", "VersionMajor"] = Version.Major;
Changed = true;
}
if (versionMinor == -1) {
Config["Debug", "VersionMinor"] = Version.Minor;
Changed = true;
}
buildingGrade = Mathf.Clamp(Convert.ToInt32(GetConfig("Walls", "Grade (0 -> 4, (0 = Twigs 4 = Armoured))", 3)), 0, 4);
versionMajor = Convert.ToInt32(GetConfig("Debug", "VersionMajor", Version.Major));
versionMinor = Convert.ToInt32(GetConfig("Debug", "VersionMinor", Version.Minor));
loadOverrideCorrupted = Convert.ToBoolean(GetConfig("Debug", "LoadOverrideCorrupted", false));
permissionBlock = (Dictionary<string, object>) GetConfig("Permission", "AccessControl", new Dictionary<string, object>());
createChatCommand = Convert.ToString(GetConfig("Commands", "Start lift creation", "newlift"));
helpChatCommand = Convert.ToString(GetConfig("Commands", "Reset lift movement", "liftaid"));
pluginPrefix = Convert.ToString(GetConfig("Formatting", "PluginPrefix", "Up·Lift·ed"));
prefixColor = Convert.ToString(GetConfig("Formatting", "PrefixColor", "#468499"));
prefixFormat = Convert.ToString(GetConfig("Formatting", "PrefixFormat", "<color={0}>{1}</color>: "));
enableEntIdKillProtection = Convert.ToBoolean(GetConfig("HealthCare", "EnableEntIdKillProtection", true));
enableRemoverToolProtection = Convert.ToBoolean(GetConfig("HealthCare", "EnableRemoverToolProtection", true));
enableSetHomeDeny = Convert.ToBoolean(GetConfig("HealthCare", "EnableSetHomeDeny", true));
isGroundBlockVulnerable = Convert.ToBoolean(GetConfig("HealthCare", "IsGroundBlockVulnerable", true));
doorDestructionKillsLiftCabin = Convert.ToBoolean(GetConfig("HealthCare", "DoorDestructionKillsLiftCabin", true));
lastStableFloor = Convert.ToInt32(GetConfig("HealthCare", "LastStableFloor", 18));
enableClanShare = Convert.ToBoolean(GetConfig("Support", "EnableClanSharing", true));
enableFriendShare = Convert.ToBoolean(GetConfig("Support", "EnableFriendSharing", true));
sleepWatchEnabled = Convert.ToBoolean(GetConfig("AbuseControl", "SleepWatchEnabled", true));
sleepWatchDelay = Convert.ToSingle(GetConfig("AbuseControl", "SleepWatchDelay", 180));
sleepWatchInterval = Convert.ToSingle(GetConfig("AbuseControl", "SleepWatchInterval", 60));
sleepWatchMoveDown = Convert.ToBoolean(GetConfig("AbuseControl", "SleepWatchMoveDown", true));
preventPlacementInCaves = Convert.ToBoolean(GetConfig("AbuseControl", "PreventPlacementInCaves", true));
preventPlacementAboveDeployables = Convert.ToBoolean(GetConfig("AbuseControl", "PreventPlacementAboveDeployables", true));
admAccessSwitchable = Convert.ToBoolean(GetConfig("Administrative", "AdmAccessSwitchable", true));
admSwitchEnabledAtLogin = Convert.ToBoolean(GetConfig("Administrative", "AdmSwitchEnabledAtLogin", false));
admAccessToggleCmd = Convert.ToString(GetConfig("Administrative", "AdmAccessToggleCmd", "liftadmin"));
admAccessAuthLevel = Convert.ToInt32(GetConfig("Administrative", "AdmAccessAuthLevel", 2));
admAccessPermission = Convert.ToString(GetConfig("Administrative", "AdmAccessPermission", "admaccess"));
admPseudoPerms = (List<object>) GetConfig("Administrative", "AdmPseudoPerms", new List<object> {
"fauxadm.allowed", "fakeadmin.allow"
}
);
defaultMoveSpeed = Convert.ToInt32(GetConfig("Defaults", "defaultMoveSpeed", 1));
if (!Changed) return;
SaveConfig();
Changed = false;
}
private void Init() {
LoadVariables();
LoadDefaultMessages();
permission.RegisterPermission(Title + "." + admAccessPermission, this);
cmd.AddChatCommand(createChatCommand, this, "chatCmdTowerLift");
cmd.AddChatCommand(helpChatCommand, this, "chatCmdLiftReset");
cmd.AddChatCommand(admAccessToggleCmd, this, "chatCmdToggleAdm");
cmd.AddConsoleCommand("upl." + admAccessToggleCmd, this, "cmdToggleAdm");
cmd.AddChatCommand("liftowner", this, "chatCmdLiftOwner");
UpL = this;
hasFullyLoaded = false;
aclVars = new List<ConsoleSystem.Command>();
}
private void Unload() {
SaveData(true);
if (Interface.Oxide.IsShuttingDown) return;
foreach (ConsoleSystem.Command cmd in aclVars.ToList()) ConsoleSystem.Index.Server.Dict.Remove(cmd.FullName?.ToLower());
foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) LiftUI.DestroyAllUi(player);
List<Elevator> objs1 = UnityEngine.Object.FindObjectsOfType<Elevator>().ToList();
foreach (Elevator obj in objs1) {
obj.enabled = false;
UnityEngine.Object.Destroy(obj);
}
/*var objs3 = UnityEngine.Object.FindObjectsOfType<Prevent_Building>().ToList(); foreach (var obj in objs3) GameObject.Destroy(obj);*/
List<CabinComfort> objs4 = UnityEngine.Object.FindObjectsOfType<CabinComfort>().ToList();
foreach (CabinComfort obj in objs4) UnityEngine.Object.Destroy(obj);
}
private void OnPluginLoaded(Plugin name) {
if (!initialized || name.Name == Title) return;
if (name.Name == "Clans" && enableClanShare) clansEnabled = true;
if (name.Name == "Friends" && enableFriendShare) friendsEnabled = true;
if (clansEnabled || friendsEnabled) sharingPlugins = true;
}
private void OnPluginUnloaded(Plugin name) {
if (!initialized || name.Name == Title) return;
if (name.Name == "Clans") clansEnabled = false;
if (name.Name == "Friends") friendsEnabled = false;
if (!clansEnabled && !friendsEnabled) sharingPlugins = false;
}
private void OnServerInitialized() {
CreateAcl();
CreateOverview();
crossReference = new Dictionary<uint, Elevator>();
playerStartups = new Dictionary<ulong, Elevator>();
foreach (string pseudoPerm in admPseudoPerms.ConvertAll(obj => Convert.ToString(obj)).ToList()) if (permission.PermissionExists(pseudoPerm)) pseudoPerms.Add(pseudoPerm.ToLower());
adminLiftEntkill = new Dictionary<string, bool>();
adminAccessEnabled = new Dictionary<string, bool>();
foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) SetPlayer(player);
foreach (BasePlayer player in BasePlayer.sleepingPlayerList.ToList()) SetPlayer(player);
if (TOD_Sky.Instance.Cycle.Hour > TOD_Sky.Instance.SunriseTime + 1.5 && TOD_Sky.Instance.Cycle.Hour < TOD_Sky.Instance.SunsetTime - 1.5) isDayTime = true;
else isDayTime = false;
lastHour = -1d;
if (Clans && enableClanShare) clansEnabled = true;
if (Friends && enableFriendShare) friendsEnabled = true;
initialized = true;
DynamicConfigFile _file = new DynamicConfigFile(Title);
_file.Settings = new JsonSerializerSettings() {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
;
Dictionary<uint, object> fromJson = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<uint, object>>(Title) ?? new Dictionary<uint, object>();
int ct1 = 0;
int ct2 = 0;
foreach (KeyValuePair<uint, object> storedElev in fromJson) {
ct1++;
BaseNetworkable ent = BaseNetworkable.serverEntities.Find(storedElev.Key);
if (ent == null) continue;
Elevator elev = (ent as ProceduralLift).gameObject.AddComponent<Elevator>();
try {
if (elev.Ld2Prt(ent as ProceduralLift, JsonConvert.DeserializeObject<ELStorage>((string) storedElev.Value))) ct2++;
}
catch (Exception ex) {
if (!loadOverrideCorrupted) {
PrintWarning("Loading problem detected at:" + ex.ToString());
PrintWarning("Plugin HALTED to protect the datafile.Contact the Developer");
Interface.Oxide.UnloadPlugin(UpL.Title);
return;
}
PrintWarning($"Failed loading of lift at '{ent.transform.position.ToString()} ");
}
}
Puts($"Loaded \'{ct2} of {ct1}\' Lifts from disk");
hasFullyLoaded = true;
if (!enableEntIdKillProtection) Unsubscribe(nameof(OnServerCommand));
if (!enableSetHomeDeny) Unsubscribe(nameof(OnPlayerCommand));
if (!enableRemoverToolProtection) Unsubscribe(nameof(canRemove));
}
private object OnEntityStabilityCheck(StabilityEntity stabilityEntity) {
if (stabilityEntity.GetComponentInParent<ProceduralLift>()) {
return false;
}
return null;
}
private void SaveData(bool isUnload = false) {
if (!hasFullyLoaded) {
PrintWarning("Lifts not saved to file due to before loading issue!");
return;
}
DynamicConfigFile _file = new DynamicConfigFile(Title);
_file.Settings = new JsonSerializerSettings() {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
;
Dictionary<uint, object> toJson = new Dictionary<uint, object>();
int ct1 = 0;
int ct2 = 0;
foreach (Elevator mapElevator in UnityEngine.Object.FindObjectsOfType<Elevator>().ToList()) {
if (mapElevator.lift == null) continue;
ct1++;
if (mapElevator.IsReady) {
ct2++;
bool success = false;
ELStorage data = mapElevator.Sv2Prt(out success, isUnload);
if (success) toJson.Add(mapElevator.lift.net.ID, JsonConvert.SerializeObject(data));
else PrintWarning("Excluded damaged entry from being saved");
}
}
Interface.Oxide.DataFileSystem.WriteObject(Title, toJson);
Puts($"Saved \'{ct2} of {ct1}\' Lifts to disk");
}
private void OnServerSave() {
SaveData();
}
private static bool HasFriend(string owner, string friend) {
if (enableFriendShare && UpL.Friends) return UpL.Friends.Call("HasFriend", owner, friend) != null && (bool) UpL.Friends.CallHook("HasFriend", owner, friend);
return false;
}
private void OnPlayerConnected(BasePlayer player) {
if (player != null) SetPlayer(player);
}
private void SetPlayer(BasePlayer player) {
if (player.Connection != null && player.net.connection.authLevel >= admAccessAuthLevel || IsPseudoAdmin(player.UserIDString) || permission.UserHasPermission(player.UserIDString, admAccessPermission)) {
adminAccessEnabled[player.UserIDString] = admAccessSwitchable ? admSwitchEnabledAtLogin : true;
adminLiftEntkill[player.UserIDString] = false;
}
}
private static bool SameClanS(string owner, string member) {
if (enableClanShare && UpL.Clans) {
object o = UpL.Clans.Call("GetClanOf", owner);
object m = UpL.Clans.Call("GetClanOf", member);
return o != null && m != null && (string) o == (string) m;
}
return false;
}
private static bool ClanCheck(string owner, string oldTag, out string newTag) {
newTag = default(string);
if (clansEnabled) {
object tag = UpL.Clans.Call("GetClanOf", owner);
if (tag != null) newTag = (string) tag;
if (newTag != oldTag && oldTag != "") return true;
}
return false;
}
private bool CrtPrcdrlLft(BasePlayer player, BaseEntity baseEntity, out ProceduralLift l, out int offset) {
l = default(ProceduralLift);
offset = default(int);
float angle = 360f - Vector3.SignedAngle(player.transform.position - baseEntity.transform.position, baseEntity.transform.forward, Vector3.up) - 180f;
int offsetDown = Mathf.FloorToInt(angle / 45);
bool isEven = offsetDown % 2 == 0;
Vector3 liftPosition = baseEntity.transform.position + new Vector3(0, 3.60f, 0);
ProceduralLift liftEntity = (ProceduralLift) GameManager.server.CreateEntity(StringPool.Get(2518050576), liftPosition, Quaternion.Euler(0, baseEntity.transform.eulerAngles.y, 0), true);
if (liftEntity == null) return false;
liftEntity.transform.localRotation *= Quaternion.Euler(0, (isEven ? offsetDown : offsetDown + 1) * 45, 0);
liftEntity.OwnerID = player.userID;
l = liftEntity;
offset = -1;
if (offsetDown == 7 || offsetDown == 0) offset = 1;
else if (offsetDown == 1 || offsetDown == 2) offset = 2;
else if (offsetDown == 3 || offsetDown == 4) offset = 3;
else if (offsetDown == 5 || offsetDown == 6) offset = 4;
return true;
}
private void chatCmdLiftOwner(BasePlayer player, string command, string[] args) {
bool value = false;
if (!adminAccessEnabled.TryGetValue(player.UserIDString, out value)) return;
if (args == null || args.Length < 1) return;
IPlayer newOwner = covalence.Players.FindPlayer(args[0]);
if (newOwner == null) return;
Ray ray = player.eyes.BodyRay();
RaycastHit raycastHit;
if (!Physics.Raycast(ray, out raycastHit, 10f, 2097153)) return;
BaseEntity baseEntity = raycastHit.GetEntity();
if (!baseEntity) return;
Elevator obj;
if (crossReference.TryGetValue(baseEntity.net.ID, out obj) && obj != null) {
obj.SetOwner(Convert.ToUInt64(newOwner.Id));
player.ChatMessage($"Changed lift ownership to {newOwner.Name}");
return;
}
}
private void chatCmdToggleAdm(BasePlayer player, string command, string[] args) {
bool value = false;
if (!adminAccessEnabled.TryGetValue(player.UserIDString, out value)) {
if (admAccessSwitchable) player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You are not permitted for this command"));
return;
}
bool value2 = adminLiftEntkill[player.UserIDString];
bool value3 = value2;
if (!value && args.Length > 0 && args[0].ToLower() == "kill") return;
if (value && args.Length > 0 && args[0].ToLower() == "kill") {
value3 = adminLiftEntkill[player.UserIDString];
value3 = !value3;
adminLiftEntkill[player.UserIDString] = value3;
if (value3) player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Lift admin entkill enabled"));
else player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Lift admin entkill disabled"));
}
else if (admAccessSwitchable) {
value = !value;
adminAccessEnabled[player.UserIDString] = value;
if (value) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Lift admin access enabled"));
}
else {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Lift admin access disabled"));
adminLiftEntkill[player.UserIDString] = false;
}
}
}
private void cmdToggleAdm(ConsoleSystem.Arg arg) {
if (arg != null && arg.Connection != null && arg.Connection.player != null) chatCmdToggleAdm((BasePlayer) arg.Connection.player, admAccessToggleCmd, arg.Args != null ? arg.Args : new string[] {
}
);
}
private void chatCmdLiftReset(BasePlayer player, string command, string[] args) {
Ray ray = player.eyes.BodyRay();
RaycastHit raycastHit;
if (!Physics.Raycast(ray, out raycastHit, 10f, 2097153)) return;
BaseEntity baseEntity = raycastHit.GetEntity();
if (!baseEntity) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Nothing valid to reset was found"));
return;
}
Elevator obj;
if (crossReference.TryGetValue(baseEntity.net.ID, out obj) && obj != null) {
if (obj.IsOwner(player) || IsAdm(player)) obj.RstMvmnt(player);
return;
}
else {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Nothing valid to reset was found"));
}
}
private Vector3 GtGrndBldng(Vector3 sourcePos) {
sourcePos.y = TerrainMeta.HeightMap.GetHeight(sourcePos);
RaycastHit hitinfo;
if (Physics.Raycast(sourcePos, Vector3.down, out hitinfo, 2097152)) {
sourcePos.y = Math.Max(hitinfo.point.y, sourcePos.y);
return sourcePos;
}
if (Physics.Raycast(sourcePos, Vector3.up, out hitinfo, 2097152)) sourcePos.y = Math.Max(hitinfo.point.y, sourcePos.y);
return sourcePos;
}
private void chatCmdTowerLift(BasePlayer player, string command, string[] args) {
if (!(bool) GetAccess("CanCreate", player.UserIDString, false)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You are not permitted for this command"));
return;
}
Ray ray = player.eyes.BodyRay();
RaycastHit raycastHit;
if (!Physics.Raycast(ray, out raycastHit, 10f, 2097152)) return;
BaseEntity baseEntity = raycastHit.GetEntity();
if (!baseEntity || !(baseEntity is BuildingBlock)) return;
bool canPlaceFloor = (bool) GetAccess("CanPlaceOnFloor", player.UserIDString, false);
if (!canPlaceFloor && baseEntity.ShortPrefabName != "foundation") {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You can place on foundations only"));
return;
}
if (baseEntity.ShortPrefabName == "foundation" || (canPlaceFloor && baseEntity.ShortPrefabName == "floor")) {
if (preventPlacementInCaves) {
RaycastHit hit;
if (Physics.Raycast(baseEntity.transform.position + Vector3.up, Vector3.up, out hit, 100f, 8454144) && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You cannot build under the terrain/caves/cliffs"));
return;
}
}
OBB obb = baseEntity.WorldSpaceBounds();
if (player.IsBuildingBlocked(obb) && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You are building blocked on that position"));
return;
}
if (preventPlacementAboveDeployables) if (Physics.CheckBox(obb.position + Vector3.up * 3, obb.extents, obb.rotation, 256, QueryTriggerInteraction.Ignore) && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You cannot place on deployed objects"));
return;
}
if (baseEntity.OwnerID != player.userID && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You do not own this foundation"));
return;
}
if ((int) (baseEntity as BuildingBlock).grade < 2 && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("The foundation needs to be at least of grade Stone"));
return;
}
int startLevel = 1;
if (canPlaceFloor && baseEntity.ShortPrefabName == "floor") {
Vector3 sourcePos = baseEntity.transform.position;
Vector3 groundPos = GtGrndBldng(sourcePos);
startLevel = Mathf.CeilToInt((sourcePos.y - groundPos.y) / 3f);
}
int maxPlace = (int) GetAccess("MaxPlacementFloor", player.UserIDString, 1, true);
int maxLevel = (int) GetAccess("MaxFloorLevel", player.UserIDString, 1, true);
int maxRange = lastStableFloor + 1 - startLevel;
if (maxPlace != -1 && startLevel > maxPlace || maxLevel != -1 && maxLevel - startLevel < 1 || maxRange < 2) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You cannot place anymore on this level"));
return;
}
List<Collider> list = Pool.GetList<Collider>();
Vis.Colliders<Collider>(baseEntity.transform.TransformPoint(Vector3.zero), 4f, list, 536870912, QueryTriggerInteraction.Collide);
foreach (Collider current in list) if (!(current.transform.root == baseEntity.gameObject.transform.root)) {
BaseEntity baseEntity2 = current.gameObject.ToBaseEntity();
Elevator obj;
if (baseEntity2 && crossReference.TryGetValue(baseEntity2.net.ID, out obj) && obj != null && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("Too close by another installed lift"));
Pool.FreeList<Collider>(ref list);
return;
}
}
Pool.FreeList<Collider>(ref list);
int count = 0;
if (crossReference.Count > 0) count = (int) crossReference.Where(a => a.Value != null && a.Value.GetOwner == player.userID && a.Key == a.Value.liftID).ToList().Count();
int limit = (int) GetAccess("MaxLiftPerUser", player.UserIDString, 1, true);
if (limit > 0 && count >= limit && !IsAdm(player)) {
player.ChatMessage(string.Format(prefixFormat, prefixColor, pluginPrefix) + msg("You reached your placement limit"));
return;
}
int offsetDown;
ProceduralLift procLift;
Elevator elev;
if (CrtPrcdrlLft(player, baseEntity, out procLift, out offsetDown)) {
baseEntity.RefreshEntityLinks();
elev = procLift.gameObject.AddComponent<Elevator>();
playerStartups[player.userID] = elev;
playerStartups[player.userID].controlUI = new LiftUI();
playerStartups[player.userID].controlUI.IntPlcmnt(elev, procLift, player, baseEntity, offsetDown, startLevel, maxRange, maxLevel);
}
else {
UpL.playerStartups.Remove(player.userID);
}
}
}
private void OnTick() {
if (lastHour == Math.Floor(TOD_Sky.Instance.Cycle.Hour)) return;
lastHour = Math.Floor(TOD_Sky.Instance.Cycle.Hour);
if (TOD_Sky.Instance.Cycle.Hour > TOD_Sky.Instance.SunriseTime + 1.5 && TOD_Sky.Instance.Cycle.Hour < TOD_Sky.Instance.SunsetTime - 1.5) isDayTime = true;
else isDayTime = false;
}
private void OnTimeSunrise() {
isDayTime = true;
}
private void OnTimeSunset() {
isDayTime = false;
}
[ConsoleCommand("_ul.commands")]
private void CmdLftCmmnds(ConsoleSystem.Arg arg) {
if (!arg.HasArgs(2)) return;
BasePlayer player = arg.Connection?.player as BasePlayer;
if (player == null) return;
uint elevatorID = arg.GetUInt(0, 0u);
if (elevatorID == 0u) return;
string action = arg.GetString(1, "");
if (action == "") return;
int num = arg.GetInt(2, -1);
if (num == -1) return;
Elevator obj = null;
if (crossReference.TryGetValue(elevatorID, out obj) && obj != null) obj.UIEnterCommands(player, r(action), num);
}
[ConsoleCommand("_ul.placement")]
private void CmdLftPlcmnt(ConsoleSystem.Arg arg) {
if (!arg.HasArgs(2)) return;
BasePlayer player = arg.Connection?.player as BasePlayer;
if (player == null) return;
string action = arg.GetString(0, "");
if (action == "") return;
int num = arg.GetInt(1, -1);
if (num == -1) return;
Elevator obj = null;
if (playerStartups.TryGetValue(player.userID, out obj)) obj.controlUI.UpdtPlcmnt(player, action, num);
}
public class ELStorage {
public float timeToTake = 0f;
public float timeTaken = 0f;
public ulong ownerID = 0uL;
public uint groundBlockID = 0u;
public uint[] doorsID = new uint[1];
public int[] fShares = new int[1];
public int startSock;
public List<int> cQueue = new List<int>();
public List<int> pQueue = new List<int>();
public int _uFloor = 1;
public int _cFloor = 1;
public int _dFloor = 1;
public int _lcFloor = 1;
public int _lFloor = 1;
public float initialHeight;
public int _state;
public int _call;
public int _floor;
public int _last;
public int _tower;
public int _power;
public int _panel;
public int _lightmode;
public int moveSpeed;
public int maxSpeed;
public int fuelConsume;
public bool enableFuel;
public bool enableCost;
public float costMultiplier;
public int floorTime;
public int closeTime;
public int _sharemode;
public ulong skinID;
public string clanTag;
public string oldTag;
public uint cTime;
public List<ulong> _passengers = new List<ulong>();
public ELStorage() {
}
}
public enum CabinState {
Waiting = 0, Idle = 1, Busy = 2, UpKeep = 3
}
public enum MoveDirection {
None = 0, Up = 1, Down = 2
}
public enum LastQueue {
None = 0, Call = 1, Panel = 2, Force = 3
}
public enum TowerState {
Creating = 0, Ready = 1, Loading = 2, Saving = 3, None = 4, Spawned = 5
}
public enum QState {
Single = 1, None = 0, Multiple = 2,
}
public enum PowerState {
Internal = 0, TC = 1, FoC = 2
}
public enum FloorState {
Open = 2, Closed = 3, Busy = 1, None = 0
}
public enum CabinLightMode {
Dynamic = 0, AlwaysOn = 1, Disabled = 2
}
public enum ShareMode {
None = 0, Clan = 1, Friends = 2, Full = 3, Public = 4, Disabled = 5,
}
public enum FloorShare {
Public = -1, Full = 0, Friends = 1, Clan = 2, Excluded = 3, Hidden = 4, HiddenVIP = 5
}
public class Elevator : FacepunchBehaviour {
private Oxide.Core.Libraries.Time time = Interface.Oxide.GetLibrary<Core.Libraries.Time>();
private string msg(string key, string id = null) {
return UpL.lang.GetMessage(key, UpL, id);
}
public LiftUI controlUI;
/*Prevent_Building preventBuild;*/
private CabinComfort cabinComfort;
private BoxCollider boxCollider;
private List<uint> toBeProtected = new List<uint>();
private int moveSpeed = UpL.defaultMoveSpeed;
private int maxSpeed = 1;
private int floorTime = 3;
private int fuelConsume = 3;
private int closeTime = 160;
private bool enableFuel = true;
private bool enableCost = true;
private float costMultiplier = 1.0f;
private bool calledDestroy = false;
private float timeToTake = 0f;
private float timeTaken = 0f;
private ItemContainer storeBox = null;
private ItemContainer[] tunaBoxes;
private ulong skinID = 0uL;
private string knockEffectGuid = "c76bed57f17dc634bb4b7726b69e4a11";
private BuildingManager.Building baseBuilding;
private BuildingPrivlidge buildingPrivilege;
private float initialHeight;
private List<int> cQueue = new List<int>();
private List<int> pQueue = new List<int>();
private int startSock;
private int _uFloor = 1;
private int _cFloor = 1;
private int _dFloor = 1;
private int _lcFloor = 1;
private int _lFloor = 1;
private Vector3 _currentPosition = new Vector3();
public ProceduralLift lift;
public uint liftID;
private BasePlayer ownerPlayer = null;
private BasePlayer lastUser = null;
private string clanTag = string.Empty;
private string oldTag = string.Empty;
private uint cTime;
private ulong ownerID;
private BaseEntity groundBlock = null;
private BaseEntity roofBlock = null;
private Vector3[] stops;
private Door[] doors;
private FloorShare[] floorShares;
private SimpleLight cabinLight;
private SimpleBuildingBlock floorGrill;
private Recycler recyclerBox;
private CodeLock cabinLock;
private Mailbox fuelBox;
private Vector3[] socketPoints = new Vector3[5];
private int[] socketOrder = new int[5];
private BaseEntity[][] baseBlocksFloors;
private bool doorSwitched = false;
private CabinState _state = CabinState.Idle;
private QState _call = QState.None;
private QState _panel = QState.None;
private PowerState
// ... [Code preview truncated due to length. Full source in attached file] ...