Merge pull request #82 from xPaw/ml-plugin-update
Multilingual plugin update
This commit is contained in:
commit
88042ce5a9
|
@ -204,6 +204,7 @@ extern bool g_bmod_dod;
|
|||
extern bool g_dontprecache;
|
||||
extern int g_srvindex;
|
||||
extern cvar_t* amxmodx_version;
|
||||
extern cvar_t* amxmodx_language;
|
||||
extern cvar_t* hostname;
|
||||
extern cvar_t* mp_timelimit;
|
||||
extern fakecmd_t g_fakecmd;
|
||||
|
|
|
@ -52,18 +52,18 @@ const char *translate(AMX *amx, cell amxaddr, const char *key)
|
|||
amx_cl_langs = CVAR_GET_POINTER("amx_client_languages");
|
||||
if ( (int)amx_cl_langs->value == 0 )
|
||||
{
|
||||
pLangName = g_vault.get("server_language");
|
||||
pLangName = amxmodx_language->string;
|
||||
} else {
|
||||
pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(g_langMngr.GetDefLang())->pEdict, "lang");
|
||||
}
|
||||
} else if (addr[0] == LANG_SERVER) {
|
||||
pLangName = g_vault.get("server_language");
|
||||
pLangName = amxmodx_language->string;
|
||||
} else if (addr[0] >= 1 && addr[0] <= gpGlobals->maxClients) {
|
||||
if (!amx_cl_langs)
|
||||
amx_cl_langs = CVAR_GET_POINTER("amx_client_languages");
|
||||
if ( (int)amx_cl_langs->value == 0 )
|
||||
{
|
||||
pLangName = g_vault.get("server_language");
|
||||
pLangName = amxmodx_language->string;
|
||||
} else {
|
||||
pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(addr[0])->pEdict, "lang");
|
||||
}
|
||||
|
@ -110,9 +110,9 @@ const char *translate(AMX *amx, cell amxaddr, const char *key)
|
|||
}
|
||||
|
||||
if (addr[0] != LANG_SERVER)
|
||||
def = g_langMngr.GetDef(g_vault.get("server_language"), key, status);
|
||||
def = g_langMngr.GetDef(amxmodx_language->string, key, status);
|
||||
|
||||
if (!def && (strcmp(pLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0))
|
||||
if (!def && (strcmp(pLangName, "en") != 0 && strcmp(amxmodx_language->string, "en") != 0))
|
||||
def = g_langMngr.GetDef("en", key, status);
|
||||
}
|
||||
|
||||
|
|
|
@ -142,9 +142,11 @@ cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONL
|
|||
cvar_t init_amxmodx_modules = {"amxmodx_modules", "", FCVAR_SPONLY};
|
||||
cvar_t init_amxmodx_debug = {"amx_debug", "1", FCVAR_SPONLY};
|
||||
cvar_t init_amxmodx_mldebug = {"amx_mldebug", "", FCVAR_SPONLY};
|
||||
cvar_t init_amxmodx_language = {"amx_language", "en", FCVAR_SERVER};
|
||||
cvar_t init_amxmodx_cl_langs = {"amx_client_languages", "", FCVAR_SERVER};
|
||||
cvar_t* amxmodx_version = NULL;
|
||||
cvar_t* amxmodx_modules = NULL;
|
||||
cvar_t* amxmodx_language = NULL;
|
||||
cvar_t* hostname = NULL;
|
||||
cvar_t* mp_timelimit = NULL;
|
||||
|
||||
|
@ -465,12 +467,6 @@ int C_Spawn(edict_t *pent)
|
|||
g_vault.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
|
||||
g_vault.loadVault();
|
||||
|
||||
if (strlen(g_vault.get("server_language")) < 1)
|
||||
{
|
||||
g_vault.put("server_language", "en");
|
||||
g_vault.saveVault();
|
||||
}
|
||||
|
||||
// ###### Init time and freeze tasks
|
||||
g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f;
|
||||
g_task_time = gpGlobals->time + 99999.0f;
|
||||
|
@ -1446,9 +1442,11 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
|
|||
CVAR_REGISTER(&init_amxmodx_modules);
|
||||
CVAR_REGISTER(&init_amxmodx_debug);
|
||||
CVAR_REGISTER(&init_amxmodx_mldebug);
|
||||
CVAR_REGISTER(&init_amxmodx_language);
|
||||
CVAR_REGISTER(&init_amxmodx_cl_langs);
|
||||
|
||||
amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);
|
||||
amxmodx_language = CVAR_GET_POINTER(init_amxmodx_language.name);
|
||||
|
||||
REG_SVR_COMMAND("amxx", amx_command);
|
||||
|
||||
|
|
|
@ -134,12 +134,23 @@ amx_extendmap_max 90
|
|||
// Default value: 15
|
||||
amx_extendmap_step 15
|
||||
|
||||
// Server language in ISO 639-1 format
|
||||
// Please see data/lang/languages.txt file for a list of supported languages
|
||||
//
|
||||
// Default value: en
|
||||
amx_language "en"
|
||||
|
||||
// If you set this to 0, clients cannot chose their language, instead they use
|
||||
// whatever language the server is configured to use.
|
||||
//
|
||||
// Default value: 1
|
||||
amx_client_languages 1
|
||||
|
||||
// If you set this to 0, clients will not see a message about amx_langmenu when they join the server
|
||||
//
|
||||
// Default value: 1
|
||||
amx_language_display_msg 1
|
||||
|
||||
// Plugin Debug mode
|
||||
// 0 - No debugging (garbage line numbers)
|
||||
// 1 - Plugins with "debug" option in plugins.ini are put into debug mode
|
||||
|
|
|
@ -34,13 +34,13 @@
|
|||
#include <amxmodx>
|
||||
#include <amxmisc>
|
||||
|
||||
#define DISPLAY_MSG // Comment to disable message on join
|
||||
|
||||
new g_menuLang[MAX_PLAYERS][2]
|
||||
new g_serverLang
|
||||
new g_menuLang[MAX_PLAYERS]
|
||||
new g_langNum
|
||||
new g_coloredMenus
|
||||
|
||||
new g_cvarDisplayClientMessage;
|
||||
new g_cvarClientLanguages;
|
||||
|
||||
public plugin_init()
|
||||
{
|
||||
register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team")
|
||||
|
@ -48,35 +48,21 @@ public plugin_init()
|
|||
register_dictionary("common.txt")
|
||||
register_dictionary("languages.txt")
|
||||
|
||||
register_cvar("amx_language", "en", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)
|
||||
//Set to zero to disable client effects
|
||||
register_cvar("amx_client_languages", "1")
|
||||
register_concmd("amx_setlang", "cmdLang", ADMIN_CFG, "<language>")
|
||||
g_cvarClientLanguages = register_cvar("amx_client_languages", "1")
|
||||
g_cvarDisplayClientMessage = register_cvar("amx_language_display_msg", "1")
|
||||
register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL)
|
||||
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_serverLang = get_lang_id(lang)
|
||||
g_coloredMenus = colored_menus()
|
||||
}
|
||||
|
||||
#if defined DISPLAY_MSG
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
public client_disconnect(id)
|
||||
|
@ -86,45 +72,20 @@ public client_disconnect(id)
|
|||
|
||||
public dispInfo(id)
|
||||
{
|
||||
if (get_cvar_num("amx_client_languages"))
|
||||
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
|
||||
client_print(id, print_chat, "%L", id, "TYPE_LANGMENU")
|
||||
}
|
||||
|
||||
public cmdLangMenu(id, level, cid)
|
||||
{
|
||||
new buffer[3]
|
||||
|
||||
if (!get_cvar_num("amx_client_languages"))
|
||||
if (!get_pcvar_num(g_cvarClientLanguages))
|
||||
{
|
||||
client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
|
||||
return PLUGIN_HANDLED
|
||||
}
|
||||
|
||||
new buffer[3]
|
||||
get_user_info(id, "lang", buffer, 2)
|
||||
g_menuLang[id][0] = get_lang_id(buffer)
|
||||
g_menuLang[id][1] = g_serverLang
|
||||
g_menuLang[id] = get_lang_id(buffer)
|
||||
|
||||
showMenu(id)
|
||||
|
||||
|
@ -133,83 +94,60 @@ public cmdLangMenu(id, level, cid)
|
|||
|
||||
showMenu(id)
|
||||
{
|
||||
if (!get_cvar_num("amx_client_languages"))
|
||||
return PLUGIN_HANDLED
|
||||
if (!get_pcvar_num(g_cvarClientLanguages))
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
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 = formatex(menuBody, charsmax(menuBody), (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 += 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")
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
return 1
|
||||
show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2, menuBody, -1, "Language Menu")
|
||||
}
|
||||
|
||||
public actionMenu(id, key)
|
||||
{
|
||||
if (!get_cvar_num("amx_client_languages"))
|
||||
if (!get_pcvar_num(g_cvarClientLanguages))
|
||||
{
|
||||
return 0
|
||||
|
||||
new isAdmin = access(id, ADMIN_CFG)
|
||||
}
|
||||
|
||||
if (key == 0)
|
||||
{
|
||||
if (g_menuLang[id][0] < (g_langNum-1))
|
||||
g_menuLang[id][0]++
|
||||
if (g_menuLang[id] < (g_langNum - 1))
|
||||
{
|
||||
g_menuLang[id]++
|
||||
}
|
||||
else
|
||||
g_menuLang[id][0] = 0
|
||||
{
|
||||
g_menuLang[id] = 0
|
||||
}
|
||||
|
||||
showMenu(id)
|
||||
}
|
||||
|
||||
if (isAdmin && (key == 1))
|
||||
else if(key == 1)
|
||||
{
|
||||
if (g_menuLang[id][1] < (g_langNum - 1))
|
||||
g_menuLang[id][1]++
|
||||
else
|
||||
g_menuLang[id][1] = 0
|
||||
new pLang[3], pLang_old[3]
|
||||
|
||||
showMenu(id)
|
||||
}
|
||||
get_lang(g_menuLang[id], pLang)
|
||||
get_user_info(id, "lang", pLang_old, 2)
|
||||
|
||||
new pLang[3], pLang_old[3], sLang[3], sLang_old[3], lName[64]
|
||||
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
|
||||
|
||||
get_lang(g_menuLang[id][0], pLang)
|
||||
get_lang(g_menuLang[id][1], sLang)
|
||||
get_user_info(id, "lang", pLang_old, 2)
|
||||
get_lang(g_serverLang, sLang_old)
|
||||
|
||||
if (isAdmin && (key == 2) && !equali(sLang, sLang_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)
|
||||
format(lName, 63, "%L", pLang, "LANG_NAME")
|
||||
client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName)
|
||||
new lName[64]
|
||||
formatex(lName, charsmax(lName), "%L", pLang, "LANG_NAME")
|
||||
client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName)
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
|
@ -222,8 +160,11 @@ get_lang_id(lang[])
|
|||
for (new i = 0; i < g_langNum; i++)
|
||||
{
|
||||
get_lang(i, tLang)
|
||||
|
||||
if (equali(tLang, lang))
|
||||
{
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user