Lua API
  • 🔎Overview
  • Introduction
    • 🚀Creating scripts
      • 🧠First Steps
      • 🖥️Adding UI
      • 📚Creating Libraries
  • API
    • 🌐Global Functions
    • ⚙️Instances
      • 🔢Math
      • ☎️Events
        • event_t
      • 🎮Game
        • global_vars_t
        • cengine_client
          • cnet_chan
        • ccsgo_input
        • cinput_system
        • cgame_ui_funcs
        • ccvar
          • convar
      • 🕹️Mods
        • events_t
      • ✏️Draw
        • ⚙️Types
          • ⚙️rect
          • ⚙️vec2
          • ⚙️color
          • ⚙️accessor
        • 🖥️Adapter
        • ✏️Layer
          • outline_mode
          • rounding
          • glow_parts
          • text_params
            • text_alignment
          • shadow_dir
          • command
            • render_mode
        • 🖼️Managed
          • 🖼️texture
            • svg_texture
            • animated_texture
          • 🖼️shader
          • ™️font_base
            • font
            • font_gdi
            • glyph_t
            • font_flags
      • 🙋Entities
        • entity_list_t
          • entity_entry_t
        • base_entity
          • schema_accessor_t
          • cs2_weapon_base_gun
          • cs2_player_pawn
          • cs2_player_controller
          • cs2_weapon_base
          • cs2_grenade_projectile
        • ccsweapon_base_vdata
          • cfiring_mode
        • chandle
        • csweapon_mode
        • csweapon_type
        • weapon_id
        • csweapon_category
        • observer_mode_t
      • 🖥️Gui
        • ⚙️Types
          • ⚙️bits
          • ⚙️control_id
        • context
          • user_t
        • context_input
          • mouse_button
        • notification_system
          • notification
        • control
          • control_type
          • value_param
          • checkbox
          • slider
          • label
          • selectable
          • button
          • color_picker
          • spacer
          • text_input
          • combo_box
          • image
        • container
          • control_container
            • layout
            • group
      • ⚙️Utils
    • ⚙️Types
      • ⚙️ptr
      • ⚙️ref_holder_t
      • ⚙️vector
      • ⚙️vector4d
      • 🎮veccolor
      • 🎮color
      • 🎮cview_setup
      • 🎮cuser_cmd
      • 🎮game_event_t
    • 🟰Enums
      • 🟰client_frame_stage
      • 🟰input_bit_mask
Powered by GitBook

© 2025 - FATALITY

On this page
Export as PDF

Last updated 3 months ago

Adding UI

Now that you know the basics, let’s extend our script by allowing the user to toggle the text. We can do this by adding a control to the menu.

Creating a control

Let’s start by creating a simple checkbox:

Each control has a unique ID, which the UI framework uses to distinguish controls within containers. It’s very important that your control’s ID doesn’t conflict with others, as that could result in a broken state or worse.

To create the ID, call and pass the desired ID.

Then, create the checkbox by calling and passing the ID structure you've created.

Constructing the row

By default, controls are typically placed in rows - layouts that stack elements in a specific manner. We provide a simple helper function - .

Adding the row to a group

With the control and row ready, let’s add them to a group.

To view group and control IDs, you can enable Debug mode in the SCRIPTS tab.

In this example, we'll use the lua>elements a group. First, locate that group in the global context:

That's it!

Using the value

Next, let’s modify our previous script so the text only appears if the checkbox is checked. Wrap your drawing code in an if statement before rendering the text:

and close it after.

The final script should look something like this:

And here's the result:

Then call its method to include your row:

It is very important to call method if you add multiple controls, so the layout will stack everything correctly.

local group = gui.ctx:find('lua>elements a');
group:add(row);
if cb:get_value():get() then
local cb = gui.checkbox(gui.control_id('my_checkbox'));
local row = gui.make_control('My checkbox', cb);
local group = gui.ctx:find('lua>elements a');
group:add(row);

local function on_present_queue()
    if cb:get_value():get() then
        local d = draw.surface;
        d.font = draw.fonts['gui_main'];
        d:add_text(draw.vec2(50, 50),
            'Hello drawing! My first script speaking.',
            draw.color.white()
        );
    end
end

events.present_queue:add(on_present_queue);
  1. Introduction
  2. 🚀Creating scripts

🖥️Adding UI

PreviousFirst StepsNextCreating Libraries
  • Adding UI
  • Creating a control
  • Constructing the row
  • Adding the row to a group
  • Using the value
local cb = gui.checkbox(gui.control_id('my_checkbox'));
local row = gui.make_control('My checkbox', cb);
gui.control_id
gui.checkbox
gui.make_control
add
reset()