14.12.2011, 12:57
Introduction
Many people think dialogs are the only useful thing and menus are very complicated to create and all.But today I am going to show you how to create a simple menu.I will be creating a teleport menu you can customize it as you want.This is not a copy paste tutorial as you will have to read and understand what is written otherwise it won't work.This tutorial is also written in ZCMD make sure you have
in the top.
Starting Steps
First we have to create a menu.The prefix before it is Menu: like we do it in Float: bool: etc.
So now we have created the variable to store the menu.
Now a bit of explanation about CreateMenu arguments
Adding some menu items
Although 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:
Getting what the user selected and executing it
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 teleport menu, so we should get teleported to the position we choose. When a player selects an item on a menu the script calls the callback: public OnPlayerSelectedMenuRow(playerid, row). 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 'GetPlayerMenu':
Now, when somebody selects something on the menu, their menuid will be saved in 'CurrentMenu'.
Now we have to check that the menu they selected on is the menu we want:
Now I'll explain how the switch works, in the top there is this:
this defines what to check, in this case its the menu row then in between the braces under 'switch' there are 'case's, these are the different conditions that the variable in the 'switch' brackets can be, you can define these. Under the cases are more braces, this is where you put functions to take place if that case is the right one.
When everything is done correctly, like I've showed in those examples, the effects for menu items are created successfully.
The Command
Now for the command which makes the player view the menu.
Credits
Me-For the tutorial
Zeex-For ZCMD
Hope you liked this tutorial
Many people think dialogs are the only useful thing and menus are very complicated to create and all.But today I am going to show you how to create a simple menu.I will be creating a teleport menu you can customize it as you want.This is not a copy paste tutorial as you will have to read and understand what is written otherwise it won't work.This tutorial is also written in ZCMD make sure you have
pawn Код:
#include <zcmd>
Starting Steps
First we have to create a menu.The prefix before it is Menu: like we do it in Float: bool: etc.
pawn Код:
new Menu:teleport
pawn Код:
teleport = CreateMenu("Teleports", 2, 200.0, 100.0, 150.0, 150.0);
pawn Код:
CreateMenu(title, columns, Float:x, Float:y, Float:col1width, Float:col2width);
pawn Код:
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
Although 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.
pawn Код:
AddMenuItem(teleport, 0, "LS");
AddMenuItem(teleport, 0, "LS");
AddMenuItem(teleport, 0, "SF");
AddMenuItem(teleport, 0, "SF");
AddMenuItem(teleport, 0, "LV");
AddMenuItem(teleport, 0, "LV");
AddMenuItem(teleport, 1, "Grove Street");
AddMenuItem(teleport, 1, "Starfish Tower");
AddMenuItem(teleport, 1, "Wheel Arch Angels");
AddMenuItem(teleport, 1, "Jizzys");
AddMenuItem(teleport, 1, "4 Dragons");
AddMenuItem(teleport, 1, "Come-a-Lot");
pawn Код:
AddMenuItem(menuid, column, text);
pawn Код:
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
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 teleport menu, so we should get teleported to the position we choose. When a player selects an item on a menu the script calls the callback: public OnPlayerSelectedMenuRow(playerid, row). 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 'GetPlayerMenu':
pawn Код:
new Menu:CurrentMenu = GetPlayerMenu(playerid);
Now we have to check that the menu they selected on is the menu we want:
pawn Код:
if(CurrentMenu == teleport)
{
switch(row)
{
case 0: //Grove Street
{
SetPlayerPos(playerid, 2493.9133, -1682.3986, 13.3382);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to Grove Street");
}
case 1: //Starfish Tower
{
SetPlayerPos(playerid, 1541.2833, -1362.4741, 329.6457);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the top of Starfish Tower");
}
case 2: //Wheel Arch Angels
{
SetPlayerPos(playerid, -2705.5503, 206.1621, 4.1797);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the Wheel Arch Angels tuning-shop");
}
case 3: //Jizzys
{
SetPlayerPos(playerid, -2617.5156, 1390.6353, 7.1105);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to Jizzy's Nightclub!");
}
case 4: //4Dragons
{
SetPlayerPos(playerid, 2028.5538, 1008.3543, 10.8203);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the Four Dragons Casino");
}
case 5: //Com-a-Lot
{
SetPlayerPos(playerid, 2169.1838, 1122.5426, 12.6107);
SetPlayerInterior(playerid, 0);
SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to the Come-a-Lot casino!");
}
}
}
pawn Код:
switch(row)
When everything is done correctly, like I've showed in those examples, the effects for menu items are created successfully.
The Command
Now for the command which makes the player view the menu.
pawn Код:
CMD:teleport(playerid, params[])
{
ShowMenuForPlayer(teleport,playerid);
return 1;
}
Me-For the tutorial
Zeex-For ZCMD
Hope you liked this tutorial