I recently got this error on one of my plugins that was working a couple days ago:
I cannot figure out what it wants me to add. Here is my code:Code:File: ExtraCommand.lua Line: 15 Object reference not set to an instance of an object: at ConsoleSystem.Broadcast (System.String strCommand, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Game.Rust.Libraries.Rust.BroadcastChat (System.String name, System.String message, System.String userid) [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
Thanks.Code:-- Global Variables local pluginAbb = "<color=#ffa500ff>[ExtraCMD]</color>"function PLUGIN:Init() self:LoadDefaultConfig() if self.Config.MainSettings.PluginEnabled == "false" then rust.BroadcastChat("Extra Command disabled by configuration!") return else rust.BroadcastChat("Extra Command by Zane Newberry Loaded!") end --THIS IS LINE 15 -- Checking for command permission nodes, if they don't exist, it creates it. if not permission.PermissionExists("helpCmd") then permission.RegisterPermission("helpCmd", self.Plugin) end -- Creating Chat Commands command.AddChatCommand( "help", self.Plugin, "cmdHelp" ) -- Other Utilities needed gHelpTableCount, gPageCount = self:countTable(self.Config.PlayerCommands.HelpCommandList) endfunction PLUGIN:LoadDefaultConfig() -- Creating Configuration Groups self.Config.MainSettings = self.Config.MainSettings or {} self.Config.Messages = self.Config.Messages or {} self.Config.PlayerCommands = self.Config.PlayerCommands or {} -- Creating configurations in the above groups self.Config.MainSettings.MaxLinesForListCommands = self.Config.MainSettings.MaxLinesForListCommands or "5" self.Config.MainSettings.PluginEnabled = self.Config.MainSettings.PluginEnabled or "true" self.Config.Messages.doesntHavePermissionMsg = self.Config.Messages.doesntHavePermissionMsg or "You do not have permission to use this command!" self.Config.PlayerCommands.HelpCommandList = self.Config.PlayerCommands.HelpCommandList or { "cmd1", "cmd2", "cmd3", "cmd4", "When adding commands, don't forget then ,"} self:SaveConfig() end -- ================================================================== Utility Functions ========================================================================= -- This function checks to see if the players has permission function PLUGIN:checkForNode(steamID, perm) if permission.UserHasPermission(steamID, perm) then return true else return false end end -- This function counts how many values are in a table function PLUGIN:countTable(tab) local maxPerPage = self.Config.MainSettings.MaxLinesForListCommands local count = 0 for i,value in pairs(tab) do count = count + 1 end local pageCount = count / maxPerPage if count < 5 then pageCount = 1 end return count, math.ceil(pageCount) end -- ================================================================== Command Functions =========================================================================-- The Help Command Function function PLUGIN:cmdHelp(player, cmd, args) local steamID = rust.UserIDFromPlayer(player) if not self:checkForNode(steamID, "helpCmd") then rust.SendChatMessage(player, pluginAbb, self.Config.Messages.doesntHavePermissionMsg) return end -- Checks to see if there are any commands defined in the table if gHelpTableCount == 0 then rust.SendChatMessage(player, pluginAbb, "There are no server commands defined!") return end local maxPerPage = self.Config.MainSettings.MaxLinesForListCommands local helpTable = self.Config.PlayerCommands.HelpCommandList if args.Length == 0 then rust.SendChatMessage(player, pluginAbb, "Please add a page number! Total Pages: ".. gPageCount ..", /help <PageNumber>") return end if tonumber(args[0]) > gPageCount or tonumber(args[0]) < 1 then rust.SendChatMessage(player, pluginAbb, "That page does not exist! Total Pages: ".. gPageCount) return end local cmdEndPoint = args[0] * maxPerPage local cmdStartPoint = cmdEndPoint - 4 local currentNumber = cmdStartPoint rust.SendChatMessage(player, pluginAbb, "Page ".. args[0] .." out of ".. gPageCount) local count = 1 while count <= 5 do rust.SendChatMessage(player, tostring(currentNumber), helpTable[currentNumber]) currentNumber = currentNumber + 1 count = count + 1 end end
Solved Object reference not set (broadcasting in Init)
Discussion in 'Rust Development' started by Analyze, Jul 30, 2015.
-
Wulf Community Admin
Which line is 15? I can't tell without your full plugin.
-
Code:
rust.BroadcastChat("Extra Command by Zane Newberry Loaded!") end --THIS IS LINE 15
-
I know next to nothing when it comes to this, but am I wrong to assume when the server is starting up and it tries to rust.BroadcastChat before its finished loading that would cause a problem?
-
Wulf Community Admin
You shouldn't be broadcasting anything in Init(), the server isn't finished starting then and no players will be on. Your plugin will work on reload, but not on startup.
-
)
-
Wulf Community Admin
Since your messages appear to be only for debugging and extra info, I'd use print() instead.
-