2014-08-04 12:12:15 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// Multilingual System Plugin
|
|
|
|
//
|
2004-07-31 01:06:58 +00:00
|
|
|
|
|
|
|
#include <amxmodx>
|
|
|
|
#include <amxmisc>
|
|
|
|
|
2014-07-27 09:37:58 +00:00
|
|
|
new g_menuLang[MAX_PLAYERS]
|
2004-07-31 01:06:58 +00:00
|
|
|
new g_langNum
|
|
|
|
new g_coloredMenus
|
|
|
|
|
2014-07-27 07:54:46 +00:00
|
|
|
new g_cvarDisplayClientMessage;
|
|
|
|
new g_cvarClientLanguages;
|
|
|
|
|
2004-09-09 05:17:28 +00:00
|
|
|
public plugin_init()
|
|
|
|
{
|
2005-09-12 21:06:24 +00:00
|
|
|
register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team")
|
|
|
|
register_dictionary("multilingual.txt")
|
|
|
|
register_dictionary("common.txt")
|
|
|
|
register_dictionary("languages.txt")
|
|
|
|
|
2014-07-27 07:54:46 +00:00
|
|
|
g_cvarClientLanguages = register_cvar("amx_client_languages", "1")
|
|
|
|
g_cvarDisplayClientMessage = register_cvar("amx_language_display_msg", "1")
|
2005-09-12 21:06:24 +00:00
|
|
|
register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL)
|
|
|
|
register_menu("Language Menu", 1023, "actionMenu")
|
|
|
|
|
|
|
|
g_langNum = get_langsnum()
|
|
|
|
g_coloredMenus = colored_menus()
|
2004-07-31 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public client_putinserver(id)
|
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
if (get_pcvar_num(g_cvarDisplayClientMessage) && get_pcvar_num(g_cvarClientLanguages) && !is_user_bot(id))
|
2014-07-27 09:51:36 +00:00
|
|
|
{
|
2005-09-12 21:06:24 +00:00
|
|
|
set_task(10.0, "dispInfo", id)
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2004-08-13 11:20:32 +00:00
|
|
|
}
|
2004-07-31 01:06:58 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public client_disconnect(id)
|
|
|
|
{
|
2005-02-21 00:31:52 +00:00
|
|
|
remove_task(id)
|
|
|
|
}
|
|
|
|
|
2004-09-09 05:17:28 +00:00
|
|
|
public dispInfo(id)
|
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
client_print(id, print_chat, "%L", id, "TYPE_LANGMENU")
|
2004-07-31 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public cmdLangMenu(id, level, cid)
|
2004-09-09 05:17:28 +00:00
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
if (!get_pcvar_num(g_cvarClientLanguages))
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
|
|
|
client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
|
|
|
|
return PLUGIN_HANDLED
|
|
|
|
}
|
2014-07-27 07:54:46 +00:00
|
|
|
|
|
|
|
new buffer[3]
|
2014-07-29 14:32:32 +00:00
|
|
|
get_user_info(id, "lang", buffer, charsmax(buffer))
|
2014-07-27 07:54:46 +00:00
|
|
|
g_menuLang[id] = get_lang_id(buffer)
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
showMenu(id)
|
2014-07-27 07:54:46 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
return PLUGIN_HANDLED
|
2004-07-31 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 05:17:28 +00:00
|
|
|
showMenu(id)
|
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
if (!get_pcvar_num(g_cvarClientLanguages))
|
2014-07-27 09:51:36 +00:00
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
return
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
|
|
|
|
new menuBody[512], pLang[3]
|
2014-07-27 07:54:46 +00:00
|
|
|
|
|
|
|
get_lang(g_menuLang[id], pLang)
|
|
|
|
|
2014-07-27 09:51:36 +00:00
|
|
|
new len = formatex(menuBody, charsmax(menuBody), (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU")
|
2005-09-12 21:06:24 +00:00
|
|
|
|
2014-07-27 09:51:36 +00:00
|
|
|
len += formatex(menuBody[len], charsmax(menuBody) - len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME")
|
|
|
|
len += formatex(menuBody[len], charsmax(menuBody) - len, "^n2. %L", id, "SAVE_LANG")
|
|
|
|
formatex(menuBody[len], charsmax(menuBody) - len, "^n^n0. %L", id, "EXIT")
|
2014-07-27 07:54:46 +00:00
|
|
|
|
|
|
|
show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2, menuBody, -1, "Language Menu")
|
2004-07-31 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public actionMenu(id, key)
|
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
if (!get_pcvar_num(g_cvarClientLanguages))
|
2014-07-27 09:51:36 +00:00
|
|
|
{
|
2005-09-12 21:06:24 +00:00
|
|
|
return 0
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
|
|
|
|
if (key == 0)
|
|
|
|
{
|
2014-07-27 09:51:36 +00:00
|
|
|
if (g_menuLang[id] < (g_langNum - 1))
|
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
g_menuLang[id]++
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
else
|
2014-07-27 09:51:36 +00:00
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
g_menuLang[id] = 0
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
|
|
|
|
showMenu(id)
|
|
|
|
}
|
2014-07-27 07:54:46 +00:00
|
|
|
else if(key == 1)
|
2005-09-12 21:06:24 +00:00
|
|
|
{
|
2014-07-27 07:54:46 +00:00
|
|
|
new pLang[3], pLang_old[3]
|
2005-09-12 21:06:24 +00:00
|
|
|
|
2014-07-27 07:54:46 +00:00
|
|
|
get_lang(g_menuLang[id], pLang)
|
2014-07-29 14:32:32 +00:00
|
|
|
get_user_info(id, "lang", pLang_old, charsmax(pLang_old))
|
2014-07-27 07:54:46 +00:00
|
|
|
|
|
|
|
if (!equali(pLang, pLang_old))
|
|
|
|
{
|
|
|
|
client_cmd(id, "setinfo ^"lang^" ^"%s^"", pLang)
|
|
|
|
set_user_info(id, "lang", pLang); // In case setinfo breaks (slowhacking and all), this will at least be a fallback while the user is connect
|
|
|
|
|
|
|
|
new lName[64]
|
2014-07-27 09:51:36 +00:00
|
|
|
formatex(lName, charsmax(lName), "%L", pLang, "LANG_NAME")
|
2014-07-27 07:54:46 +00:00
|
|
|
client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName)
|
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
2004-07-31 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
get_lang_id(lang[])
|
|
|
|
{
|
|
|
|
new tLang[3]
|
|
|
|
|
|
|
|
for (new i = 0; i < g_langNum; i++)
|
|
|
|
{
|
|
|
|
get_lang(i, tLang)
|
2014-07-27 09:51:36 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
if (equali(tLang, lang))
|
2014-07-27 09:51:36 +00:00
|
|
|
{
|
2005-09-12 21:06:24 +00:00
|
|
|
return i
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|
2005-09-12 21:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
2014-07-27 09:51:36 +00:00
|
|
|
}
|