> 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/documentacao/events.md).

# Eventos

Kills, dano, rodadas, bomba e compras.

```lua
events.on(name, fn)
events.off(name, fn)
```

`fn` recebe uma tabela com os dados do evento. O campo `name` sempre tem o nome do evento.

```lua
events.on("player_death", function(e)
    local me = entities.local_player()
    if me and e.attacker == me.index then
        print("You killed " .. e.victim_name .. (e.headshot and " (headshot)" or ""))
    end
end)
```

## Eventos disponíveis

Os jogadores aparecem pelo **índice** (o mesmo de [`entities.get`](/documentacao/api/entities.md)) e pelo nome.

### player\_death

Um jogador morreu.

| Campo                       | Tipo            |                                              |
| --------------------------- | --------------- | -------------------------------------------- |
| `attacker`, `attacker_name` | integer, string | Quem matou                                   |
| `victim`, `victim_name`     | integer, string | Quem morreu                                  |
| `assister`, `assister_name` | integer, string | Quem deu a assistência (0 e `""` se ninguém) |
| `weapon`                    | string          | Arma, como `"AK-47"`                         |
| `headshot`                  | boolean         | Foi na cabeça                                |
| `wallbang`                  | boolean         | Atravessou parede                            |

### player\_hurt

Um jogador levou dano.

| Campo                       | Tipo            |                                                                                                           |
| --------------------------- | --------------- | --------------------------------------------------------------------------------------------------------- |
| `attacker`, `attacker_name` | integer, string | Quem acertou                                                                                              |
| `victim`, `victim_name`     | integer, string | Quem levou                                                                                                |
| `damage`                    | integer         | Dano causado                                                                                              |
| `health`                    | integer         | Vida que sobrou                                                                                           |
| `hitgroup`                  | string          | `"head"`, `"chest"`, `"stomach"`, `"left_arm"`, `"right_arm"`, `"left_leg"`, `"right_leg"` ou `"generic"` |
| `weapon`                    | string          | Arma                                                                                                      |

### round\_start / round\_end

| Evento        | Campos                                      |
| ------------- | ------------------------------------------- |
| `round_start` | —                                           |
| `round_end`   | `winner` (2 = T, 3 = CT), `reason` (string) |

### Bomba

| Evento          | Campos                                           |
| --------------- | ------------------------------------------------ |
| `bomb_planted`  | `player`, `player_name`, `site` (`"A"` ou `"B"`) |
| `bomb_defused`  | `player`, `player_name`                          |
| `bomb_exploded` | —                                                |

### Outros

| Evento          | Campos                            |
| --------------- | --------------------------------- |
| `weapon_fire`   | `player`, `player_name`, `weapon` |
| `item_purchase` | `player`, `player_name`, `item`   |

{% hint style="info" %}
Um nome que nenhum evento usa não dá erro: a função só nunca é chamada. Confira a grafia, sempre em minúsculas com `_`.
{% endhint %}


---

# 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/documentacao/events.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.
