1. I'm working on my own plugin, and I'm new to Rust, so this will help me start out. I am having problems with one of my classes. It's a class that holds Authorization Level based functions, and they are all static. When I say a command and run a function in that class, it throws an object reference error, but not sure why. When I run any method inside AuthLevel class, it throws this error. What I don't understand is that I have other static classes with static methods and variables, that I can call and get/set without any errors. It's just this one class. Any help would be appreciated, and thanks.

    Here is the error:

    (03:35:54) | ExType: TypeInitializationException

    (03:35:55) | Failed to call hook 'CallAction' on plugin 'AdminMenu v0.1.0' (NullReferenceException: Object reference not set to an instance of an object)

    (03:35:55) | at (wrapper stelemref) object:stelemref (object,intptr,object)

    at Oxide.Plugins.AdminMenu+AuthLevel..cctor () [0x00000] in <filename unknown>:0

    And here is the code:

    Code:
            static class AuthLevel
            {
                static public int[] auth_levels =
                {
                    0, //No Access
                    1,
                    2,
                    3 //Full Access
                };            public static string[][] allowedCommandsPerAuthLevel =
                {
                    allowedCommandsPerAuthLevel[0] = new string[] { },
                    allowedCommandsPerAuthLevel[1] = new string[] {
                        "viewbans", "ban", "kick", "unban" },
                    allowedCommandsPerAuthLevel[2] = new string[] {
                        "open", "close", "reload", "airdrop", "vectortp", "listplayers", "listadmins", "viewbans", "kick", "kickall", "ban", "unban", "tp", "spawnanimal",
                        "kill", "mute", "give", "say", "godmode", "noclip", "deathloop", "setmoney", "popup", "turrets", "setfire", "rename", "airdrop", "airstrike", "clearinv",
                        "repairinv", "rotate", "listkits", "addkit", "deletekit", "loadkit", "clonekit", "saveplayerkit"
                    },
                    allowedCommandsPerAuthLevel[3] = new string[] {
                        "open", "close", "reload", "airdrop", "vectortp", "listplayers", "listadmins", "viewbans", "kick", "kickall", "ban", "unban", "tp", "spawnanimal", "kill",
                        "mute", "give", "say", "godmode", "noclip", "deathloop", "setmoney", "popup", "turrets", "setfire", "rename", "airdrop", "airstrike", "clearinv", "repairinv",
                        "rotate", "listkits", "addkit", "deletekit", "loadkit", "clonekit", "saveplayerkit", "setpermission", "acceptauthrequest", "freezetime", "settime", "setpassword", "setjoinmsg"
                    }
                };            public static int returnAuthLevelFromID(string ID)
                {
                    return 3;
                }            public static bool commandAllowed(BasePlayer player, string command, string ID)
                {
                    int auth_level = returnAuthLevelFromID(ID);                if (allowedCommandsPerAuthLevel[auth_level].ToList().FindIndex(element => element == command) < 0)
                        return false;                return true;
                }            public static bool test()
                {
                    return true;
                }
            }

    Code:
            [ChatCommand("adminmenu")]
            void CallAction(BasePlayer player, string command, string[] args)
            {
                //if (AuthLevel.returnAuthLevelFromID(player.UserIDString) < 1)
                //return;            /*if (args == null)
                    return;            if (args[0] == null)
                    return;*/            string arg_command = "test";//args[0];            if (!(AuthLevel.test())) //player, arg_command, "" TODO FIX AuthLevel object reference error
                {
                    SendMessage(player, "{0} {1}", "[AdminMenu]: ", "You are not authorized to use this command.");
                    return;
                }            switch(command.ToLower())
                {            }            SendMessage(player, "{0} {1}", "[AdminMenu]: ", "The '" + arg_command + "' command has executed successfully.");
                //SendMessage(player, "AdminMenu v{0}. Type -help for a list of commands.", AdminMenuInfoAttribute.Version);
                //Puts("Player {0} has executed command {1}", player.displayName, command);
            }
     
  2. I would not make the class static and instead just the methods inside of it.
     
  3. Alright thanks, will try it and post results.

    EDIT: Nope still getting same result in console. Even with a non-static class.
    [DOUBLEPOST=1497975902][/DOUBLEPOST]If I have to, I don't mind moving the methods outside of the class, I just like to have neat, organized functions. I tried moving the test method outside of the class, and voila, it worked.
     
    Last edited by a moderator: Jun 20, 2017
  4. Ok so I've narrowed it down to being a problem with how I initialize my allowedCommandsPerAuthLevel array.

    EDIT: Can a mod/admin close this. I have figured out what was causing the error. Thanks again Ryan for your help.
     
    Last edited by a moderator: Jun 20, 2017