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

Annotation of /statscfg.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Stats Configuration Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     * originally developed by OLO
6 :     *
7 :     * This file is part of AMX Mod X.
8 :     *
9 :     *
10 :     * This program is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by the
12 :     * Free Software Foundation; either version 2 of the License, or (at
13 :     * your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful, but
16 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 :     * General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software Foundation,
22 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * In addition, as a special exception, the author gives permission to
25 :     * link the code of this program with the Half-Life Game Engine ("HL
26 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
27 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
28 :     * respects for all of the code used other than the HL Engine and MODs
29 :     * from Valve. If you modify this file, you may extend this exception
30 :     * to your version of the file, but you are not obligated to do so. If
31 :     * you do not wish to do so, delete this exception statement from your
32 :     * version.
33 :     */
34 :    
35 :     #include <amxmodx>
36 :     #include <amxmisc>
37 :    
38 :     #define MAX_MENU_DATA 64
39 :    
40 :     new g_menuData[MAX_MENU_DATA][32]
41 :     new g_menuDataVar[MAX_MENU_DATA][32]
42 :     new g_menuDataId[MAX_MENU_DATA]
43 :     new g_menuDataNum
44 :     new g_menuPosition[33]
45 :     new g_fileToSave[64]
46 :     new bool:g_modified
47 :     new g_coloredMenus
48 :    
49 :     public plugin_precache()
50 :     {
51 :     register_clcmd("amx_statscfgmenu", "cmdCfgMenu", ADMIN_CFG, "- displays stats configuration menu")
52 :     register_dictionary("statscfg.txt")
53 :     register_dictionary("common.txt")
54 :     register_concmd("amx_statscfg", "cmdCfg", ADMIN_CFG, "- displays help for stats configuration")
55 :     }
56 :    
57 :     public plugin_init()
58 :     {
59 :     register_plugin("Stats Configuration", AMXX_VERSION_STR, "AMXX Dev Team")
60 :     register_menucmd(register_menuid("Stats Configuration"), 1023, "actionCfgMenu")
61 :    
62 :     get_configsdir(g_fileToSave, 63)
63 :     format(g_fileToSave, 63, "%s/stats.ini", g_fileToSave)
64 :     loadSettings(g_fileToSave)
65 :     g_coloredMenus = colored_menus()
66 :     }
67 :    
68 :     public cmdCfg(id, level, cid)
69 :     {
70 :     if (!cmd_access(id, level, cid, 1))
71 :     return PLUGIN_HANDLED
72 :    
73 :     new cmds[32]
74 :     read_argv(1, cmds, 31)
75 :    
76 :     new option = equali(cmds, "on") ? 1 : 0
77 :    
78 :     if (!option)
79 :     option = equali(cmds, "off") ? 2 : 0
80 :    
81 :     if (read_argc() > 2 && option)
82 :     {
83 :     new var[32], enabled = 0
84 :     read_argv(2, var, 31)
85 :    
86 :     for (new a = 0; a < g_menuDataNum; ++a)
87 :     {
88 :     if (containi(g_menuDataVar[a], var) != -1)
89 :     {
90 :     g_modified = true
91 :     ++enabled
92 :     if (option == 1)
93 :     {
94 :     set_xvar_num(g_menuDataId[a], 1)
95 :     console_print(id, "%L: %s", id, "STATS_ENABLED", g_menuData[a])
96 :     } else {
97 :     set_xvar_num(g_menuDataId[a], 0)
98 :     console_print(id, "%L: %s", id, "STATS_DISABLED", g_menuData[a])
99 :     }
100 :     }
101 :     }
102 :    
103 :     if (enabled)
104 :     console_print(id, "%L", id, "TOTAL_NUM", enabled)
105 :     else
106 :     console_print(id, "%L", id, "NO_OPTION", var)
107 :     }
108 :     else if (equali(cmds, "save"))
109 :     {
110 :     if (saveSettings(g_fileToSave))
111 :     {
112 :     g_modified = false
113 :     console_print(id, "%L", id, "STATS_CONF_SAVED")
114 :     }
115 :     else
116 :     console_print(id, "%L", id, "STATS_CONF_FAILED")
117 :     }
118 :     else if (equali(cmds, "load"))
119 :     {
120 :     if (loadSettings(g_fileToSave))
121 :     {
122 :     g_modified = false
123 :     console_print(id, "%L", id, "STATS_CONF_LOADED")
124 :     }
125 :     else
126 :     console_print(id, "%L", id, "STATS_CONF_FAIL_LOAD")
127 :     }
128 :     else if (equali(cmds, "list"))
129 :     {
130 :     new arg1[8]
131 :     new start = read_argv(2, arg1, 7) ? str_to_num(arg1) : 1
132 :    
133 :     if (--start < 0) start = 0
134 :    
135 :     if (start >= g_menuDataNum)
136 :     start = g_menuDataNum - 1
137 :    
138 :     new end = start + 10
139 :    
140 :     if (end > g_menuDataNum)
141 :     end = g_menuDataNum
142 :    
143 :     new lName[16], lVariable[16], lStatus[16]
144 :    
145 :     format(lName, 15, "%L", id, "NAME")
146 :     format(lVariable, 15, "%L", id, "VARIABLE")
147 :     format(lStatus, 15, "%L", id, "STATUS")
148 :     console_print(id, "^n----- %L: -----", id, "STATS_CONF")
149 :     console_print(id, " %-29.28s %-24.23s %-9.8s", lName, lVariable, lStatus)
150 :    
151 :     if (start != -1)
152 :     {
153 :     new lOnOff[16]
154 :    
155 :     for (new a = start; a < end; ++a)
156 :     {
157 :     format(lOnOff, 15, "%L", id, get_xvar_num(g_menuDataId[a]) ? "ON" : "OFF")
158 :     console_print(id, "%3d: %-29.28s %-24.23s %-9.8s", a + 1, g_menuData[a], g_menuDataVar[a], lOnOff)
159 :     }
160 :     }
161 :    
162 :     console_print(id, "----- %L -----", id, "STATS_ENTRIES_OF", start + 1, end, g_menuDataNum)
163 :    
164 :     if (end < g_menuDataNum)
165 :     console_print(id, "----- %L -----", id, "STATS_USE_MORE", end + 1)
166 :     else
167 :     console_print(id, "----- %L -----", id, "STATS_USE_BEGIN")
168 :     }
169 :     else if (equali(cmds, "add") && read_argc() > 3)
170 :     {
171 :     if (g_menuDataNum < MAX_MENU_DATA)
172 :     {
173 :     read_argv(2, g_menuData[g_menuDataNum], 31)
174 :     read_argv(3, g_menuDataVar[g_menuDataNum], 31)
175 :     g_menuDataId[g_menuDataNum] = get_xvar_id(g_menuDataVar[g_menuDataNum])
176 :     ++g_menuDataNum
177 :     }
178 :     else
179 :     console_print(id, "%L", id, "CANT_ADD_STATS")
180 :     } else {
181 :     console_print(id, "%L", id, "COM_STATS_USAGE")
182 :     console_print(id, "%L", id, "COM_STATS_COM")
183 :     console_print(id, "%L", id, "COM_STATS_ON")
184 :     console_print(id, "%L", id, "COM_STATS_OFF")
185 :     console_print(id, "%L", id, "COM_STATS_SAVE")
186 :     console_print(id, "%L", id, "COM_STATS_LOAD")
187 :     console_print(id, "%L", id, "COM_STATS_LIST")
188 :     console_print(id, "%L", id, "COM_STATS_ADD")
189 :     }
190 :    
191 :     return PLUGIN_HANDLED
192 :     }
193 :    
194 :     public cmdCfgMenu(id, level, cid)
195 :     {
196 :     if (cmd_access(id, level, cid, 1))
197 :     displayCfgMenu(id, g_menuPosition[id] = 0)
198 :    
199 :     return PLUGIN_HANDLED
200 :     }
201 :    
202 :     displayCfgMenu(id, pos)
203 :     {
204 :     if (pos < 0)
205 :     return
206 :    
207 :     new menu_body[512], start = pos * 7
208 :    
209 :     if (start >= g_menuDataNum)
210 :     start = pos = g_menuPosition[id] = 0
211 :    
212 :     new len = format(menu_body, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "STATS_CONF", pos + 1, ((g_menuDataNum / 7)+((g_menuDataNum % 7) ? 1 : 0)))
213 :     new end = start + 7, keys = MENU_KEY_0|MENU_KEY_8, k = 0
214 :    
215 :     if (end > g_menuDataNum)
216 :     end = g_menuDataNum
217 :    
218 :     for (new a = start; a < end; ++a)
219 :     {
220 :     keys |= (1<<k)
221 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "%d. %s\y\R%L^n\w" : "%d. %s %L^n", ++k, g_menuData[a], id, get_xvar_num(g_menuDataId[a]) ? "ON" : "OFF")
222 :     }
223 :    
224 :     if (g_menuDataNum == 0)
225 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "\d%L\w" : "%L", id, "NO_STATS")
226 :    
227 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "^n8. %L\y\R%s^n\w" : "^n8. %L %s^n", id, "SAVE_CONF", g_modified ? "*" : "")
228 :    
229 :     if (end != g_menuDataNum)
230 :     {
231 :     format(menu_body[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
232 :     keys |= MENU_KEY_9
233 :     }
234 :     else
235 :     format(menu_body[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
236 :    
237 :     show_menu(id, keys, menu_body, -1, "Stats Configuration")
238 :     }
239 :    
240 :     public actionCfgMenu(id, key)
241 :     {
242 :     switch (key)
243 :     {
244 :     case 7:
245 :     {
246 :     if (saveSettings(g_fileToSave))
247 :     {
248 :     g_modified = false
249 :     client_print(id, print_chat, "* %L", id, "STATS_CONF_SAVED")
250 :     }
251 :     else
252 :     client_print(id, print_chat, "* %L", id, "STATS_CONF_FAILED")
253 :    
254 :     displayCfgMenu(id, g_menuPosition[id])
255 :     }
256 :     case 8: displayCfgMenu(id, ++g_menuPosition[id])
257 :     case 9: displayCfgMenu(id, --g_menuPosition[id])
258 :     default:
259 :     {
260 :     g_modified = true
261 :     new a = g_menuPosition[id] * 7 + key
262 :     set_xvar_num(g_menuDataId[a], 1 - get_xvar_num(g_menuDataId[a]))
263 :    
264 :     displayCfgMenu(id, g_menuPosition[id])
265 :     }
266 :     }
267 :    
268 :     return PLUGIN_HANDLED
269 :     }
270 :    
271 :     saveSettings(filename[])
272 :     {
273 :     if (file_exists(filename))
274 :     delete_file(filename)
275 :    
276 :     if (!write_file(filename, ";Generated by Stats Configuration Plugin. Do not modify!^n;Variable Description"))
277 :     return 0
278 :    
279 :     new text[256]
280 :    
281 :     for (new a = 0; a < g_menuDataNum; ++a)
282 :     {
283 :     if (get_xvar_num(g_menuDataId[a]))
284 :     {
285 :     format(text, 255, "%-24.23s ;%s", g_menuDataVar[a], g_menuData[a])
286 :     write_file(filename, text)
287 :     }
288 :     }
289 :    
290 :     return 1
291 :     }
292 :    
293 :     loadSettings(filename[])
294 :     {
295 :     if (!file_exists(filename))
296 :     return 0
297 :    
298 :     new text[256], name[32]
299 :     new len, pos = 0, xid
300 :    
301 :     while (read_file(filename, pos++, text, 255, len))
302 :     {
303 :     if (text[0] == ';') continue // line is a comment
304 :    
305 :     parse(text, name, 31)
306 :    
307 :     if ((xid = get_xvar_id(name)) != -1)
308 :     set_xvar_num(xid, 1)
309 :     }
310 :    
311 :     return 1
312 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4