A short tutorial that explains how to use the menu system of the game. This menu system is different to SA-MP dialogs and better reflects the traditional UI of the original game.
Menus in SA-MP
Menus look very complicated and difficult to script for the most players, although it isn't. Here I will show you how to create a simple menu. At the end we will have created a teleport menu.
First menu steps
First we have to create a menu. The prefix before is
Menu: this makes the variable the correct tag. There are different types for different uses such as
Text3D: etc. Write the following code near the top of your script:
Okay, we created the variable to store the menu. Now we have to create the menu and assign the variable we created to the menu. Type this into
Now a bit of an explanation about the CreateMenu arguments.
|title||The heading of the menu|
|columns||The number here defines how much columns are used (2 is maximum)|
|Float:x||The heigth position of the menu on screen (left to right)|
|Float:y||The width position of the menu on screen (up and down)|
|Float:col1width||The width of the first column|
|Float:col2width||The width of the second column|
Add some menu items
Ok, now we've got the Menu, but we need some items, under which you can choose in the menu. You add them underneath the
CreateMenu that we made earlier.
The explanation for AddMenuItem:
|menuid||The menuid of the menu where the item shall be displayed|
|column||The column in which the item shall be shown|
|text||The text of the item|
Creating the effects for the items
Okay, now that we have created a full menu with items what should happen when you choose an item? In our example we want to make a teleportmenu, so we should get teleported to the position we choose. When a player selects an item on a menu the script calls the callback OnPlayerSelectedMenuRow. The best way to do it is to do it with a switch, this is like several if statements to check if a variable is worth certain values. But first we only want these effects for the menu we want so we need to create a variable that holds what menu the player is looking at, this is done with
Now, when somebody selects something on the menu, their menuid will be saved in
Now we have to check that the menu they selected on is the menu we want:
Now in between these brackets is where the
switch is, this checks what item the player selected or
row this can be done with
if statements checking what
row it is, but the
switch is a much simpler way of writing it.
Now we need a command to show the menu. This is the easiest step. Just a comparison with
strcmp and a
ShowMenuForPlayer. This is done in
OnPlayerCommandText. Or, if you have a command processor already, use that instead to call
Really easy, wasn't it?
Okay, after you read this AND understood it, try your own menu. As you could see, it isn't that difficult, but will impress the players on your server all the more. And you can script really cool effects with this. It's also very cool for general stores or supermarkets for the things you can buy. Then you can subtract some money as effect and the price is shown in another column in the menu. But now, work on your own.
You can also add TogglePlayerControllable with
ShowPlayerMenu and TogglePlayerControllable with
true at end of
OnPlayerSelectedMenuRow so that player may not move while they are browsing menus.
I hope you learned something from this tutorial. If you have any questions, ask in the forums/discord.