-
Notifications
You must be signed in to change notification settings - Fork 23
Extending the Admin Menu
The admin menu can be easily extended to add plugin commands or even a new tab.
The admin menu is stored under
Shine.AdminMenu
Note that like the vote menu, this is all client side only.
Also note, that when I say GUI objects, I mean SGUI objects. Do not attempt to use the game's basic GUIObjects, that is not what this system uses. See here for the basics of this system.
This will add a command to the admin menu's commands tab.
Plugin:AddAdminMenuCommand( string Category, string Name, string Command, boolean MultiplePlayers[, DoClick, string Tooltip ])
The category should be the same for all your plugin's commands, ideally, the name of the plugin in a nice format. The second argument is the text that will be displayed on the button. The third argument is the console command to run, e.g. "sh_commandhere".
The MultiplePlayers boolean determines if the command expects a single player, or can accept multiple players. If set to false, the menu will warn the player when they try to run the command on more than one player.
DoClick is optional. If not specified, the button will simply run the given command on the selected player(s) with no extra arguments. Alternatively, you can pass in a table of Name -> Argument pairs to add a sub-menu to the button. This will give the player these options when they click your button. You can also pass in a function, which takes the button being pressed and the rows selected as its arguments which will be called on click instead.
Tooltip is also optional. If specified, the button will use the given text as a tooltip.
Example:
This is how the fun commands plugin loads its commands.
function Plugin:SetupAdminMenuCommands()
local Category = "Fun Commands"
self:AddAdminMenuCommand( Category, "Go To", "sh_goto", false, nil,
"Teleports you to the selected player." )
self:AddAdminMenuCommand( Category, "Bring", "sh_bring", false, nil,
"Brings the selected player to you." )
self:AddAdminMenuCommand( Category, "Slay", "sh_slay", false, nil,
"Kills the selected player." )
self:AddAdminMenuCommand( Category, "Darwin Mode", "sh_darwin", true, {
"Enable", "true",
"Disable", "false"
}, "Toggles invulnerability and infinite\nammo on the selected player(s)." )
end
This will add a new tab to the admin menu. This tab will only exist if the plugin is active. If the plugin is disabled, this tab will be removed.
Plugin:AddAdminMenuTab( string Name, table Data )
The name is the text that will appear on the tab's button. The Data table must contain an OnInit
function value, and may also contain an OnCleanup
function.
When the tab is selected, the OnInit
function will be run. It will be passed the panel to populate, and, if you saved any data in your OnCleanup
function, the data you last saved.
The OnCleanup
function is run when the tab is being switched away. This function should be responsible for saving anything about the GUI elements you want to restore when the tab is switched back to. It should also remove any timers/hooks you may have set up for your tab.
IMPORTANT NOTE: GUI elements are destroyed immediately after OnCleanup
is executed. You should not attempt to use the destroyed objects after this function has been run.
Example:
function Plugin:SetupAdminMenuCommands()
self:AddAdminMenuTab( "Awesome Tab", {
OnInit = function( Panel, Data )
--Create your GUI objects here, and make sure they're parented to Panel.
if Data and Data.ImportantInformation then
--Do something here.
end
end,
OnCleanup = function( Panel )
--You can save data about your objects by returning a table here.
return { ImportantInformation = true }
end
} )
end
A simple helper function for running console commands.
AdminMenu:RunCommand( string Command, string Args )
Runs the given command, and passes Args as the arguments.
If you are creating popup windows or other UI elements over your tab, then you should use this to make sure they are removed if the player closes the admin menu.
AdminMenu:DestroyOnClose( Object )
If you have since removed the element you told the admin menu to destroy on close, you should run this to stop the admin menu trying to destroy it again.
AdminMenu:DontDestroyOnClose( Object )