> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/examples/player-radar.md).

# Радар игроков

HUD-радар, который показывает игроков поблизости точками.

Небольшой квадрат на HUD, где точками отмечены игроки поблизости. Радар поворачивается вместе с камерой. Пример показывает, как рисовать через `Render2D`, брать цвета темы, работать с сущностями и почему список сущностей лучше получать один раз за кадр.

```java
package my;

import hex.script.api.ColorPicker;
import hex.script.api.Entity;
import hex.script.api.Render2D;
import hex.script.api.Script;
import hex.script.api.Slider;

public class PlayerRadar extends Script {

    private final Slider size = slider("Размер", 70f, 40f, 160f, 5f);
    private final Slider range = slider("Радиус", 40f, 10f, 100f, 5f).postfix("м");
    private final ColorPicker enemy = colorPicker("Враги", 0xFFFF3B30);
    private final ColorPicker friend = colorPicker("Друзья", 0xFF57D977);

    @Override
    public String description() {
        return "Показывает игроков поблизости точками";
    }

    @Override
    public void onRender2D(Render2D render) {
        if (!player().present()) return;

        float box = size.value();
        float x = 10f;
        float y = 10f;
        float cx = x + box / 2f;
        float cy = y + box / 2f;

        render.drawBlur(x, y, box, box, 4f, 1f, 8f, 0.6f, render.themeColor("rect"));
        render.drawClientOutline(x, y, box, box, 4f, 1f,
                render.fade(0), render.fade(90), render.fade(180), render.fade(270));
        render.drawClientRect(cx - 1f, cy - 1f, 2f, 2f, 1f, render.themeColor("text"));

        double scale = box / 2.0 / range.value();
        double yaw = Math.toRadians(player().yaw());
        double sin = Math.sin(yaw);
        double cos = Math.cos(yaw);

        for (Entity other : entities().players(range.value())) {
            double dx = other.x() - player().x();
            double dz = other.z() - player().z();
            double rx = dx * cos + dz * sin;
            double rz = dz * cos - dx * sin;

            float px = (float) (cx + rx * scale);
            float py = (float) (cy + rz * scale);
            if (px < x + 2f || px > x + box - 2f || py < y + 2f || py > y + box - 2f) continue;

            int color = other.friend() ? friend.value() : enemy.value();
            render.drawClientRect(px - 1.5f, py - 1.5f, 3f, 3f, 1.5f, color);
        }
    }
}
```

## Разбор

**Поворот под камеру.** Смещение до каждого игрока поворачивается на угол взгляда, поэтому направление «вперёд» на радаре всегда смотрит вверх. `player().yaw()` возвращает градусы, так что перед синусом нужен `Math.toRadians`.

**Цвета из темы.** `themeColor("rect")` и `themeColor("text")` берут цвета текущей темы Quick, а `fade(0..270)` дают четыре точки бегущего градиента для обводки. Так радар выглядит как часть интерфейса Quick, а не как отдельный оверлей.

**Сущности один раз за кадр.** `entities().players(range)` собирает новый массив при каждом вызове. Если вызывать его в цикле или дважды за кадр, это лишняя работа шестьдесят раз в секунду.

**Точки за краем.** Радиус радара и радиус поиска совпадают, но диагональ квадрата длиннее радиуса, поэтому проверять границы всё равно нужно.

**Всё в рендере.** Все вычисления здесь дешёвые, поэтому они находятся прямо в `onRender2D`. Если бы понадобился отсортированный список или поиск по табу, их стоило бы делать в `onTick()` и сохранять в поле.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.quickclient.cc/examples/player-radar.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
