1. I have a plugin that is using PLUGIN:OnRunCommand to catch commmands admins are using and log them. I got the plugin working great, but I have a side effect. The plugin goes to grab the player ID, but if a player doesn't issue the command, it spits out this code:
    Code:
    [Oxide] 3:06 PM [Error] Failed to call hook 'OnRunCommand' on plugin 'Admin Anti-Abuse'
    File: adminanticheat.lua Line: 26 attempt to index field 'connection' (a nil value):
    at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0
    at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in <filename unknown>:0
    at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
    at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    [Oxide] 3:06 PM [Error] Failed to call hook 'OnRunCommand' on plugin 'Admin Anti-Abuse'
    File: adminanticheat.lua Line: 26 attempt to index field 'connection' (a nil value):
    at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in <filename unknown>:0
    at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in <filename unknown>:0
    at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
    at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    [Oxide] 3:06 PM [Info] [BetterLoot] BetterLoot: Refreshed 6 containers (0 destroyed)
    Is there a way to stop these errors from occurring? I tried using pcall() to catch errors, but that didn't work. Here is the problem code:
    Code:
    function PLUGIN:OnRunCommand(arg)
    local player = arg.connection.player
    local steamID = rust.UserIDFromPlayer(player)
    local msg = arg:GetString(0, "text")
    local name = player.displayName
    local msgedit = explodeString(msg)
    Thanks.
     
    Last edited by a moderator: Jul 14, 2015
  2. if not arg.connection then return end
     
  3. Thanks, that did it :D