Quick RunCommand Question

Hello,

Hi,
You have two solutions to make the player execute a conCommand from buttonClick

  1. Using DoClick from your button
    You first have to find the button that opens the tab
    then you should see the function


buttonName.DoClick = function()
        -- code
        -- add this :
        RunConsoleCommand("awarn_menu")
    end


  1. From here : https://wiki.garrysmod.com/page/DButton/SetConsoleCommand


local buttonName = vgui.Create( "DButton" )
-- ...
buttonName:SetConsoleCommand( "awarn_menu" )


Warning, this function overrides Do.Click function.

Wait, why not just do this:



self.shop = vgui.Create( "DPanel", self.shop )
self:Shop()
function self.shop.OnMousePressed()
    RunConsoleCommand( "awarn_menu", "run_menu_warn_test" )
end
self.sheet:AddSheet( "Shop", self.shop, "icon16/user_orange.png" )


Then you wouldn’t need to make the button a DButton (I think)

Why the hell use pastebin instead of typing it here?

[editline]3rd February 2016[/editline]

I think he is using the DPanel for more stuff than just a simple placeholder.

[editline]3rd February 2016[/editline]

And also, while I’m at it, let me answer your question:
As you can see from the code, the item returned by DPropertySheed:AddSheet is a

DTab, which in turn inherits from

DButton therefore, through the wiki you can see that the DButton has the method

DButton/SetConsoleCommand which would make your code look like this:

[lua]
self.shop = vgui.Create( “DPanel”, self.shop )
self:Shop()
local sheet = self.sheet:AddSheet( “Shop”, self.shop, “icon16/user_orange.png” )
sheet.Tab:SetConsoleCommand( “awarn_menu”, “run_menu_warn_test” )
[/lua]

This does not work unfortantly