amxmodx/plugins/multilingual.sma

206 lines
5.6 KiB
Plaintext
Raw Normal View History

2004-07-31 05:06:58 +04:00
/* AMX Mod X script.
* Multilingual System Plugin
*
* by the AMX Mod X Development Team
*
* This file is part of AMX Mod X.
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
#include <amxmodx>
#include <amxmisc>
2004-08-13 15:20:32 +04:00
#define DISPLAY_MSG // Comment to disable message on join
2004-07-31 05:06:58 +04:00
new g_menuLang[33][2]
new g_serverLang
new g_langNum
new g_coloredMenus
2004-09-09 09:17:28 +04:00
public plugin_init()
{
2004-07-31 13:51:34 +04:00
register_plugin("Multi-Lingual System",AMXX_VERSION_STR,"AMXX Dev Team")
2004-07-31 05:06:58 +04:00
register_dictionary("multilingual.txt")
2004-07-31 13:51:34 +04:00
register_dictionary("common.txt")
2004-08-21 00:54:47 +04:00
register_dictionary("languages.txt")
2004-08-05 15:04:51 +04:00
register_cvar("amx_language","en",FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)
2004-08-30 07:31:00 +04:00
//Set to zero to disable client effects
register_cvar("amx_client_languages", "1")
2004-08-05 15:04:51 +04:00
register_concmd("amx_setlang","cmdLang",ADMIN_CFG,"<language>")
2004-08-13 15:20:32 +04:00
register_clcmd("amx_langmenu","cmdLangMenu",ADMIN_ALL)
2004-07-31 05:06:58 +04:00
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("amxx_language",lang)
g_serverLang = get_lang_id(lang)
g_langNum = get_langsnum()
g_coloredMenus = colored_menus()
}
2004-08-13 15:20:32 +04:00
#if defined DISPLAY_MSG
public client_putinserver(id) {
2004-08-30 07:31:00 +04:00
if (get_cvar_num("amx_client_languages"))
set_task(10.0,"dispInfo",id)
2004-08-13 15:20:32 +04:00
}
2004-07-31 05:06:58 +04:00
2004-09-09 09:17:28 +04:00
public dispInfo(id)
{
2004-08-30 07:31:00 +04:00
if (get_cvar_num("amx_client_languages"))
client_print(id,print_chat,"%L",id,"TYPE_LANGMENU")
2004-08-13 15:20:32 +04:00
}
#endif
2004-07-31 05:06:58 +04:00
public cmdLang(id,level,cid) {
if (!cmd_access(id,level,cid,2))
return PLUGIN_HANDLED
2004-09-09 09:17:28 +04:00
2004-07-31 05:06:58 +04:00
new arg[3]
read_argv(1,arg,2)
if ( !lang_exists(arg) ) {
2004-07-31 13:51:34 +04:00
console_print(id,"[AMXX] %L",id,"LANG_NOT_EXISTS")
2004-07-31 05:06:58 +04:00
return PLUGIN_HANDLED
}
set_vaultdata("server_language",arg)
set_cvar_string("amxx_language",arg)
g_serverLang = get_lang_id(arg)
return PLUGIN_HANDLED
}
2004-09-09 09:17:28 +04:00
public cmdLangMenu(id,level,cid)
{
2004-08-21 00:54:47 +04:00
new buffer[3]
2004-09-09 09:17:28 +04:00
if (!get_cvar_num("amx_client_languages"))
2004-09-17 02:39:07 +04:00
{
2004-09-19 04:37:58 +04:00
client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
2004-09-09 09:17:28 +04:00
return PLUGIN_HANDLED
2004-09-17 02:39:07 +04:00
}
2004-09-09 09:17:28 +04:00
2004-08-21 00:54:47 +04:00
get_user_info(id,"lang",buffer,2)
g_menuLang[id][0] = get_lang_id(buffer)
2004-07-31 05:06:58 +04:00
g_menuLang[id][1] = g_serverLang
showMenu(id)
return PLUGIN_HANDLED
}
2004-09-09 09:17:28 +04:00
showMenu(id)
{
if (!get_cvar_num("amx_client_languages"))
return PLUGIN_HANDLED
2004-08-21 00:54:47 +04:00
new menuBody[512],pLang[3]
2004-07-31 05:06:58 +04:00
get_lang(g_menuLang[id][0],pLang)
new len = format( menuBody,511,(g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"),id,"LANG_MENU" )
2004-08-21 00:54:47 +04:00
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" )
2004-07-31 05:06:58 +04:00
if ( access(id,ADMIN_CFG) ) {
2004-08-21 00:54:47 +04:00
new sLang[3]
2004-07-31 05:06:58 +04:00
get_lang(g_menuLang[id][1],sLang)
2004-08-22 15:49:12 +04:00
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" )
2004-07-31 05:06:58 +04:00
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")
2004-09-09 09:17:28 +04:00
return 1
2004-07-31 05:06:58 +04:00
}
public actionMenu(id,key) {
2004-08-30 07:31:00 +04:00
if (!get_cvar_num("amx_client_languages"))
2004-09-09 09:17:28 +04:00
return 0
2004-09-01 15:41:07 +04:00
2004-07-31 05:06:58 +04:00
new isAdmin = access(id,ADMIN_CFG)
if ( key==0 ) {
if ( g_menuLang[id][0]<(g_langNum-1) )
g_menuLang[id][0]++
else
g_menuLang[id][0] = 0
showMenu(id)
}
if ( isAdmin && (key==1) ) {
if ( g_menuLang[id][1]<(g_langNum-1) )
g_menuLang[id][1]++
else
g_menuLang[id][1] = 0
showMenu(id)
}
2004-08-21 00:54:47 +04:00
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_lang(g_serverLang,sLang_old)
if ( isAdmin && (key==2) && !equali(sLang,sLang_old) ) {
2004-07-31 05:06:58 +04:00
set_vaultdata("server_language",sLang)
set_cvar_string("amxx_language",sLang)
g_serverLang = g_menuLang[id][1]
2004-08-21 00:54:47 +04:00
format(lName,63,"%L",sLang,"LANG_NAME")
client_print(id,print_chat,"%L",pLang,"SET_LANG_SERVER",lName)
2004-07-31 05:06:58 +04:00
}
2004-08-21 00:54:47 +04:00
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)
2004-07-31 05:06:58 +04:00
}
2004-09-09 09:17:28 +04:00
return 0
2004-07-31 05:06:58 +04:00
}
get_lang_id(lang[]) {
new tLang[3]
for (new i=0;i<g_langNum;i++) {
get_lang(i,tLang)
if ( equali(tLang,lang) )
return i
}
return 0
2004-09-19 04:37:58 +04:00
}