From db4041114f14b51a570b767c4277475468ba1dfa Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 8 Oct 2004 19:26:26 +0000 Subject: [PATCH] Fixed a bug in amx_client_languages Added lang_phrase --- amxmodx/CLang.cpp | 4 ++-- amxmodx/amxmodx.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index cdad7c57..be7d7036 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -536,7 +536,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len) // Handle player ids (1-32) and server language if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER { - if ((int)CVAR_GET_FLOAT("amx_client_languages")) + if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0) { cpLangName = g_vault.get("server_language"); } else { @@ -545,7 +545,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len) } else if (*pAmxLangName == LANG_SERVER) { // LANG_SERVER cpLangName = g_vault.get("server_language"); } else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) { // Direct Client Id - if ((int)CVAR_GET_FLOAT("amx_client_languages")) + if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0) { cpLangName = g_vault.get("server_language"); } else { diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 035ecd18..f7d91ecb 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2680,6 +2680,35 @@ cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL lang_phrase(AMX *amx, cell *params) +{ + int len = 0; + int iLang = params[1]; + + const char *cpLangName=NULL; + // Handle player ids (1-32) and server language + if (iLang == LANG_SERVER) { // LANG_SERVER + cpLangName = g_vault.get("server_language"); + } else if (iLang >= 1 && iLang <= 32) { // Direct Client Id + if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0) + { + cpLangName = g_vault.get("server_language"); + } else { + cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(iLang)->pEdict, "lang"); + } + } + if (!cpLangName || strlen(cpLangName) < 1) + cpLangName = "en"; + + const char *str = get_amxstring(amx, params[2], 0, len); + + const char *dat = g_langMngr.GetDef(cpLangName, str); + + set_amxstring(amx, params[3], dat?dat:"ML_LNOTFOUND", params[4]); + + return 1; +} + AMX_NATIVE_INFO amxmod_Natives[] = { { "client_cmd", client_cmd }, { "client_print", client_print }, @@ -2839,5 +2868,6 @@ AMX_NATIVE_INFO amxmod_Natives[] = { { "md5", amx_md5 }, { "md5_file", amx_md5_file }, { "plugin_flags", plugin_flags}, + { "lang_phrase", lang_phrase}, { NULL, NULL } };