# Начало разработки

Для начала, вам нужно [создать проект](/nachalo-razrabotki/sozdanie-proekta.md), создать основной файл и написать код скрипта

### Формат скрипта

```javascript
//name=Имя скрипта
//description=Описание скрипта

import type {Bot, TitleEvent, MessageEvent} from "./types/objects"

(function () { // список функций (эвенты)
    return {
        onBotUpdate: function (bot: Bot) {
            // Вызывается при обновлении бота каждый тик
            // ...
        },
        onBotChat: function (event: MessageEvent, bot: Bot) {
            // Вызывается при получении пакета сообщения в чате
            // ...
        },
        onBotGuiChange: function(type: string, bot: Bot) {
            // Вызывается при изменении открытого контейнера (GUI)
            // ...
        },
        onBotTitle: function(event: TitleEvent, bot: Bot) {
            // Вызывается при получении пакета Title (actionbar, title, subtitle)
            // ...
        },
        onBotHologramTitle: function(title: string, bot: Bot) {
            // Вызывается при получении голограммы (1 вызов на 1 линию голограммы)
            // ...
        }
    };
})();
```

### Пример скрипта

```javascript
//name=Имя скрипта
//description=Описание скрипта

import type {Bot, TitleEvent, MessageEvent} from "./types/objects"

(function () { // список функций (эвенты)
    return {
        onBotUpdate: function(bot: Bot) {
            if (bot.getTicksExisted() % 20 == 0) {
                // Выполнение кода каждые 20 тиков (1 секунда)
                bot.getPlayerOwner().sendDebugMessage("20 ticks passed");
            }
        },

        onBotChat: function(event: MessageEvent, bot: Bot) {
            bot.getPlayerOwner().sendDebugMessage('Received: ' + event.getText());
        },

        onBotGuiChange: function(type: string, bot: Bot) {
            if (type == 'ServerOpenWindowPacket') {
                var container = bot.getOpenContainer(); // получаем открытое gui
                if (container != null) { // проверяем что у бота открыто какое либо GUI
                    var title = container.getTitle(); // получаем название gui
                    var list = container.getItems(); // получаем список предметов gui

                    bot.getPlayerOwner().sendDebugMessage('открыл GUI: имя=' + title + ' размер=' + list.size());
                    bot.getPlayerOwner().sendDebugMessage('res ' + Utils.calc('2 + 2'));

                    container.slotClick(10); // кликаем на 10 слот
                }
            }
        },

        onBotTitle: function(event: TitleEvent, bot: Bot) {
            bot.getPlayerOwner().sendDebugMessage('бот ' + bot.getName() + ' получил тайтл с типом ' 
                + event.getType() + ' и сообщением ' + event.getMessage());
        },

        onBotHologramTitle: function(title: string, bot: Bot) {
            bot.getPlayerOwner().sendDebugMessage('Увидел голограмму ' + title + ' aboba');
        }
    };
})();
```


---

# Agent Instructions: 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:

```
GET https://docs.bebraproxy.net/nachalo-razrabotki.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
