### Get Various Information Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Demonstrates how to retrieve various pieces of information from the local player entity, such as health, armor, scope status, team, movement flags, and velocity. ```APIDOC ## GET Local Player Information ### Description Retrieves key attributes of the local player pawn, including health, armor status, aiming status, team affiliation, movement flags, and velocity. ### Method GET ### Endpoint /api/entities/local_pawn ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```lua local lp = entities.get_local_pawn() -- Check if the local pawn is valid before proceeding if lp == nil then return end -- Get Health local m_iHealth = lp.m_iHealth:get() print("Health: " .. m_iHealth) -- Get Helmet Status local m_bPrevHelmet = lp.m_bPrevHelmet:get() print("Has Helmet: " .. tostring(m_bPrevHelmet)) -- Get Armor Value local m_ArmorValue = lp.m_ArmorValue:get() print("Armor: " .. m_ArmorValue) -- Get Scope Status local m_bIsScoped = lp.m_bIsScoped:get() print("Is Scoped: " .. tostring(m_bIsScoped)) -- Get Team Number local m_iTeamNum = lp.m_iTeamNum:get() print("Team: " .. m_iTeamNum) -- Get Movement Flags local m_fFlags = lp.m_fFlags:get() print("Movement Flags: " .. m_fFlags) -- Get Velocity local velocity = lp:get_abs_velocity() if velocity:length() > 0.1 then print("Player is moving.") else print("Player is stationary.") end -- Check for slow walk status local slowwalk = gui.ctx:find("misc>movement>slowwalk") if velocity:length() > 0.1 then if slowwalk:get_value():get() then print("Movement Type: Slow Walk") else print("Movement Type: Normal Walk") end end ``` ### Response #### Success Response (200) - **m_iHealth** (number) - The current health points of the player. - **m_bPrevHelmet** (boolean) - Indicates if the player is wearing a helmet. - **m_ArmorValue** (number) - The current armor points of the player. - **m_bIsScoped** (boolean) - Indicates if the player is currently aiming down sights. - **m_iTeamNum** (number) - The team number the player belongs to (e.g., 2 for Terrorists, 3 for Counter-Terrorists). - **m_fFlags** (number) - Flags indicating the player's current movement state (e.g., 65664 for jumping, 65665 for standing, 65666 for jumping while crouching, 65667 for crouching). - **velocity** (object) - A vector representing the player's current velocity. The length of this vector indicates movement speed. #### Response Example ```json { "m_iHealth": 100, "m_bPrevHelmet": true, "m_ArmorValue": 100, "m_bIsScoped": false, "m_iTeamNum": 3, "m_fFlags": 65665, "velocity": {"x": 0, "y": 0, "z": 0} } ``` ``` -------------------------------- ### Get Various Player Information (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Demonstrates how to retrieve various player-specific information such as health, armor, scope status, team number, movement flags, and velocity. It includes checks for nil values to prevent errors and interprets movement flags and velocity to determine player actions like moving or being in the air. It also shows how to check if the 'slowwalk' feature is active. ```lua local lp = entities.get_local_pawn() --获取yourself (C_BaseEntity,C_CSPlayerPawnBase,C_CSPlayerPawn) if lp == nil then return end --防止nil导致崩溃 local m_iHealth = lp.m_iHealth:get() print(m_iHealth) -- 血量值0-100 local m_bPrevHelmet = lp.m_bPrevHelmet:get() print(m_bPrevHelmet) -- 是否带头甲 true or false 可以理解为全甲还是半甲 local m_ArmorValue = lp.m_ArmorValue:get() print(m_ArmorValue) -- 护甲值0-100 local m_bIsScoped = lp.m_bIsScoped:get() print(m_bIsScoped) -- 是否开镜 true or false local m_iTeamNum = lp.m_iTeamNum:get() print(m_iTeamNum) -- 阵营2=T 3=CT local m_fFlags = lp.m_fFlags:get() print(m_fFlags) --65664跳跃 --但是最好理解为在空中因为不仅仅只有跳跃的时候再空中 --例如你从高出下落的时候也算在空中 --65665站着 --65666跳蹲 --65667蹲下 local velocity = lp:get_abs_velocity() --获取自身的velocity也就是所谓的移动速度向量 if velocity:length() > 0.1 then print("移动") end --通过velocity的length来判断是否移动 local slowwalk = gui.ctx:find("misc>movement>slowwalk") if velocity:length() > 0.1 then if slowwalk:get_value():get() then print("静步/慢走/假走?") else print("正常移动") end end --通过判断slowwalk开关来判断移动的类型 ``` -------------------------------- ### Get Players Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Retrieves a list of all players in the current game, with an option to filter for enemies only. ```APIDOC ## GET Players ### Description Fetches a list of all player entities currently in the game. Optionally, it can filter this list to return only enemy players. ### Method GET ### Endpoint /api/entities/players ### Parameters #### Query Parameters - **enemy** (boolean) - Optional. If set to `true`, only enemy players will be returned. #### Request Body None ### Request Example ```lua -- Get all players in the game local all_players = entities.get_players() -- Get only enemy players local enemies = entities.get_players(true) -- Iterate through all players and print their names for _, player in ipairs(all_players) do print(player:get_name()) end ``` ### Response #### Success Response (200) - **players** (table[cs2_player_pawn]) - A table containing player pawn objects. Each object represents a player entity in the game. #### Response Example ```json [ { "handle": "0x12345678", "name": "Player1", "team": 2 }, { "handle": "0x87654321", "name": "Player2", "team": 3 } ] ``` ``` -------------------------------- ### Get Player State Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Encapsulates player state logic into a reusable function `get_player_state()` for quick status checks. ```APIDOC ## GET Player State ### Description A utility function that returns the current state of the local player, including whether they are moving, standing, jumping, crouching, or in a combination of these states. ### Method GET ### Endpoint /api/entities/player_state ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```lua local function get_player_state() local lp = entities.get_local_pawn() if lp == nil then return end local m_fFlags = lp['m_fFlags']:get() local velocity = lp:get_abs_velocity() local slowwalk = gui.ctx:find("misc>movement>slowwalk") if m_fFlags == 65664 then return "in air" elseif m_fFlags == 65666 then return "in air duck" elseif m_fFlags == 65667 then return velocity:length() > 0.1 and "in duck moving" or "in duck" elseif velocity:length() > 0.1 then return slowwalk:get_value():get() and "in slowwalk" or "in moving" else return "in standing" end end -- Example usage within an event loop: events.present_queue:add(function() local d = draw.surface; d.font = draw.fonts['gui_main']; local me_state = get_player_state() local x, y = 20, 320 d:add_text(draw.vec2(x, y), "player state:" .. me_state, draw.color.white() ); end) ``` ### Response #### Success Response (200) - **player_state** (string) - A string describing the player's current state (e.g., "in air", "in duck moving", "in standing", "in slowwalk", "in moving"). #### Response Example ```json { "player_state": "in moving" } ``` ``` -------------------------------- ### Get Player State Function (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Encapsulates player state retrieval into a reusable function `get_player_state()`. This function analyzes movement flags and velocity to determine if the player is standing, moving, in the air, ducking, or performing a jump crouch. It also checks for the 'slowwalk' status to differentiate between normal movement and slow walking. ```lua local function get_player_state() local lp = entities.get_local_pawn() if lp == nil then return end local m_fFlags = lp['m_fFlags']:get() local velocity = lp:get_abs_velocity() local slowwalk = gui.ctx:find("misc>movement>slowwalk") if m_fFlags == 65664 then return "in air"--在空中,也能当在跳跃 elseif m_fFlags == 65666 then return "in air duck"--在空中蹲下,可以理解为跳蹲 elseif m_fFlags == 65667 then return velocity:length() > 0.1 and "in duck moving" or "in duck" --蹲下移动和蹲下不动 elseif velocity:length() > 0.1 then return slowwalk:get_value():get() and "in slowwalk" or "in moving" --慢走和正常移动 else return "in standing"--站着不动 end end ``` -------------------------------- ### Lua HTTP GET and POST Requests Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Demonstrates making simple GET and POST requests using the http library in Lua. The GET request retrieves data, while the POST request sends parameters and a JSON body for an update action. Both examples include basic success and error handling by checking the response status. ```lua -- 简单的GET请求 http.get("https://api.example.com/data", function(success, response) if success and response.status == 200 then print("请求成功!") print("响应内容:", response.body) else print("请求失败:", response.status_message) end end) -- 带参数的POST请求 http.post("https://api.example.com/submit", { headers = { ["Content-Type"] = "application/json", ["Authorization"] = "Bearer your_token_here" }, params = { ["user_id"] = "12345", ["action"] = "update" }, json = { name = "张三", age = 30, interests = {"编程", "游戏", "音乐"} } }, function(success, response) if success and response.status == 200 then -- 尝试解析JSON响应 local data = json.parse(response.body) print("操作结果:", data.result) else print("请求失败:", response.status, response.status_message) end end) ``` -------------------------------- ### Get Player List Function (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/entities.md Provides a function `entities.get_players(enemy)` that iterates through all active players in the current game session. It returns a table containing player entities, with an optional `enemy` boolean parameter to filter the list and return only enemy players if set to true. The function ensures that only valid player handles are processed. ```lua function entities.get_players(enemy) local players = {} entities.players:for_each(function(entry) if entry.handle:valid() then local player = entry.handle:get() if enemy then if player:is_enemy() then table.insert(players, player) end else table.insert(players, player) end end end) return players end ``` -------------------------------- ### Example: Download File Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Illustrates how to download a file using `http.get` with `stream_response` enabled, including callbacks for completion and data reception. ```APIDOC ## Download File ### Description Downloads a file from a URL, with options to track progress and handle completion. ### Method `http.get(url, options, callbacks)` ### Endpoint `http://example.com/files/document.txt` ### Parameters #### Options - **stream_response** (boolean) - Set to `true` to enable streaming response. #### Callbacks - **completed**(function) - Called when the download is complete. - **success** (boolean) - Indicates if the download was successful. - **response** (table) - The final response object. - **data_received**(function) - Called when chunks of data are received. - **success** (boolean) - Indicates if data reception was successful. - **data** (table) - **download_progress** (number) - The current download progress (0 to 1). ### Request Example ```lua http.get("http://example.com/files/document.txt", { stream_response = true }, { completed = function(success, response) if success and response.status == 200 then print("File download complete") -- Logic to save the file else print("File download failed") end end, data_received = function(success, data) if success then print("Download progress:", math.floor(data.download_progress * 100), "%") -- Logic to handle partial data end end }) ``` ``` -------------------------------- ### Lua:根据复选框状态显示文本 Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/first-steps.md 此代码片段展示了如何在Fatality Lua脚本中根据复选框的状态来控制文本的显示。它修改了`on_present_queue`回调函数,使用`cb:get_value():get()`检查复选框是否被选中,只有在选中时才绘制文本。 ```lua 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 world', draw.color.white() ); end end ``` -------------------------------- ### Example: Submit Form Data Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Shows how to submit form data to a server using the `http.post` method. ```APIDOC ## Submit Form Data ### Description Submits form data to a specified endpoint using an HTTP POST request. ### Method `http.post(url, options, callback)` ### Endpoint `http://example.com/submit-form` ### Parameters #### Query Parameters - **username** (string) - The username for the form. - **email** (string) - The email address for the form. - **message** (string) - The message content for the form. ### Request Example ```lua http.post("http://example.com/submit-form", { params = { username = "user123", email = "user@example.com", message = "This is a test message" } }, function(success, response) if success and response.status == 200 then print("Form submitted successfully!") else print("Form submission failed:", response.status_message) end end) ``` ``` -------------------------------- ### Lua Example: Submitting Form Data Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Demonstrates submitting form data to a server endpoint using http.post. This example sends user information and a message as URL parameters, with a basic check for a successful submission (HTTP status 200). ```lua http.post("http://example.com/submit-form", { params = { username = "user123", email = "user@example.com", message = "这是一条测试消息" } }, function(success, response) if success and response.status == 200 then print("表单提交成功!") else print("表单提交失败:", response.status_message) end end) ``` -------------------------------- ### Example: Fetch Weather Data Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Demonstrates how to fetch current weather data for a specific location using the `http.get` method and process the JSON response. ```APIDOC ## Fetch Weather Data ### Description Fetches current weather data from an API and prints the temperature and condition. ### Method `http.get(url, options, callback)` ### Endpoint `http://api.weatherapi.com/v1/current.json` ### Parameters #### Query Parameters - **key** (string) - Required - Your API key for the weather service. - **q** (string) - Required - The location (e.g., "Beijing"). ### Request Example ```lua http.get("http://api.weatherapi.com/v1/current.json", { params = { key = "your_api_key", q = "Beijing" } }, function(success, response) if success and response.status == 200 then local weather_data = json.parse(response.body) print("Beijing current temperature:", weather_data.current.temp_c, "°C") print("Weather condition:", weather_data.current.condition.text) else print("Failed to fetch weather data") end end) ``` ### Response #### Success Response (200) - **current** (table) - Contains current weather information. - **temp_c** (number) - Temperature in Celsius. - **condition** (table) - **text** (string) - Text description of the weather condition. #### Response Example ```json { "location": { "name": "Beijing", "region": "Beijing", "country": "China" }, "current": { "temp_c": 25.0, "condition": { "text": "Partly cloudy" } } } ``` ``` -------------------------------- ### Lua - Basic HTTP GET Request (Windows Socket API) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Demonstrates how to create and send a simple HTTP GET request using the Windows Socket API in Lua. It involves setting up socket parameters, sending the request string, and receiving the response. This method is limited to HTTP and does not support HTTPS. ```lua local request = "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" -- Set target server information local addr = ffi.new("sockaddr_in") addr.sin_family = AF_INET addr.sin_port = htons(80) -- Standard HTTP port addr.sin_addr.s_addr = inet_addr("93.184.216.34") -- IP address for example.com -- Send request if send(sock, request, #request, 0) == -1 then error("Failed to send") end -- Receive response local buffer = ffi.new("char[4096]") local received = recv(sock, buffer, 4096, 0) if received > 0 then local response = ffi.string(buffer, received) print(response) else error("Failed to receive response") end ``` -------------------------------- ### Lua:在屏幕上显示“hello world” Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/first-steps.md 这是一个基础的Fatality Lua脚本,演示了如何在渲染帧中向屏幕添加文本。它定义了一个回调函数,使用`draw.surface`绘制文本,并将其注册到`events.present_queue`事件。 ```lua local function on_present_queue() local d = draw.surface; d.font = draw.fonts['gui_main']; d:add_text(draw.vec2(50, 50), 'hello world', draw.color.white() ); end events.present_queue:add(on_present_queue); ``` -------------------------------- ### events.setup_view_pre Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/events.md Called every time the game sets up the view. This event is invoked *before* the game function runs. ```APIDOC ## events.setup_view_pre ### Description Called every time the game sets up the view. This event is invoked *before* the game function runs. ### Method ADD_CALLBACK ### Endpoint events.setup_view_pre ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```lua events.setup_view_pre:add(function() print('View setup started') end) ``` ### Response #### Success Response (200) - None #### Response Example ```json {} ``` ``` -------------------------------- ### Create Multi-Select Combo Box (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/gui.md Shows how to create a multi-select combo box, analogous to Fatality's RAGE 'Hitboxes' selection. It includes setting `allow_multiple = true` to enable multi-selection. ```lua local lua_a = gui.ctx:find("lua>elements a") local hitbox = { "Head", "Chest", "Stomach", "Arms", "Legs", "Feet" } local hitboxes_id = "my_hitboxes" local hitboxes = gui.combo_box(gui.control_id(hitboxes_id)) hitboxes.allow_multiple = true --启用多选模式,默认为单选 local make_hitbox = gui.make_control("Hitboxes",hitboxes) for _, select in ipairs(hitbox) do local selectable = gui.selectable(gui.control_id(hitboxes_id .. ">" .. select), select) hitboxes:add(selectable) end lua_a:add(make_hitbox) lua_a:reset(); ``` -------------------------------- ### events.setup_view_post Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/events.md Called every time the game sets up view information. This event is invoked *after* the game function runs. ```APIDOC ## events.setup_view_post ### Description Called every time the game sets up view information. This event is invoked *after* the game function runs. ### Method ADD_CALLBACK ### Endpoint events.setup_view_post ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```lua events.setup_view_post:add(function() print('View setup completed') end) ``` ### Response #### Success Response (200) - None #### Response Example ```json {} ``` ``` -------------------------------- ### Accessing game_vars.cur_time Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/game/global-vars-t.md Gets the elapsed time in seconds since the server's game session started. This float value may be software-synced but does not represent the exact wall-clock time. ```plaintext game.global_vars.cur_time ``` -------------------------------- ### Create Single-Select Combo Box (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/gui.md Demonstrates creating a single-select combo box, similar to the 'Pitch' selection in Fatality's AA. It involves finding a UI context, defining options, creating a combo box, and adding selectable items. ```lua local lua_a = gui.ctx:find("lua>elements a") local list = { "None", "Down", "Up", "Zoro", "Custom" } local pitch_id = "my_pitch" local pitch = gui.combo_box(gui.control_id(pitch_id)) local make_pitch = gui.make_control("Pitch",pitch) for _, select in ipairs(list) do local selectable = gui.selectable(gui.control_id(pitch_id..">"..select), select) pitch:add(selectable) end lua_a:add(make_pitch) lua_a:reset(); ``` -------------------------------- ### Lua:构建UI布局和添加控件 Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/first-steps.md 该代码段演示了如何在Fatality Lua脚本中构建用户界面布局。它创建了一个带有标签的行控件,使用`gui.make_control()`,然后查找一个特定的UI分组(`'lua>elements a'`),并将该行控件添加到该分组中,使其在UI中可见。 ```lua -- 创建一个带标签的行 local row = gui.make_control('显示文本', cb); -- 找到目标分组 local group = gui.ctx:find('lua>elements a'); -- 将行添加到分组中 group:add(row); ``` -------------------------------- ### Get Checkbox Value Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/gui/control/checkbox.md Retrieves the current boolean value of the checkbox. It returns a value_param object, from which the actual boolean value can be obtained using 'get()'. ```lua local val = cb:get_value():get(); ``` -------------------------------- ### Add callback to setup_view_post event Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/events.md Adds a callback function that is executed after the game sets up view information. View details can be retrieved from the game.view_render service. ```lua events.setup_view_post:add(function() print('View setup completed') end) ``` -------------------------------- ### add_line_multicolor Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/draw/layer.md Adds a multicolor line to the drawing layer. You can specify the start and end points, start color, end color, and thickness. ```APIDOC ## add_line_multicolor ### Description Adds a multicolor line. ### Method ADD ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **a** (vec2) - Required - The starting point. - **b** (vec2) - Required - The ending point. - **c** (color) - Required - The starting color. - **c2** (color) - Required - The ending color. - **thickness** (float) - Optional - Line thickness. Defaults to `1.0`. ### Request Example ```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 ); ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Get Direct Value from Control (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/gui/control/value-param.md Retrieves the value associated with any active key bindings for a control. Similar to 'get', the return type is determined by the control's configuration. ```Lua ctrl:get_value():get_direct(); ``` -------------------------------- ### Create Font and Display Text in Lua Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/draw.md Demonstrates creating a 16-point font with anti-aliasing and DPI scaling disabled. It then uses this font to display 'hello world' in white at coordinates (50, 50) on the screen. This requires the 'draw' and 'events' modules. ```lua local layer = draw.surface local flags = bit.bor(draw.font_flags.no_dpi, draw.font_flags.anti_alias) local verdana = draw.font("Verdana.ttf", 16, flags) verdana:create() local function on_present_queue() local d = draw.surface; d.font = verdana d:add_text(draw.vec2(50, 50), 'hello world', draw.color.white() ); end events.present_queue:add(on_present_queue); ``` -------------------------------- ### Get Game Latency Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/utils.md Retrieves the current network latency for a game by accessing its network channel. This function checks if the network channel exists and is not null before attempting to get and print the latency in milliseconds. ```lua local chan = game.engine:get_netchan(); if chan and not chan:is_null() then print('当前延迟: ' .. tostring(math.round(chan:get_latency() * 1000.0)) .. 'ms'); end ``` -------------------------------- ### Create Slider Control (Lua) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/example/gui.md Illustrates the creation of slider controls, like the 'HS scale DMG' in Fatality's RAGE, using a different UI management approach. It defines multiple sliders with custom formatting and labels. ```lua local lua_a = gui.ctx:find("lua>elements a") local my_menu = { id = {}, menu = {}, } my_menu.id = { Hit_Chance = gui.slider(gui.control_id("my_hc"), -1, 100, { {min = 1, add = 0, format = '%%.0f%%' }, {min = -1, format = 'Auto'}}), Pointscale = gui.slider(gui.control_id("my_mp"), 0, 100, { "%%.0f%%" }), Min_damage = gui.slider(gui.control_id("my_dmg"), 0, 125, { {min = 101, add = -100, format = 'HP+%%.0f' }, {min = 1, add = 0, format = '%%.0fhp' }, {min = 0, format = 'Lethal' } }), } my_menu.menu = { Hit_Chance = gui.make_control('Hit chance', my_menu.id.Hit_Chance), Pointscale = gui.make_control('Pointscale', my_menu.id.Pointscale), Min_damage = gui.make_control('Min damage', my_menu.id.Min_damage), } lua_a:add(my_menu.menu.Hit_Chance) lua_a:add(my_menu.menu.Pointscale) lua_a:add(my_menu.menu.Min_damage) lua_a:reset(); --在添加多个组件之后一定要调用一次reset()来避免组件堆叠 ``` -------------------------------- ### Get Slider Value Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/gui/control/slider.md Retrieves the current value of the slider control. The returned value is encapsulated in a 'value_param' type, which provides a 'get()' method to extract the float value. ```lua local val = slider:get_value():get(); ``` -------------------------------- ### Lua Example: Downloading a File Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/http.md Illustrates how to download a file using http.get with the `stream_response` option enabled. It includes callbacks for `data_received` to show download progress and `completed` to handle the final success or failure of the download, including saving the file. ```lua http.get("http://example.com/files/document.txt", { stream_response = true }, { completed = function(success, response) if success and response.status == 200 then print("文件下载完成") -- 保存文件逻辑 else print("文件下载失败") end end, data_received = function(success, data) if success then print("下载进度:", math.floor(data.download_progress * 100), "%") -- 处理部分数据 end end }) ``` -------------------------------- ### Add Multicolor Line - Lua Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/draw/layer.md Adds a multi-colored line to the drawing layer. Requires start and end points (vec2), start color, end color, and optional thickness. No return value. ```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 ); ``` -------------------------------- ### Create Layout with Control Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/gui.md Wraps a control within a layout, making it presentable and stackable with other controls. ```APIDOC ## POST /api/gui/make-control ### Description Wraps a control into a layout, typically used for displaying controls within grouping boxes. ### Method POST ### Endpoint /api/gui/make-control ### Parameters #### Request Body - **text** (string) - Required - The label for the control. - **c** (object) - Required - The control object to be wrapped. ### Request Example ```json { "text": "Submit", "c": { "type": "button", "label": "Submit" } } ``` ### Response #### Success Response (200) - **layout** (object) - The layout object containing the control. #### Response Example ```json { "layout": { "type": "container", "children": [ { "type": "label", "text": "Submit" }, { "type": "button", "label": "Submit" } ] } } ``` ``` -------------------------------- ### Get Saturation Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/draw/types/color.md Retrieves the saturation component of a color. ```APIDOC ## GET SATURATION ### Description Returns the saturation value of the color. ### Method Implicit (method call on a color object) ### Endpoint N/A (Object Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local saturation = color_object:s() ``` ### Response #### Success Response (200) * **float** (float) - The saturation of the color (0 to 1). #### Response Example ```json { "value": 0.75 } ``` ``` -------------------------------- ### Add callback to render_start_post event Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/events.md Adds a callback function that is executed after the game begins its scene rendering process. It receives the view setup information as an argument. ```lua events.render_start_post:add(function(setup) print('Rendering completed with setup:', setup) end) ``` -------------------------------- ### Get Hue Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/draw/types/color.md Retrieves the hue component of a color. ```APIDOC ## GET HUE ### Description Returns the hue value of the color. ### Method Implicit (method call on a color object) ### Endpoint N/A (Object Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local hue = color_object:h() ``` ### Response #### Success Response (200) * **int** (int) - The hue of the color (0 to 359). #### Response Example ```json { "value": 180 } ``` ``` -------------------------------- ### API Overview Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/sidebar.md This section provides a general overview of the available API categories. ```APIDOC ## API Documentation Overview This document provides detailed information on the various modules and their associated types within the Project Fatality API. The API is structured into several categories: * **Global**: For global functionalities. * **FFi**: For Foreign Function Interface interactions. * **Bit**: For bit manipulation operations. * **HTTP**: For handling HTTP requests. * **Files**: For file system operations. * **Json**: For JSON parsing and manipulation. * **Math**: For mathematical functions. * **Events**: For event handling and system notifications. * **Game**: For game-specific functionalities and data structures. * **Mods**: For module-related operations. * **Entities**: For managing and interacting with game entities. * **Draw**: For rendering and drawing functionalities. * **GUI**: For user interface elements and interactions. ``` -------------------------------- ### C_BaseModelEntity 类字段 Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/Netprops.md C_BaseModelEntity 是 CS2 中的一个基础模型实体类,提供了渲染、碰撞、发光等核心功能。它包含渲染组件、碰撞箱组件、最后命中部位、模型效果初始化状态、静态道具标识、贴花管理、生命值、渲染模式、渲染特效、淡入淡出控制、渲染颜色、渲染属性、立方体贴图渲染、插值禁用、碰撞属性、发光属性、背面发光乘数、淡出距离、淡出比例、阴影强度、对象剔除、贴花添加、贴花位置、贴花前向轴、贴花愈合速率、传播贴花配置、视图偏移、客户端透明度属性、客户端覆盖色调以及是否使用客户端覆盖色调等属性。 ```Markdown C_BaseModelEntity 是CS2中的一个基础模型实体类,包含了渲染、碰撞、发光等相关属性。 | 属性名 | 类型 | 描述 | |--------|------|------| | m_CRenderComponent | `CRenderComponent*` | 渲染组件指针 | | m_CHitboxComponent | `CHitboxComponent` | 碰撞箱组件 | | m_LastHitGroup | `HitGroup_t` | 最后被击中的部位 | | m_bInitModelEffects | `bool` | 是否初始化模型效果 | | m_bIsStaticProp | `bool` | 是否为静态道具 | | m_nLastAddDecal | `int32` | 最后添加的贴花 | | m_nDecalsAdded | `int32` | 已添加的贴花数量 | | m_iOldHealth | `int32` | 旧的生命值 | | m_nRenderMode | `RenderMode_t` | 渲染模式 | | m_nRenderFX | `RenderFx_t` | 渲染特效 | | m_bAllowFadeInView | `bool` | 是否允许在视图中淡入淡出 | | m_clrRender | `Color` | 渲染颜色 | | m_vecRenderAttributes | `C_UtlVectorEmbeddedNetworkVar` | 渲染属性向量 | | m_bRenderToCubemaps | `bool` | 是否渲染到立方体贴图 | | m_bNoInterpolate | `bool` | 是否禁用插值 | | m_Collision | `CCollisionProperty` | 碰撞属性 | | m_Glow | `CGlowProperty` | 发光属性 | | m_flGlowBackfaceMult | `float32` | 背面发光乘数 | | m_fadeMinDist | `float32` | 最小淡出距离 | | m_fadeMaxDist | `float32` | 最大淡出距离 | | m_flFadeScale | `float32` | 淡出比例 | | m_flShadowStrength | `float32` | 阴影强度 | | m_nObjectCulling | `uint8` | 对象剔除 | | m_nAddDecal | `int32` | 添加贴花 | | m_vDecalPosition | `Vector` | 贴花位置 | | m_vDecalForwardAxis | `Vector` | 贴花前向轴 | | m_flDecalHealBloodRate | `float32` | 贴花血液愈合速率 | | m_flDecalHealHeightRate | `float32` | 贴花高度愈合速率 | | m_ConfigEntitiesToPropagateMaterialDecalsTo | `C_NetworkUtlVectorBase>` | 传播材质贴花的实体配置 | | m_vecViewOffset | `CNetworkViewOffsetVector` | 视图偏移向量 | | m_pClientAlphaProperty | `CClientAlphaProperty*` | 客户端透明度属性指针 | | m_ClientOverrideTint | `Color` | 客户端覆盖色调 | | m_bUseClientOverrideTint | `bool` | 是否使用客户端覆盖色调 | ``` -------------------------------- ### Get Grenade Type Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/entities/base-entity/cs2-grenade-projectile.md Retrieves the type of the grenade projectile. ```APIDOC ## GET /api/entities/cs2_grenade_projectile/get_grenade_type ### Description Returns the type of the grenade projectile. ### Method GET ### Endpoint /api/entities/cs2_grenade_projectile/get_grenade_type ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```lua local type = gren:get_grenade_type(); ``` ### Response #### Success Response (200) - **type** (int) - The grenade type. #### Response Example ```json { "type": 1 } ``` ``` -------------------------------- ### GUI API Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/sidebar.md Documentation for the GUI API, covering types, contexts, controls, and notification systems. ```APIDOC ## GUI API This section details the GUI API, used for creating and managing user interface elements. ### Endpoint /api/gui.md ### GUI Types * **Types**: Core types for GUI elements. * **bits**: Bit flags for GUI states. (api/gui/types/bits.md) * **control_id**: Unique identifier for controls. (api/gui/types/control-id.md) ### Context Management * **Context**: Manages the GUI rendering context. * **user_t**: User-specific context data. (api/gui/context/user-t.md) * **Context Input**: Handles user input within the GUI context. * **mouse_button**: Represents mouse button states. (api/gui/context-input/mouse-button.md) ### Notification System * **Notification System**: Manages system notifications. * **notification**: Structure for a single notification. (api/gui/notification-system/notification.md) ### Controls * **Control**: Base class for all UI controls. * **control_type**: Enumeration of control types. (api/gui/control/control-type.md) * **value_param**: Generic parameter for control values. (api/gui/control/value-param.md) * **checkbox**: Checkbox control. (api/gui/control/checkbox.md) * **slider**: Slider control. (api/gui/control/slider.md) * **selectable**: Selectable item control. (api/gui/control/selectable.md) * **button**: Button control. (api/gui/control/button.md) * **color_picker**: Color picker control. (api/gui/control/color-picker.md) * **spacer**: Spacer element for layout. (api/gui/control/spacer.md) * **text_input**: Text input field control. (api/gui/control/text-input.md) * **combo_box**: Dropdown combo box control. (api/gui/control/combo-box.md) ``` -------------------------------- ### Get Texture Size (get_size) Source: https://github.com/0x786b/fatality-chinese-docs/blob/main/api/draw/managed/texture.md Retrieves the dimensions (width and height) of the texture. ```APIDOC ## GET /texture/get_size ### Description Returns the size of this texture. ### Method GET ### Endpoint /texture/get_size ### Parameters No parameters required. ### Request Example ```lua local tex_size = tex:get_size(); ``` ### Response #### Success Response (200) - **size** (vec2) - The dimensions of the texture (width and height). #### Response Example ```json { "size": { "x": 1920, "y": 1080 } } ``` ```