← Tools
Dialog builder
Pick a style, write the title, the text and the buttons, try the dialog as a player would, and copy the code that shows it and handles the answer.
Each line is an item, which {RRGGBB} colours.
Preview
Click a row to pick it, and a button (or a double click) to answer. The arrows, Enter and Esc work as in the game.
Teleports
| Los Santos |
| San Fierro |
| Las Venturas |
| Mount Chiliad |
| Back |
Press a button in the preview to see what OnDialogResponse is given.
Within what the client holds.
Code
Code for
SA-MP and open.mp take this code just as it is: the choice only picks the includes it is compiled with.
Show the dialog
#define DIALOG_TELEPORTS 3
ShowPlayerDialog(playerid, DIALOG_TELEPORTS, DIALOG_STYLE_LIST, "Teleports", "Los Santos\nSan Fierro\nLas Venturas\n{FFFF00}Mount Chiliad\n{AAAAAA}Back", "Go", "Close");Handle the answer (if you have an OnDialogResponse already, add the if to it)
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == DIALOG_TELEPORTS)
{
if (!response)
{
// "Close" or Esc
return 1;
}
switch (listitem)
{
case 0: // Los Santos
{
}
case 1: // San Fierro
{
}
case 2: // Las Venturas
{
}
case 3: // Mount Chiliad
{
}
case 4: // Back
{
}
}
return 1;
}
return 0;
}Paste a ShowPlayerDialog to edit it
How SA-MP dialogs work
- A player sees one dialog at a time: ShowPlayerDialog replaces the one they have open, and an ID of -1 closes it.
- OnDialogResponse is given response 1 for the left button or Enter, and 0 for the right button or Esc, even when there is no right button.
- In a list, listitem is the row picked, from 0, and inputtext its text without colours. In a table it is the first column’s text, and the header row is not counted.
- Pawn compilers refuse very long lines, so a long text is put together piece by piece with strcat, in a string big enough for all of it.