[Half-Life AMXX] / multilingual.sma Repository:
ViewVC logotype

Annotation of /multilingual.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X script.
2 :     * Multilingual System Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     *
6 :     * This file is part of AMX Mod X.
7 :     *
8 :     *
9 :     * This program is free software; you can redistribute it and/or modify it
10 :     * under the terms of the GNU General Public License as published by the
11 :     * Free Software Foundation; either version 2 of the License, or (at
12 :     * your option) any later version.
13 :     *
14 :     * This program is distributed in the hope that it will be useful, but
15 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
16 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 :     * General Public License for more details.
18 :     *
19 :     * You should have received a copy of the GNU General Public License
20 :     * along with this program; if not, write to the Free Software Foundation,
21 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 :     *
23 :     * In addition, as a special exception, the author gives permission to
24 :     * link the code of this program with the Half-Life Game Engine ("HL
25 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
26 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
27 :     * respects for all of the code used other than the HL Engine and MODs
28 :     * from Valve. If you modify this file, you may extend this exception
29 :     * to your version of the file, but you are not obligated to do so. If
30 :     * you do not wish to do so, delete this exception statement from your
31 :     * version.
32 :     */
33 :    
34 :     #include <amxmodx>
35 :     #include <amxmisc>
36 :    
37 :     #define DISPLAY_MSG // Comment to disable message on join
38 :    
39 :     new g_menuLang[33][2]
40 :     new g_serverLang
41 :     new g_langNum
42 :     new g_coloredMenus
43 :    
44 :     public plugin_init()
45 :     {
46 :     register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team")
47 :     register_dictionary("multilingual.txt")
48 :     register_dictionary("common.txt")
49 :     register_dictionary("languages.txt")
50 :    
51 :     register_cvar("amx_language", "en", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)
52 :     //Set to zero to disable client effects
53 :     register_cvar("amx_client_languages", "1")
54 :     register_concmd("amx_setlang", "cmdLang", ADMIN_CFG, "<language>")
55 :     register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL)
56 :     register_menu("Language Menu", 1023, "actionMenu")
57 :    
58 :     new lang[3]
59 :    
60 :     if (vaultdata_exists("server_language"))
61 :     {
62 :     get_vaultdata("server_language", lang, 2)
63 :     } else {
64 :     copy(lang, 2, "en")
65 :     set_vaultdata("server_language", lang)
66 :     }
67 :    
68 :     set_cvar_string("amx_language", lang)
69 :    
70 :     g_langNum = get_langsnum()
71 :     g_serverLang = get_lang_id(lang)
72 :     g_coloredMenus = colored_menus()
73 :     }
74 :    
75 :     #if defined DISPLAY_MSG
76 :     public client_putinserver(id)
77 :     {
78 :     if (get_cvar_num("amx_client_languages") && !is_user_bot(id))
79 :     set_task(10.0, "dispInfo", id)
80 :     }
81 :    
82 :     public client_disconnect(id)
83 :     {
84 :     remove_task(id)
85 :     }
86 :    
87 :     public dispInfo(id)
88 :     {
89 :     if (get_cvar_num("amx_client_languages"))
90 :     client_print(id, print_chat, "%L", id, "TYPE_LANGMENU")
91 :     }
92 :     #endif
93 :    
94 :     public cmdLang(id, level, cid)
95 :     {
96 :     if (!cmd_access(id, level, cid, 2))
97 :     return PLUGIN_HANDLED
98 :    
99 :     new arg[3]
100 :     read_argv(1, arg, 2)
101 :    
102 :     if (!lang_exists(arg))
103 :     {
104 :     console_print(id, "[AMXX] %L", id, "LANG_NOT_EXISTS")
105 :     return PLUGIN_HANDLED
106 :     }
107 :    
108 :     set_vaultdata("server_language", arg)
109 :     set_cvar_string("amx_language", arg)
110 :     g_serverLang = get_lang_id(arg)
111 :    
112 :     return PLUGIN_HANDLED
113 :     }
114 :    
115 :     public cmdLangMenu(id, level, cid)
116 :     {
117 :     new buffer[3]
118 :    
119 :     if (!get_cvar_num("amx_client_languages"))
120 :     {
121 :     client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
122 :     return PLUGIN_HANDLED
123 :     }
124 :    
125 :     get_user_info(id, "lang", buffer, 2)
126 :     g_menuLang[id][0] = get_lang_id(buffer)
127 :     g_menuLang[id][1] = g_serverLang
128 :    
129 :     showMenu(id)
130 :    
131 :     return PLUGIN_HANDLED
132 :     }
133 :    
134 :     showMenu(id)
135 :     {
136 :     if (!get_cvar_num("amx_client_languages"))
137 :     return PLUGIN_HANDLED
138 :    
139 :     new menuBody[512], pLang[3]
140 :    
141 :     get_lang(g_menuLang[id][0], pLang)
142 :    
143 :     new len = format(menuBody, 511, (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU")
144 :    
145 :     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")
146 :    
147 :     if (access(id, ADMIN_CFG))
148 :     {
149 :     new sLang[3]
150 :    
151 :     get_lang(g_menuLang[id][1], sLang)
152 :     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")
153 :     len += format(menuBody[len], 511-len, "3. %L", id, "SAVE_LANG")
154 :     } else {
155 :     len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG")
156 :     }
157 :    
158 :     format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT")
159 :    
160 :     show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3, menuBody, -1, "Language Menu")
161 :    
162 :     return 1
163 :     }
164 :    
165 :     public actionMenu(id, key)
166 :     {
167 :     if (!get_cvar_num("amx_client_languages"))
168 :     return 0
169 :    
170 :     new isAdmin = access(id, ADMIN_CFG)
171 :    
172 :     if (key == 0)
173 :     {
174 :     if (g_menuLang[id][0] < (g_langNum-1))
175 :     g_menuLang[id][0]++
176 :     else
177 :     g_menuLang[id][0] = 0
178 :    
179 :     showMenu(id)
180 :     }
181 :    
182 :     if (isAdmin && (key == 1))
183 :     {
184 :     if (g_menuLang[id][1] < (g_langNum - 1))
185 :     g_menuLang[id][1]++
186 :     else
187 :     g_menuLang[id][1] = 0
188 :    
189 :     showMenu(id)
190 :     }
191 :    
192 :     new pLang[3], pLang_old[3], sLang[3], sLang_old[3], lName[64]
193 :    
194 :     get_lang(g_menuLang[id][0], pLang)
195 :     get_lang(g_menuLang[id][1], sLang)
196 :     get_user_info(id, "lang", pLang_old, 2)
197 :     get_lang(g_serverLang, sLang_old)
198 :    
199 :     if (isAdmin && (key == 2) && !equali(sLang, sLang_old))
200 :     {
201 :     set_vaultdata("server_language", sLang)
202 :     set_cvar_string("amx_language", sLang)
203 :     g_serverLang = g_menuLang[id][1]
204 :     format(lName, 63, "%L", sLang, "LANG_NAME")
205 :     client_print(id, print_chat, "%L", pLang, "SET_LANG_SERVER", lName)
206 :     }
207 :    
208 :     if (!equali(pLang, pLang_old) && ((isAdmin && (key == 2)) || (!isAdmin && (key == 1))))
209 :     {
210 :     client_cmd(id, "setinfo ^"lang^" ^"%s^"", pLang)
211 :     format(lName, 63, "%L", pLang, "LANG_NAME")
212 :     client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName)
213 :     }
214 :    
215 :     return 0
216 :     }
217 :    
218 :     get_lang_id(lang[])
219 :     {
220 :     new tLang[3]
221 :    
222 :     for (new i = 0; i < g_langNum; i++)
223 :     {
224 :     get_lang(i, tLang)
225 :     if (equali(tLang, lang))
226 :     return i
227 :     }
228 :    
229 :     return 0
230 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4