27.10.2009, 20:15
(
Последний раз редактировалось Daren_Jacobson; 20.07.2011 в 22:50.
)
Dialogs, a wonderful new feature in 0.3.
This tutorial is created to help you understand and implement them.
First, you must understand the difference between a guide and a tutorial, a guide shows you exactly what to do, and usually gives you the code; a tutorial shows you how to do it, and may give some examples. I am going against my better judgement and implementing some guide parts, just to not be annoyed by the people that don't know how to write their own code.
Note: Putting a dialog in OnPlayerConnect will make the spawn gui not visible.
Understand
Dialogs are not things that are created, they are shown, or they are not.
It is possible to make them creatable, but is quite un-efficient, I will show you some possibilities later in the tutorial.
First, the function:
Second, the definition:
Now, how to use these parameters correctly
This would make a dialog appear to playerid, as a msgbox, a title of WARNING, and it saying Warning, your money has dropped below 100<linebreak>would you like to take out a loan? and yes or no buttons.
simple.
This would make a dialog appear to playerid, with the style of input, a title of login, and it saying "Welcome back<linebreak>Insert password to login." With "login" and "cancel" buttons.
Not quite as simple, yet still easy.
You should be able to figure out most of it, but now it is a list, with the items of
Implement
NOTE: I HAVE NOT TESTED ANY OF THESE METHODS, THEY SHOULD WORK.
As I was saying before there can be a semi-dynamic way. Here it is:
I say semi-dynamic because there is an unknown limit of how many dialogs can be used, hence the variable will have to be changed per script.
now a non-dynamic, easily changeable, way:
can be used by
and 2 different ways of doing that are
then if you show that dialog in multiple spots, it is easier to change it by changing the define.
also a useful define to make it so no dialog is shown (if there is one up it goes away.) %1 is playerid.
Continued on to next post.
This tutorial is created to help you understand and implement them.
First, you must understand the difference between a guide and a tutorial, a guide shows you exactly what to do, and usually gives you the code; a tutorial shows you how to do it, and may give some examples. I am going against my better judgement and implementing some guide parts, just to not be annoyed by the people that don't know how to write their own code.
Note: Putting a dialog in OnPlayerConnect will make the spawn gui not visible.
Understand
Dialogs are not things that are created, they are shown, or they are not.
It is possible to make them creatable, but is quite un-efficient, I will show you some possibilities later in the tutorial.
First, the function:
pawn Код:
ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[])
- playerid: the user to which you want the dialog to be shown to
- dialogid: the id of the dialog, used for OnDialogResponse
- style: specifies what kind of dialog is wanted, an input box(allows user input), a msgbox(shows text to the user), or a listbox(allows user to choose from a list of items)
- caption: a title for the box, should be brief, and to the point(use "Login" not "insert password to login")
- info: the main text of the box, used to describe what the box is about, listitems are placed in here (seperated by new lines (\n)) and tabs can be placed by using \t
- button1: the text of button1 (on the left) usually "yes" or "accept" or "done"
- button2: the text of button2 (on the right) usually "no" or "cancel"
Now, how to use these parameters correctly
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE, DIALOG_STYLE_MSGBOX, "WARNING", "Warning, your money has dropped below 100\nwould you like to take out a loan?", "yes", "no");
simple.
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE + 1, DIALOG_STYLE_INPUT, "Login", "Welcome back\nInsert password to login", "login", "cancel");
Not quite as simple, yet still easy.
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE + 2, DIALOG_STYLE_LIST, "Destination", "LSPD\nLVPD\nSFPD\nLS Bank\nLS Airport", "warp", "cancel");
- LSPD
- LVPD
- SFPD
- LS Bank
- LS Airport
Implement
NOTE: I HAVE NOT TESTED ANY OF THESE METHODS, THEY SHOULD WORK.
As I was saying before there can be a semi-dynamic way. Here it is:
pawn Код:
#define MAX_DIALOGS (15)
#define DIALOG_BASE (324)
enum DialogInfo
{
DTaken,
DStyle,
DCap[64], //I have never used an array(string) in an enum like this before, untested
DInfo[512], //if you don't need it this big make it smaller.
DBut1[24],
DBut2[24]
}
new Dialogs[MAX_DIALOGS][DialogInfo];
//handleid is NOT dialog id, multiple dialogs with the same text can be shown with different id's
CreateDialog(style, caption[], info[], button1[], button2[]) //returns handleid
{
new handleid = 0;
//Tempted to use foreach here, not going to, for portability.
for ( ; handleid < MAX_DIALOGS; handleid++)
{
if (Dialogs[handleid][DTaken] == 0) break;
}
Dialogs[handleid][DTaken] = 1;
Dialogs[handleid][DStyle] = style;
format(Dialogs[handleid][DCap], sizeof(Dialogs[handleid][DCap]), caption);
format(Dialogs[handleid][DInfo], sizeof(Dialogs[handleid][DInfo]), info);
format(Dialogs[handleid][DBut1], sizeof(Dialogs[handleid][DBut1]), button1);
format(Dialogs[handleid][DBut2], sizeof(Dialogs[handleid][DBut2]), button2);
return handleid;
}
ShowDialog(playerid, dialogid, handleid)
{
if (Dialogs[handleid][PTaken] == 0) return 0;
return ShowPlayerDialog(playerid, dialogid, Dialogs[handleid][PStyle], Dialogs[handleid][PCap], Dialogs[handleid][PInfo], Dialogs[handleid][PBut1], Dialogs[handleid][PBut2]);
}
now a non-dynamic, easily changeable, way:
pawn Код:
#define LOGINDIALOGPARAMS(%1,%2) %1, %2, DIALOG_STYLE_INPUT, "Login", "Welcome back!\nInsert password to login", "login", "cancel"
pawn Код:
ShowPlayerDialog(LOGINDIALOGPARAMS(playerid, dialogid));
pawn Код:
#define LOGINDIALOG(%1,%2) ShowPlayerDialog(%1, %2, DIALOG_STYLE_INPUT, "Login", "Welcome back!\nInsert password to login", "login", "cancel")
//used like this
LOGINDIALOG(playerid, dialogid);
//or
#define LOGINDIALOGPARAMS DIALOG_STYLE_INPUT, "Login", "Welcome back!\nInsert password to login", "login", "cancel"
//used like this
ShowPlayerDialog(playerid, dialogid, LOGINDIALOGPARAMS);
also a useful define to make it so no dialog is shown (if there is one up it goes away.) %1 is playerid.
pawn Код:
#define HidePlayerDialog(%1) ShowPlayerDialog(%1,-1,0,"","","","")