> For the complete documentation index, see [llms.txt](https://docs.perfectcs2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.perfectcs2.com/exemplos/hud.md).

# HUD com velocidade

Um painel com a sua velocidade, o FPS e a hora, que dá para arrastar com o menu aberto. Mostra:

* um painel no estilo do menu (`render.shadow`, `rect_filled` e `rect` arredondados);
* `input.mouse_pos`, `input.is_key_pressed` e `input.is_mouse_down` para arrastar;
* a posição salva com `storage` e lida com `utils.split`.

Salve como `speed_hud.lua` na pasta de scripts e ligue na aba **Scripts**.

```lua
-- @name Speed HUD
-- @author perfect
-- @version 1.0
-- @description Panel with your speed, FPS and the time. Drag it with the menu open.

ui.group("HUD", "Panel on the screen")
local enabled = ui.toggle("Enabled", "Show the panel", true)
local accent  = ui.toggle("Menu color", "Use the accent color of the menu", true)

-- Position, saved between sessions.
local saved = utils.split(storage.get("pos", "24,520"), ",")
local x, y = tonumber(saved[1]), tonumber(saved[2])
local dragging, grab_x, grab_y = false, 0, 0
local WIDTH, HEIGHT = 190, 64

local function drag()
    local mx, my = input.mouse_pos()
    local over = mx >= x and mx <= x + WIDTH and my >= y and my <= y + HEIGHT
    if menu.is_open() and over and input.is_key_pressed("MouseLeft") then
        dragging, grab_x, grab_y = true, mx - x, my - y
    end
    if not dragging then return end
    if input.is_mouse_down(1) then
        x, y = mx - grab_x, my - grab_y
    else
        dragging = false
        storage.set("pos", math.floor(x) .. "," .. math.floor(y))
    end
end

callbacks.add("draw", function()
    if not enabled:get() then return end
    drag()

    local me = entities.local_player()
    local speed = me and math.floor(me.speed) or 0
    local tint = accent:get() and menu.accent() or color(255, 255, 255)

    render.shadow(x, y, WIDTH, HEIGHT, 10, 18, 0.6)
    render.rect_filled(x, y, WIDTH, HEIGHT, color(14, 14, 16, 230), 10)
    render.rect(x, y, WIDTH, HEIGHT, color(255, 255, 255, 25), 10)
    render.text(x + 14, y + 12, icons.person_running, tint, { font = "icons", size = 16 })
    render.text(x + 40, y + 9, speed .. " u/s", color(255, 255, 255), { size = 18, font = "bold" })
    render.text(x + 40, y + 36, string.format("%d fps  ·  %s", math.floor(client.fps()), os.date("%H:%M")),
        color(170, 170, 180), { size = 13 })

    -- Speed bar: full at 250 u/s (running with a knife).
    local fill = utils.clamp(speed / 250, 0, 1)
    render.rect_filled(x + 14, y + HEIGHT - 8, WIDTH - 28, 3, color(255, 255, 255, 20), 2)
    render.rect_filled(x + 14, y + HEIGHT - 8, (WIDTH - 28) * fill, 3, tint, 2)
end)
```

O painel só pode ser arrastado com o menu aberto, para não atrapalhar o jogo.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.perfectcs2.com/exemplos/hud.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
