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

Annotation of /mapsmenu.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Maps Menu 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_MAPS 64
39 :    
40 :     new g_mapName[MAX_MAPS][32]
41 :     new g_mapNums
42 :     new g_menuPosition[33]
43 :    
44 :     new g_voteCount[5]
45 :    
46 :     new g_voteSelected[33][4]
47 :     new g_voteSelectedNum[33]
48 :    
49 :     new g_coloredMenus
50 :    
51 :     new g_choosed
52 :    
53 :     public plugin_init()
54 :     {
55 :     register_plugin("Maps Menu", AMXX_VERSION_STR, "AMXX Dev Team")
56 :     register_dictionary("mapsmenu.txt")
57 :     register_dictionary("common.txt")
58 :     register_clcmd("amx_mapmenu", "cmdMapsMenu", ADMIN_MAP, "- displays changelevel menu")
59 :     register_clcmd("amx_votemapmenu", "cmdVoteMapMenu", ADMIN_VOTE, "- displays votemap menu")
60 :    
61 :     register_menucmd(register_menuid("Changelevel Menu"), 1023, "actionMapsMenu")
62 :     register_menucmd(register_menuid("Which map do you want?"), 527, "voteCount")
63 :     register_menucmd(register_menuid("Change map to"), 527, "voteCount")
64 :     register_menucmd(register_menuid("Votemap Menu"), 1023, "actionVoteMapMenu")
65 :     register_menucmd(register_menuid("The winner: "), 3, "actionResult")
66 :    
67 :     new maps_ini_file[64];
68 :     get_configsdir(maps_ini_file, 63);
69 :     format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file);
70 :    
71 :     if (!file_exists(maps_ini_file))
72 :     format(maps_ini_file, 63, "mapcycle.txt")
73 :    
74 :     load_settings(maps_ini_file)
75 :    
76 :     g_coloredMenus = colored_menus()
77 :     }
78 :    
79 :     public autoRefuse()
80 :     {
81 :     log_amx("Vote: %L", "en", "RESULT_REF")
82 :     client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_REF")
83 :     }
84 :    
85 :     public actionResult(id, key)
86 :     {
87 :     remove_task(4545454)
88 :    
89 :     switch (key)
90 :     {
91 :     case 0:
92 :     {
93 :     new _modName[10]
94 :     get_modname(_modName, 9)
95 :    
96 :     if (!equal(_modName, "zp"))
97 :     {
98 :     message_begin(MSG_ALL, SVC_INTERMISSION)
99 :     message_end()
100 :     }
101 :    
102 :     set_task(2.0, "delayedChange", 0, g_mapName[g_choosed], strlen(g_mapName[g_choosed]) + 1)
103 :     log_amx("Vote: %L", "en", "RESULT_ACC")
104 :     client_print(0, print_chat, "%L", LANG_PLAYER, "RESULT_ACC")
105 :     }
106 :     case 1: autoRefuse()
107 :     }
108 :    
109 :     return PLUGIN_HANDLED
110 :     }
111 :    
112 :     public checkVotes(id)
113 :     {
114 :     id -= 34567
115 :     new num, ppl[32], a = 0
116 :    
117 :     get_players(ppl, num, "c")
118 :     if (num == 0) num = 1
119 :     g_choosed = -1
120 :    
121 :     for (new i = 0; i < g_voteSelectedNum[id]; ++i)
122 :     if (g_voteCount[a] < g_voteCount[i])
123 :     a = i
124 :    
125 :     new votesNum = g_voteCount[0] + g_voteCount[1] + g_voteCount[2] + g_voteCount[3] + g_voteCount[4]
126 :     new iRatio = votesNum ? floatround(get_cvar_float("amx_votemap_ratio") * float(votesNum), floatround_ceil) : 1
127 :     new iResult = g_voteCount[a]
128 :    
129 :     if (iResult >= iRatio)
130 :     {
131 :     g_choosed = g_voteSelected[id][a]
132 :     client_print(0, print_chat, "%L %s", LANG_PLAYER, "VOTE_SUCCESS", g_mapName[g_choosed])
133 :     log_amx("Vote: %L %s", "en", "VOTE_SUCCESS", g_mapName[g_choosed])
134 :     }
135 :    
136 :     if (g_choosed != -1)
137 :     {
138 :     if (is_user_connected(id))
139 :     {
140 :     new menuBody[512]
141 :     new len = format(menuBody, 511, g_coloredMenus ? "\y%L: \w%s^n^n" : "%L: %s^n^n", id, "THE_WINNER", g_mapName[g_choosed])
142 :    
143 :     len += format(menuBody[len], 511 - len, g_coloredMenus ? "\y%L^n\w" : "%L^n", id, "WANT_CONT")
144 :     format(menuBody[len], 511-len, "^n1. %L^n2. %L", id, "YES", id, "NO")
145 :    
146 :     show_menu(id, 0x03, menuBody, 10, "The winner: ")
147 :     set_task(10.0, "autoRefuse", 4545454)
148 :     } else {
149 :     new _modName[10]
150 :     get_modname(_modName, 9)
151 :    
152 :     if (!equal(_modName, "zp"))
153 :     {
154 :     message_begin(MSG_ALL, SVC_INTERMISSION)
155 :     message_end()
156 :     }
157 :    
158 :     set_task(2.0, "delayedChange", 0, g_mapName[g_choosed], strlen(g_mapName[g_choosed]) + 1)
159 :     }
160 :     } else {
161 :     client_print(0, print_chat, "%L", LANG_PLAYER, "VOTE_FAILED")
162 :     log_amx("Vote: %L", "en", "VOTE_FAILED")
163 :     }
164 :    
165 :     remove_task(34567 + id)
166 :     }
167 :    
168 :     public voteCount(id, key)
169 :     {
170 :     if (key > 3)
171 :     {
172 :     client_print(0, print_chat, "%L", LANG_PLAYER, "VOT_CANC")
173 :     remove_task(34567 + id)
174 :     set_cvar_float("amx_last_voting", get_gametime())
175 :     log_amx("Vote: Cancel vote session")
176 :    
177 :     return PLUGIN_HANDLED
178 :     }
179 :    
180 :     if (get_cvar_float("amx_vote_answers"))
181 :     {
182 :     new name[32]
183 :    
184 :     get_user_name(id, name, 31)
185 :     client_print(0, print_chat, "%L", LANG_PLAYER, "X_VOTED_FOR", name, key + 1)
186 :     }
187 :    
188 :     ++g_voteCount[key]
189 :    
190 :     return PLUGIN_HANDLED
191 :     }
192 :    
193 :     isMapSelected(id, pos)
194 :     {
195 :     for (new a = 0; a < g_voteSelectedNum[id]; ++a)
196 :     if (g_voteSelected[id][a] == pos)
197 :     return 1
198 :     return 0
199 :     }
200 :    
201 :     displayVoteMapsMenu(id, pos)
202 :     {
203 :     if (pos < 0)
204 :     return
205 :    
206 :     new menuBody[512], b = 0, start = pos * 7
207 :    
208 :     if (start >= g_mapNums)
209 :     start = pos = g_menuPosition[id] = 0
210 :    
211 :     new len = format(menuBody, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "VOTEMAP_MENU", pos + 1, (g_mapNums / 7 + ((g_mapNums % 7) ? 1 : 0)))
212 :     new end = start + 7, keys = MENU_KEY_0
213 :    
214 :     if (end > g_mapNums)
215 :     end = g_mapNums
216 :    
217 :     for (new a = start; a < end; ++a)
218 :     {
219 :     if (g_voteSelectedNum[id] == 4 || isMapSelected(id, pos * 7 + b))
220 :     {
221 :     ++b
222 :    
223 :     if (g_coloredMenus)
224 :     len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_mapName[a])
225 :     else
226 :     len += format(menuBody[len], 511-len, "#. %s^n", g_mapName[a])
227 :     } else {
228 :     keys |= (1<<b)
229 :     len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_mapName[a])
230 :     }
231 :     }
232 :    
233 :     if (g_voteSelectedNum[id])
234 :     {
235 :     keys |= MENU_KEY_8
236 :     len += format(menuBody[len], 511-len, "^n8. %L^n", id, "START_VOT")
237 :     }
238 :     else
239 :     len += format(menuBody[len], 511-len, g_coloredMenus ? "^n\d8. %L^n\w" : "^n#. %L^n", id, "START_VOT")
240 :    
241 :     if (end != g_mapNums)
242 :     {
243 :     len += format(menuBody[len], 511-len, "^n9. %L...^n0. %L^n", id, "MORE", id, pos ? "BACK" : "EXIT")
244 :     keys |= MENU_KEY_9
245 :     }
246 :     else
247 :     len += format(menuBody[len], 511-len, "^n0. %L^n", id, pos ? "BACK" : "EXIT")
248 :    
249 :     if (g_voteSelectedNum[id])
250 :     len += format(menuBody[len], 511-len, g_coloredMenus ? "^n\y%L:^n\w" : "^n%L:^n", id, "SEL_MAPS")
251 :     else
252 :     len += format(menuBody[len], 511-len, "^n^n")
253 :    
254 :     for (new c = 0; c < 4; c++)
255 :     {
256 :     if (c < g_voteSelectedNum[id])
257 :     len += format(menuBody[len], 511-len, "%s^n", g_mapName[g_voteSelected[id][c]])
258 :     else
259 :     len += format(menuBody[len], 511-len, "^n")
260 :     }
261 :    
262 :     new menuName[64]
263 :     format(menuName, 63, "%L", "en", "VOTEMAP_MENU")
264 :    
265 :     show_menu(id, keys, menuBody, -1, menuName)
266 :     }
267 :    
268 :     public cmdVoteMapMenu(id, level, cid)
269 :     {
270 :     if (!cmd_access(id, level, cid, 1))
271 :     return PLUGIN_HANDLED
272 :    
273 :     if (get_cvar_float("amx_last_voting") > get_gametime())
274 :     {
275 :     client_print(id, print_chat, "%L", id, "ALREADY_VOT")
276 :     return PLUGIN_HANDLED
277 :     }
278 :    
279 :     g_voteSelectedNum[id] = 0
280 :    
281 :     if (g_mapNums)
282 :     {
283 :     displayVoteMapsMenu(id, g_menuPosition[id] = 0)
284 :     } else {
285 :     console_print(id, "%L", id, "NO_MAPS_MENU")
286 :     client_print(id, print_chat, "%L", id, "NO_MAPS_MENU")
287 :     }
288 :    
289 :     return PLUGIN_HANDLED
290 :     }
291 :    
292 :     public cmdMapsMenu(id, level, cid)
293 :     {
294 :     if (!cmd_access(id, level, cid, 1))
295 :     return PLUGIN_HANDLED
296 :    
297 :     if (g_mapNums)
298 :     {
299 :     displayMapsMenu(id, g_menuPosition[id] = 0)
300 :     } else {
301 :     console_print(id, "%L", id, "NO_MAPS_MENU")
302 :     client_print(id, print_chat, "%L", id, "NO_MAPS_MENU")
303 :     }
304 :    
305 :     return PLUGIN_HANDLED
306 :     }
307 :    
308 :     public delayedChange(mapname[])
309 :     server_cmd("changelevel %s", mapname)
310 :    
311 :     public actionVoteMapMenu(id, key)
312 :     {
313 :     switch (key)
314 :     {
315 :     case 7:
316 :     {
317 :     new Float:voting = get_cvar_float("amx_last_voting")
318 :    
319 :     if (voting > get_gametime())
320 :     {
321 :     client_print(id, print_chat, "%L", id, "ALREADY_VOT")
322 :     return PLUGIN_HANDLED
323 :     }
324 :    
325 :     if (voting && voting + get_cvar_float("amx_vote_delay") > get_gametime())
326 :     {
327 :     client_print(id, print_chat, "%L", id, "VOT_NOW_ALLOW")
328 :     return PLUGIN_HANDLED
329 :     }
330 :    
331 :     g_voteCount = {0, 0, 0, 0, 0}
332 :    
333 :     new Float:vote_time = get_cvar_float("amx_vote_time") + 2.0
334 :     set_cvar_float("amx_last_voting", get_gametime() + vote_time)
335 :     new iVoteTime = floatround(vote_time)
336 :    
337 :     set_task(vote_time, "checkVotes", 34567 + id)
338 :    
339 :     new menuBody[512]
340 :     new players[32]
341 :     new pnum, keys, len
342 :    
343 :     get_players(players, pnum)
344 :    
345 :     if (g_voteSelectedNum[id] > 1)
346 :     {
347 :     len = format(menuBody, 511, g_coloredMenus ? "\y%L^n\w^n" : "%L^n^n", id, "WHICH_MAP")
348 :    
349 :     for (new c = 0; c < g_voteSelectedNum[id]; ++c)
350 :     {
351 :     len += format(menuBody[len], 511, "%d. %s^n", c + 1, g_mapName[g_voteSelected[id][c]])
352 :     keys |= (1<<c)
353 :     }
354 :    
355 :     keys |= (1<<8)
356 :     len += format(menuBody[len], 511, "^n9. %L^n", id, "NONE")
357 :     } else {
358 :     len = format(menuBody, 511, g_coloredMenus ? "\y%L^n%s?^n\w^n1. %L^n2. %L^n" : "%L^n%s?^n^n1. %L^n2. %L^n", id, "CHANGE_MAP_TO", g_mapName[g_voteSelected[id][0]], id, "YES", id, "NO")
359 :     keys = MENU_KEY_1|MENU_KEY_2
360 :     }
361 :    
362 :     new menuName[64]
363 :     format(menuName, 63, "%L", "en", "WHICH_MAP")
364 :    
365 :     for (new b = 0; b < pnum; ++b)
366 :     if (players[b] != id)
367 :     show_menu(players[b], keys, menuBody, iVoteTime, menuName)
368 :    
369 :     format(menuBody[len], 511, "^n0. %L", id, "CANC_VOTE")
370 :     keys |= MENU_KEY_0
371 :     show_menu(id, keys, menuBody, iVoteTime, menuName)
372 :    
373 :     new authid[32], name[32]
374 :    
375 :     get_user_authid(id, authid, 31)
376 :     get_user_name(id, name, 31)
377 :    
378 :     switch (get_cvar_num("amx_show_activity"))
379 :     {
380 :     case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_V_MAP_2", name)
381 :     case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_V_MAP_1")
382 :     }
383 :    
384 :     log_amx("Vote: ^"%s<%d><%s><>^" vote maps (map#1 ^"%s^") (map#2 ^"%s^") (map#3 ^"%s^") (map#4 ^"%s^")",
385 :     name, get_user_userid(id), authid,
386 :     g_voteSelectedNum[id] > 0 ? g_mapName[g_voteSelected[id][0]] : "",
387 :     g_voteSelectedNum[id] > 1 ? g_mapName[g_voteSelected[id][1]] : "",
388 :     g_voteSelectedNum[id] > 2 ? g_mapName[g_voteSelected[id][2]] : "",
389 :     g_voteSelectedNum[id] > 3 ? g_mapName[g_voteSelected[id][3]] : "")
390 :     }
391 :     case 8: displayVoteMapsMenu(id, ++g_menuPosition[id])
392 :     case 9: displayVoteMapsMenu(id, --g_menuPosition[id])
393 :     default:
394 :     {
395 :     g_voteSelected[id][g_voteSelectedNum[id]++] = g_menuPosition[id] * 7 + key
396 :     displayVoteMapsMenu(id, g_menuPosition[id])
397 :     }
398 :     }
399 :    
400 :     return PLUGIN_HANDLED
401 :     }
402 :    
403 :     public actionMapsMenu(id, key)
404 :     {
405 :     switch (key)
406 :     {
407 :     case 8: displayMapsMenu(id, ++g_menuPosition[id])
408 :     case 9: displayMapsMenu(id, --g_menuPosition[id])
409 :     default:
410 :     {
411 :     new a = g_menuPosition[id] * 8 + key
412 :     new _modName[10]
413 :    
414 :     get_modname(_modName, 9)
415 :     if (!equal(_modName, "zp"))
416 :     {
417 :     message_begin(MSG_ALL, SVC_INTERMISSION)
418 :     message_end()
419 :     }
420 :    
421 :     new authid[32], name[32]
422 :    
423 :     get_user_authid(id, authid, 31)
424 :     get_user_name(id, name, 31)
425 :    
426 :     switch (get_cvar_num("amx_show_activity"))
427 :     {
428 :     case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_CHANGEL_2", name, g_mapName[a])
429 :     case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "ADMIN_CHANGEL_1", g_mapName[a])
430 :     }
431 :    
432 :     log_amx("Cmd: ^"%s<%d><%s><>^" changelevel ^"%s^"", name, get_user_userid(id), authid, g_mapName[a])
433 :     set_task(2.0, "delayedChange", 0, g_mapName[a], strlen(g_mapName[a]) + 1)
434 :     /* displayMapsMenu(id, g_menuPosition[id]) */
435 :     }
436 :     }
437 :    
438 :     return PLUGIN_HANDLED
439 :     }
440 :    
441 :     displayMapsMenu(id, pos)
442 :     {
443 :     if (pos < 0)
444 :     return
445 :    
446 :     new menuBody[512]
447 :     new start = pos * 8
448 :     new b = 0
449 :    
450 :     if (start >= g_mapNums)
451 :     start = pos = g_menuPosition[id] = 0
452 :    
453 :     new len = format(menuBody, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "CHANGLE_MENU", pos + 1, (g_mapNums / 8 + ((g_mapNums % 8) ? 1 : 0)))
454 :     new end = start + 8
455 :     new keys = MENU_KEY_0
456 :    
457 :     if (end > g_mapNums)
458 :     end = g_mapNums
459 :    
460 :     for (new a = start; a < end; ++a)
461 :     {
462 :     keys |= (1<<b)
463 :     len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_mapName[a])
464 :     }
465 :    
466 :     if (end != g_mapNums)
467 :     {
468 :     format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
469 :     keys |= MENU_KEY_9
470 :     }
471 :     else
472 :     format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
473 :    
474 :     new menuName[64]
475 :     format(menuName, 63, "%L", "en", "CHANGLE_MENU")
476 :    
477 :     show_menu(id, keys, menuBody, -1, menuName)
478 :     }
479 :    
480 :     load_settings(filename[])
481 :     {
482 :     if (!file_exists(filename))
483 :     return 0
484 :    
485 :     new text[256]
486 :     new a, pos = 0
487 :    
488 :     while (g_mapNums < MAX_MAPS && read_file(filename, pos++, text, 255, a))
489 :     {
490 :     if (text[0] == ';') continue
491 :     if (parse(text, g_mapName[g_mapNums], 31) < 1) continue
492 :     if (!is_map_valid(g_mapName[g_mapNums])) continue
493 :    
494 :     g_mapNums++
495 :     }
496 :    
497 :     return 1
498 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4