Parent Directory | Revision Log
Revision 1 - (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 MAX_MAPS 128 | ||
39 : | #define SELECTMAPS 5 | ||
40 : | |||
41 : | new g_mapName[MAX_MAPS][32] | ||
42 : | new g_mapNums | ||
43 : | |||
44 : | new g_nextName[SELECTMAPS] | ||
45 : | new g_voteCount[SELECTMAPS + 2] | ||
46 : | new g_mapVoteNum | ||
47 : | new g_teamScore[2] | ||
48 : | new g_lastMap[32] | ||
49 : | |||
50 : | new g_coloredMenus | ||
51 : | new bool:g_selected = false | ||
52 : | |||
53 : | public plugin_init() | ||
54 : | { | ||
55 : | register_plugin("Nextmap Chooser", AMXX_VERSION_STR, "AMXX Dev Team") | ||
56 : | register_dictionary("mapchooser.txt") | ||
57 : | register_dictionary("common.txt") | ||
58 : | |||
59 : | new MenuName[64] | ||
60 : | |||
61 : | format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM") | ||
62 : | register_menucmd(register_menuid(MenuName), (-1^(-1<<(SELECTMAPS+2))), "countVote") | ||
63 : | register_cvar("amx_extendmap_max", "90") | ||
64 : | register_cvar("amx_extendmap_step", "15") | ||
65 : | |||
66 : | if (cstrike_running()) | ||
67 : | register_event("TeamScore", "team_score", "a") | ||
68 : | |||
69 : | get_localinfo("lastMap", g_lastMap, 31) | ||
70 : | set_localinfo("lastMap", "") | ||
71 : | |||
72 : | new maps_ini_file[64] | ||
73 : | get_configsdir(maps_ini_file, 63); | ||
74 : | format(maps_ini_file, 63, "%s/maps.ini", maps_ini_file); | ||
75 : | |||
76 : | if (!file_exists(maps_ini_file)) | ||
77 : | get_cvar_string("mapcyclefile", maps_ini_file, 63) | ||
78 : | if (loadSettings(maps_ini_file)) | ||
79 : | set_task(15.0, "voteNextmap", 987456, "", 0, "b") | ||
80 : | |||
81 : | g_coloredMenus = colored_menus() | ||
82 : | } | ||
83 : | |||
84 : | public checkVotes() | ||
85 : | { | ||
86 : | new b = 0 | ||
87 : | |||
88 : | for (new a = 0; a < g_mapVoteNum; ++a) | ||
89 : | if (g_voteCount[b] < g_voteCount[a]) | ||
90 : | b = a | ||
91 : | |||
92 : | |||
93 : | if (g_voteCount[SELECTMAPS] > g_voteCount[b] | ||
94 : | && g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS+1]) | ||
95 : | { | ||
96 : | new mapname[32] | ||
97 : | |||
98 : | get_mapname(mapname, 31) | ||
99 : | new Float:steptime = get_cvar_float("amx_extendmap_step") | ||
100 : | set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime) | ||
101 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_EXT", steptime) | ||
102 : | log_amx("Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes", mapname, steptime) | ||
103 : | |||
104 : | return | ||
105 : | } | ||
106 : | |||
107 : | if (g_voteCount[b] && g_voteCount[SELECTMAPS + 1] <= g_voteCount[b]) | ||
108 : | { | ||
109 : | set_cvar_string("amx_nextmap", g_mapName[g_nextName[b]]) | ||
110 : | } | ||
111 : | |||
112 : | new smap[32] | ||
113 : | |||
114 : | get_cvar_string("amx_nextmap", smap, 31) | ||
115 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHO_FIN_NEXT", smap) | ||
116 : | log_amx("Vote: Voting for the nextmap finished. The nextmap will be %s", smap) | ||
117 : | } | ||
118 : | |||
119 : | public countVote(id, key) | ||
120 : | { | ||
121 : | if (get_cvar_float("amx_vote_answers")) | ||
122 : | { | ||
123 : | new name[32] | ||
124 : | get_user_name(id, name, 31) | ||
125 : | |||
126 : | if (key == SELECTMAPS) | ||
127 : | client_print(0, print_chat, "%L", LANG_PLAYER, "CHOSE_EXT", name) | ||
128 : | else if (key < SELECTMAPS) | ||
129 : | client_print(0, print_chat, "%L", LANG_PLAYER, "X_CHOSE_X", name, g_mapName[g_nextName[key]]) | ||
130 : | } | ||
131 : | ++g_voteCount[key] | ||
132 : | |||
133 : | return PLUGIN_HANDLED | ||
134 : | } | ||
135 : | |||
136 : | bool:isInMenu(id) | ||
137 : | { | ||
138 : | for (new a = 0; a < g_mapVoteNum; ++a) | ||
139 : | if (id == g_nextName[a]) | ||
140 : | return true | ||
141 : | return false | ||
142 : | } | ||
143 : | |||
144 : | public voteNextmap() | ||
145 : | { | ||
146 : | new winlimit = get_cvar_num("mp_winlimit") | ||
147 : | new maxrounds = get_cvar_num("mp_maxrounds") | ||
148 : | |||
149 : | if (winlimit) | ||
150 : | { | ||
151 : | new c = winlimit - 2 | ||
152 : | |||
153 : | if ((c > g_teamScore[0]) && (c > g_teamScore[1])) | ||
154 : | { | ||
155 : | g_selected = false | ||
156 : | return | ||
157 : | } | ||
158 : | } | ||
159 : | else if (maxrounds) | ||
160 : | { | ||
161 : | if ((maxrounds - 2) > (g_teamScore[0] + g_teamScore[1])) | ||
162 : | { | ||
163 : | g_selected = false | ||
164 : | return | ||
165 : | } | ||
166 : | } else { | ||
167 : | new timeleft = get_timeleft() | ||
168 : | |||
169 : | if (timeleft < 1 || timeleft > 129) | ||
170 : | { | ||
171 : | g_selected = false | ||
172 : | return | ||
173 : | } | ||
174 : | } | ||
175 : | |||
176 : | if (g_selected) | ||
177 : | return | ||
178 : | |||
179 : | g_selected = true | ||
180 : | |||
181 : | new menu[512], a, mkeys = (1<<SELECTMAPS + 1) | ||
182 : | new pos = format(menu, 511, g_coloredMenus ? "\y%L:\w^n^n" : "%L:^n^n", LANG_SERVER, "CHOOSE_NEXTM") | ||
183 : | new dmax = (g_mapNums > SELECTMAPS) ? SELECTMAPS : g_mapNums | ||
184 : | |||
185 : | for (g_mapVoteNum = 0; g_mapVoteNum < dmax; ++g_mapVoteNum) | ||
186 : | { | ||
187 : | a = random_num(0, g_mapNums - 1) | ||
188 : | |||
189 : | while (isInMenu(a)) | ||
190 : | if (++a >= g_mapNums) a = 0 | ||
191 : | |||
192 : | g_nextName[g_mapVoteNum] = a | ||
193 : | pos += format(menu[pos], 511, "%d. %s^n", g_mapVoteNum + 1, g_mapName[a]) | ||
194 : | mkeys |= (1<<g_mapVoteNum) | ||
195 : | g_voteCount[g_mapVoteNum] = 0 | ||
196 : | } | ||
197 : | |||
198 : | menu[pos++] = '^n' | ||
199 : | g_voteCount[SELECTMAPS] = 0 | ||
200 : | g_voteCount[SELECTMAPS + 1] = 0 | ||
201 : | |||
202 : | new mapname[32] | ||
203 : | get_mapname(mapname, 31) | ||
204 : | |||
205 : | if ((winlimit + maxrounds) == 0 && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max"))) | ||
206 : | { | ||
207 : | pos += format(menu[pos], 511, "%d. %L^n", SELECTMAPS + 1, LANG_SERVER, "EXTED_MAP", mapname) | ||
208 : | mkeys |= (1<<SELECTMAPS) | ||
209 : | } | ||
210 : | |||
211 : | format(menu[pos], 511, "%d. %L", SELECTMAPS+2, LANG_SERVER, "NONE") | ||
212 : | new MenuName[64] | ||
213 : | |||
214 : | format(MenuName, 63, "%L", "en", "CHOOSE_NEXTM") | ||
215 : | show_menu(0, mkeys, menu, 15, MenuName) | ||
216 : | set_task(15.0, "checkVotes") | ||
217 : | client_print(0, print_chat, "%L", LANG_SERVER, "TIME_CHOOSE") | ||
218 : | client_cmd(0, "spk Gman/Gman_Choose2") | ||
219 : | log_amx("Vote: Voting for the nextmap started") | ||
220 : | } | ||
221 : | |||
222 : | loadSettings(filename[]) | ||
223 : | { | ||
224 : | if (!file_exists(filename)) | ||
225 : | return 0 | ||
226 : | |||
227 : | new szText[32] | ||
228 : | new a, pos = 0 | ||
229 : | new currentMap[32] | ||
230 : | |||
231 : | get_mapname(currentMap, 31) | ||
232 : | |||
233 : | while ((g_mapNums < MAX_MAPS) && read_file(filename, pos++, szText, 31, a)) | ||
234 : | { | ||
235 : | if (szText[0] != ';' && parse(szText, g_mapName[g_mapNums], 31) && is_map_valid(g_mapName[g_mapNums]) | ||
236 : | && !equali(g_mapName[g_mapNums], g_lastMap) && !equali(g_mapName[g_mapNums], currentMap)) | ||
237 : | ++g_mapNums | ||
238 : | } | ||
239 : | |||
240 : | return g_mapNums | ||
241 : | } | ||
242 : | |||
243 : | public team_score() | ||
244 : | { | ||
245 : | new team[2] | ||
246 : | |||
247 : | read_data(1, team, 1) | ||
248 : | g_teamScore[(team[0]=='C') ? 0 : 1] = read_data(2) | ||
249 : | } | ||
250 : | |||
251 : | public plugin_end() | ||
252 : | { | ||
253 : | new current_map[32] | ||
254 : | |||
255 : | get_mapname(current_map, 31) | ||
256 : | set_localinfo("lastMap", current_map) | ||
257 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |