What Are TextDraws in SA-MP?
TextDraws are SA-MP's built-in system for rendering text and graphical elements directly on a player's screen — without requiring any client-side modifications. They're used to create everything from simple status bars to complex, animated HUD interfaces. Unlike in-game objects or labels, TextDraws exist in screen space, meaning they stay fixed on the player's view regardless of where the camera points.
Types of TextDraws
| Type | Function | Scope |
|---|---|---|
| Global TextDraw | TextDrawCreate |
Visible to all players |
| Player TextDraw | CreatePlayerTextDraw |
Visible to one player only |
For HUD elements that vary per player (like health bars or names), always use Player TextDraws. Global TextDraws are better for server-wide announcements or background watermarks.
Creating a Basic TextDraw
Here's a minimal example that shows a welcome message:
new Text:WelcomeTD;
public OnGameModeInit()
{
WelcomeTD = TextDrawCreate(320.0, 240.0, "Welcome to the Server!");
TextDrawAlignment(WelcomeTD, 2); // Center align
TextDrawColor(WelcomeTD, 0xFFFFFFFF);
TextDrawFont(WelcomeTD, 1);
TextDrawLetterSize(WelcomeTD, 0.4, 1.6);
return 1;
}
public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, WelcomeTD);
return 1;
}
Designing a Health Bar with TextDraw Boxes
One of the most popular visual effects is a custom health bar. This is achieved using box-style TextDraws layered together. The technique involves:
- A dark background box (the bar's track).
- A coloured foreground box (the fill level).
- A text label showing the numeric value.
Update the foreground box's width dynamically using TextDrawTextSize combined with PlayerTextDrawSetString or by recreating the draw on each health change event.
Using Sprites and Model Previews
TextDraws aren't limited to text. You can display:
- Sprites — GTA texture sprites using
TextDrawFont(td, 4)andTextDrawSetPreviewModelcombinations. - 3D Model Previews — Rotating 3D weapon or vehicle models using
TextDrawFont(td, 5)andTextDrawSetPreviewModel(td, modelid).
Model previews are particularly effective in weapon shop menus and vehicle selection screens, giving players a clear visual of what they're choosing.
Animation and Selectability
TextDraws can be made clickable using TextDrawShowForPlayer with select mode enabled via SelectTextDraw. This is the foundation for in-game menus and custom UIs. When a player clicks a TextDraw, OnPlayerClickTextDraw fires, allowing you to handle the interaction.
Performance Considerations
- SA-MP limits you to 2048 global TextDraws and 256 player TextDraws per player.
- Always destroy TextDraws when they're no longer needed using
TextDrawDestroyorPlayerTextDrawDestroy. - Avoid updating TextDraws on every server tick — use timers or event-driven updates instead.
Tools to Help You Design TextDraws
Designing TextDraws by hand with raw coordinates is tedious. The community has developed TextDraw editors — in-game and standalone tools that let you visually drag and position elements, then export the generated Pawn code directly. Search the SA-MP forums for the latest TextDraw editor releases.