10.02.2012, 19:30
(
Последний раз редактировалось 2KY; 30.04.2012 в 13:10.
Причина: Added the dialog part!
)
Introduction
Although I recommend the use of the YSI Library y_language (I believe that's what it's called, but I cannot find a link at the moment), I personally use a different system to manage different languages within my server. It's simple, and to the point, and only involves two (2) dialogs, one (1) player-variable, and one (1) stock.
Along with this tutorial, comes the availability of a new function, SendMessage;
Now, this function is rather basic, and for my needs, I edit it to be like so:
Due to the fact that I use only two languages on my server, English, and Spanish.
Let's get started..
First of all, create a variable at the top of your script (a 'GLOBAL' variable - global being in quotes due to the fact that it is independent for each user.)
Create it like so:
Second, you're going to need to create the function explained above, which is the main purpose of this tutorial - SendMessage. To do this, go OUTSIDE of a callback in your script, and copy-paste this function. (I will explain further in comments next to the code)
Of course this code could also be compressed like so, to save lines:
The usage for this function is like so: (I'm using an example from my mode..)
See how easy that is? And it even supports hex colors in the message! (I don't see why it wouldn't, but it sounds good)
Now, onto the dialog! (This is optional, and below, I will teach you how to create this in command form aswell!)
First off, I like the define the dialog IDs at the top of the script to avoid overlapping dialog IDs.
(I assume you know how to define a 'string' as an ID)
NOTE: You will probably have to edit these dialog IDs, as this is not a purely copy-paste tutorial.
The next part is completely dependent on preference. I, personally, like to have them select their language when they connect, so.. under the callback OnPlayerConnect, place the following code: (Can also be placed inside of login, register, and many other incidents of code)
For me, instead of having to go to every single incidence that I allow them to change their language, I created a define at the top of my script to define the available languages..
Now, of course, this code is edited to my server. Since the language hasn't been selected yet, I have chosen to display the messages in both languages (English in CYAN (a light blue) and Spanish in WHITE (well... white)).
You can change this accordingly, as it is YOUR server.
Now to make the dialogs themselves actually work. Do this by going under your OnDialogResponse callback, which is called every time a player hits a button on their dialog. (response || (OR) !response)
I didn't really comment the above code as it's pretty self explainatory, but if you don't understand it, feel free to comment below, and I will explain it in further detail.
All done!
If you've followed all the steps correctly, you will have created a language "system", although by request I could create more functions to go along with this. The reason I didn't before was due to efficiency.
Processing:
Is faster than:
If you would like the function however, here you are:
You're now on your way to creating a multi-language gamemode!
Well, have a nice day, and I hope you have learned something!
Although I recommend the use of the YSI Library y_language (I believe that's what it's called, but I cannot find a link at the moment), I personally use a different system to manage different languages within my server. It's simple, and to the point, and only involves two (2) dialogs, one (1) player-variable, and one (1) stock.
Along with this tutorial, comes the availability of a new function, SendMessage;
pawn Код:
SendMessage(playerid, colour, Language1[], Language2[])
pawn Код:
SendMessage(playerid, colour, English[], Spanish[])
Let's get started..
First of all, create a variable at the top of your script (a 'GLOBAL' variable - global being in quotes due to the fact that it is independent for each user.)
Create it like so:
pawn Код:
new
player_Language[MAX_PLAYERS] = -1;
/*
-1, in this example, is associated with NULL, meaning that there is no language selected at the moment.
Useful for detecting if a player has selected their language or not.
0, in this example, will be associated with English. As English is the primary language of this community, why not make it ID 0 so it's first on the list?
1 will be associated with Spanish, our secondary language for our community.
*/
pawn Код:
stock SendMessage(playerid, colour, Language1[], Language2[])
{
switch( player_Language[playerid] )
{
case 0: //Language 1
{
SendClientMessage(playerid, colour, Language1);
}
case 1: //Language 2
{
SendClientMessage(playerid, colour, Language2);
}
/*
case 2: //Language 3
{
SendClientMessage(playerid, colour, Language3);
}
Our header ( stock SendMessage(...) ) will also read:
stock SendMessage(playerid, colour, Language1[], Language2[], Language3[]);
If you wished to add another language.
*/
}
return true;
}
pawn Код:
stock SendMessage(playerid, colour, Language1[], Language2[]) {
switch( player_Language[playerid] ) {
case 0: { SendClientMessage(playerid, colour, Language1); }
case 1: { SendClientMessage(playerid, colour, Language2); }
}
return true;
}
pawn Код:
SendMessage(playerid, -1, ""#CYAN"[Success] "#WHITE"You have reloaded the MOTD!", ""#CYAN"[Йxito] "#WHITE"Usted ha recargado el MOTD!");
Now, onto the dialog! (This is optional, and below, I will teach you how to create this in command form aswell!)
First off, I like the define the dialog IDs at the top of the script to avoid overlapping dialog IDs.
(I assume you know how to define a 'string' as an ID)
pawn Код:
#define DIALOG_LANGUAGE 1
#define DIALOG_LANGUAGE_SUCCESS 2
The next part is completely dependent on preference. I, personally, like to have them select their language when they connect, so.. under the callback OnPlayerConnect, place the following code: (Can also be placed inside of login, register, and many other incidents of code)
For me, instead of having to go to every single incidence that I allow them to change their language, I created a define at the top of my script to define the available languages..
pawn Код:
#define LANGUAGE_SELECTION "English\nSpanish"
pawn Код:
if( player_Language[playerid] == -1) {
ShowPlayerDialog(playerid, DIALOG_LANGUAGE, DIALOG_STYLE_LIST, ""#CYAN"Select your language "#WHITE"(Seleccione su idioma)", LANGUAGE_SELECTION, "OK", "");
}
You can change this accordingly, as it is YOUR server.
Now to make the dialogs themselves actually work. Do this by going under your OnDialogResponse callback, which is called every time a player hits a button on their dialog. (response || (OR) !response)
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_LANGUAGE:
{
if( response ) //They clicked 'OK'
{
switch( listitem ) //Checks through the available languages (Defined above)
{
case 0: //English
{
player_Language[playerid] = 0;
ShowPlayerDialog(playerid, DIALOG_LANGUAGE_SUCCESS, DIALOG_STYLE_MSGBOX, ""#CYAN"You have successfully set your language!", ""#WHITE"Your account has been set to "#CYAN"english!\n"#WHITE"If you wish to change this, type "#CYAN"/changelanguage "#WHITE"at any time.", "OK", "");
}
case 1:
{
player_Language[playerid] = 1;
ShowPlayerDialog(playerid, DIALOG_LANGUAGE_SUCCESS, DIALOG_STYLE_MSGBOX, ""#CYAN"Ha configurado correctamente su idioma!", ""#WHITE"Su cuenta ha sido establecido en "#CYAN"inglйs!\n"#WHITE"Si desea cambiar esta "#CYAN"/changelanguage "#WHITE"el tipo en cualquier momento.", "Bueno", "");
}
}
}
else return ShowPlayerDialog(playerid, DIALOG_LANGUAGE, DIALOG_STYLE_LIST, ""#CYAN"Select your language "#WHITE"(Seleccione su idioma)", LANGUAGE_SELECTION, "OK", ""); //If they hit ESC while on the dialog (trying to bug the system?)
}
}
return true;
}
All done!
If you've followed all the steps correctly, you will have created a language "system", although by request I could create more functions to go along with this. The reason I didn't before was due to efficiency.
Processing:
pawn Код:
if(player_Language[playerid] == 1) { //english
pawn Код:
if(GetPlayerLanguage(playerid) == English) {
pawn Код:
stock GetPlayerLanguage ( playerid )
{
return player_Language[playerid];
// Returns 0 for English, and 1 for Spanish.
}
Well, have a nice day, and I hope you have learned something!