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