Parent Directory
|
Revision Log
Revision 17 - (view) (download)
1 : | ian | 1 | /* AMX Mod X |
2 : | * Nextmap Chooser 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 SELECTMAPS 5 | ||
39 : | |||
40 : | ian | 17 | #define charsof(%1) (sizeof(%1)-1) |
41 : | ian | 1 | |
42 : | ian | 17 | new Array:g_mapName; |
43 : | new g_mapNums; | ||
44 : | |||
45 : | ian | 1 | new g_nextName[SELECTMAPS] |
46 : | new g_voteCount[SELECTMAPS + 2] | ||
47 : | new g_mapVoteNum | ||
48 : | new g_teamScore[2] | ||
49 : | new g_lastMap[32] | ||
50 : | |||
51 : | new g_coloredMenus | ||
52 : | new bool:g_selected = false | ||
53 : | |||
54 : | public plugin_init() | ||
55 : | { | ||
56 : | register_plugin("Nextmap Chooser", AMXX_VERSION_STR, "AMXX Dev Team") | ||
57 : | register_dictionary("mapchooser.txt") | ||
58 : | register_dictionary("common.txt") | ||
59 : | |||
60 : | ian | 17 | g_mapName=ArrayCreate(32); |
61 : | |||
62 : | ian | 1 | new MenuName[64] |
63 : | |||
64 : | format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM") | ||
65 : | register_menucmd(register_menuid(MenuName), (-1^(-1<<(SELECTMAPS+2))), "countVote") | ||
66 : | register_cvar("amx_extendmap_max", "90") | ||
67 : | register_cvar("amx_extendmap_step", "15") | ||
68 : | |||
69 : | if (cstrike_running()) | ||
70 : | register_event("TeamScore", "team_score", "a") | ||
71 : | |||
72 : | get_localinfo("lastMap", g_lastMap, 31) | ||
73 : | set_localinfo("lastMap", "") | ||
74 : | |||
75 : | new maps_ini_file[64] | ||
76 : | get_configsdir(maps_ini_file, 63); | ||
77 : | format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file); | ||
78 : | |||
79 : | if (!file_exists(maps_ini_file)) | ||
80 : | get_cvar_string("mapcyclefile", maps_ini_file, 63) | ||
81 : | if (loadSettings(maps_ini_file)) | ||
82 : | set_task(15.0, "voteNextmap", 987456, "", 0, "b") | ||
83 : | |||
84 : | g_coloredMenus = colored_menus() | ||
85 : | ian | 17 | |
86 : | ian | 1 | } |
87 : | |||
88 : | public checkVotes() | ||
89 : | { | ||
90 : | new b = 0 | ||
91 : | |||
92 : | for (new a = 0; a < g_mapVoteNum; ++a) | ||
93 : | if (g_voteCount[b] < g_voteCount[a]) | ||
94 : | b = a | ||
95 : | |||
96 : | |||
97 : | if (g_voteCount[SELECTMAPS] > g_voteCount[b] | ||
98 : | && g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS+1]) | ||
99 : | { | ||
100 : | new mapname[32] | ||
101 : | |||
102 : | get_mapname(mapname, 31) | ||
103 : | new Float:steptime = get_cvar_float("amx_extendmap_step") | ||
104 : | set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime) | ||
105 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_EXT", steptime) | ||
106 : | log_amx("Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes", mapname, steptime) | ||
107 : | |||
108 : | return | ||
109 : | } | ||
110 : | |||
111 : | ian | 17 | new smap[32] |
112 : | ian | 1 | if (g_voteCount[b] && g_voteCount[SELECTMAPS + 1] <= g_voteCount[b]) |
113 : | { | ||
114 : | ian | 17 | ArrayGetString(g_mapName, g_nextName[b], smap, charsof(smap)); |
115 : | set_cvar_string("amx_nextmap", smap); | ||
116 : | ian | 1 | } |
117 : | |||
118 : | |||
119 : | get_cvar_string("amx_nextmap", smap, 31) | ||
120 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_NEXT", smap) | ||
121 : | log_amx("Vote: Voting for the nextmap finished. The nextmap will be %s", smap) | ||
122 : | } | ||
123 : | |||
124 : | public countVote(id, key) | ||
125 : | { | ||
126 : | if (get_cvar_float("amx_vote_answers")) | ||
127 : | { | ||
128 : | new name[32] | ||
129 : | get_user_name(id, name, 31) | ||
130 : | |||
131 : | if (key == SELECTMAPS) | ||
132 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHOSE_EXT", name) | ||
133 : | else if (key < SELECTMAPS) | ||
134 : | ian | 17 | { |
135 : | new map[32]; | ||
136 : | ArrayGetString(g_mapName, g_nextName[key], map, charsof(map)); | ||
137 : | client_print(0, print_chat, "%L", LANG_PLAYER, "X_CHOSE_X", name, map); | ||
138 : | } | ||
139 : | ian | 1 | } |
140 : | ++g_voteCount[key] | ||
141 : | |||
142 : | return PLUGIN_HANDLED | ||
143 : | } | ||
144 : | |||
145 : | bool:isInMenu(id) | ||
146 : | { | ||
147 : | for (new a = 0; a < g_mapVoteNum; ++a) | ||
148 : | if (id == g_nextName[a]) | ||
149 : | return true | ||
150 : | return false | ||
151 : | } | ||
152 : | |||
153 : | public voteNextmap() | ||
154 : | { | ||
155 : | new winlimit = get_cvar_num("mp_winlimit") | ||
156 : | new maxrounds = get_cvar_num("mp_maxrounds") | ||
157 : | |||
158 : | if (winlimit) | ||
159 : | { | ||
160 : | new c = winlimit - 2 | ||
161 : | |||
162 : | if ((c > g_teamScore[0]) && (c > g_teamScore[1])) | ||
163 : | { | ||
164 : | g_selected = false | ||
165 : | return | ||
166 : | } | ||
167 : | } | ||
168 : | else if (maxrounds) | ||
169 : | { | ||
170 : | if ((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1])) | ||
171 : | { | ||
172 : | g_selected = false | ||
173 : | return | ||
174 : | } | ||
175 : | } else { | ||
176 : | new timeleft = get_timeleft() | ||
177 : | |||
178 : | if (timeleft < 1 || timeleft > 129) | ||
179 : | { | ||
180 : | g_selected = false | ||
181 : | return | ||
182 : | } | ||
183 : | } | ||
184 : | |||
185 : | if (g_selected) | ||
186 : | return | ||
187 : | |||
188 : | g_selected = true | ||
189 : | |||
190 : | new menu[512], a, mkeys = (1<<SELECTMAPS + 1) | ||
191 : | ian | 17 | |
192 : | ian | 1 | new pos = format(menu, 511, g_coloredMenus ? "\y%L:\w^n^n" : "%L:^n^n", LANG_SERVER, "CHOOSE_NEXTM") |
193 : | new dmax = (g_mapNums > SELECTMAPS) ? SELECTMAPS : g_mapNums | ||
194 : | |||
195 : | for (g_mapVoteNum = 0; g_mapVoteNum < dmax; ++g_mapVoteNum) | ||
196 : | { | ||
197 : | a = random_num(0, g_mapNums - 1) | ||
198 : | |||
199 : | while (isInMenu(a)) | ||
200 : | if (++a >= g_mapNums) a = 0 | ||
201 : | |||
202 : | g_nextName[g_mapVoteNum] = a | ||
203 : | ian | 17 | pos += format(menu[pos], 511, "%d. %a^n", g_mapVoteNum + 1, ArrayGetStringHandle(g_mapName, a)); |
204 : | ian | 1 | mkeys |= (1<<g_mapVoteNum) |
205 : | g_voteCount[g_mapVoteNum] = 0 | ||
206 : | } | ||
207 : | |||
208 : | menu[pos++] = '^n' | ||
209 : | g_voteCount[SELECTMAPS] = 0 | ||
210 : | g_voteCount[SELECTMAPS + 1] = 0 | ||
211 : | |||
212 : | new mapname[32] | ||
213 : | get_mapname(mapname, 31) | ||
214 : | |||
215 : | if ((winlimit + maxrounds) == 0 && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max"))) | ||
216 : | { | ||
217 : | pos += format(menu[pos], 511, "%d. %L^n", SELECTMAPS + 1, LANG_SERVER, "EXTED_MAP", mapname) | ||
218 : | mkeys |= (1<<SELECTMAPS) | ||
219 : | } | ||
220 : | |||
221 : | format(menu[pos], 511, "%d. %L", SELECTMAPS+2, LANG_SERVER, "NONE") | ||
222 : | new MenuName[64] | ||
223 : | |||
224 : | format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM") | ||
225 : | show_menu(0, mkeys, menu, 15, MenuName) | ||
226 : | set_task(15.0, "checkVotes") | ||
227 : | client_print(0, print_chat, "%L", LANG_SERVER, "TIME_CHOOSE") | ||
228 : | client_cmd(0, "spk Gman/Gman_Choose2") | ||
229 : | log_amx("Vote: Voting for the nextmap started") | ||
230 : | } | ||
231 : | ian | 17 | stock bool:ValidMap(mapname[]) |
232 : | { | ||
233 : | if ( is_map_valid(mapname) ) | ||
234 : | { | ||
235 : | return true; | ||
236 : | } | ||
237 : | // If the is_map_valid check failed, check the end of the string | ||
238 : | new len = strlen(mapname) - 4; | ||
239 : | |||
240 : | // The mapname was too short to possibly house the .bsp extension | ||
241 : | if (len < 0) | ||
242 : | { | ||
243 : | return false; | ||
244 : | } | ||
245 : | if ( equali(mapname[len], ".bsp") ) | ||
246 : | { | ||
247 : | // If the ending was .bsp, then cut it off. | ||
248 : | // the string is byref'ed, so this copies back to the loaded text. | ||
249 : | mapname[len] = '^0'; | ||
250 : | |||
251 : | // recheck | ||
252 : | if ( is_map_valid(mapname) ) | ||
253 : | { | ||
254 : | return true; | ||
255 : | } | ||
256 : | } | ||
257 : | |||
258 : | return false; | ||
259 : | } | ||
260 : | ian | 1 | |
261 : | loadSettings(filename[]) | ||
262 : | { | ||
263 : | if (!file_exists(filename)) | ||
264 : | return 0 | ||
265 : | |||
266 : | new szText[32] | ||
267 : | new currentMap[32] | ||
268 : | |||
269 : | ian | 17 | new buff[256]; |
270 : | |||
271 : | ian | 1 | get_mapname(currentMap, 31) |
272 : | |||
273 : | ian | 17 | new fp=fopen(filename,"r"); |
274 : | |||
275 : | while (!feof(fp)) | ||
276 : | ian | 1 | { |
277 : | ian | 17 | buff[0]='^0'; |
278 : | |||
279 : | fgets(fp, buff, charsof(buff)); | ||
280 : | |||
281 : | parse(buff, szText, charsof(szText)); | ||
282 : | |||
283 : | |||
284 : | if (szText[0] != ';' && | ||
285 : | ValidMap(szText) && | ||
286 : | !equali(szText, g_lastMap) && | ||
287 : | !equali(szText, currentMap)) | ||
288 : | { | ||
289 : | ArrayPushString(g_mapName, szText); | ||
290 : | ++g_mapNums; | ||
291 : | } | ||
292 : | |||
293 : | ian | 1 | } |
294 : | ian | 17 | |
295 : | fclose(fp); | ||
296 : | ian | 1 | |
297 : | return g_mapNums | ||
298 : | } | ||
299 : | |||
300 : | public team_score() | ||
301 : | { | ||
302 : | new team[2] | ||
303 : | |||
304 : | read_data(1, team, 1) | ||
305 : | g_teamScore[(team[0]=='C') ? 0 : 1] = read_data(2) | ||
306 : | } | ||
307 : | |||
308 : | public plugin_end() | ||
309 : | { | ||
310 : | new current_map[32] | ||
311 : | |||
312 : | get_mapname(current_map, 31) | ||
313 : | set_localinfo("lastMap", current_map) | ||
314 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |