menu

The menu namespace contains many functions related to User Interface functionality inside of your script!

Declaration:

namespace menu
{

    // remove an element by it's label
    void remove_element(string label);
    
    // toggle with a name and specified value
    toggle_t@ add_toggle(string label, bool value = false);
    
    // slider with a float value (uses C-style formatting, google "printf" formatting  for more information)
    slider_float_t@ add_slider_float(string label, float min, float max, float value = 0.f, string format_text = "%.1f")
    
    // slider with an integer value (uses C-style formatting, google "printf" formatting for more information)
    slider_int_t@ add_slider_int(string label, int min, int max, int value = 0.f, string format_text = "%d");
    
    // combo (aka. multi-select) with your specified elements
    combo_t@ add_combo(string label, array<string>@ combo_elements, int value = 0);
    
    // multi-combo, you will need to call set_value to set default values (if you wish)
    multi_combo_t@ add_multi_combo(string label, array<string>@ combo_elements);
    
    // specified text positioned automatically in the menu
    label_t@ add_label(string label);
    
    // separator between elements
    divider_t@ add_divider(string label);
    
    // seperator with a label in the middle
    label_divider_t@ add_label_divider(string label);
    
    // button that can be clicked to call your code
    button_t@ add_button(string label);
    
    // colorpicker to allow custom coloring of anything
    colorpicker_t@ add_colorpicker(string label);
    
    // add a keybind which allows you to easily create per-key functions
    keybind_t@ add_keybind(string label, bind_t&in bind);

}

Information:

All of these functions should be called in the beginning of your script, and not a callback! They will add/remove from the "elements" subtab in the "scripting" tab!

Examples:

Creating a button with a function that gets called on click which adds to a value

// create a button and increment a value when it's clicked
auto my_button = menu::add_button("Click me!");
auto my_value = 1; // start with one
auto did_alert = false;

// add 1 to "my_value"
void my_button_callback() { my_value += 1; }

// register the callback with the button
my_button.set_interaction_callback(my_button_callback);

// check if "my_value" is 3 and if so, alert the user
void render()
{

    if (m_value == 3 && !did_alert)
    {
    
        cheat::add_log("my_value is 3!");
        did_alert = true;
    
    }

}

Creating a combo and a multi-combo and checking their values

auto my_combo = menu::add_combo("My combo", { "One", "Two", "Three" });
auto my_multi_combo = menu::add_combo("My multi-combo", { "Option 1", "Option 2" });

// check if "my_combo" has "three" selected
// also check if "my_multi_combo" has all options selected
void render()
{
    
    // counting starts from 0
    if (my_combo.get_value() == 2)
    { /* run your code */ }
    
    // multi-combos take an "idx" parameter in their "get_value" function
    if (my_multi_combo.get_value(0) && my_multi_combo.get_value(1))
    { /* both options are selected, run code */ }

}

Last updated