Hi there, I'm currently doing some testing to learn how to code plugins.
I have this code:
This gets called a lot more than I was expecting, when people are not chatting etc. How would I filter out anything other than chat and commands?Code:void OnRunCommand(ConsoleSystem.Arg arg) { Puts("OnRunCommand Called"); string message = arg.GetString(0); BasePlayer player = arg.connection.player as BasePlayer; if (message.Length > 0) { if (message.StartsWith("/")) { ConVar.Server.Log("Oxide/Logs/Test.txt", "[COMMAND] [" + player.UserIDString + "] " + player.displayName + ": " + message); } else { ConVar.Server.Log("Oxide/Logs/Test.txt", "[CHAT] [" + player.UserIDString + "] " + player.displayName + ": " + message); } } }
Also I sometimes get this exception:
This could be related as when I filter out everything except chat/commands it may stop appearing.Code:[Oxide] 13:03 [Info] [TrueLogger] OnRunCommand Called [Oxide] 13:03 [Error] Failed to call hook 'OnRunCommand' on plugin 'TrueLogger v0.1.0' (NullReferenceException: Object reference not set to an instance of an object) [Oxide] 13:03 [Debug] at Oxide.Plugins.TrueLogger.OnRunCommand (.Arg arg) [0x00000] in <filename unknown>:0 at Oxide.Plugins.TrueLogger.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0
Also how can I find out the properties of an object such as ItemContainer?
Solved OnRunCommand help
Discussion in 'Rust Development' started by TheOnlyTermin, May 14, 2016.
-
You might want to check out the source code of Spyon for Rust | Oxide
If arg.connection is null and arg.isAdmin is set then a command was run via RCON.
If the command was not run via RCON and arg.connection is null or arg.connection.player is null then you may ignore the command.
You may ignore all commands where arg.cmd is null or arg.cmd.namefull is null.
I'm not exactly sure in which cases OnRunCommand is called and a situation arises where one of the above rules isn't true, but they do arise and I've tested it a lot and the above rules guarantee that all chat commands, user commands and RCON commands pass through.
Also, whenever an RCON command is called, the OnRunCommand hook is called twice, so you'll have to filter the duplicate. -
Thanks I'll give it a test now, do you know how I can find out the properties such as arg.isAdmin etc?
I get weird logs like this:
Code:[CHAT] [76561197965206646] [S4S] INDI: 1152393492
-
This kind of stuff is provided directly by Rust, so we'll have to work with what Rust gives us.
If you implemented the rules I mentioned (as shown in the Spyon source code) then you shouldn't get weird commands anymore. -
Thanks for your help!