draw
Draw on the overlay: shapes, text, 3D lines, images and fonts.
Draw from on_frame. Calls anywhere else, and while the game is not on screen, do nothing. render is another name for the same table.
Positions are screen pixels from the top-left corner. Sizes are pixels. Colours are packed integers from color(). 3D functions take vectors in game units: {x = …, y = …, z = …}.
| Function | What it does |
|---|---|
draw.screen() | Screen size in pixels. |
draw.line(x1, y1, x2, y2, col[, thickness]) | A straight line. |
draw.rect(x, y, w, h, col[, rounding][, thickness]) | A rectangle outline. |
draw.rect_filled(x, y, w, h, col[, rounding]) | A filled rectangle. |
draw.circle(x, y, radius, col[, thickness]) | A circle outline. |
draw.circle_filled(x, y, radius, col) | A filled circle. |
draw.text(x, y, text, col[, size]) | Text in the menu font. (x, y) is the top-left corner of the text. |
draw.text_size(text[, size]) | How big the text will be. Use it to centre or right-align. |
draw.text_outline(x, y, text, col[, size]) | Text with a thin black outline, readable on any background. |
draw.gradient(x, y, w, h, col1, col2[, horizontal]) | A rectangle that fades from one colour to another. |
draw.polygon(points, col) | A filled convex shape (triangle, arrow, diamond). Concave shapes draw wrong. |
draw.polyline(points, col[, thickness][, closed]) | Connected lines through the points. |
draw.world_to_screen(x, y, z) | Turns a world position into screen pixels. Takes three numbers, not a vector. |
draw.line3d(a, b, col[, thickness]) | A line between two world points. Drawn only when both ends are in front of the camera. |
draw.circle3d(center, radius, col[, thickness]) | A flat circle on the ground around a world point (32 segments). |
draw.box3d(min, max, col[, thickness]) | A 3D box outline between two corners. |
draw.load_image(file) | Loads a PNG or JPG from the script's data folder. Do it once, outside on_frame. |
draw.load_image_data(bytes) | Loads an image from bytes in memory, for example the body of an http.get reply. |
draw.image(handle, x, y, w, h[, tint][, rounding]) | Draws an image. |
draw.image_size(handle) | Original size of a loaded image. 0, 0 for a bad handle. |
draw.load_font(file[, size]) | Loads a .ttf, .otf or .ttc font. Looks in the script's data folder first, then in Windows\Fonts. |
draw.font_ready(handle) | True once the font can be used. |
draw.text_font(handle, x, y, text, col[, size]) | Text in a loaded font. Uses the menu font until the font is ready. |
draw.text_size_font(handle, text[, size]) | Text size in a loaded font. |
#draw.screen
draw.screen()Screen size in pixels.
Returns
local w, h = draw.screen()
draw.text(w / 2, h / 2, "centre", white)#draw.line
draw.line(x1, y1, x2, y2, col[, thickness])A straight line.
Arguments
x1, y1numberx2, y2numbercolcolorthicknessnumberoptional#draw.rect
draw.rect(x, y, w, h, col[, rounding][, thickness])A rectangle outline.
Arguments
x, ynumberw, hnumbercolcolorroundingnumberoptionalthicknessnumberoptional#draw.rect_filled
draw.rect_filled(x, y, w, h, col[, rounding])A filled rectangle.
Arguments
x, ynumberw, hnumbercolcolorroundingnumberoptionaldraw.rect_filled(20, 20, 180, 60, color(12, 14, 18, 210), 8)#draw.circle
draw.circle(x, y, radius, col[, thickness])A circle outline.
Arguments
x, ynumberradiusnumbercolcolorthicknessnumberoptional#draw.circle_filled
draw.circle_filled(x, y, radius, col)A filled circle.
Arguments
x, ynumberradiusnumbercolcolor#draw.text
draw.text(x, y, text, col[, size])Text in the menu font. (x, y) is the top-left corner of the text.
Arguments
x, ynumbertextstringcolcolorsizenumberoptional#draw.text_size
draw.text_size(text[, size])How big the text will be. Use it to centre or right-align.
Arguments
textstringsizenumberoptionalReturns
local tw, th = draw.text_size(label, 16)
draw.text(x - tw / 2, y, label, white, 16)#draw.text_outline
draw.text_outline(x, y, text, col[, size])Text with a thin black outline, readable on any background.
Arguments
x, ynumbertextstringcolcolorsizenumberoptional#draw.gradient
draw.gradient(x, y, w, h, col1, col2[, horizontal])A rectangle that fades from one colour to another.
Arguments
x, y, w, hnumbercol1colorcol2colorhorizontalbooleanoptional#draw.polygon
draw.polygon(points, col)A filled convex shape (triangle, arrow, diamond). Concave shapes draw wrong.
Arguments
pointsnumber[]{x1, y1, x2, y2, ...}, at least 3 points, up to 128.colcolordraw.polygon({ 100, 100, 120, 140, 80, 140 }, color(255, 200, 0))#draw.polyline
draw.polyline(points, col[, thickness][, closed])Connected lines through the points.
Arguments
pointsnumber[]colcolorthicknessnumberoptionalclosedbooleanoptional#draw.world_to_screen
draw.world_to_screen(x, y, z)Turns a world position into screen pixels. Takes three numbers, not a vector.
Arguments
x, y, znumberReturns
local sx, sy, ok = draw.world_to_screen(p.head.x, p.head.y, p.head.z + 10)
if ok then draw.text(sx, sy, p.name, white) end#draw.line3d
draw.line3d(a, b, col[, thickness])A line between two world points. Drawn only when both ends are in front of the camera.
Arguments
a, bvectorcolcolorthicknessnumberoptional#draw.circle3d
draw.circle3d(center, radius, col[, thickness])A flat circle on the ground around a world point (32 segments).
Arguments
centervectorradiusnumbercolcolorthicknessnumberoptionaldraw.circle3d(me.pos, 60, color(120, 200, 255), 2)#draw.box3d
draw.box3d(min, max, col[, thickness])A 3D box outline between two corners.
Arguments
min, maxvectorcolcolorthicknessnumberoptional#draw.load_image
draw.load_image(file)Loads a PNG or JPG from the script's data folder. Do it once, outside on_frame.
Arguments
filestringscripts/data/<script>/.Returns
- Up to 16 images per script, 2048 x 2048, 8 MB. Images are freed when the script unloads or reloads.
local logo = draw.load_image("logo.png")#draw.load_image_data
draw.load_image_data(bytes)Loads an image from bytes in memory, for example the body of an http.get reply.
Arguments
bytesstringReturns
#draw.image
draw.image(handle, x, y, w, h[, tint][, rounding])Draws an image.
Arguments
handleintegerx, y, w, hnumbertintcoloroptionalcolor(255, 255, 255, a) to fade.roundingnumberoptional#draw.image_size
draw.image_size(handle)Original size of a loaded image. 0, 0 for a bad handle.
Arguments
handleintegerReturns
#draw.load_font
draw.load_font(file[, size])Loads a .ttf, .otf or .ttc font. Looks in the script's data folder first, then in Windows\Fonts.
Arguments
filestringarial.ttf or segoeuib.ttf.sizenumberoptionalReturns
- 8 fonts in total across all scripts. Loading the same file and size again returns the same handle. Covers Latin, Latin Extended and Cyrillic.
local big = draw.load_font("segoeuib.ttf", 28)#draw.font_ready
draw.font_ready(handle)True once the font can be used.
Arguments
handleintegerReturns
#draw.text_font
draw.text_font(handle, x, y, text, col[, size])Text in a loaded font. Uses the menu font until the font is ready.
Arguments
handleintegerx, ynumbertextstringcolcolorsizenumberoptional#draw.text_size_font
draw.text_size_font(handle, text[, size])Text size in a loaded font.
Arguments
handleintegertextstringsizenumberoptional