Skip to content

Rendering

Draw from your script's Render callback. Make game decisions in Update, keep the values you want to show, and draw them in Render.

local status = "Ready"

function Render()
    RenderTopRightText(status, 12, 12, 14, Color("#00FF00"), true)
    local tc = GetAssignedPlayer():GetTownCenters()[1]
    if tc then RenderWorldCircle(tc:GetPosition(), 8, Color("#FFFF00")) end
end

Arguments. Screen positions are { x, y } in pixels. World positions are { x, y, z } in tiles, as Object:GetPosition() returns them. Missing coordinates read as 0. color is a Color or an ARGB integer and defaults to opaque white; thickness defaults to 1; segments defaults to 32; size defaults to the current font size. Draw calls return nothing, and draw nothing when the view or minimap isn't available.

Background renders. Scripts normally run on a background worker. While it is on, every Render (on the worker, or on the frame thread when the worker is idle) records its drawing and WololoLabs replays it every frame until the next Render, projecting world shapes with the current camera. In such a recorded pass:

  • GetScreenSize returns the size the last drawn frame had, so screen-relative placement is the same in every pass (0, 0 only before the first frame);
  • the queries GetZoom, GetCameraPosition, IsOnScreen, IsWorldPosOnScreen, WorldToScreen and WorldToMinimap return zero, false or nil, so prefer the world and minimap draw calls over projecting positions yourself;
  • RenderObjectBounds, RenderObjectBoundsFilled, RenderMinimapRect and RenderMinimapRectFilled draw nothing.

On screen

Call Draws
RenderText(text, position[, size[, color[, center[, border]]]]) Text. center = true centres it on position; border = true adds a black outline.
RenderTopRightText(text[, marginX = 12[, marginY = 12[, size[, color[, border]]]]]) Text anchored to the top-right corner.
RenderTextTable(id, rows, origin[, style]) A table with its top-left at origin; see Text tables. Returns width, height of the table named id as last drawn, 0, 0 before its first frame, so an overlay frame can fit it.
RenderLine(from, to[, color[, thickness]]) A line.
RenderCircle(center, radius[, color[, thickness[, segments]]]) A circle outline.
RenderCircleFilled(center, radius[, color[, segments]]) A filled circle.
RenderRect(min, max[, color[, rounding[, cornerFlags[, thickness]]]]) A rectangle outline between two corners.
RenderRectFilled(min, max[, color[, rounding[, cornerFlags]]]) A filled rectangle.

In the world

Call Draws
RenderWorldLine(from, to[, color[, thickness]]) A line on the map.
RenderWorldPolyline(points[, color[, thickness[, closed]]]) One joined line through the points; closed = true joins the last to the first. Needs two points.
RenderWorldRect(center, halfWidth, halfHeight[, color[, thickness]]) A rectangle outline. halfWidth = 3 is 6 tiles wide.
RenderWorldRectFilled(center, halfWidth, halfHeight[, color]) A filled rectangle.
RenderWorldCircle(center, radius[, color[, thickness[, segments]]]) A circle outline. segments is limited to 8..192; a radius of 0 or less draws nothing.
RenderWorldCircleFilled(center, radius[, color[, segments]]) A filled circle.
RenderWorldConvexFilled(points[, color]) A filled convex shape, points in order around it. Needs three points.
RenderWorldText(text, position[, size[, color[, center[, border]]]]) Text at a map position.
RenderWorldLabel(text, position[, size[, textColor[, backgroundColor[, offsetY]]]]) Text on a filled box, centred on a map position. The background defaults to translucent black; offsetY moves it by screen pixels, negative is up.
RenderWorldButton(id, text, position[, style]) A clickable button over a map position; the game does not get the click. Start id with your script's own prefix and read clicks with TakeButtonClicks. Optional style: offsetX, offsetY (screen pixels), alpha 0.1-1 (default 0.6), scale 0.5-2 (default 0.8). Draws nothing off screen.
TakeButtonClicks(prefix) Ids of your world buttons clicked since the last call whose id starts with prefix, oldest first; other scripts' clicks stay queued. Call it from Update: buttons are drawn on the frame thread. At most 64 clicks wait.
RenderObjectBounds(object[, color[, thickness]]) The outline of an object's footprint.
RenderObjectBoundsFilled(object[, color]) The filled footprint.

A shape with a point that can't be projected is not drawn.

On the minimap

Positions are world positions; the API places them on the minimap.

Call Draws
RenderMinimapDot(position, radius[, color]) A dot.
RenderMinimapLine(from, to, thickness[, color]) A line. Note thickness comes before color and is required.
RenderMinimapRect(center, halfWidth, halfHeight, color, thickness) A rectangle outline. thickness is required, so pass nil for the default colour.
RenderMinimapRectFilled(center, halfWidth, halfHeight[, color]) A filled rectangle.

View and camera

Call Returns
GetScreenSize() The game window's drawing area in pixels, as a Vector2.
GetScreenPanelRect(name) Where the game placed a HUD panel, as screen pixels { x, y, width, height }. "MapPanel" is the game's minimap. Returns nil, "panel not shown" when the panel is hidden or no match is on screen, and nil, "panel rectangles unavailable" when the game screen or its layout cannot be read. It follows resolution, UI scale and HUD changes as the game makes them.
IsOnScreen(position) true when a screen position is inside the window.
IsWorldPosOnScreen(position) true when a world position is in the camera's view.
WorldToScreen(position) The screen position of a world position, or nil.
WorldToMinimap(position) The minimap position, in screen pixels, of a world position, or nil.
GetCameraPosition() The map point at the camera's centre, or nil.
GetZoom() The camera zoom, or nil.
SetCameraPosition(position) Moves the local camera now. Returns nothing, or nil, "native camera control unavailable". It is not a game command.

Text tables

RenderTextTable draws aligned columns of text, numbers, game icons and progress bars, measured when the frame is drawn, so it is safe from a Render that runs on the worker.

rows is an array. Each row is an array of cells, or the string "-" for a separator line. A row may also have color (its text colour), accent (a thin bar at its left in that colour) and band (a background band in that colour). A cell is text, a number, or a table:

Cell field Meaning
text The cell's text.
detail Smaller, dimmer text after it, such as "/3" beside a value.
color, detailColor Colours for the two texts; color defaults to the row's.
icon { kind = "unit", "research" or "resource", id }: a game icon before the text; id from GetIconId.
bar, barColor A progress bar, 0 to 1, after the text.
Style field Meaning
size, scale Text size in pixels (default the overlay font) and a multiple of it.
align Per column: "left" (default), "right" or "center".
background, border, rounding The panel behind the table; none by default. rounding defaults to 6.
padding, columnGap, rowGap Spacing in pixels.
iconScale, detailScale, barWidth Icon and detail size as multiples of the text size (1.25, 0.85), and bar width in pixels.

Columns are as wide as their widest cell.

Batches and overlay frames

Use a batch when a script draws thousands of shapes, such as every unit on a minimap or a box over every unit on the map. Build it in Update and draw it in Render with one call. A frame keeps drawing the batch it was given while Update rebuilds it, so a rebuild never changes a frame halfway.

Call Does
RenderBatch() A new, empty batch of shapes that stays between frames.
RenderDrawBatch(batch[, origin[, scale]]) Draws every shape into a frame at origin + point * scale, behind the WololoLabs windows; each point's z is ignored. origin defaults to { x = 0, y = 0 }; scale is a { x, y } or one number, default 1.
RenderDrawWorldBatch(batch[, { layer }]) Draws every shape on the game view, its points taken as map positions (tiles, z the height) and projected through the camera when the frame is drawn, so the batch follows each pan and zoom without a rebuild. Boxes and circles lie on the ground. Draws nothing while there is no game view. layer = "world" (the default) draws in call order under every window. layer = "top" draws over every "world" batch but still under the mod's windows, and leaves out any shape touching a game HUD panel (command panel, minimap, resource bar, menus, chat and the rest), so the batch never covers the game's UI. When the panel rectangles cannot be read, a top batch is not drawn and the log says so once.
RenderSetChams(players[, gaiaTypes]) Draws objects hidden by fog as flat silhouettes of their real sprites. players maps player ids to colours for their units and buildings; gaiaTypes maps gaia object types (resources, animals, trees) to colours, at most 23 distinct ones. A colour is an ARGB integer or a colour table, read as other Render calls read it. Anything without a colour stays hidden as usual, and no colours turn chams off. The game no longer treats those objects as drawn, so they cannot be hovered, selected or targeted. Returns true, or false and a reason when this game build cannot draw them. Silhouettes are drawn under the WololoLabs windows and over the game's interface.
RenderSetChamsHealthBars(shown) Whether the silhouettes RenderSetChams draws for players' units and buildings show the game's health bar, as it shows one for a selected unit. Gaia silhouettes never do. Off at start.
RenderOverlayFrame(id, rect[, movable]) Submits a named screen frame { x, y, width, height } and returns where it stands.
SetOverlayFrame(id, rect) Moves and sizes a frame the next time it is submitted, even mid-drag.

A batch has these methods. color is a Color or an ARGB integer such as 0xAAFF0000 (cheaper: no table per shape) and defaults to opaque white. center, from, to and anchor are tables with x, y and an optional z (default 0), so a Vector3 from object:GetPosition() works as it is. Sizes are in the batch's units, except dot radii and text, which stay in screen pixels. segments is clamped to 8-192.

Method Does
batch:AddQuadFilled(x1, y1, x2, y2, x3, y3, x4, y4[, color]) Adds a filled quad, corners in drawing order.
batch:AddQuad(x1, y1, x2, y2, x3, y3, x4, y4[, color[, thickness]]) Adds a quad outline; thickness defaults to 1.
batch:AddBox(center, halfWidth, halfHeight[, color[, thickness]]) Adds the outline of a box from center - half to center + half.
batch:AddBoxFilled(center, halfWidth, halfHeight[, color]) Adds a filled box.
batch:AddLine(from, to[, color[, thickness]]) Adds a line.
batch:AddCircle(center, radius[, color[, thickness[, segments]]]) Adds a circle outline; segments defaults to 32.
batch:AddCircleFilled(center, radius[, color[, segments]]) Adds a filled circle.
batch:AddDot(center, pixelRadius[, color[, segments]]) Adds a filled circle whose radius is in screen pixels; segments defaults to 16.
batch:AddText(text, anchor[, color[, style]]) Adds text at anchor. Optional style: size (default the overlay font), offsetX, offsetY (screen pixels), centered, outlined. One style table can serve every call.
batch:AddIcon(kind, iconId, anchor[, style]) Adds the game's own icon, a square of screen pixels centred on anchor. kind is "unit", "research" or "resource" and iconId comes from GetIconId. Optional style: size (8 to 128, default 32), offsetX, offsetY (screen pixels), alpha (0.1 to 1, default 1), progress (0 to 1 draws a bar under the icon) and barColor. An icon with no file, or id -1, draws as ? and is logged once.
batch:Clear() Removes every shape.
batch:GetCount() The number of shapes.

Both draw calls skip shapes wholly off screen. A batch holds at most 200,000 shapes. A coordinate, size, thickness, origin or scale that is not a finite number, or a frame field that is missing, not finite, or a width or height below 1, raises a Lua error.

With movable = true, RenderOverlayFrame shows the frame's bounds in a transparent window the player can drag and resize, and returns where the frame stands, which can lag a drag by a frame; rect only places a frame that has no position yet. With movable = false it draws nothing and returns rect. The frame does not save itself: save the result in your settings when it changes. Use SetOverlayFrame when a setting changes or to reset a layout, never every frame with RenderOverlayFrame's result, which would stop a drag.

Store batch corners in frame units, 0 to 1, and draw with the frame's position as origin and its size as scale, so moving or resizing the frame doesn't need a rebuild.

local dots = RenderBatch()
local frame = { x = 1555, y = 890, width = 350, height = 190 }

function Update()
    dots:Clear()
    dots:AddQuadFilled(0.49, 0.49, 0.49, 0.51, 0.51, 0.51, 0.51, 0.49, 0xAAFF0000)
end

function Render()
    local placed = RenderOverlayFrame("my-frame", frame, true)
    RenderDrawBatch(dots, { x = placed.x, y = placed.y }, { x = placed.width, y = placed.height })
end

A batch of map positions drawn with RenderDrawWorldBatch follows the camera the same way:

local boxes = RenderBatch()
local nameStyle = { size = 16, offsetY = 30, centered = true, outlined = true }

function Update()
    boxes:Clear()
    for _, object in ipairs(GetIndexedObjects(2, -1) or {}) do
        local position = object:GetPosition()
        if position then
            boxes:AddBox(position, 0.5, 0.5, 0xFFFF0000, 2)
            boxes:AddText(object:GetMasterName(), position, 0xFFFFFFFF, nameStyle)
        end
    end
end

function Render()
    RenderDrawWorldBatch(boxes)
end

The view can be unavailable while the game changes state; keep Render free of game logic so a missed frame doesn't matter.