I'm trying to create a custom help plugin for my server and when I uploaded it to my server, I get this message.
Screenshot
Solved Specified cast is not valid
Discussion in 'Rust Development' started by Alpha Toon, Jun 8, 2016.
-
Wulf Community Admin
I'd need to see the full log and code, but that looks like an error specific to that plugin and something it is trying to cast to.
-
I'm using code from another plugin to help with this, but I figure since I'm the only one using it, there shouldn't be an issue.
Code:using Oxide.Game.Rust.Libraries; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using UnityEngine; using System.Linq; using Oxide.Core; using System;namespace Oxide.Plugins { [Info("Help Text", "Alpha Toon", "1.0.0")] class HelpText : RustPlugin { #region Configuration Data private bool configChanged; // Plugin settings private const string DefaultChatPrefix = "Alpha Gaming"; private const string DefaultChatPrefixColor = "#008000ff"; public string ChatPrefix { get; private set; } public string ChatPrefixColor { get; private set; } //Plugin options private const string DefaultHelpText = "Insert text here"; public string HelpText { get; private set; } #endregion private void Init() => LoadConfigValues(); protected override void LoadDefaultConfig() => PrintWarning("New configuration file created.") [ChatCommand("help")] private void Help(BasePlayer player, string command, string[] args) { SendMessage(player, HelpText) } private void LoadConfigValues() { // Plugin settings ChatPrefix = GetConfigValue("Settings", "ChatPrefix", DefaultChatPrefix); ChatPrefixColor = GetConfigValue("Settings", "ChatPrefixColor", DefaultChatPrefixColor); //Plugin options HelpText = GetConfigValue("Messages", "HelpText", DefaultHelpText); if (!configChanged) return; PrintWarning("Configuration file updated."); SaveConfig(); } private T GetConfigValue<T>(string category, string setting, T defaultValue) { var data = Config[category] as Dictionary<string, object>; object value; if (data == null) { data = new Dictionary<string, object>(); Config[category] = data; configChanged = true; } if (data.TryGetValue(setting, out value)) return (T)Convert.ChangeType(value, typeof(T)); value = defaultValue; data[setting] = value; configChanged = true; return (T)Convert.ChangeType(value, typeof(T)); } private void SetConfigValue<T>(string category, string setting, T newValue) { var data = Config[category] as Dictionary<string, object>; object value; if (data != null && data.TryGetValue(setting, out value)) { value = newValue; data[setting] = value; configChanged = true; } SaveConfig(); } private void SendMessage(BasePlayer player, string message, params object[] args) => player?.SendConsoleCommand("chat.add", -1, string.Format($"<color={ChatPrefixColor}>{ChatPrefix}</color>: {message}", args), 1.0); } }
-
Wulf Community Admin
-
-
Wulf Community Admin
-
I'm just going to scrap the idea of having a config file for myself as I guess it's more complicated that it seems to me. I think it'll be easier for me just to add what I want directly into the file. Thanks for the help though.
-
Wulf Community Admin
-
If I'm not mistaken then you're missing multiple semicolons:
protected override void LoadDefaultConfig() => PrintWarning("New configuration file created.")
SendMessage(player, HelpText) -
Wulf Community Admin
-
I have found an alternative to what I originally was using, but the config file is left blank even though I defined what should be put into the file.
-
Wulf Community Admin