leet.ui

A script can show the player a toast notification, ask a yes/no question and draw over the game. Notifications and questions appear in the leet interface; nothing goes to the game chat.

The player can turn script notifications and questions off in Settings → General. The script gets no error then: the notification is simply not shown, and the question gets the answer null at once.

FunctionDoes
notifyShows a toast notification.
promptAsks the player a yes/no question; the answer comes to a callback.
screenReturns the game screen size in pixels.
drawLineDraws a line. Inside onDraw only.
drawRectDraws a rectangle outline. Inside onDraw only.
fillRectDraws a filled rectangle. Inside onDraw only.
drawCircleDraws a circle outline. Inside onDraw only.
fillCircleDraws a filled circle. Inside onDraw only.
fillTriangleDraws a filled triangle. Inside onDraw only.
drawPolylineDraws connected line segments, open or closed. Inside onDraw only.
drawTextDraws text. Inside onDraw only.
textSizeMeasures the box drawText would fill. Works anywhere.

leet.ui.notify

TypeScript
leet.ui.notify(text: string, kind?: "info" | "success" | "warning" | "error"): undefined

Shows a toast notification. Returns nothing.

JavaScript
leet.ui.notify('Fishing bot started', 'success');

Parameters

  • text (string): the message. Up to 160 Latin or 80 Cyrillic characters; longer text is cut.
  • kind (string, optional): "info" (default), "success", "warning" or "error". Case-insensitive.

Keep in mind

  • If the player turned script notifications off (Settings → General, the Notifications switch or its Scripts category), the toast is not shown and the call still succeeds.
  • Identical notifications posted at the same moment are shown once.

Careful. Only a few notifications get through per frame; the rest are dropped. Do not call notify every frame (for example from the render event or onDraw); report changes instead.

Errors: leet: text must be a string (text is not a string), leet: unknown notice kind (kind is not one of the four).

leet.ui.prompt

TypeScript
leet.ui.prompt(text: string, callback: (answer: boolean | null) => void,
               options?: { accept?: string; decline?: string; seconds?: number }): undefined

Asks the player a yes/no question on a card with two buttons, like a friend's teleport request. The script does not wait: the function returns at once, and the answer comes to callback later, once.

JavaScript
leet.ui.prompt('Admin nearby. Pause the bot?', (answer) => {
    if (answer === true) pauseBot();
    else if (answer === null) leet.ui.notify('No answer, the bot keeps going');
}, { accept: 'Pause', decline: 'Keep going', seconds: 20 });

Parameters

  • text (string): the question. Up to 160 Latin or 80 Cyrillic characters; longer text is cut.
  • callback (function): gets true (accepted), false (declined) or null (no answer: the time ran out, or the player turned script prompts off).
  • options.accept (string, optional): the accept button's words, up to 32 bytes; (Y) is added. Default: "Accept (Y)".
  • options.decline (string, optional): the decline button's words, up to 32 bytes; (N) is added. Default: "Decline (N)".
  • options.seconds (number, optional): how long the card waits for an answer, 3 to 60. Default 15.

Keep in mind

  • With the menu hidden, the player answers with Y and N, unless the server's own cursor is on screen (for example, in chat). With the menu open, the player clicks a button.
  • Cards wait in a queue; the one on screen takes the answer.
  • If the player turned prompts off in Settings → General (Prompts, or its Scripts category), no card is shown and callback gets null at once.
  • A script's Stop closes its cards, and a reconnect closes every card. Their callbacks never run.
ErrorWhen
leet: invalid prompt argumentstext is not a string, callback is not a function, options is not an object, a button's words are not a string, or seconds is outside 3–60.
leet: too many promptsThe script already has 4 questions waiting for an answer, or the client's queue is full.

Drawing on screen

The draw calls (drawLine, drawRect, fillRect, drawCircle, fillCircle, fillTriangle, drawPolyline, drawText) put simple shapes and text on the game screen. They work only inside a leet.events.onDraw handler; anywhere else they throw leet: draw calls work only inside onDraw.

Coordinates. Screen pixels, with (0, 0) in the top-left corner; x grows to the right, y grows down. leet.ui.screen() gives the screen size. Every coordinate, size and radius must be a finite number within ±100000.

Colors. A color is a number 0xAARRGGBB: alpha, red, green, blue, one byte each. It is a whole number from 0x00000000 to 0xFFFFFFFF.

ColorValue
Opaque white0xFFFFFFFF
Opaque red0xFFFF0000
Opaque green0xFF00FF00
Half-transparent black0x80000000

Careful. Do not forget the alpha. 0xFF0000 (written by habit as "red") is 0x00FF0000, with alpha 00, so it is fully invisible. Always write all eight digits, starting with the alpha.

Order and layering. Later draw calls are drawn over earlier ones, so draw backgrounds first and text last. Everything you draw appears under the client's menu and HUD.

Limits.

LimitValueError when exceeded
Draw calls per frame, all scripts together4096leet: too many draw calls
Text length per drawText256 charactersleet: text is too long
Points in all drawPolyline calls together, per frame65536leet: too many draw calls
Points per drawPolyline2 to 1024leet: invalid draw arguments
Coordinates, sizes, radiuswithin ±100000leet: invalid draw arguments
Corner rounding0 to 100000leet: invalid draw arguments
Line thickness0.5 to 50leet: invalid draw arguments
Text size6 to 128leet: invalid draw arguments

leet.ui.screen

TypeScript
leet.ui.screen(): { width: number, height: number }

Returns the game screen size { width, height } in pixels. Works anywhere, not only inside onDraw, and never throws.

JavaScript
const { width, height } = leet.ui.screen();
mp.console.logInfo(`game screen: ${width} x ${height}`);

No parameters.

Keep in mind

  • Right after the game window appears, both values can be 0 for a moment. Skip drawing until they are not.

leet.ui.drawLine

TypeScript
leet.ui.drawLine(x1: number, y1: number, x2: number, y2: number, color: number, thickness?: number): undefined

Draws a straight line from (x1, y1) to (x2, y2). Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const { width, height } = leet.ui.screen();
    leet.ui.drawLine(0, height - 2, width, height - 2, 0xC0FFC107, 2); // underline the bottom of the screen
});

leet.events.onUnload(offDraw);

Parameters

  • x1, y1 (number): start point, in pixels.
  • x2, y2 (number): end point, in pixels.
  • color (number): 0xAARRGGBB.
  • thickness (number, optional): line width in pixels, 0.5 to 50. Default 1.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a coordinate, the color or the thickness is missing, not a number, out of range, or the color is not a whole number).

leet.ui.drawRect

TypeScript
leet.ui.drawRect(x: number, y: number, width: number, height: number, color: number, thickness?: number, rounding?: number): undefined

Draws the outline of a rectangle whose top-left corner is (x, y), with rounded corners if you want them. Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const { width, height } = leet.ui.screen();
    const size = 200;
    const x = (width - size) / 2;
    const y = (height - size) / 2;
    leet.ui.drawRect(x, y, size, size, 0xFFFFFFFF, 2);            // sharp corners
    leet.ui.drawRect(x - 10, y - 10, size + 20, size + 20, 0x80FFFFFF, 1, 12); // rounded
});

leet.events.onUnload(offDraw);

Parameters

  • x, y (number): top-left corner, in pixels.
  • width, height (number): size, in pixels.
  • color (number): 0xAARRGGBB.
  • thickness (number, optional): line width in pixels, 0.5 to 50. Default 1. Pass undefined to keep the default when you only want to set rounding.
  • rounding (number, optional): corner radius in pixels, 0 to 100000. Default 0, sharp corners.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a number, the color, the thickness or the rounding is missing, not a number, out of range, or the color is not a whole number).

leet.ui.fillRect

TypeScript
leet.ui.fillRect(x: number, y: number, width: number, height: number, color: number, rounding?: number): undefined

Draws a filled rectangle whose top-left corner is (x, y), with rounded corners if you want them. Handy as a background for text. Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    leet.ui.fillRect(20, 200, 300, 28, 0xB0000000, 6); // background, rounded
});

leet.events.onUnload(offDraw);

Parameters

  • x, y (number): top-left corner, in pixels.
  • width, height (number): size, in pixels.
  • color (number): 0xAARRGGBB.
  • rounding (number, optional): corner radius in pixels, 0 to 100000. Default 0, sharp corners.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a number, the color or the rounding is missing, not a number, out of range, or the color is not a whole number).

Tip. The recipes "A watermark panel at the top center" and "A panel sized to its text" build a full panel with a border and text.

leet.ui.drawCircle

TypeScript
leet.ui.drawCircle(x: number, y: number, radius: number, color: number, thickness?: number): undefined

Draws the outline of a circle centered at (x, y). Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const { width, height } = leet.ui.screen();
    leet.ui.drawCircle(width / 2, height / 2, 120, 0x80FFFFFF, 1.5); // FOV circle
});

leet.events.onUnload(offDraw);

Parameters

  • x, y (number): center, in pixels.
  • radius (number): radius, in pixels.
  • color (number): 0xAARRGGBB.
  • thickness (number, optional): line width in pixels, 0.5 to 50. Default 1.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a number, the color or the thickness is missing, not a number, out of range, or the color is not a whole number).

leet.ui.fillCircle

TypeScript
leet.ui.fillCircle(x: number, y: number, radius: number, color: number): undefined

Draws a filled circle centered at (x, y). Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const { width } = leet.ui.screen();
    leet.ui.fillCircle(width - 24, 24, 8, 0xFF34C759); // green dot in the top-right corner
});

leet.events.onUnload(offDraw);

Parameters

  • x, y (number): center, in pixels.
  • radius (number): radius, in pixels.
  • color (number): 0xAARRGGBB.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a number or the color is missing, not a number, out of range, or the color is not a whole number).

leet.ui.fillTriangle

TypeScript
leet.ui.fillTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: number): undefined

Draws a filled triangle with corners (x1, y1), (x2, y2) and (x3, y3). Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const cx = leet.ui.screen().width / 2;
    leet.ui.fillTriangle(cx, 60, cx - 22, 98, cx + 22, 98, 0xE0FFC107);
});

leet.events.onUnload(offDraw);

Parameters

  • x1, y1 (number): first corner, in pixels.
  • x2, y2 (number): second corner, in pixels.
  • x3, y3 (number): third corner, in pixels.
  • color (number): 0xAARRGGBB.

Errors: leet: draw calls work only inside onDraw (called outside an onDraw handler), leet: too many draw calls (the per-frame draw call limit is reached), leet: invalid draw arguments (a coordinate or the color is missing, not a number, out of range, or the color is not a whole number).

leet.ui.drawPolyline

TypeScript
leet.ui.drawPolyline(points: number[], color: number, thickness?: number, closed?: boolean): undefined

Draws line segments through a list of points: from the first point to the second, from the second to the third, and so on. With closed, the last point is also joined to the first. Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const { width, height } = leet.ui.screen();
    const points = [];
    for (let i = 0; i < 6; i++) {
        const a = (Math.PI / 3) * i;
        points.push(width / 2 + Math.cos(a) * 40, height / 2 + Math.sin(a) * 40);
    }
    leet.ui.drawPolyline(points, 0xFFFFFFFF, 2, true); // a closed hexagon
});

leet.events.onUnload(offDraw);

Parameters

  • points (number[]): a flat array [x1, y1, x2, y2, ...] of 2 to 1024 points, so an even count of numbers, at least 4. Every number is a coordinate in pixels within ±100000.
  • color (number): 0xAARRGGBB.
  • thickness (number, optional): line width in pixels, 0.5 to 50. Default 1.
  • closed (boolean, optional): true joins the last point to the first. Default false.
ErrorWhen
leet: draw calls work only inside onDrawCalled outside an onDraw handler.
leet: too many draw callsThe per-frame draw call limit is reached, or this call would exceed 65536 polyline points in the frame.
leet: invalid draw argumentspoints is not an array; it has fewer than 4 numbers, an odd count, or more than 1024 points; a point is not a number or is out of range; or the color or thickness is invalid.

leet.ui.drawText

TypeScript
leet.ui.drawText(text: string, x: number, y: number, color: number, size?: number, centered?: boolean): undefined

Draws text with a small shadow for readability. Returns nothing.

JavaScript
const offDraw = leet.events.onDraw(() => {
    const vehicle = mp.players.local.vehicle;
    if (!vehicle) return;
    const { width, height } = leet.ui.screen();
    const kmh = Math.round(vehicle.getSpeed() * 3.6);
    leet.ui.drawText(`${kmh}`, width / 2, height - 90, 0xFFFFFFFF, 40, true);
    leet.ui.drawText('km/h', width / 2, height - 45, 0xB0FFFFFF, 14, true);
});

leet.events.onUnload(offDraw);

Parameters

  • text (string): the text, up to 256 characters. \n starts a new line; an empty string draws nothing. Use textSize to measure it.
  • x (number): left edge of the text in pixels, or the horizontal center with centered.
  • y (number): top of the text, in pixels.
  • color (number): 0xAARRGGBB.
  • size (number, optional): text size in pixels, 6 to 128. Default 16.
  • centered (boolean, optional): true centers the text horizontally on x. Default false.
ErrorWhen
leet: draw calls work only inside onDrawCalled outside an onDraw handler.
leet: too many draw callsThe per-frame draw call limit is reached.
leet: text is too longtext is longer than 256 characters.
leet: invalid draw argumentstext is not a string, or a coordinate, the color or the size is missing, not a number, out of range, or the color is not a whole number.

Outside onDraw the call throws:

JavaScript
try {
    leet.ui.drawText('hello', 10, 10, 0xFFFFFFFF);
} catch (e) {
    mp.console.logError(e.message); // leet: draw calls work only inside onDraw
}

leet.ui.textSize

TypeScript
leet.ui.textSize(text: string, size?: number): { width: number, height: number }

Measures text: returns { width, height } in pixels, the size of the box that drawText(text, x, y, color, size) would fill. Works anywhere, not only inside onDraw.

JavaScript
const MARGIN = 16;

const offDraw = leet.events.onDraw(() => {
    const { width } = leet.ui.screen();
    const text = `Players online: ${mp.players.length}`;
    const box = leet.ui.textSize(text, 18);
    leet.ui.drawText(text, width - MARGIN - box.width, MARGIN, 0xFFFFFFFF, 18); // right-aligned
});

leet.events.onUnload(offDraw);

Parameters

  • text (string): the text to measure. \n starts a new line.
  • size (number, optional): text size in pixels, 6 to 128. Default 16. Use the same size you pass to drawText.

Keep in mind

  • width is the width of the widest line. It may be off by a pixel, and rare characters outside Latin and Cyrillic are estimated.
  • height is size times the number of lines.
  • An empty string gives width 0 and height equal to size.

Errors: leet: invalid draw arguments (text is not a string, or size is not a number or is outside 6 to 128).

Recipes

Report progress without flooding the screen

JavaScript
leet.ui.notify('Fishing bot started', 'success');

let casts = 0;
const timer = setInterval(() => {
    try {
        casts++;
        // ... bot logic ...
        if (casts % 50 === 0) leet.ui.notify(`Casts so far: ${casts}`);
    } catch (e) {
        clearInterval(timer);
        leet.ui.notify(`Bot error: ${e.message}`, 'error');
    }
}, 2000);

leet.events.onUnload(() => {
    clearInterval(timer);
    leet.ui.notify(`Fishing bot stopped after ${casts} casts`, 'warning');
});

Report events, not the state on every tick. onUnload runs on Stop, so the player sees the summary.

A watermark panel at the top center

JavaScript
const pad = (n) => String(n).padStart(2, '0');
const PANEL_W = 300;
const PANEL_H = 28;

const offDraw = leet.events.onDraw(() => {
    const { width } = leet.ui.screen();
    if (width === 0) return;

    const now = new Date();
    const text = `leet  |  ${mp.players.local.name}  |  ${pad(now.getHours())}:${pad(now.getMinutes())}`;
    const x = (width - PANEL_W) / 2;
    const y = 8;

    leet.ui.fillRect(x, y, PANEL_W, PANEL_H, 0xB0000000, 6);     // background, rounded
    leet.ui.drawRect(x, y, PANEL_W, PANEL_H, 0xFF4CAF50, 1, 6);  // border, same rounding
    leet.ui.drawText(text, width / 2, y + 6, 0xFFFFFFFF, 16, true); // centered text
});

leet.events.onUnload(offDraw);

The background is drawn first, the border and text over it. While screen() gives 0, the script draws nothing.

A status dot that turns red when an admin is near

JavaScript
let adminNear = 0;
const offAdmins = leet.events.onAdminNearby((e) => {
    adminNear += e.entered ? 1 : -1;
}, 150);

const offDraw = leet.events.onDraw(() => {
    const { width } = leet.ui.screen();
    const color = adminNear > 0 ? 0xFFFF3B30 : 0xFF34C759;
    leet.ui.fillCircle(width - 24, 24, 8, color);
});

leet.events.onUnload(() => {
    offAdmins();
    offDraw();
});

The counter goes up when an admin enters the radius and down when one leaves, so the dot stays red while at least one is near. Stop removes both subscriptions.

A warning sign while an admin is near

JavaScript
let adminNear = 0;
const offAdmins = leet.events.onAdminNearby((e) => {
    adminNear += e.entered ? 1 : -1;
}, 150);

const offDraw = leet.events.onDraw(() => {
    if (adminNear <= 0) return;
    const { width } = leet.ui.screen();
    const cx = width / 2;
    const top = 60;
    leet.ui.fillTriangle(cx, top, cx - 22, top + 38, cx + 22, top + 38, 0xE0FFC107);
    leet.ui.drawText('!', cx, top + 12, 0xFF000000, 22, true);
});

leet.events.onUnload(() => {
    offAdmins();
    offDraw();
});

The triangle is drawn before the exclamation mark, so the mark shows on top.

Speed graph of the last 10 seconds

JavaScript
const history = [];
const sample = setInterval(() => {
    const vehicle = mp.players.local.vehicle;
    history.push(vehicle ? vehicle.getSpeed() * 3.6 : 0);
    if (history.length > 100) history.shift();
}, 100);

const offDraw = leet.events.onDraw(() => {
    if (history.length < 2) return;
    const { height } = leet.ui.screen();
    const left = 20, bottom = height - 200, w = 300, h = 80, maxKmh = 200;

    leet.ui.fillRect(left, bottom - h, w, h, 0x90000000, 4);
    const points = [];
    history.forEach((kmh, i) => {
        points.push(left + (i / 99) * w, bottom - Math.min(kmh / maxKmh, 1) * h);
    });
    leet.ui.drawPolyline(points, 0xFF4FC3F7, 2);
});

leet.events.onUnload(() => {
    clearInterval(sample);
    offDraw();
});

A timer samples the speed 10 times a second, and onDraw only draws. The history.length < 2 check is there because a polyline needs at least 2 points.

A panel sized to its text

JavaScript
const PAD = 8;

const offDraw = leet.events.onDraw(() => {
    const pos = mp.players.local.position;
    const text = `X ${pos.x.toFixed(1)}\nY ${pos.y.toFixed(1)}\nZ ${pos.z.toFixed(1)}`;
    const box = leet.ui.textSize(text, 16);
    const x = 20;
    const y = 200;
    leet.ui.fillRect(x, y, box.width + PAD * 2, box.height + PAD * 2, 0xA0000000, 6);
    leet.ui.drawText(text, x + PAD, y + PAD, 0xFFFFFFFF, 16);
});

leet.events.onUnload(offDraw);

textSize gets the same size as drawText, so the background fits the three lines with a PAD margin.


Next: World