add menu button to run command and open console


(NovaPrime) #1

is there a way to open console and run a command from in-game menu? If so, how would I type it in the menu system and make a button?

Example:

BUTTON( 6, 176, WINDOW_WIDTH-12, 18, "STATS", .3, 14, close ingame_main ; exec "!stats" ; exec consoleorwhatever )

thanks in advance!


(ailmanki) #2

use the cmd ‘toggleconsole’


(Indloon) #3

This is how you can run a cg_draw2d command for example -


BUTTON( 6, 176, WINDOW_WIDTH-12, 18, "DISABLE DRAW2D", .3, 14, close ingame_main ; open your_menu_def; exec "cg_draw2d 0" )

Should work with every command.

And for opening console you also need to use command, such as pressing “~”, what actually is a bind of “toggleconsole” command.

So theoretically for opening console, this is what it should look like:


BUTTON( 6, 176, WINDOW_WIDTH-12, 18, "OPEN CONSOLE", .3, 14, close ingame_main; exec "toggleconsole" )

I guess you’re using Silent mod, and want to show stats for others, well I guess it should look like this -


BUTTON( 6, 176, WINDOW_WIDTH-12, 18, "STATS", .3, 14, close ingame_main ; exec "say !stats; toggleconsole"  )

Note/!\ - These code snippets are not tested, yet! :smiley: