NullReferenceException at writecfg/ToggleAdminError
[Error] Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <34b1f54ef897408a984fc5263cc0e3f6>:0
at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <85aea7c67fac4e319f4fa8cf1ef7aa15>:0
at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <85aea7c67fac4e319f4fa8cf1ef7aa15>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0
18:01 [Info] Unloaded plugin Admin Toggle v1.0.5 by LaserHydra
18:01 [Info] Loaded plugin Admin Toggle v1.0.5 by LaserHydra
18:01 [Error] Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <34b1f54ef897408a984fc5263cc0e3f6>:0
at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <85aea7c67fac4e319f4fa8cf1ef7aa15>:0
at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <85aea7c67fac4e319f4fa8cf1ef7aa15>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0
In response to Ideal ():
[Error] Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Ob...

Me too.

Same. Bump.
I do not quite understand how it works. Since I imagined this, it does not come out ..))))
Everything is orderly. The idea is good and necessary.
Suppose I'm an admin with a name in the game Perfect_root, green.
I want to be a Player with a name in the game Evgen, blue.
I assign the rights for the plugin to the group admin: o.grant group admin admintoggle.use
I set up the Player's name: / setplayername Evgen
Then I send: / toggleadmin
Nothing happens. In the chat I write as Admin. My name does not change.
I re-enter the server again.
My name remains the same Perfect_root, but I lose the rights of Adm. My name is и.
I'm posting again: / toggleadmin
I'm writing to chat. No changes.
I'm disconnected and connect to the server.
I'm writing to chat. I have the Player's name, blue. It seems all good. But I lost the rights of Adm and the command / toggleadmin
for me inaccessible. I can not regain the face of the Administrator. I ship the ownerid, but I do not have the right to use this command))
Again I send: / toggleadmin
I'm going to the server. I have the Player's name, green - but the Administrator's rights))))
To achieve the correct combination of Player Name - But with Administrator rights, I have to go to the server several times and send a command to the chat several times. Here are a few examples in the screenshot. Absolute impermanence.
And further...
When I'm in the guise of a player named Perfect_root (blue), then in addition to the console error when sending a message to the chat.
Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceE
xception: Object reference not set to an instance of an object)
  at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <c44bcbbacce34b
a9802838be07d2459c>:0
  at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x001b3] in <235
7f6deeeb144b2a7ed33ef63c60250>:0
  at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object
& ret, System.Object[] args) [0x002b4] in <2357f6deeeb144b2a7ed33ef63c60250>:0
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod meth
od, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[]
 args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] arg
s) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0​


1) The server recognizes me in any case as an Administrator. This is translated into the chat. Even if I then write to the chat as a Player, it is already known before that I as an Administrator have visited the server. It becomes very strange when I as a Perfect administrator .. go to the server, the amount on the server does not change, but Evgen writes. :)
2) To me the plugins are referenced by the Administrator ID or simply by the Steam account ID.
3) In the chat I write as a Player. But at the same time I do not have the rights of the Administrator.
4) I am with the name of the Administrator, but I do not have the rights Adm.
5) The server always notifies everyone that the Administrator has logged in, regardless of the name I entered.
6) I am with the player's name, but the Administrator's rights.
We need something to fix it. It turns out complete confusion!

At this point the plugin can not be considered working.

Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)

at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <6eb90eff27a14f75a3dde064677999bf>:0

at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <28c100da51ee4f0184b834b9f09b90e4>:0

at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <28c100da51ee4f0184b834b9f09b90e4>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0

Exact same errors as above.  Wouldn't work correctly either.  However, it did successfully mess up my permissions even after removing it...as I can't use admin commands, and my name won't show up green either still.  Any help you can provide me with to reverse this damage would be great.
23:41 [Error] Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <163a73e6656f475ba4abd6edb1629935>:0

at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <c8953fa2ead24388b7b703d3e3fff06d>:0

at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <c8953fa2ead24388b7b703d3e3fff06d>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0


Merged post

@Ruhadre How did it mess up your permissions ? I'm currently also trying to re-work how this plugin works but I sadly don't have as much understanding and I couldn't fix this mod T^T I tried using it but it didn't mess up my permissions tho.

Merged post

As a Bug report to @LazerHydra,

Everything went fine throughout compiling the plugin, until I used the command /toggleadmin, which then results with the output asking me to setup my name (/setplayername <Name>). I then setup my name and it was all good.

After that, I used the command /toggleadmin. It was then that the above error message popped up in the console, and there was no output afterwards. I was not turned into an admin, but my name has changed to the player name and could not be changed back.

Additional Information

Game Version
Protocol: 2137.172.1
Build Date: 12/11/2018 01:38:24
Unity Version: 2018.1.4f1
Changeset: 30725
Branch: release

Oxide Version

Oxide.Rust Version: 2.0.4095

Plugin Version 1.0.5

 

 

Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
  at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in :0
at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <5545fa1eb9a74971b79ac045d7a999de>:0
at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <5545fa1eb9a74971b79ac045d7a999de>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0

Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)

at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00028] in <6eb90eff27a14f75a3dde064677999bf>:0

at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <28c100da51ee4f0184b834b9f09b90e4>:0

at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <28c100da51ee4f0184b834b9f09b90e4>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0

I get this error trying to use the toggle,
(I need to manually readd myself to the Oxide userlist also)

Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00026] in :0

at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <03700b43aefe41b9b1d7045f038f0063>:0

at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <03700b43aefe41b9b1d7045f038f0063>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0
This is caused by the two lines in the AdminToggle.cs file that are 'ConVar.Server.writecfg(null)'. It looks like the author is trying to save the ServerUsers it just modified in order to add/remove them from the owner list.

I couldn't find any detail on ConVar.Server.writecfg or the ConsoleSystem.Arg command that it's suppose to accept, but I did find code in the UMod source code that does 'ServerUsers.Save()' to save the modified ServerUsers.

If you replace 'ConVar.Server.writecfg(null)' with 'ServerUsers.Save()' it should fix the problem.

The automatic client disconnect isn't working for me now but that's another issue. Also be sure to add 'admintoggle.use' to your individual user in order to use /toggleadmin once you've reconnected.

Merged post

There's also another mod called Convert Status that does the same thing but doesn't require a reconnect.

If you want to continue using Admin Toggle, I'll post what to change to achieve the same thing a little later today.

Merged post

To modify AdminToggle to not require a reconnect, add this before ServerUsers.Save() when enabling admin mode:

player.SetPlayerFlag(BasePlayer.PlayerFlags.IsAdmin, true);
player.Connection.authLevel = 2;

And this when disabling Admin mode:
player.SetPlayerFlag(BasePlayer.PlayerFlags.IsAdmin, false);
player.Connection.authLevel = 0;

You should then remove these two lines near the end of that method:
SendChatMessage(player, "AdminToggle", "You will be kicked in 5 seconds to update your status. Please reconnect!");
timer.Once(5, () => player.SendConsoleCommand("client.disconnect"));

This will disable things like F1 give, and the auth level checks for other mods. I've noticed that some other umod plugins such as Admin Panel don't register the change until a reconnect.

Error

Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object)
  at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00026] in <609bd19bad6a45a5826ebd5a2931cc3f>:0
  at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <d6d720e017ec42cd88649e99dae5095e>:0 /s out
  at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <d6d720e017ec42cd88649e99dae5095e>:0
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0
Failed to call hook 'ToggleAdmin' on plugin 'AdminToggle v1.0.5' (NullReferenceException: Object reference not set to an instance of an object) at ConVar.Server.writecfg (ConsoleSystem+Arg arg) [0x00026] in <396141fde09c4c65a45b8addaf757edb>:0 at Oxide.Plugins.AdminToggle.ToggleAdmin (BasePlayer player) [0x0026b] in <14566f18215644b9a2a843ef4dc18e48>:0 /s out at Oxide.Plugins.AdminToggle.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x002b4] in <14566f18215644b9a2a843ef4dc18e48>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0