### Lua Shader Constructor and Gaussian Blur Example Source: https://ctcake.gitbook.io/ctcake-docs/shader-or-lua-api Demonstrates how to create a shader object in Lua using the `draw.shader` constructor, passing HLSL source code as a string. The example includes a complete HLSL implementation for a Gaussian blur effect on a texture. ```lua local blur = draw.shader([[ // define constant buffer. cbuffer cb : register(b0) { float4x4 mvp; float2 tex; float time; float alpha; }; // define input. struct PS_INPUT { float4 pos : SV_POSITION; float4 col : COLOR0; float2 uv : TEXCOORD0; }; // use texture sampler and texture. sampler sampler0; Texture2D texture0; float4 main(PS_INPUT inp) : SV_Target { float radius = 2.0; // blur radius float2 inv_size = 1.0 / tex.xy; // inversed size of the texture float weight = 0.0; // total weight float4 color = 0.0; // total color // perform a gaussian blur for (float x = -radius; x <= radius; x += 1.0) { for (float y = -radius; y <= radius; y += 1.0) { float2 coord = inp.uv + float2(x, y) * inv_size; color += texture0.Sample(sampler0, coord) * exp(-((x * x + y * y) / (2.0 * radius * radius))); weight += exp(-((x * x + y * y) / (2.0 * radius * radius))); } } // average the color color /= weight; color.a *= inp.col.a; // apply alpha modulation return color; } ]]); ``` -------------------------------- ### events.render_start_post Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time game starts scene rendering process. This event is called after the game's function runs. ```APIDOC ## events.render_start_post ### Description Invoked every time game starts scene rendering process. This event is called after the game's function runs. ### Method EVENT ### Endpoint events.render_start_post ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **setup** (cview_setup) - View setup information. #### Response Example None ``` -------------------------------- ### events.render_start_pre Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time game starts the scene rendering process. This event is called before the game's function runs. ```APIDOC ## events.render_start_pre ### Description Invoked every time game starts the scene rendering process. This event is called before the game's function runs. ### Method EVENT ### Endpoint events.render_start_pre ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get Brightness Value Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the brightness value of a color. This method is part of the Color API. ```APIDOC ## v /color/{id}/v ### Description Returns brightness value of the color. ### Method GET ### Endpoint /color/{id}/v ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the color to retrieve. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **brightness** (float) - Brightness (0 to 1). #### Response Example { "brightness": 0.9 } ``` -------------------------------- ### schema_accessor_t get Method Source: https://ctcake.gitbook.io/ctcake-docs/schema_accessor_t-or-lua-api Retrieves the value referenced by the schema_accessor_t. ```APIDOC ## GET /websites/ctcake_gitbook_io ### Description Retrieves the value referenced by the schema_accessor_t. ### Method GET ### Endpoint `/websites/ctcake_gitbook_io` ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **value** (``) - The referenced value. #### Response Example ```json { "value": "example_value" } ``` ``` -------------------------------- ### events.override_view Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time the game internally overrides view information. You are free to change whatever you like in the provided view setup. ```APIDOC ## events.override_view ### Description Invoked every time the game internally overrides view information. You are free to change whatever you like in the provided view setup. ### Method EVENT ### Endpoint events.override_view ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **setup** (cview_setup) - View setup information. #### Response Example None ``` -------------------------------- ### Get Screen Size Lua API Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api/cengine_client-or-lua-api Returns the dimensions of the client's window screen. This method takes no arguments and returns two integers: width and height. ```lua local w, h = game.engine:get_screen_size(); ``` -------------------------------- ### Get Observer Target (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/cs2_player_controller-or-lua-api Returns the pawn that the controller is currently spectating or observing. This method takes no arguments and returns a base_entity object. ```lua local obs = ctrl:get_observer_target(); ``` -------------------------------- ### Get Resource Directory using ws.get_resource_dir (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/ws-or-lua-api Retrieves the resource directory for the current script, recommended for Workshop scripts. It takes no arguments and returns a string representing the resource directory path. ```lua local resource_dir = ws.get_resource_dir(); local tex = draw.texture(resource_dir . '/my_texture.png'); ``` -------------------------------- ### Create a Managed Object in GPU Memory (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/managed-or-lua-api The `create` method is used to initialize a managed object in the GPU's memory. This method should only be called once per object. It takes no arguments and returns nothing. Example usage involves calling `create` on an object like a texture or font. ```lua tex:create(); ``` -------------------------------- ### Get Observer Pawn (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/cs2_player_controller-or-lua-api Returns the entity that functions as the observer pawn for this controller. This is relevant in spectator modes. It takes no arguments and returns a base_entity object. ```lua local obs_pawn = ctrl:get_observer_pawn(); ``` -------------------------------- ### Add Line (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/draw-or-lua-api/layer-or-lua-api Adds a straight line to the layer. This function requires the start and end points of the line, and the line color. Optional parameters include line thickness. It returns nothing. ```lua layer:add_line( draw.vec2(50, 50), draw.vec2(150, 150), draw.color(255, 0, 0) ); ``` -------------------------------- ### Get Shared Texture using Lua Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/draw-or-lua-api/adapter-or-lua-api Retrieves a shared texture, which typically mirrors the downsampled back buffer but is updated once before rendering starts. This provides a consistent texture for multiple rendering stages. It takes no arguments and returns a pointer to the shared texture. ```lua local shared = adapter:get_shared_texture(); ``` -------------------------------- ### events.setup_view_post Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time the game sets up the view information. This event is called after the game's function runs. You can retrieve the view information from the `game.view_render` service. ```APIDOC ## events.setup_view_post ### Description Invoked every time the game sets up the view information. This event is called after the game's function runs. You can retrieve the view information from the `game.view_render` service. ### Method EVENT ### Endpoint events.setup_view_post ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### events.setup_view_pre Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time the game sets up the view. This event is called before the game's function runs. ```APIDOC ## events.setup_view_pre ### Description Invoked every time the game sets up the view. This event is called before the game's function runs. ### Method EVENT ### Endpoint events.setup_view_pre ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Add Multicolor Line using Lua Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/draw-or-lua-api/layer-or-lua-api Adds a multicolor line to the drawing layer. Requires start and end points, start and end colors, and line thickness. The thickness defaults to 1.0. ```lua layer:add_line_multicolor( draw.vec2(50, 50), draw.vec2(150, 150), draw.color(255, 0, 0), draw.color(0, 0, 255), 2.0 ); ``` -------------------------------- ### Lua: Basic 'Hello World' Script Source: https://ctcake.gitbook.io/ctcake-docs/first-steps-or-lua-api This script demonstrates a basic 'Hello World' functionality using the Lua API. It sets up a callback function to draw text on the screen when the 'present_queue' event is triggered. It relies on the 'draw' and 'events' modules. ```lua local function on_present_queue() 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 events.present_queue:add(on_present_queue); ``` -------------------------------- ### Get or Set Rectangle Height (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api This method allows you to get the current height of a rectangle or set a new height. Setting the height returns a new rectangle object with the updated dimensions. ```lua local current_height = rect:height(); local new_rect_height = rect:height(50.0); ``` -------------------------------- ### Get Cursor Movement Delta (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api/context_input-or-lua-api Calculates and returns the difference between the current and previous cursor positions. This method helps in determining the magnitude and direction of cursor movement, returning a vec2 object. ```Lua local delta = gui.input:cursor_delta(); ``` -------------------------------- ### Get Value using schema_accessor_t in Lua Source: https://ctcake.gitbook.io/ctcake-docs/schema_accessor_t-or-lua-api Demonstrates how to retrieve the value of a field using the 'get()' method of the schema_accessor_t type. This is typically used to access entity properties within an event's scope. ```lua local health = player.m_iHealth:get(); ``` -------------------------------- ### Access Global Variables Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api/global_vars_t-or-lua-api This section details how to access various global variables that provide information about the game's state, performance, and environment. ```APIDOC ## Global Variables API ### Description This API allows read-only access to global variables that provide information about the game's state, performance, and environment. These variables are crucial for understanding game timing, client connections, and map details. ### Method GET ### Endpoint `game.global_vars.{field}` ### Parameters #### Path Parameters - **field** (string) - Required - The name of the global variable to access (e.g., `real_time`, `frame_count`, `map_name`). ### Request Example ```lua -- Example of accessing the real_time variable local currentTime = game.global_vars.real_time print("Current time since game start: " .. currentTime .. " seconds") -- Example of accessing the map_name variable local currentMap = game.global_vars.map_name print("Currently loaded map: " .. currentMap) ``` ### Response #### Success Response (200) - **value** (any) - The value of the requested global variable. The type depends on the variable (e.g., `float`, `int`, `string`). #### Response Example ```json { "value": 123.456 // Example for real_time (float) } ``` ```json { "value": "NukeTown" // Example for map_name (string) } ``` ### Available Global Variables: #### `real_time` - **Type**: `float` - **Description**: Time passed since the game start, in seconds. #### `frame_count` - **Type**: `int` - **Description**: Amount of frames rendered since the game start. #### `abs_frame_time` - **Type**: `float` - **Description**: Absolute (averaged) frame time, calculated over a set of previous frame times. #### `max_clients` - **Type**: `int` - **Description**: Maximum amount of clients on the current server. #### `ticks_this_frame` - **Type**: `int` - **Description**: Amount of ticks passed during the currently rendered frame. #### `frame_time` - **Type**: `float` - **Description**: Time, in which a previous frame was rendered. #### `cur_time` - **Type**: `float` - **Description**: Time passed since the server's game start. #### `tick_fraction` - **Type**: `float` - **Description**: Current tick's fractional value. #### `tick_count` - **Type**: `int` - **Description**: Ticks passed since the server's game start. #### `map_path` - **Type**: `string` - **Description**: Relative path to the current loaded map's file. #### `map_name` - **Type**: `string` - **Description**: Name of the currently loaded map. ``` -------------------------------- ### Rect Height Method API Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Get or set the height of a rectangle. ```APIDOC ## Rect Height Method ### Description This method allows you to either retrieve the current height of the rectangle or set a new height, adjusting the rectangle's dimensions accordingly. ### Method `rect:height(value?)` ### Arguments - **Get height**: None. - **Set height**: `value` (float) - The new height for the rectangle. ### Returns - **Get height**: `float` - The current height of the rectangle. - **Set height**: `rect` - A new rectangle object with the updated height. ### Request Example ```lua -- Get height local current_height = rect:height(); -- Set height local half_height = rect:height(rect:height() * 0.5); ``` ``` -------------------------------- ### events.handle_input Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time the game processes mouse/controller input. This is a good place to alter mouse movement, if needed. ```APIDOC ## events.handle_input ### Description Invoked every time the game processes mouse/controller input. This is a good place to alter mouse movement, if needed. ### Method EVENT ### Endpoint events.handle_input ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **type** (input_type_t) - Type of the input. - **value** (ref_holder_t) - Input value. #### Response Example None ``` -------------------------------- ### Rect Width Method API Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Get or set the width of a rectangle. ```APIDOC ## Rect Width Method ### Description This method allows you to either retrieve the current width of the rectangle or set a new width, adjusting the rectangle's dimensions accordingly. ### Method `rect:width(value?)` ### Arguments - **Get width**: None. - **Set width**: `value` (float) - The new width for the rectangle. ### Returns - **Get width**: `float` - The current width of the rectangle. - **Set width**: `rect` - A new rectangle object with the updated width. ### Request Example ```lua -- Get width local current_width = rect:width(); -- Set width local half_width = rect:width(rect:width() * 0.5); ``` ``` -------------------------------- ### Rect Size Method API Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Get or set the size (width and height) of a rectangle. ```APIDOC ## Rect Size Method ### Description This method allows you to either retrieve the current size (as a `vec2`) of the rectangle or set a new size, adjusting both width and height simultaneously. ### Method `rect:size(value?)` ### Arguments - **Get size**: None. - **Set size**: `value` (vec2) - The new size vector (x for width, y for height) for the rectangle. ### Returns - **Get size**: `vec2` - The current size of the rectangle. - **Set size**: `rect` - A new rectangle object with the updated size. ### Request Example ```lua -- Get size local current_size = rect:size(); -- Set size local half_size = rect:size(rect:size() * draw.vec2(0.5, 0.5)); ``` ``` -------------------------------- ### Client Frame Stages Source: https://ctcake.gitbook.io/ctcake-docs/client_frame_stage-or-lua-api This section details the available frame stage constants used within the client's frame rendering pipeline. ```APIDOC ## Client Frame Stages API ### Description This API provides constants representing different stages of the client-side frame rendering process. These are typically used for debugging or event handling within the game engine. ### Method N/A (Constants) ### Endpoint N/A (Constants) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) This API does not have requestable endpoints. It defines constants available for use in code. #### Response Example N/A ## Frame Stage Constants ### undefined `Field` This describes a stage that is not defined. You should realistically never receive this type. ### start `Field` Frame build process is starting. ### render_start `Field` Frame render process is starting. ### net_update_start `Field` Network update process is starting. ### net_update_preprocess `Field` Network update is about to be processed by the engine. ### net_pre_entity_packet `Field` Incoming entity packets are about to be processed by the game. ### net_update_postdataupdate_start `Field` Entity information is about to be updated. ### net_update_postdataupdate_end `Field` Entity information is about to finish updating. ### net_update_end `Field` Network update process is ending. ### net_creation `Field` New entities are about to be created. ### render_end `Field` Frame rendering process is ending. ``` -------------------------------- ### Construct Combo Box Instance (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/combo_box-or-lua-api Demonstrates how to construct a new combo_box instance using its ID. This is the primary way to create a combo box in the Lua API. ```lua local cb = gui.combo_box(gui.control_id('my_id')); ``` -------------------------------- ### Get Saturation Value Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the saturation value of a color. This method is part of the Color API. ```APIDOC ## s /color/{id}/s ### Description Returns saturation value of the color. ### Method GET ### Endpoint /color/{id}/s ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the color to retrieve. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **saturation** (float) - Saturation (0 to 1). #### Response Example { "saturation": 0.75 } ``` -------------------------------- ### GUI Input Event Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api This endpoint is invoked every time the GUI processes input. It provides details about the system message, WPARAM, and LPARAM. ```APIDOC ## Input Event Handler ### Description Invoked every time the GUI processes input. This handler receives system message details. ### Method EVENT ### Endpoint /input ### Parameters #### Arguments - **msg** (int) - Description: System message. [See documentation](https://learn.microsoft.com/en-us/windows/win32/winmsg/about-messages-and-message-queues#system-defined-messages) - **w** (int) - Description: WPARAM. - **l** (int) - Description: LPARAM. ### Request Example ```json { "msg": 123, "w": 456, "l": 789 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the input processing. #### Response Example ```json { "status": "processed" } ``` ``` -------------------------------- ### Get Previous Cursor Position (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api/context_input-or-lua-api Retrieves the cursor's position from the previous input event. This is useful for calculating movement deltas and is part of the GUI input context, returning a vec2 object. ```Lua local prev = gui.input:cursor_prev(); ``` -------------------------------- ### Get Hue Value Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the hue value of a color. This method is part of the Color API. ```APIDOC ## h /color/{id}/h ### Description Return hue value of the color. ### Method GET ### Endpoint /color/{id}/h ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the color to retrieve. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **hue** (int) - Hue (0 to 359). #### Response Example { "hue": 180 } ``` -------------------------------- ### Text Input Constructor Source: https://ctcake.gitbook.io/ctcake-docs/text_input-or-lua-api Constructs a new text input instance with a specified ID. ```APIDOC ## Constructor (text_input) ### Description Constructs a new text input instance. ### Method `gui.text_input(id)` ### Parameters #### Path Parameters * **id** (control_id) - Required - The ID for the text input control. ### Request Example ```lua local sp = gui.text_input(gui.control_id('my_id')); ``` ### Response #### Success Response (Instance) * **text_input** (text_input) - The newly created text input instance. #### Response Example ```lua -- local sp variable holds the text_input instance ``` ``` -------------------------------- ### events.present_queue Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked each time the game queues a frame for rendering. This is the only permitted location for drawing on screen. ```APIDOC ## events.present_queue ### Description Invoked each time the game queues a frame for rendering. This is the only permitted location for drawing on screen. ### Method EVENT ### Endpoint events.present_queue ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Command API Methods Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/draw-or-lua-api/layer-or-lua-api/command-or-lua-api This section details the methods available on a command object for safe manipulation of rendering parameters. ```APIDOC ## Command API Methods ### Description This section details the methods available on a command object for safe manipulation of rendering parameters. ### `set_texture` Method #### Description Sets a texture in a safe manner. #### Method `set_texture` #### Arguments - **tex** (texture) - The texture object to set. #### Returns Nothing. #### Example ```lua cmd:set_texture(my_tex) ``` ### `set_shader` Method #### Description Sets a fragment shader in a safe manner. #### Method `set_shader` #### Arguments - **sh** (shader) - The shader object to set. #### Returns Nothing. #### Example ```lua cmd:set_shader(my_shader) ``` ``` -------------------------------- ### Create vec2 Instances (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/vec2-or-lua-api Demonstrates how to create new vec2 instances in Lua. This includes creating a default vector (0,0), a vector with a single value for both X and Y coordinates, and a vector with distinct X and Y coordinates. ```lua local vec = draw.vec2(); ``` ```lua local vec = draw.vec2(5); ``` ```lua local vec = draw.vec2(5, 10); ``` -------------------------------- ### Get Blue Color Component Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the blue component of a color. This method is part of the Color API. ```APIDOC ## get_b /color/{id}/b ### Description Returns blue color value. ### Method GET ### Endpoint /color/{id}/b ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the color to retrieve. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **color_value** (int) - The blue color value. #### Response Example { "color_value": 150 } ``` -------------------------------- ### Get Alpha Color Component Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the alpha (opacity) component of a color. This method is part of the Color API. ```APIDOC ## get_a /color/{id}/a ### Description Returns opacity color value. ### Method GET ### Endpoint /color/{id}/a ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the color to retrieve. #### Query Parameters None. #### Request Body None. ### Request Example None. ### Response #### Success Response (200) - **color_value** (int) - The alpha color value. #### Response Example { "color_value": 255 } ``` -------------------------------- ### Game API Reference Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api This section details the available fields within the game API, each providing access to a specific game service or global variable. ```APIDOC ## Game API Fields ### Description This API provides access to various internal game services and global variables. ### Method N/A (Accessing fields of a global object) ### Endpoint N/A ### Parameters None ### Request Example ```lua -- Accessing the global_vars service local vars = game.global_vars -- Accessing the engine service local engine = game.engine -- Accessing the input service local input = game.input -- Accessing the input_system service local input_system = game.input_system -- Accessing the game_ui_funcs service local ui_funcs = game.game_ui_funcs ``` ### Response #### Success Response (N/A) - **global_vars** (global_vars_t) - Service exposing global variables like frame time or server time. - **engine** (cengine_client) - Service exposing engine-related functions. - **input** (ccsgo_input) - Service exposing the command input system. - **input_system** (cinput_system) - Service exposing the control input system. - **game_ui_funcs** (cgame_ui_funcs) - Service exposing the game's UI functions. #### Response Example N/A (Direct field access) ``` -------------------------------- ### Lua: Access Drawing Surface Source: https://ctcake.gitbook.io/ctcake-docs/first-steps-or-lua-api This Lua code demonstrates how to access the drawing surface provided by the API. It assigns the surface object to a local variable 'd' for easier access in subsequent drawing operations. This is a prerequisite for rendering anything on the screen. ```lua local d = draw.surface; ``` -------------------------------- ### Get Weapon Type | Lua Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/entities-or-lua-api/base_entity-or-lua-api/cs2_weapon_base_gun-or-lua-api Returns the classification or type of the weapon. This function does not take any arguments and returns a cSWeapon_type. ```lua local type = wep:get_type(); ``` -------------------------------- ### Label Constructor Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api/control/label-or-lua-api Constructs a new label control with specified ID, text, color, and font style. ```APIDOC ## Constructor: __call ### Description Constructs the label. ### Method __call ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local lab = gui.label(id, 'Hello!'); ``` ### Response #### Success Response (200) - **label** (label) - Label object. #### Response Example ```json { "example": "label object" } ``` ``` -------------------------------- ### Get Weapon ID | Lua Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/entities-or-lua-api/base_entity-or-lua-api/cs2_weapon_base_gun-or-lua-api Retrieves a unique identifier for the weapon. This method takes no arguments and returns a weapon_id type. ```lua local wep_id = wep:get_id(); ``` -------------------------------- ### Workshop Utilities API Source: https://ctcake.gitbook.io/ctcake-docs/ws-or-lua-api This section provides documentation for various functions within the Workshop utilities API. ```APIDOC ## get_item_id ### Description Returns the current Item ID. Local scripts always return 0. ### Method `ws.get_item_id()` ### Parameters None ### Returns - **number**: The Item ID. ### Request Example ```lua local item_id = ws.get_item_id(); ``` ``` ```APIDOC ## get_build_id ### Description Returns the current Build ID. Local scripts always return 0. ### Method `ws.get_build_id()` ### Parameters None ### Returns - **number**: The Build ID. ### Request Example ```lua local build_id = ws.get_build_id(); ``` ``` ```APIDOC ## get_title ### Description Returns the current script title. ### Method `ws.get_title()` ### Parameters None ### Returns - **string**: The script title. ### Request Example ```lua local title = ws.get_title(); ``` ``` ```APIDOC ## test_capability ### Description Returns whether the current script has a specific capability enabled. ### Method `ws.test_capability(cpb)` ### Parameters #### Query Parameters - **cpb** (string) - Required - Capability ID (e.g., `ffi`, `clipboard`, `fs`). ### Returns - **bool**: True if the script has the provided capability. ### Request Example ```lua if ws.test_capability('clipboard') then utils.clipboard_set('Hello!'); end ``` ``` ```APIDOC ## get_resource_dir ### Description Returns the resource directory for the current script. Recommended for Workshop scripts where resources are unpacked. ### Method `ws.get_resource_dir()` ### Parameters None ### Returns - **string**: The resource directory path (e.g., `fatality/resource/12345`). ### Request Example ```lua local resource_dir = ws.get_resource_dir(); local tex = draw.texture(resource_dir .. '/my_texture.png'); ``` ``` -------------------------------- ### Text Input Methods Source: https://ctcake.gitbook.io/ctcake-docs/text_input-or-lua-api Details the methods available for manipulating a text input instance. ```APIDOC ## Methods ### set_value #### Description Sets the new text value for the input field. #### Arguments * **str** (string) - Required - The new string value to set for the input. #### Returns * Nothing. #### Request Example ```lua input:set_value('Hello!'); ``` ``` -------------------------------- ### Get Center Point (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Calculates and returns the center point of a rectangle. This method requires no arguments and outputs a 'vec2' object. ```lua local center = rect:center(); ``` -------------------------------- ### Selectable Constructor Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api/control/selectable-or-lua-api Constructs a new selectable control with a given ID and text string. ```APIDOC ## __call Selectable Constructor ### Description Constructs a new selectable control with a given ID and text string. ### Method __call (constructor) ### Endpoint N/A (Lua API constructor) ### Parameters #### Arguments - **id** (`control_id`) - Required - Control ID. - **str** (`string`) - Required - Text string to display. ### Request Example ```lua local sel = gui.selectable(id, 'Hello!'); ``` ### Response #### Success Response - **selectable** (`selectable`) - The newly constructed selectable object. #### Response Example ```json // No direct JSON response, returns a Lua object ``` ``` -------------------------------- ### add_line_multicolor Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/draw-or-lua-api/layer-or-lua-api Adds a multicolor line to the layer. This function allows for gradient lines by specifying start and end points along with their respective colors. ```APIDOC ## POST /layer/add_line_multicolor ### Description Adds a multicolor line with specified start and end points, colors, and thickness. ### Method POST ### Endpoint /layer/add_line_multicolor ### Parameters #### Request Body - **a** (vec2) - Required - Start point of the line. - **b** (vec2) - Required - End point of the line. - **c** (color) - Required - Start color of the line. - **c2** (color) - Required - End color of the line. - **thickness** (float) - Optional - Thickness of the line. Defaults to 1.0. ### Request Example ```json { "a": [50, 50], "b": [150, 150], "c": [255, 0, 0], "c2": [0, 0, 255], "thickness": 2.0 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Create GUI Control with Label (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api The `make_control` function wraps a given control with a label, creating a layout that can be added to groupboxes for display. It accepts the label text and the control object as arguments and returns a layout object. Additional controls can be appended to stack on the left. ```lua local row = gui.make_control('Hello checkbox!', my_cb); ``` -------------------------------- ### Get Player Pawn (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/cs2_player_controller-or-lua-api Returns the pawn instance currently controlled by this controller. This method takes no arguments and returns a cs2_player_pawn object. ```lua local pawn = ctrl:get_pawn(); ``` -------------------------------- ### Font Constructor (__call) Source: https://ctcake.gitbook.io/ctcake-docs/font-or-lua-api Constructs a font object using various methods: from a file, from memory, or from memory with codepoint pairs. ```APIDOC ## __call Font Constructor ### Description Constructs a font object. ### Method __call (constructor) ### Endpoint N/A (Lua API) ### Parameters #### From file * **path** (string) - Required - Path to a ttf/otf file. * **size** (float) - Required - Font height, in pixels. * **fl** (font_flags) - Optional - Font flags. Use `bit` library to construct them. Defaults to `0`. * **mi** (int) - Optional - Starting codepoint. Defaults to `0`. * **ma** (int) - Optional - Ending codepoint. Defaults to `255` (entire ASCII code page). #### From memory * **mem** (ptr) - Required - Pointer to a font file in memory. * **sz** (int) - Required - Font file size, in bytes. * **size** (float) - Required - Font height, in pixels. * **fl** (font_flags) - Optional - Font flags. Use `bit` library to construct them. Defaults to `0`. * **mi** (int) - Optional - Starting codepoint. Defaults to `0`. * **ma** (int) - Optional - Ending codepoint. Defaults to `255` (entire ASCII code page). #### From memory, with codepoint pairs * **mem** (ptr) - Required - Pointer to a font file in memory. * **sz** (int) - Required - Font file size, in bytes. * **size** (float) - Required - Font height, in pixels. * **fl** (font_flags) - Optional - Font flags. Use `bit` library to construct them. Defaults to `0`. * **pairs** (table[{int, int}...]) - Required - Min/max pairs. This is a standard array, consisting of {int, int} pairs. ### Request Example ```lua -- Example for creating font from file local cool_font = draw.font('myfont.ttf', 16); ``` ### Response #### Success Response (font) * **font object** (font) - The newly constructed font object. #### Response Example ```lua -- font object returned by the constructor -- Example: local myFont = draw.font('arial.ttf', 24) ``` ### Error Handling Passing an invalid pointer, an invalid path, or a memory region that is smaller than the declared size will result in a crash. ``` -------------------------------- ### Get Ceiled Rectangle (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Returns a new rectangle with all coordinate values rounded up to the nearest integer. This method is argument-free and returns a 'rect' object. ```lua local ceiled = rect:ceil(); ``` -------------------------------- ### for_each - Entity List Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/entities-or-lua-api/entity_list_t-or-lua-api Loops through the entities in the list in forward order. ```APIDOC ## for_each (Method) ### Description Loops through the entities in the list in forward order. ### Method `for_each` ### Parameters #### Arguments * **fn** (`function(entity_entry_t)`) - Function callback to be executed for each entity. ### Returns * Nothing. ### Example ```lua entities.players:for_each(function (entry) -- ... end); ``` ``` -------------------------------- ### Get Bottom-Left Vector (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Retrieves the bottom-left corner vector of a rectangle. This method takes no arguments and returns a 'vec2' object representing the coordinates. ```lua local bl = rect:bl(); ``` -------------------------------- ### combo_box Constructor Source: https://ctcake.gitbook.io/ctcake-docs/combo_box-or-lua-api Constructs a new combo_box instance with a given ID. ```APIDOC ## combo_box (__call Constructor) ### Description Constructs the combo box. ### Method __call (Constructor) ### Endpoint N/A (Lua API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local cb = gui.combo_box(gui.control_id('my_id')) ``` ### Response #### Success Response - **combo_box** (combo_box) - Combo box instance. #### Response Example ```json { "combo_box": "instance_of_combo_box" } ``` ``` -------------------------------- ### Get Rectangle with Half Width Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Returns a new rectangle that has half the width of the original rectangle. This method takes no arguments and returns the modified rectangle. ```lua local half = rect:half_width(); ``` -------------------------------- ### Get Brightness Value - Lua Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the brightness value of a color. This method takes no arguments and returns a float between 0 and 1, representing the brightness. ```lua local brightness = col:v(); ``` -------------------------------- ### Create Color Instance (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Constructs a new color instance. Supports default (translucent black), integer RGBA components, or hex string formats. ```lua local white = draw.color(255, 255, 255); local hex_color = draw.color("#aabbccdd"); ``` -------------------------------- ### Get Saturation Value - Lua Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the saturation value of a color. This method takes no arguments and returns a float between 0 and 1, representing the saturation. ```lua local saturation = col:s(); ``` -------------------------------- ### Container Add Control Source: https://ctcake.gitbook.io/ctcake-docs/container-or-lua-api Adds a control to the container. ```APIDOC ## add ### Description Adds a control to the container. ### Method N/A (Lua method) ### Endpoint N/A (Lua method) ### Parameters #### Arguments - **ctrl** (control) - Required - Control to add. ### Request Example ```lua container:add(my_control); ``` ### Response #### Success Response - Nothing. #### Response Example N/A ``` -------------------------------- ### Get Hue Value - Lua Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the hue value of a color. This method takes no arguments and returns an integer between 0 and 359, representing the hue. ```lua local hue = col:h(); ``` -------------------------------- ### Input Bitmask Fields Source: https://ctcake.gitbook.io/ctcake-docs/api/enums-or-lua-api/input_bit_mask-or-lua-api This section lists all available input bitmask fields. Each field represents a specific button state used in user commands. ```APIDOC ## Input Bitmask Fields This section lists all available input bitmask fields. Each field represents a specific button state used in user commands. ### in_attack `Field` ### in_attack2 `Field` ### in_jump `Field` ### in_duck `Field` ### in_forward `Field` ### in_back `Field` ### in_use `Field` ### in_turnleft `Field` ### in_turnright `Field` ### in_moveleft `Field` ### in_reload `Field` ### in_speed `Field` ### in_joyautosprint `Field` ### in_useorreload `Field` ### in_score `Field` ### in_zoom `Field` ### in_look_at_weapon `Field` ``` -------------------------------- ### Get Color Integer Representation (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Converts a color object to its integer representation in various color formats (RGBA, ARGB, BGRA, ABGR). ```lua local num_rgba = col:rgba(); local num_argb = col:argb(); local num_bgra = col:bgra(); local num_abgr = col:abgr(); ``` -------------------------------- ### Text Input Fields Source: https://ctcake.gitbook.io/ctcake-docs/text_input-or-lua-api Describes the available fields for a text input instance. ```APIDOC ## Fields ### placeholder * **Type**: `string` * **Description**: The placeholder text displayed when the input is empty. ### value (Read only) * **Type**: `string` * **Description**: The current text value of the input. This field is read-only and should be modified using the `set_value` method. ``` -------------------------------- ### Get Active Weapon (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/cs2_player_controller-or-lua-api Retrieves the weapon that the player is currently holding and actively using. This method takes no arguments and returns a cs2_weapon_base_gun object. ```lua local wep = player:get_active_weapon(); ``` -------------------------------- ### events.event Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/events-or-lua-api Invoked every time a game event fires. We do not listen to every single event that exists in the game. If you need something that we don't listen to, please use `mods.events` ```APIDOC ## events.event ### Description Invoked every time a game event fires. We do not listen to every single event that exists in the game. If you need something that we don't listen to, please use `mods.events` ### Method EVENT ### Endpoint events.event ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **event** (game_event_t) - Game event. #### Response Example None ``` -------------------------------- ### Get Network Channel Lua API Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api/cengine_client-or-lua-api Retrieves the Network Channel used for network communication. This method returns a 'cnet_chan' instance or 'nil' if it does not exist. ```lua local chan = game.engine:get_netchan(); ``` -------------------------------- ### set_text Method Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/gui-or-lua-api/control/label-or-lua-api Sets the text of an existing label control to a new string. ```APIDOC ## Method: set_text ### Description Sets the new text for the label. ### Method set_text ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua lab:set_text('New hello!'); ``` ### Response #### Success Response (200) Returns Nothing. #### Response Example ```json { "example": "null" } ``` ``` -------------------------------- ### Get Last Timestamp Lua API Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api/cengine_client-or-lua-api Retrieves the last recorded timestamp in seconds. This method takes no arguments and returns a float representing the timestamp. ```lua local last_time = game.engine:get_last_timestamp(); ``` -------------------------------- ### Get Rounded Rectangle (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Returns a new rectangle with all coordinate values rounded to the nearest integer. This method takes no arguments and returns a 'rect' object. ```lua local rounded = rect:round(); ``` -------------------------------- ### Construct text_input | Lua Source: https://ctcake.gitbook.io/ctcake-docs/text_input-or-lua-api Constructs a new text input control instance using its ID. This is the primary way to create a text input element in the GUI. ```lua local sp = gui.text_input(gui.control_id('my_id')); ``` -------------------------------- ### Get Floored Rectangle (Lua) Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Returns a new rectangle with all coordinate values rounded down to the nearest integer. This method takes no arguments and returns a 'rect' object. ```lua local floored = rect:floor(); ``` -------------------------------- ### Lua: Define a Callback Function Source: https://ctcake.gitbook.io/ctcake-docs/first-steps-or-lua-api This snippet shows the basic structure for defining a local callback function in Lua. It's a common pattern for handling events. The function currently has no implementation, serving as a placeholder. ```lua local function on_present_queue() end ``` -------------------------------- ### Get Bottom-Right Vector of Rectangle Source: https://ctcake.gitbook.io/ctcake-docs/rect-or-lua-api Retrieves the coordinates of the bottom-right corner of the rectangle as a `vec2` object. This method takes no arguments and is useful for geometric calculations or rendering. ```lua local br = rect:br(); ``` -------------------------------- ### Execute Client Command Lua API Source: https://ctcake.gitbook.io/ctcake-docs/api/instances-or-lua-api/game-or-lua-api/cengine_client-or-lua-api Executes a client-sided console command. It takes a command string and an optional boolean to control restrictions. This function does not return any value. ```lua game.engine:client_cmd('say Hello!'); ``` -------------------------------- ### Construct Texture from File Source: https://ctcake.gitbook.io/ctcake-docs/texture-or-lua-api Constructs a texture object by loading it from a specified file path. This method takes a string representing the path to the texture file as input and returns a texture object. Ensure the provided path points to a valid and supported texture file format. ```lua local tex = draw.texture('funny_meme.png'); ``` -------------------------------- ### Get Alpha Color Value - Lua Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the alpha (opacity) component of a color. This method takes no arguments and returns an integer representing the alpha value. ```lua local a = col:get_a(); ``` -------------------------------- ### Get Blue Color Value - Lua Source: https://ctcake.gitbook.io/ctcake-docs/color-or-lua-api Retrieves the blue component of a color. This method takes no arguments and returns an integer representing the blue color value. ```lua local b = col:get_b(); ```