> 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/contador-de-kills.md).

# Contador de kills

Conta as suas kills e headshots, mostra no canto da tela e guarda os totais entre uma sessão e outra. Mostra:

* o evento [`player_death`](/documentacao/events.md) e `entities.local_player()` para saber se a kill foi sua;
* [`storage`](/documentacao/api/storage.md) para manter os totais;
* `ui.text` com a descrição atualizada e um `ui.button`;
* um ícone (`icons.crosshairs`) na cor de destaque do menu.

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

```lua
-- @name Kill Counter
-- @author perfect
-- @version 1.0
-- @description Counts your kills and headshots, keeps the totals between sessions.

ui.group("Kill Counter", "Saved between sessions")
local show  = ui.toggle("Show on screen", "Counter in the corner", true)
local stats = ui.text("Totals", "")
ui.button("Reset", "Start counting again", function()
    storage.clear()
end, "Reset")

local function totals()
    return storage.get("kills", 0), storage.get("headshots", 0)
end

local function refresh()
    local kills, headshots = totals()
    local rate = kills > 0 and math.floor(headshots / kills * 100) or 0
    stats:description(string.format("%d kills, %d headshots (%d%%)", kills, headshots, rate))
end
refresh()

events.on("player_death", function(e)
    local me = entities.local_player()
    if not me or e.attacker ~= me.index or e.victim == me.index then return end
    local kills, headshots = totals()
    storage.set("kills", kills + 1)
    if e.headshot then storage.set("headshots", headshots + 1) end
    refresh()
end)

callbacks.add("draw", function()
    if not show:get() then return end
    local kills, headshots = totals()
    render.text(24, 470, icons.crosshairs, menu.accent(), { font = "icons", size = 16 })
    render.text(48, 470, kills .. " kills  ·  " .. headshots .. " HS", color(255, 255, 255), { size = 15, shadow = true })
end)
```

O botão **Reset** apaga tudo com `storage.clear()`.


---

# 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/contador-de-kills.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.
