Jump to content

Multi-Language Quest 3.0


Recommended Posts

Hello to everyone. I'm share my multi-language system with you. I hope you're like it.

 

Step 1.

 

- Open questlua_pc.cpp and add these.

	int pc_get_lang(lua_State* L)
	{
		char szQuery[QUERY_MAX_LEN];
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		snprintf(szQuery,sizeof(szQuery),"select lang from player%s where id = '%u'",get_table_postfix(),ch->GetPlayerID());
		SQLMsg * pMsg = DBManager::instance().DirectQuery(szQuery);
		MYSQL_ROW row;
		for(int i = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++i)
		{
			lua_pushstring(L,row[0]);
		}
		return 1;
	}

	int pc_set_lang(lua_State* L)
	{
		char szQuery[QUERY_MAX_LEN];
		if(!lua_isstring(L,1))
		{
			return 0;
		}
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		snprintf(szQuery,sizeof(szQuery),"update player%s set lang = '%s' where id = '%u'",get_table_postfix(),lua_tostring(L,1),ch->GetPlayerID());
		std::auto_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery(szQuery));
		if(pmsg->Get()->uiInsertID == 0)
		{
			return 0;
		}
		return 1;
	}

- After add these.

			{ "get_lang", pc_get_lang},
			{ "set_lang", pc_set_lang},

Step 2.

 

- Player.sql

CREATE TABLE `NewTable` (
`id`  int(11) NOT NULL AUTO_INCREMENT ,
`account_id`  int(11) NOT NULL DEFAULT 0 ,
`name`  varchar(24) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'NONAME' ,
`job`  tinyint(2) UNSIGNED NOT NULL DEFAULT 0 ,
`voice`  tinyint(1) UNSIGNED NOT NULL DEFAULT 0 ,
`dir`  tinyint(2) NOT NULL DEFAULT 0 ,
`x`  int(11) NOT NULL DEFAULT 0 ,
`y`  int(11) NOT NULL DEFAULT 0 ,
`z`  int(11) NOT NULL DEFAULT 0 ,
`map_index`  int(11) NOT NULL DEFAULT 0 ,
`exit_x`  int(11) NOT NULL DEFAULT 0 ,
`exit_y`  int(11) NOT NULL DEFAULT 0 ,
`exit_map_index`  int(11) NOT NULL DEFAULT 0 ,
`hp`  smallint(4) NOT NULL DEFAULT 0 ,
`mp`  smallint(4) NOT NULL DEFAULT 0 ,
`stamina`  smallint(6) NOT NULL DEFAULT 0 ,
`random_hp`  smallint(5) UNSIGNED NOT NULL DEFAULT 0 ,
`random_sp`  smallint(5) UNSIGNED NOT NULL DEFAULT 0 ,
`playtime`  int(11) NOT NULL DEFAULT 0 ,
`level`  tinyint(2) UNSIGNED NOT NULL DEFAULT 1 ,
`level_step`  tinyint(1) NOT NULL DEFAULT 0 ,
`st`  smallint(3) NOT NULL DEFAULT 0 ,
`ht`  smallint(3) NOT NULL DEFAULT 0 ,
`dx`  smallint(3) NOT NULL DEFAULT 0 ,
`iq`  smallint(3) NOT NULL DEFAULT 0 ,
`exp`  int(11) NOT NULL DEFAULT 0 ,
`gold`  int(11) NOT NULL DEFAULT 0 ,
`stat_point`  smallint(3) NOT NULL DEFAULT 0 ,
`skill_point`  smallint(3) NOT NULL DEFAULT 0 ,
`quickslot`  tinyblob NULL ,
`ip`  varchar(15) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT '0.0.0.0' ,
`part_main`  int(7) NOT NULL DEFAULT 0 ,
`part_base`  tinyint(4) NOT NULL DEFAULT 0 ,
`part_hair`  smallint(4) NOT NULL DEFAULT 0 ,
`skill_group`  tinyint(4) NOT NULL DEFAULT 0 ,
`skill_level`  blob NULL ,
`alignment`  int(11) NOT NULL DEFAULT 0 ,
`last_play`  datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
`change_name`  tinyint(1) NOT NULL DEFAULT 0 ,
`mobile`  varchar(24) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`sub_skill_point`  smallint(3) NOT NULL DEFAULT 0 ,
`stat_reset_count`  tinyint(4) NOT NULL DEFAULT 0 ,
`horse_hp`  smallint(4) NOT NULL DEFAULT 0 ,
`horse_stamina`  smallint(4) NOT NULL DEFAULT 0 ,
`horse_level`  tinyint(2) UNSIGNED NOT NULL DEFAULT 0 ,
`horse_hp_droptime`  int(10) UNSIGNED NOT NULL DEFAULT 0 ,
`horse_riding`  tinyint(1) NOT NULL DEFAULT 0 ,
`horse_skill_point`  smallint(3) NOT NULL DEFAULT 0 ,
`lang`  varchar(5) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
PRIMARY KEY (`id`),
INDEX `account_id_idx` USING BTREE (`account_id`),
INDEX `name_idx` USING BTREE (`name`)
)
ENGINE=MyISAM
DEFAULT CHARACTER SET=latin1 COLLATE=latin1_swedish_ci
AUTO_INCREMENT=321434631
CHECKSUM=0
ROW_FORMAT=DYNAMIC
DELAY_KEY_WRITE=0
;

Step 3.

 

- How to use to this system in my game? 

 

I'll share example with you.

quest mLanguage begin
	state start begin
		function load_setting()
			local data = {
				["extension"] = {"tr","en"},
				["en"] = {
					["letter"] = "Change Language"
					["language"] = {"Turkish","English","Close"},
					["dialog"] = {"Please select a language... ", "No longer your language is %s. "},
				},
				["tr"] = {
					["letter"] = "Dilini Değiştir",
					["language"] = {"Türkçe","Ingilizce","Kapat"},
					["dialog"] = {"Lütfen bir dil seçiniz.. ","Artık diliniz %s oldu. "},
				},
			}
			return data
		end		
		when letter begin
			if(pc.get_lang() == 0) then
				send_letter("Select language")
			else
				send_letter(mLanguage.load_setting()[pc.get_lang()]["letter"])
			end
		end
		when button or info begin
			local data = mLanguage.load_setting()		
			if(pc.get_lang() != 0) then
				say(data[pc.get_lang()]["dialog"][1])
				say("")
				local s = select_table(data[pc.get_lang()]["language"])
				if(s >= table.getn(data[pc.get_lang()]["language"])) then
					return
				else
					pc.set_lang(data["extension"][s])
					say(string.format(data[pc.get_lang()]["dialog"][2],data[pc.get_lang()]["language"][s]))
				end
			else
				say(data["en"]["dialog"][1])
				say("")
				local s = select_table(data["en"]["language"])
				if(s >= table.getn(data["en"]["language"])) then
					return
				else
					pc.set_lang(data["extension"][s])
					say(string.format(data[pc.get_lang()]["dialog"][2],data[pc.get_lang()]["language"][s]))
				end
			end
		end
	end
end

This system just supported turkish and english language.

 

Regards.

  • Love 5

Plain logic saves lives.

Link to comment
Share on other sites

Hi!

 

Why MySql? Okay it's good if you have a mysql function, but in this case it's unnecessary.

 

I think it would be better, if you would do it like this:

 

questlib.lua

function pc.get_lang()
	local ret = pc.getf("mlanguage", "lang")
	return ret
end

function pc.set_lang(value)
	pc.setf("mlanguage", "lang", value)
end

And now you can use it without mysql function.

 

Best regards.

  • Love 1

SaveYourself 2 developer.

Link to comment
Share on other sites

 

 

How to get lang_status with php?
<?php
	$playerID = 12;
	$langs = "SELECT lValue FROM player.quest WHERE dwPID = ".. $playerID .." AND szName='mlanguage' AND szState='lang'";
	$langq = mysql_query($langs);
	$langt = mysql_fetch_array($langq);
	$lang = $langt[0];
?>

Try it. But change $playerID. I think you will get it from session.

 

Best regards.

SaveYourself 2 developer.

Link to comment
Share on other sites

Again you remember. MySQL Function doesn't write with lua. That's write with c++ and your function with my function result same just different codes. And pc.setqf,pc.setf,pc.getqf,pc.setf use to mysql function so result samesame.

 

your function is successful but everyone choose easy way.

 

 

Best regards.

Plain logic saves lives.

Link to comment
Share on other sites

  • 3 weeks later...
  • Premium
compile questlua_global.cpp
questlua_global.cpp: In function 'int quest::mysql_do_query(lua_State*)':
questlua_global.cpp:1362: error: 'DBManager' has not been declared
questlua_global.cpp:1373: warning: suggest parentheses around assignment used as truth value
questlua_global.cpp:1380: warning: comparison between signed and unsigned integer expressions
questlua_global.cpp:1358: warning: unused variable 'i'
questlua_global.cpp:1361: warning: unused variable 'field'
gmake: *** [OBJDIR/questlua_global.o] Error 1
Link to comment
Share on other sites

compile questlua_global.cpp
questlua_global.cpp: In function 'int quest::mysql_do_query(lua_State*)':
questlua_global.cpp:1362: error: 'DBManager' has not been declared
questlua_global.cpp:1373: warning: suggest parentheses around assignment used as truth value
questlua_global.cpp:1380: warning: comparison between signed and unsigned integer expressions
questlua_global.cpp:1358: warning: unused variable 'i'
questlua_global.cpp:1361: warning: unused variable 'field'
gmake: *** [OBJDIR/questlua_global.o] Error 1

 

#Updated.

Plain logic saves lives.

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...
On Saturday, February 08, 2014 at 5:52 PM, Aveline™ said:

	int pc_get_lang(lua_State* L)
	{
		char szQuery[QUERY_MAX_LEN];
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		snprintf(szQuery,sizeof(szQuery),"select lang from player%s where id = '%u'",get_table_postfix(),ch->GetPlayerID());
		SQLMsg * pMsg = DBManager::instance().DirectQuery(szQuery);
		MYSQL_ROW row;
		for(int i = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++i)
		{
			lua_pushstring(L,row[0]);
		}
		return 1;
	}

 

Hi,

pMsg is an allocated memory so it must be deleted.

Link to comment
Share on other sites

  • 5 months later...

Translate.lua

/usr/game/share/locale/turkey/translate.lua

Gamesrc/game/src/questlua.cpp

"%s/translate.lua"

%s/ <-- Turkey, Germany, Mexico, English, Romania

Gameforce quest list

text editing works instantly

4e9cb915f7294a3db385f9cbc0df1f9a.png

 

player table 'lang'

Turkey, Germany, Mexico, English, Romania

yea

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • 6 months later...

If the language is tr the server will read text from translate_tr.lua, if the language is de the server will read text from translate_de.lua..

Can someone make something like this?

 

Or like this:

On 04.07.2016 at 11:44 PM, panher said:

Translate.lua

/usr/game/share/locale/turkey/translate.lua

Gamesrc/game/src/questlua.cpp

"%s/translate.lua"

%s/ <-- Turkey, Germany, Mexico, English, Romania

Gameforce quest list

text editing works instantly

4e9cb915f7294a3db385f9cbc0df1f9a.png

 

player table 'lang'

Turkey, Germany, Mexico, English, Romania

yea

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.