Plugin menus and HUD
Settings menu
With ui.menu, a plugin can register a declarative page. Supported controls are text, button, switch, slider, choice, text_input, and section.
lua
local state = {
enabled = samp.storage.get("enabled", true),
size = samp.storage.get("size", 16)
}
samp.ui.menu.register({
id = "settings",
title = "Example settings",
controls = {
{
type = "switch",
id = "enabled",
title = "Enabled",
value = state.enabled
},
{
type = "slider",
id = "size",
title = "Text size",
value = state.size,
min = 10,
max = 32,
step = 1
}
}
})
samp.events.on("ui.control_changed", function(event)
if event.pageId == "settings" then
local id = event.controlId
state[id] = event.value
samp.storage.set(id, event.value)
end
end)Control changes arrive through ui.control_changed. Validate pageId and controlId before using the value.
HUD drawing
With ui.draw, drawing commands may be submitted only from draw.hud.
lua
samp.events.on("draw.hud", function()
samp.draw.text({
text = "Plugin active",
x = 24,
y = 80,
size = 16,
color = 0xFFFF8C42
})
samp.draw.progress_bar({
x1 = 24,
y1 = 108,
x2 = 204,
y2 = 116,
value = 0.75,
color = 0xFFFF6B35,
background_color = 0x66000000
})
end)Available primitives include text, lines, rectangles, filled rectangles, circles, progress bars, package images, and world-to-screen projection. Colors use 0xAARRGGBB.
Performance
Drawing is rebuilt each frame, so:
- cache text and state outside the callback;
- use
samp.format.number()for bounded number formatting; - reuse image resources;
- avoid storage access and large loops in
draw.hud; - respect slow-callback warnings before the timeout threshold is reached.