[Tutorial] MultiLanguage (Message, GameText, TextDraw, Dialog)
#1

Hi

I don't relase any my scripts/include there, but it can help many people.
It's simple include allows you to send a message in multiple languages



/*
Notka autora - usuniesz, tracisz prawo do wystawiania/korzystania z tego includa
MultiLanguageMessage by me
Last update: 29.07.2011

========================================
Wyprodukowano dla GTACenter.Info
========================================

native LanguageMessage(playerid, color, ...);
native LanguageMessageToAll(color, ...);
native LanguageTextDrawMessage(playerid, Text:ID, ...);
native LanguageGameTextForPlayer(playerid, styleid, czas, ...);
native LanguageGameTextForAll(styleid, czas, ...);
native LanguageDialogForPlayer(playerid, dialogid, style, ...);
*/

#include

#define LANGUAGE_POLISH 0
#define LANGUAGE_ENGLISH 1
#define LANGUAGE_DEFAULT 2
//An example of another:
//#define LANGUAGE_NAME 3

#define LANGUAGE_SIZE 128
#define LANGUAGE_DIALOG 100 // DIALOG ID
#define LANGUAGE_INFO "Polski\nEnglish\nInny" // Next add acc. pattern "\nLanguage"

#define ChooseLanguage(%0) ShowPlayerDialog(%0, LANGUAGE_DIALOG, DIALOG_STYLE_LIST, "Choose language", LANGUAGE_INFO, "OK", "") // Function showing the language selection dialog

stock LANGUAGE_ODR(playerid, dialogid, response, listitem) // Use this in OnDialogResponse
{
if(dialogid == LANGUAGE_DIALOG && response)
SetPVarInt(playerid, "Language", listitem);
else if(dialogid == LANGUAGE_DIALOG && !response)
SetPVarInt(playerid, "Language", 0);
}

stock LanguageMessage(playerid, color, ...)
{
new msg[LANGUAGE_SIZE];
new args = numargs();
new language = GetPVarInt(playerid, "Language");

for(new i=2; i < args; i++)
{
if(language == i-2)
{
for(new chr; chr < sizeof msg; chr++)
msg[chr] = getarg((i+1+language), chr);

if(msg[0] == '\0')
SendClientMessage(playerid, color, "Error in script: LanguageMessage doesn't work, report this problem to server admin.");
else
SendClientMessage(playerid, color, msg);
}
}
return language;
}

stock LanguageMessageToAll(color, ...)
{
new msg[LANGUAGE_SIZE];
new args = numargs();
new language;

for(new i, g = GetMaxPlayers(); i < g; i++)
{
if(IsPlayerConnected(i))
{
language = GetPVarInt(i, "Language");
for(new a=1; a < args; a++)
{
if(language == a-1)
{
for(new chr; chr < sizeof msg; chr++)
msg[chr] = getarg((a+1+language), chr);

if(msg[0] == '\0')
SendClientMessage(i, color, "Error in script: LanguageMessageToAll doesn't work, report this problem to server admin.");
else
SendClientMessage(i, color, msg);
}
}
}
}
return 1;
}

stock LanguageTextDrawMessage(playerid, Text:ID, ...)
{
new msg[LANGUAGE_SIZE];
new args = numargs();
new language = GetPVarInt(playerid, "Language");

for(new i=2; i < args; i++)
{
if(language == i-2)
{
for(new chr; chr < sizeof msg; chr++)
msg[chr] = getarg((i+1+language), chr);

if(msg[0] == '\0')
TextDrawSetString(ID, "Error in script: LanguageTextDrawMessage doesn't work, report this problem to server admin.");
else
TextDrawSetString(ID, msg);
}
}
return language;
}

stock LanguageGameTextForPlayer(playerid, styleid, czas, ...)
{
new msg[LANGUAGE_SIZE];
new args = numargs();
new language = GetPVarInt(playerid, "Language");

for(new i=3; i < args; i++)
{
if(language == i-3)
{
for(new chr; chr < sizeof msg; chr++)
msg[chr] = getarg((i+1+language), chr);

if(msg[0] == '\0')
GameTextForPlayer(playerid, "Error in script: LanguageGameTextForPlayer doesn't work, report this problem to server admin.", czas, styleid);
else
GameTextForPlayer(playerid, msg, czas, styleid);
}
}
return language;
}

stock LanguageGameTextForAll(styleid, czas, ...)
{
new msg[LANGUAGE_SIZE];
new args = numargs();
new language;

for(new a, g = GetMaxPlayers(); a < g; a++)
{
if(IsPlayerConnected(a))
{
language = GetPVarInt(a, "Language");
for(new i=2; i < args; i++)
{
if(language == i-2)
{
for(new chr; chr < sizeof msg; chr++)
msg[chr] = getarg((i+1+language), chr);

if(msg[0] == '\0')
GameTextForPlayer(a, "Error in script: LanguageGameTextForAll doesn't work, report this problem to server admin.", czas, styleid);
else
GameTextForPlayer(a, msg, czas, styleid);
}
}
}
}
return language;
}

stock LanguageDialogForPlayer(playerid, dialogid, style, ...)
{
new msg[4][LANGUAGE_SIZE];
new largs = ((numargs()-3) /5);
new language = GetPVarInt(playerid, "Language");
new last = 7;

if(language)
last += (language * 5);

for(new i=0; i < largs; i++)
{
if(language == i)
{
for(new chr; chr < sizeof msg[]; chr++)
{
msg[0][chr] = getarg((last - 3), chr);
msg[1][chr] = getarg((last - 2), chr);
msg[2][chr] = getarg((last - 1), chr);
msg[3][chr] = getarg((last), chr);
}

if((msg[0][0] == '\0') || (msg[1][0] == '\0') || (msg[2][0] == '\0'))
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Error", "Error in script: LanguageDialogForPlayer doesn't work, report this problem to server admin.", "OK", "");
else
ShowPlayerDialog(playerid, dialogid, style, msg[0], msg[1], msg[2], msg[3]);
}
}
return language;
}











This was my first Tutorial Enjoy!
Reply
#2

This is not a tutorial dude......
Reply
#3

not? ow my mistake i tought that was a tutorial xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)