Aveline™ 554 Posted February 8, 2014 Share Posted February 8, 2014 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. 5 Plain logic saves lives. Link to comment Share on other sites More sharing options...
PoOwAa 1 Posted February 8, 2014 Share Posted February 8, 2014 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. 1 SaveYourself 2 developer. Link to comment Share on other sites More sharing options...
Aveline™ 554 Posted February 8, 2014 Author Share Posted February 8, 2014 Someone want to show rank system on web-page. And your function doesn't work in this situation How to get lang_status with php? You're wrong a little understand me Best regards. Plain logic saves lives. Link to comment Share on other sites More sharing options...
PoOwAa 1 Posted February 8, 2014 Share Posted February 8, 2014 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 More sharing options...
Aveline™ 554 Posted February 8, 2014 Author Share Posted February 8, 2014 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 More sharing options...
PoOwAa 1 Posted February 8, 2014 Share Posted February 8, 2014 Yeah both use sql, but the questflags are cached when the player logs in, so it use 1 query. Your solution use lots of queries. I hope you can feel the difference. Btw your solution is good too. Best regards. SaveYourself 2 developer. Link to comment Share on other sites More sharing options...
Former Staff .InyaProduction 1125 Posted February 9, 2014 Former Staff Share Posted February 9, 2014 isnt lua_newtable just supported with the new lua version? Link to comment Share on other sites More sharing options...
Remix 45 Posted February 9, 2014 Share Posted February 9, 2014 I had the same idea.. But i was too lazy to create it 1 Link to comment Share on other sites More sharing options...
Premium .Avenue™ 783 Posted February 27, 2014 Premium Share Posted February 27, 2014 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 More sharing options...
Aveline™ 554 Posted February 27, 2014 Author Share Posted February 27, 2014 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 More sharing options...
-TÜRK- 23 Posted February 27, 2014 Share Posted February 27, 2014 Maykide gelmiş buraya, hoşgeldin! Thanks for release bro! 1 Link to comment Share on other sites More sharing options...
BeHappy4Ever 247 Posted December 29, 2015 Share Posted December 29, 2015 Just a suggestion,if the language is tr the server will read text from translate_tr.lua for example.Can someone make sonething like this? It would be so helpful for me. Thanks Link to comment Share on other sites More sharing options...
ObscureAngel 0 Posted January 6, 2016 Share Posted January 6, 2016 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 More sharing options...
TRBizeps 49 Posted June 30, 2016 Share Posted June 30, 2016 i cant compile the quest.. } expected to close { at line 3 near [ pls help. Link to comment Share on other sites More sharing options...
panher 31 Posted July 4, 2016 Share Posted July 4, 2016 (edited) 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 player table 'lang' Turkey, Germany, Mexico, English, Romania yea Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
daredevil09 5 Posted January 27, 2017 Share Posted January 27, 2017 (edited) 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 player table 'lang' Turkey, Germany, Mexico, English, Romania yea Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
raihan3 20 Posted May 19 Share Posted May 19 is that possible like that system but load translate_en.lua or translate_de.lua depend on users account database lang column ? Link to comment Share on other sites More sharing options...
Recommended Posts