Update multilingual plugin

- User pcvars
- Remove vault usage
- Remove amx_setlang (not very useful, it's covered by the cvar now)
- Remove server language from the menu (covered by the cvar now)
- Add a cvar for previously hardcoded DISPLAY_MSG
This commit is contained in:
xPaw 2014-07-27 10:54:46 +03:00
parent c97312ba41
commit 1d17835e9a

View File

@ -34,13 +34,13 @@
#include <amxmodx> #include <amxmodx>
#include <amxmisc> #include <amxmisc>
#define DISPLAY_MSG // Comment to disable message on join new g_menuLang[33]
new g_menuLang[MAX_PLAYERS][2]
new g_serverLang
new g_langNum new g_langNum
new g_coloredMenus new g_coloredMenus
new g_cvarDisplayClientMessage;
new g_cvarClientLanguages;
public plugin_init() public plugin_init()
{ {
register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team") register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team")
@ -48,34 +48,18 @@ public plugin_init()
register_dictionary("common.txt") register_dictionary("common.txt")
register_dictionary("languages.txt") register_dictionary("languages.txt")
register_cvar("amx_language", "en", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) g_cvarClientLanguages = register_cvar("amx_client_languages", "1")
//Set to zero to disable client effects g_cvarDisplayClientMessage = register_cvar("amx_language_display_msg", "1")
register_cvar("amx_client_languages", "1")
register_concmd("amx_setlang", "cmdLang", ADMIN_CFG, "<language>")
register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL) register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL)
register_menu("Language Menu", 1023, "actionMenu") register_menu("Language Menu", 1023, "actionMenu")
new lang[3]
if (vaultdata_exists("server_language"))
{
get_vaultdata("server_language", lang, 2)
} else {
copy(lang, 2, "en")
set_vaultdata("server_language", lang)
}
set_cvar_string("amx_language", lang)
g_langNum = get_langsnum() g_langNum = get_langsnum()
g_serverLang = get_lang_id(lang)
g_coloredMenus = colored_menus() g_coloredMenus = colored_menus()
} }
#if defined DISPLAY_MSG
public client_putinserver(id) public client_putinserver(id)
{ {
if (get_cvar_num("amx_client_languages") && !is_user_bot(id)) if (get_pcvar_num(g_cvarDisplayClientMessage) && get_pcvar_num(g_cvarClientLanguages) && !is_user_bot(id))
set_task(10.0, "dispInfo", id) set_task(10.0, "dispInfo", id)
} }
@ -86,45 +70,20 @@ public client_disconnect(id)
public dispInfo(id) public dispInfo(id)
{ {
if (get_cvar_num("amx_client_languages"))
client_print(id, print_chat, "%L", id, "TYPE_LANGMENU") client_print(id, print_chat, "%L", id, "TYPE_LANGMENU")
} }
#endif
public cmdLang(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[3]
read_argv(1, arg, 2)
if (!lang_exists(arg))
{
console_print(id, "[AMXX] %L", id, "LANG_NOT_EXISTS")
return PLUGIN_HANDLED
}
set_vaultdata("server_language", arg)
set_cvar_string("amx_language", arg)
g_serverLang = get_lang_id(arg)
return PLUGIN_HANDLED
}
public cmdLangMenu(id, level, cid) public cmdLangMenu(id, level, cid)
{ {
new buffer[3] if (!get_pcvar_num(g_cvarClientLanguages))
if (!get_cvar_num("amx_client_languages"))
{ {
client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED") client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
return PLUGIN_HANDLED return PLUGIN_HANDLED
} }
new buffer[3]
get_user_info(id, "lang", buffer, 2) get_user_info(id, "lang", buffer, 2)
g_menuLang[id][0] = get_lang_id(buffer) g_menuLang[id] = get_lang_id(buffer)
g_menuLang[id][1] = g_serverLang
showMenu(id) showMenu(id)
@ -133,84 +92,53 @@ public cmdLangMenu(id, level, cid)
showMenu(id) showMenu(id)
{ {
if (!get_cvar_num("amx_client_languages")) if (!get_pcvar_num(g_cvarClientLanguages))
return PLUGIN_HANDLED return
new menuBody[512], pLang[3] new menuBody[512], pLang[3]
get_lang(g_menuLang[id][0], pLang) get_lang(g_menuLang[id], pLang)
new len = format(menuBody, 511, (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU") new len = format(menuBody, 511, (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU")
len += format(menuBody[len], 511-len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME") len += format(menuBody[len], 511-len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME")
if (access(id, ADMIN_CFG))
{
new sLang[3]
get_lang(g_menuLang[id][1], sLang)
len += format(menuBody[len], 511-len, (g_coloredMenus ? "2. %L\R\r%L\w^n^n" : "2. %L %L^n^n"), id, "SERVER_LANG", sLang, "LANG_NAME")
len += format(menuBody[len], 511-len, "3. %L", id, "SAVE_LANG")
} else {
len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG") len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG")
}
format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT") format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT")
show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3, menuBody, -1, "Language Menu") show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2, menuBody, -1, "Language Menu")
return 1
} }
public actionMenu(id, key) public actionMenu(id, key)
{ {
if (!get_cvar_num("amx_client_languages")) if (!get_pcvar_num(g_cvarClientLanguages))
return 0 return 0
new isAdmin = access(id, ADMIN_CFG)
if (key == 0) if (key == 0)
{ {
if (g_menuLang[id][0] < (g_langNum-1)) if (g_menuLang[id] < (g_langNum-1))
g_menuLang[id][0]++ g_menuLang[id]++
else else
g_menuLang[id][0] = 0 g_menuLang[id] = 0
showMenu(id) showMenu(id)
} }
else if(key == 1)
if (isAdmin && (key == 1))
{ {
if (g_menuLang[id][1] < (g_langNum - 1)) new pLang[3], pLang_old[3]
g_menuLang[id][1]++
else
g_menuLang[id][1] = 0
showMenu(id) get_lang(g_menuLang[id], pLang)
}
new pLang[3], pLang_old[3], sLang[3], sLang_old[3], lName[64]
get_lang(g_menuLang[id][0], pLang)
get_lang(g_menuLang[id][1], sLang)
get_user_info(id, "lang", pLang_old, 2) get_user_info(id, "lang", pLang_old, 2)
get_lang(g_serverLang, sLang_old)
if (isAdmin && (key == 2) && !equali(sLang, sLang_old)) if (!equali(pLang, pLang_old))
{
set_vaultdata("server_language", sLang)
set_cvar_string("amx_language", sLang)
g_serverLang = g_menuLang[id][1]
format(lName, 63, "%L", sLang, "LANG_NAME")
client_print(id, print_chat, "%L", pLang, "SET_LANG_SERVER", lName)
}
if (!equali(pLang, pLang_old) && ((isAdmin && (key == 2)) || (!isAdmin && (key == 1))))
{ {
client_cmd(id, "setinfo ^"lang^" ^"%s^"", pLang) 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]
format(lName, 63, "%L", pLang, "LANG_NAME") format(lName, 63, "%L", pLang, "LANG_NAME")
client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName) client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName)
} }
}
return 0 return 0
} }