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.
| Function | Does |
|---|---|
notify | Shows a toast notification. |
prompt | Asks the player a yes/no question; the answer comes to a callback. |
screen | Returns the game screen size in pixels. |
drawLine | Draws a line. Inside onDraw only. |
drawRect | Draws a rectangle outline. Inside onDraw only. |
fillRect | Draws a filled rectangle. Inside onDraw only. |
drawCircle | Draws a circle outline. Inside onDraw only. |
fillCircle | Draws a filled circle. Inside onDraw only. |
fillTriangle | Draws a filled triangle. Inside onDraw only. |
drawPolyline | Draws connected line segments, open or closed. Inside onDraw only. |
drawText | Draws text. Inside onDraw only. |
textSize | Measures the box drawText would fill. Works anywhere. |
leet.ui.notify
leet.ui.notify(text: string, kind?: "info" | "success" | "warning" | "error"): undefinedShows a toast notification. Returns nothing.
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
notifyevery frame (for example from therenderevent oronDraw); 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
leet.ui.prompt(text: string, callback: (answer: boolean | null) => void,
options?: { accept?: string; decline?: string; seconds?: number }): undefinedAsks 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.
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): getstrue(accepted),false(declined) ornull(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
callbackgetsnullat once. - A script's Stop closes its cards, and a reconnect closes every card. Their callbacks never run.
| Error | When |
|---|---|
leet: invalid prompt arguments | text 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 prompts | The 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.
| Color | Value |
|---|---|
| Opaque white | 0xFFFFFFFF |
| Opaque red | 0xFFFF0000 |
| Opaque green | 0xFF00FF00 |
| Half-transparent black | 0x80000000 |
Careful. Do not forget the alpha.
0xFF0000(written by habit as "red") is0x00FF0000, with alpha00, 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.
| Limit | Value | Error when exceeded |
|---|---|---|
| Draw calls per frame, all scripts together | 4096 | leet: too many draw calls |
Text length per drawText | 256 characters | leet: text is too long |
Points in all drawPolyline calls together, per frame | 65536 | leet: too many draw calls |
Points per drawPolyline | 2 to 1024 | leet: invalid draw arguments |
| Coordinates, sizes, radius | within ±100000 | leet: invalid draw arguments |
| Corner rounding | 0 to 100000 | leet: invalid draw arguments |
| Line thickness | 0.5 to 50 | leet: invalid draw arguments |
| Text size | 6 to 128 | leet: invalid draw arguments |
leet.ui.screen
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.
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
0for a moment. Skip drawing until they are not.
leet.ui.drawLine
leet.ui.drawLine(x1: number, y1: number, x2: number, y2: number, color: number, thickness?: number): undefinedDraws a straight line from (x1, y1) to (x2, y2). Returns nothing.
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. Default1.
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
leet.ui.drawRect(x: number, y: number, width: number, height: number, color: number, thickness?: number, rounding?: number): undefinedDraws the outline of a rectangle whose top-left corner is (x, y), with rounded corners if you want them. Returns nothing.
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. Default1. Passundefinedto keep the default when you only want to setrounding.rounding(number, optional): corner radius in pixels, 0 to 100000. Default0, 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
leet.ui.fillRect(x: number, y: number, width: number, height: number, color: number, rounding?: number): undefinedDraws 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.
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. Default0, 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
leet.ui.drawCircle(x: number, y: number, radius: number, color: number, thickness?: number): undefinedDraws the outline of a circle centered at (x, y). Returns nothing.
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. Default1.
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
leet.ui.fillCircle(x: number, y: number, radius: number, color: number): undefinedDraws a filled circle centered at (x, y). Returns nothing.
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
leet.ui.fillTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color: number): undefinedDraws a filled triangle with corners (x1, y1), (x2, y2) and (x3, y3). Returns nothing.
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
leet.ui.drawPolyline(points: number[], color: number, thickness?: number, closed?: boolean): undefinedDraws 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.
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. Default1.closed(boolean, optional):truejoins the last point to the first. Defaultfalse.
| Error | When |
|---|---|
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, or this call would exceed 65536 polyline points in the frame. |
leet: invalid draw arguments | points 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
leet.ui.drawText(text: string, x: number, y: number, color: number, size?: number, centered?: boolean): undefinedDraws text with a small shadow for readability. Returns nothing.
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.\nstarts a new line; an empty string draws nothing. UsetextSizeto measure it.x(number): left edge of the text in pixels, or the horizontal center withcentered.y(number): top of the text, in pixels.color(number):0xAARRGGBB.size(number, optional): text size in pixels, 6 to 128. Default16.centered(boolean, optional):truecenters the text horizontally onx. Defaultfalse.
| Error | When |
|---|---|
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: text is too long | text is longer than 256 characters. |
leet: invalid draw arguments | text 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:
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
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.
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.\nstarts a new line.size(number, optional): text size in pixels, 6 to 128. Default16. Use the same size you pass todrawText.
Keep in mind
widthis the width of the widest line. It may be off by a pixel, and rare characters outside Latin and Cyrillic are estimated.heightissizetimes the number of lines.- An empty string gives
width0andheightequal tosize.
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
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
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
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
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
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
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.