/[svn]/hlds/cstrike/addons/amxmodx/scripting/deagsmapmanager.sma
ViewVC logotype

Contents of /hlds/cstrike/addons/amxmodx/scripting/deagsmapmanager.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations) (download)
Sun Jan 29 02:55:19 2012 UTC (9 years ago) by cstrike
File size: 109521 byte(s)
Updated version, URL, and date for v3.24 release
1 /********************************************************************************
2 * AMX Mod X script.
3 *
4 * Deagles' Map Manager (deagsmapmanager.sma)
5 * Copyright (C) 2006-2012 Deagles/AMXX Community
6 * Copyright (C) 2002-2005 Deagles
7 * Original Mapchooser: Copyright (C) OLO
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 * In addition, as a special exception, the author gives permission to
24 * link the code of this program with the Half-Life Game Engine ("HL
25 * Engine") and Modified Game Libraries ("MODs") developed by Valve,
26 * L.L.C ("Valve"). You must obey the GNU General Public License in all
27 * respects for all of the code used other than the HL Engine and MODs
28 * from Valve. If you modify this file, you may extend this exception
29 * to your version of the file, but you are not obligated to do so. If
30 * you do not wish to do so, delete this exception statement from your
31 * version.
32 *
33 *********************************************************************************
34 *
35 * Deagles' Map Manager v3.24
36 * Last Update: 2012-01-28
37 *
38 * by Deagles/AMXX Community & Posting/Supporting by bmann_420
39 * Link: http://forums.alliedmods.net/showthread.php?t=177180
40 *
41 *
42 * Changelog is in the .txt file
43 *
44 * The name of this plugin had several variations in the past:
45 * - "Deagles NextMap Management"
46 * - "Deagles Next Map Management"
47 * - "Deagles Map Management"
48 * - "Deagles' Map Management"
49 * - "DeagsMapManager"
50 * - "Nomination_style_voting"
51 * - "Deags_map_manage"
52 *
53 *********************************************************************************
54 */
55
56
57 #pragma semicolon 1
58 #include <amxmodx>
59 #include <amxmisc>
60
61 new const PLUGIN[] = "DeagsMapManager";
62 new const VERSION[] = "3.24";
63 new const AUTHOR[] = "Deags/AMXX Community";
64 #define DMAP_EXPECTED_DV 530
65
66 // Comment out the following line to disable the dedicated log file
67 #define DEDICATED_LOG_ENABLED
68
69 #define MAX_MAPS_AMOUNT 600
70 #define ADMIN_DMAP ADMIN_LEVEL_A
71 #define ADMIN_SUPER_DMAP ADMIN_LEVEL_F
72
73 new const DMAP_MENU_TITLE[] = "DMAP_MENU_TITLE";
74
75 #define DMAP_VOTE_TIME 20 // Total time (in seconds) from vote start to checking votes
76
77 // Task IDs
78 #define DMAP_TASKID_TIMER 1000 //
79 #define DMAP_TASKID_VTR 1010 // Vote Time Remaining
80 #define DMAP_TASKID_CONFLICT 1020 // Conflicting plugin/dictionary version message
81 #define DMAP_TASKID_TIME_DISPLAY 1030 // Show time left and next map
82 #define DMAP_TASKID_MSG_THREE 1040 // Show status or result of vote
83 #define DMAP_TASKID_ROCK_IT_NOW 1050 //
84 #define DMAP_TASKID_GET_READY 1060 //
85 #define DMAP_TASKID_ROUND_MODE 1070 //
86 #define DMAP_TASKID_TIME_DIS 1080 //
87 #define DMAP_TASKID_DELAYED_CHANGE 1090 //
88 #define DMAP_TASKID_COUNTDOWN 1100 //
89 #define DMAP_TASKID_FREEZE 1110 //
90 #define DMAP_TASKID_MSG_NOMINATED 1120 //
91 #define DMAP_TASKID_MSG_MAPS 1130 //
92 #define DMAP_TASKID_TIME_TO_VOTE 1140 //
93 #define DMAP_TASKID_ASK_FOR_NEXT 1150 //
94 #define DMAP_TASKID_LOOP_MESSAGES 1160 //
95 #define DMAP_TASKID_END_OF_ROUND 1170 //
96 // Task IDs below here are spaced 100 apart to allow for a range of IDs
97 #define DMAP_TASKID_MORE_LIST_MAPS 2000 // Timer to allow for delay in listing large number of maps
98
99
100 new maps_to_select, isbuytime = 0, isbetween = 0;
101 new ban_last_maps = 0, quiet = 0; //quiet=0 (words and sounds) quiet=1 (words only, no sound) quiet=2 (no sound, no words)
102 new Float:rtvpercent, Float:thespeed, Float:oldtimelimit;
103 new minimum = 1, minimumwait = 10, enabled = 1, cycle = 0, dofreeze = 0, maxnom = 3, maxcustnom = 5, frequency = 3, oldwinlimit = 0, addthiswait = 0;
104 new mapsurl[64], amt_custom = 0;
105 new isend = 0, isspeedset = 0, istimeset = 0, iswinlimitset = 0, istimeset2 = 0, mapssave = 0, atstart;
106 new usestandard = 1, currentplayers = 0, activeplayers = 0, counttovote = 0, countnum = 0;
107 new inprogress = 0, rocks = 0, rocked[33], hasbeenrocked = 0, waited = 0;
108 new pathtomaps[64];
109 new custompath[50];
110 new nmaps[MAX_MAPS_AMOUNT][32];
111 new listofmaps[MAX_MAPS_AMOUNT][32];
112 new totalbanned = 0;
113 new banthesemaps[MAX_MAPS_AMOUNT][32];
114 new totalmaps = 0;
115 new lastmaps[100 + 1][32];
116 new bannedsofar = 0;
117 new standard[50][32];
118 new standardtotal = 0;
119 new nmaps_num = 0; //this is number of nominated maps
120 new nbeforefill;
121 new nmapsfill[MAX_MAPS_AMOUNT][32];
122 new num_nmapsfill; //this is number of maps in users admin.cfg file that are valid
123 new bool:bIsCstrike;
124 new nnextmaps[10];
125 new nvotes[12]; // Holds the number of votes for each map
126 new nmapstoch, before_num_nmapsfill = 0, bool:mselected = false;
127 #if defined DEDICATED_LOG_ENABLED
128 new logfilename[256];
129 #endif
130 new teamscore[2], last_map[32];
131 new Nominated[MAX_MAPS_AMOUNT]; //?
132 new whonmaps_num[MAX_MAPS_AMOUNT];
133 new curtime = 0, staytime = 0, curplayers = 0, currounds = 0;
134
135 new pDmapStrict; // Pointer to dmap_strict
136 new pEmptyMap; // Pointer to amx_emptymap
137 new pEmptymapAllowed; // Pointer to emptymap_allowed
138 new pEnforceTimelimit; // Pointer to enforce_timelimit
139 new pExtendmapMax; // Pointer to amx_extendmap_max
140 new pExtendmapStep; // Pointer to amx_extendmap_step
141 new pIdleTime; // Pointer to amx_idletime"
142 new pNominationsAllowed; // Pointer to nominations_allowed
143 new pShowActivity; // Pointer to amx_show_activity
144 new pWeaponDelay; // Pointer to weapon_delay
145
146 new g_TotalVotes; // Running total used to calculate percentages
147 new bool:g_AlreadyVoted[33]; // Keep track of who voted in current round
148 new g_VoteTimeRemaining; // Used to set duration of display of vote menu
149
150 forward public hudtext16(textblock[], colr, colg, colb, posx, posy, screen, time, id);
151 forward bool:isbanned(map[]);
152 forward bool:iscustommap(map[]);
153 forward bool:islastmaps(map[]);
154 forward bool:isnominated(map[]);
155 forward public handle_nominate(id, map[], bool:bForce);
156 forward available_maps();
157 forward public getready();
158 forward public timetovote();
159 forward public messagefifteen();
160 forward public messagenominated();
161 forward public messagemaps();
162 forward public stopperson();
163 forward public countdown();
164 forward public rock_it_now();
165 forward public timedisplay();
166 forward public messagethree();
167
168 public client_connect(id) {
169 if (!is_user_bot(id)) {
170 currentplayers++;
171 }
172 return PLUGIN_CONTINUE;
173 }
174
175 public loopmessages() {
176 if (quiet == 2) { //quiet=0 (words and sounds) quiet=1 (words only, no sound) quiet=2 (no sound, no words)
177 return PLUGIN_HANDLED;
178 }
179 new timeleft = get_timeleft();
180 new partialtime = timeleft % 370;
181 new maintime = timeleft % 600;
182 if ((maintime > 122 && maintime < 128) && timeleft > 114) {
183 set_task(1.0, "timedisplay", DMAP_TASKID_TIME_DISPLAY, "", 0, "a", 5);
184 }
185 if ((partialtime > 320 && partialtime < 326) && !cycle) {
186 set_task(3.0, "messagethree", DMAP_TASKID_MSG_THREE); //, "", 0, "a", 4)
187 return PLUGIN_HANDLED;
188 }
189 return PLUGIN_HANDLED;
190 }
191
192 public timedisplay() {
193 new timeleft = get_timeleft();
194 new seconds = timeleft % 60;
195 new minutes = floatround((timeleft - seconds) / 60.0);
196 if (timeleft < 1) {
197 remove_task(DMAP_TASKID_TIME_DISPLAY);
198 remove_task(DMAP_TASKID_TIME_DIS);
199 remove_task(DMAP_TASKID_END_OF_ROUND);
200 return PLUGIN_HANDLED;
201 }
202 if (timeleft > 140) {
203 remove_task(DMAP_TASKID_TIME_DIS);
204 }
205 if (timeleft > 30) {
206 set_hudmessage(255, 255, 220, 0.02, 0.2, 0, 1.0, 1.04, 0.0, 0.05, 3);
207 } else {
208 set_hudmessage(210, 0 ,0, 0.02, 0.15, 0, 1.0, 1.04, 0.0, 0.05, 3);
209 //Flashing red:set_hudmessage(210, 0, 0, 0.02, 0.2, 1, 1.0, 1.04, 0.0, 0.05, 3);
210 }
211 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_TIME_LEFT", minutes, seconds);
212 if (timeleft < 70 && (timeleft % 5) == 1) {
213 new smap[32];
214 get_cvar_string("amx_nextmap", smap, 31);
215 set_hudmessage(0, 132, 255, 0.02, 0.27, 0, 5.0, 5.04, 0.0, 0.5, 4);
216 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_NEXTMAP", smap);
217 }
218 return PLUGIN_HANDLED;
219
220 }
221
222 public messagethree() {
223 new timeleft = get_timeleft();
224 new time2 = timeleft - timeleft % 60;
225 new minutesleft = floatround(float(time2) / 60.0);
226 new mapname[32];
227 get_mapname(mapname, 31);
228 new smap[32];
229 get_cvar_string("amx_nextmap", smap, 31);
230 if (minutesleft >= 2 && !mselected) {
231 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NEXTMAP_VOTE_REMAINING",
232 (minutesleft == 3 || minutesleft == 2) ? timeleft -100 : minutesleft - 2, (minutesleft == 3 || minutesleft == 2) ? "seconds" : "minutes");
233 } else {
234 if (mselected) {
235 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NEXTMAP_VOTED", smap, timeleft);
236 } else {
237 if (minutesleft <= 2 && timeleft) {
238 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_CURRENT_MAP_VOTE", mapname);
239 }
240 }
241 }
242 }
243
244 public client_putinserver(id) {
245 if (!is_user_bot(id)) {
246 activeplayers++;
247 }
248 return PLUGIN_CONTINUE;
249 }
250
251 public client_disconnect(id) {
252 remove_task(DMAP_TASKID_MORE_LIST_MAPS + id);
253 if (is_user_bot(id)) {
254 return PLUGIN_CONTINUE;
255 }
256 currentplayers--;
257 activeplayers--;
258 g_AlreadyVoted[id] = false;
259 if (rocked[id]) {
260 rocked[id] = 0;
261 rocks--;
262 }
263 if (get_timeleft() > 160) {
264 if (!mselected && !hasbeenrocked && !inprogress) {
265 check_if_need();
266 }
267 }
268 new kName[32];
269 get_user_name(id, kName, 31);
270
271 new n = 0;
272 while (Nominated[id] > 0 && n < nmaps_num) {
273 if (whonmaps_num[n] == id) {
274 if (get_timeleft() > 50 && quiet != 2) { //quiet=0 (words and sounds) quiet=1 (words only, no sound) quiet=2 (no sound, no words)
275 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_PLAYER_LEFT", kName, nmaps[n]);
276 #if defined DEDICATED_LOG_ENABLED
277 log_to_file(logfilename, "%s has left; %s is no longer nominated", kName, nmaps[n]);
278 #endif
279 }
280
281 new j = n;
282 while (j < nmaps_num - 1) {
283 whonmaps_num[j] = whonmaps_num[j + 1];
284 nmaps[j] = nmaps[j + 1];
285 j++;
286 }
287 nmaps_num--;
288 Nominated[id] = Nominated[id] - 1;
289 } else {
290 n++;
291 }
292 }
293 return PLUGIN_CONTINUE;
294 }
295
296 public timer(id) {
297 if (get_playersnum() == 0) {
298 curtime++;
299 if (curtime >= staytime) {
300 change_maps();
301 }
302 } else {
303 new i, noncounted, players = get_playersnum();
304 for (i = 1; i <= get_maxplayers(); i++) {
305 if ((get_user_time(i, 1) >= (get_pcvar_num(pIdleTime) * 216000)) || is_user_bot(i) || is_user_hltv(i)) {
306 noncounted++;
307 }
308 }
309 if (players == noncounted) {
310 curtime++;
311 if (curtime >= staytime) {
312 change_maps();
313 }
314 } else {
315 curtime = 0;
316 }
317 }
318 return curtime;
319 }
320
321 public change_maps() {
322
323 new map[32];
324 get_pcvar_string(pEmptyMap, map, 31);
325
326 if (get_pcvar_num(pEmptymapAllowed) == 1 && strlen(map) > 0) {
327 server_cmd("changelevel %s", map);
328 }
329 }
330
331 public list_maps(id) {
332 new m, iteration = 0;
333 client_print(id, print_chat, "%L", id, "DMAP_LISTMAPS", totalmaps);
334 if (totalmaps - (50 * iteration) >= 50) {
335 console_print(id, "%L", id, "DMAP_LISTMAPS_MAPS", iteration * 50 + 1, iteration * 50 + 50, totalmaps);
336 } else {
337 console_print(id, "%L", id, "DMAP_LISTMAPS_MAPS", iteration * 50 + 1, iteration * 50 + (totalmaps - iteration * 50), totalmaps);
338 }
339
340 for (m = 50 * iteration; (m < totalmaps && m < 50 * (iteration + 1)); m += 3)
341 if (m + 1 < totalmaps) {
342 if (m + 2 < totalmaps) {
343 console_print(id, " %s %s %s", listofmaps[m], listofmaps[m + 1], listofmaps[m + 2]);
344 } else {
345 console_print(id, " %s %s", listofmaps[m], listofmaps[m + 1]);
346 }
347 } else {
348 console_print(id, " %s", listofmaps[m]);
349 }
350 if (50 * (iteration + 1) < totalmaps) {
351 new kIdfake[6];
352 num_to_str((id + 50 * (iteration + 1)), kIdfake, 5);
353 client_print(id, print_console, "%L", id, "DMAP_LISTMAPS_MORE");
354 set_task(4.0, "more_list_maps", DMAP_TASKID_MORE_LIST_MAPS + id, kIdfake, 6);
355 }
356 return PLUGIN_CONTINUE;
357 }
358
359 public more_list_maps(idfakestr[]) {
360 new idreal = str_to_num(idfakestr);
361 new m, iteration = 0;
362 while (idreal >= 50) {
363 idreal -= 50;
364 iteration++;
365 } //Now idreal is the real id of client
366
367 if (totalmaps - (50 * iteration) >= 50) {
368 console_print(idreal, "%L", idreal, "DMAP_LISTMAPS_MAPS", iteration * 50 + 1, iteration * 50 + 50, totalmaps);
369 } else {
370 console_print(idreal, "%L", idreal, "DMAP_LISTMAPS_MAPS", iteration * 50 + 1, iteration * 50 + (totalmaps - iteration * 50), totalmaps);
371 }
372
373 for (m = 50 * iteration; (m < totalmaps && m < 50 * (iteration + 1)); m += 3) {
374 if (m + 1 < totalmaps) {
375 if (m + 2 < totalmaps) {
376 console_print(idreal, " %s %s %s", listofmaps[m], listofmaps[m + 1], listofmaps[m + 2]);
377 } else {
378 console_print(idreal, " %s %s", listofmaps[m], listofmaps[m + 1]);
379 }
380 } else {
381 console_print(idreal, " %s", listofmaps[m]);
382 }
383 }
384
385 if (50 * (iteration + 1) < totalmaps) {
386 new kIdfake[32];
387 num_to_str((idreal + 50 * (iteration + 1)), kIdfake, 31);
388 client_print(idreal, print_console, "%L", idreal, "DMAP_LISTMAPS_MORE");
389 set_task(2.0, "more_list_maps", DMAP_TASKID_MORE_LIST_MAPS + idreal, kIdfake, 6);
390 } else { //Base case has been reached
391 client_print(idreal, print_console, "%L", idreal, "DMAP_LISTMAPS_FINISHED", totalmaps);
392 }
393 }
394
395 public say_nextmap(id) {
396 new timeleft = get_timeleft();
397 new time2 = timeleft - timeleft % 60;
398 new minutesleft = floatround(float(time2) / 60.0);
399 new mapname[32];
400 get_mapname(mapname,31);
401 new smap[32];
402 get_cvar_string("amx_nextmap", smap, 31);
403 if (minutesleft >= 2 && !mselected)
404 if (get_pcvar_num(pNominationsAllowed) == 1) {
405 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_SAY_NOMINATIONS",
406 (minutesleft == 3 || minutesleft == 2) ? timeleft - 100 : minutesleft - 2, (minutesleft == 3 || minutesleft == 2) ? "sec." : "min.");
407 } else {
408 if (mselected) {
409 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NEXTMAP_VOTED", smap, timeleft);
410 } else {
411 if (inprogress) {
412 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_CURRENT_MAP_VOTE", mapname);
413 }
414 }
415 }
416 return PLUGIN_HANDLED;
417 }
418
419 public check_if_need() {
420 new Float:ratio = rtvpercent;
421 new needed = floatround(float(activeplayers) * ratio + 0.49);
422 new timeleft = get_timeleft();
423 new Float:minutesleft = float(timeleft) / 60.0;
424 new Float:currentlimit = get_cvar_float("mp_timelimit");
425 new Float:minutesplayed = currentlimit - minutesleft;
426
427 if ((minutesplayed + 0.5) >= (float(minimumwait))) {
428 if (rocks >= needed && rocks >= minimum) {
429 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_RTV_STARTING", rocks);
430 set_hudmessage(222, 70, 0, -1.0, 0.3, 1, 10.0, 10.0, 2.0, 4.0, 4);
431 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_RTV_START", rocks);
432 hasbeenrocked = 1;
433 inprogress = 1;
434 mselected = false;
435 set_task(10.0, "rock_it_now", DMAP_TASKID_ROCK_IT_NOW);
436 }
437 }
438 }
439
440 public rock_the_vote(id) {
441 new Float:ratio = rtvpercent;
442 new needed = floatround(float(activeplayers) * ratio + 0.49);
443 new kName[32];
444 get_user_name(id, kName, 31);
445 new timeleft = get_timeleft();
446 new Float:minutesleft = float(timeleft) / 60.0;
447 new Float:currentlimit = get_cvar_float("mp_timelimit");
448 new Float:minutesplayed = currentlimit - minutesleft;
449
450 if (cycle) {
451 client_print(id, print_chat, "%L", id, "DMAP_VOTING_DISABLED");
452 return PLUGIN_CONTINUE;
453 }
454 if (!enabled) {
455 client_print(id, print_chat, "%L", id, "DMAP_RTV_DISABLED");
456 return PLUGIN_CONTINUE;
457 }
458 if (inprogress) {
459 client_print(id, print_chat, "%L", id, "DMAP_VOTE_BEGINNING");
460 return PLUGIN_CONTINUE;
461 }
462 if (mselected) {
463 new smap[32];
464 get_cvar_string("amx_nextmap", smap, 31);
465 client_print(id, print_chat, "%L", id, "DMAP_VOTING_COMPLETED", smap, get_timeleft());
466 return PLUGIN_CONTINUE;
467 }
468 if (hasbeenrocked) {
469 client_print(id, print_chat, "%L", id, "DMAP_MAP_ALREADY_ROCKED", kName);
470 return PLUGIN_CONTINUE;
471 }
472 if (timeleft < 120) {
473 if (timeleft > 1) {
474 client_print(id, print_chat, "%L", id, "DMAP_NOT_ENOUGH_TIME");
475 } else {
476 client_print(id, print_chat, "%L", id, "DMAP_NO_TIMELIMIT");
477 }
478 return PLUGIN_CONTINUE;
479 }
480 if ((minutesplayed + 0.5) < (float(minimumwait))) {
481 if (float(minimumwait) - 0.5 - minutesplayed > 0.0) {
482 client_print(id, print_chat, "%L", id, "DMAP_RTV_WAIT",
483 kName, (floatround(float(minimumwait) + 0.5-minutesplayed) > 0) ? (floatround(float(minimumwait) + 0.5 - minutesplayed)) : (1));
484 } else {
485 client_print(id, print_chat, "%L", id, "DMAP_RTV_1MIN");
486 }
487 if ((get_user_flags(id) & ADMIN_MAP)) {
488 console_print(id, "%L", id, "DMAP_RTV_ADMIN_FORCE", kName);
489 }
490 return PLUGIN_CONTINUE;
491 }
492 if (!rocked[id]) {
493 rocked[id] = 1;
494 rocks++;
495 } else {
496 client_print(id, print_chat, "%L", id, "DMAP_ALREADY_ROCKED", kName);
497 return PLUGIN_CONTINUE;
498 }
499 if (rocks >= needed && rocks >= minimum) {
500 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_RTV_STARTING", rocks);
501 set_hudmessage(222, 70,0, -1.0, 0.3, 1, 10.0, 10.0, 2.0, 4.0, 4);
502 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_RTV_START", rocks);
503 hasbeenrocked = 1;
504 inprogress = 1;
505 mselected = false;
506 set_task(15.0, "rock_it_now", DMAP_TASKID_ROCK_IT_NOW);
507 } else {
508 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_RTV_NEEDED", ((needed-rocks) > (minimum-needed)) ? (needed-rocks) : (minimum-rocks));
509 }
510 return PLUGIN_CONTINUE;
511 }
512
513 public rock_it_now() {
514 hasbeenrocked = 1;
515 new timeleft = get_timeleft();
516 new Float:minutesleft=float(timeleft) / 60.0;
517 new Float:currentlimit = get_cvar_float("mp_timelimit");
518 new Float:minutesplayed = currentlimit-minutesleft;
519 new Float:timelimit;
520 counttovote = 0;
521 remove_task(DMAP_TASKID_TIME_TO_VOTE);
522 remove_task(DMAP_TASKID_GET_READY);
523 timelimit = float(floatround(minutesplayed + 1.5));
524
525 oldtimelimit = get_cvar_float("mp_timelimit");
526 istimeset = 1;
527 set_cvar_float("mp_timelimit", timelimit);
528 if (quiet != 2) {
529 console_print(0, "%L", LANG_PLAYER, "DMAP_TIMELIMIT_CHANGED", floatround(get_cvar_float("mp_timelimit")));
530 }
531 #if defined DEDICATED_LOG_ENABLED
532 log_to_file(logfilename, "Time limit changed to %d to enable vote to occur now", floatround(get_cvar_float("mp_timelimit")));
533 #endif
534
535 timeleft = get_timeleft();
536 inprogress = 1;
537 mselected = false;
538 if (quiet != 2) {
539 set_hudmessage(0, 222,50, -1.0, 0.23, 1, 6.0, 6.0, 1.0, 1.0, 4);
540 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_START_MAPVOTE");
541 } else {
542 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_START_MAPVOTE");
543 }
544 if (quiet == 0) {
545 client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use _comma(e10) bay(s18) mass(e42) cap(s50)^"");
546 }
547 set_task(3.5, "getready", DMAP_TASKID_GET_READY);
548 set_task(10.0, "startthevote");
549 remove_task(DMAP_TASKID_TIME_DIS);
550 remove_task(DMAP_TASKID_END_OF_ROUND);
551 rocks = 0;
552 new inum, players[32], i;
553 get_players(players, inum, "c");
554 for (i = 0; i < inum; ++i) {
555 rocked[i] = 0;
556 }
557 set_task(2.18, "calculate_custom");
558 return PLUGIN_HANDLED;
559 }
560
561 public admin_rockit(id, level, cid) {
562 if (!cmd_access(id, level, cid, 1)) {
563 return PLUGIN_HANDLED;
564 }
565
566 new kName[32], timeleft = get_timeleft();
567 get_user_name(id, kName, 31);
568
569 if (timeleft < 180.0) {
570 console_print(id, "%L", id, "DMAP_NOT_ENOUGH_TIME");
571 return PLUGIN_HANDLED;
572 }
573 if (inprogress || hasbeenrocked || isend) {
574 console_print(id, "%L", id, "DMAP_ALREADY_VOTING");
575 return PLUGIN_HANDLED;
576 }
577 if (cycle) {
578 console_print(id, "%L", id, "DMAP_ENABLE_VOTEMODE");
579 return PLUGIN_HANDLED;
580 }
581 if (!mselected) {
582 switch(get_pcvar_num(pShowActivity)) {
583 case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_VOTE_ROCKED_BY_ADMIN", kName);
584 case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_RTV_USED_BY_ADMIN");
585 }
586 } else {
587 switch(get_pcvar_num(pShowActivity)) {
588 case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_REVOTE_BY_ADMIN", kName);
589 case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_REVOTE");
590 }
591 }
592 remove_task(DMAP_TASKID_FREEZE);
593 remove_task(DMAP_TASKID_COUNTDOWN);
594 remove_task(DMAP_TASKID_END_OF_ROUND);
595 counttovote = 0;
596 remove_task(DMAP_TASKID_TIME_TO_VOTE);
597 remove_task(DMAP_TASKID_GET_READY);
598 #if defined DEDICATED_LOG_ENABLED
599 log_to_file(logfilename, "ADMIN <%s> calls rockthevote with %d seconds left on map", kName, timeleft);
600 #endif
601 inprogress = 1;
602 mselected = false;
603 set_task(15.0, "rock_it_now", DMAP_TASKID_ROCK_IT_NOW);
604 set_task(0.18, "calculate_custom");
605 return PLUGIN_HANDLED;
606 }
607
608 public check_votes() {
609 new timeleft = get_timeleft();
610 new b = 0, a;
611 for (a = 0; a < nmapstoch; ++a) {
612 if (nvotes[b] < nvotes[a]) {
613 b = a;
614 }
615 }
616 if (nvotes[maps_to_select] > nvotes[b]) {
617 new mapname[32];
618 get_mapname(mapname, 31);
619 new steptime = get_pcvar_num(pExtendmapStep);
620 set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime);
621 istimeset = 1;
622
623 if (quiet != 2) {
624 set_hudmessage(222, 70,0, -1.0, 0.4, 0, 4.0, 10.0, 2.0, 2.0, 4);
625 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_MAP_EXTENDED", steptime);
626 if (quiet != 1) {
627 client_cmd(0, "speak ^"barney/waitin^"");
628 }
629 }
630 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_MAP_EXTENDED2", steptime);
631 #if defined DEDICATED_LOG_ENABLED
632 log_to_file(logfilename, "Vote: Voting for the nextmap finished. Map %s will be extended to next %d minutes", mapname, steptime);
633 #endif
634 inprogress = isend = 0;
635 nmaps_num = nbeforefill;
636 num_nmapsfill = before_num_nmapsfill;
637 return PLUGIN_HANDLED;
638 }
639 if (nvotes[b] && nvotes[maps_to_select+1] <= nvotes[b]) {
640 set_cvar_string("amx_nextmap", nmaps[nnextmaps[b]]);
641 new smap[32];
642 get_cvar_string("amx_nextmap", smap, 31);
643 new players[32], inum;
644 get_players(players, inum, "c");
645 if (quiet != 2) {
646 if (timeleft <= 0 || timeleft > 300) {
647 set_hudmessage(222, 70,0, -1.0, 0.36, 0, 4.0, 10.0, 2.0, 2.0, 4);
648 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_MAP_WINS", nmaps[nnextmaps[b]], nvotes[b]);
649 } else {
650 set_hudmessage(0, 152, 255, -1.0, 0.22, 0, 4.0, 7.0, 2.1, 1.5, 4);
651 if (get_pcvar_float(pEnforceTimelimit) == 1.0 && bIsCstrike) {
652 show_hudmessage(0, "%L %L", LANG_PLAYER, "DMAP_MAP_WINS2", nmaps[nnextmaps[b]], nvotes[b], LANG_PLAYER, "DMAP_IN_SECONDS", timeleft);
653 } else {
654 show_hudmessage(0, "%L %L", LANG_PLAYER, "DMAP_MAP_WINS2", nmaps[nnextmaps[b]], nvotes[b], LANG_PLAYER, "DMAP_SHORTLY");
655 }
656 if (iscustommap(nmaps[nnextmaps[b]]) && usestandard) {
657 client_print(0, print_notify, "%L", LANG_PLAYER, "DMAP_DOWNLOAD_CUSTOM_MAP");
658 }
659 }
660 if ((containi(mapsurl, "www") != -1 || containi(mapsurl, "http") != -1) && iscustommap(nmaps[nnextmaps[b]])) {
661 //set_hudmessage(0, 152, 255, -1.0, 0.70, 1, 4.0, 12.0, 2.1, 1.5, 7);
662 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_DOWNLOAD_MAPS_URL", mapsurl);
663 }
664 if (quiet != 1) {
665 client_cmd(0, "speak ^"barney/letsgo^""); //quiet=0 (words and sounds) quiet=1 (words only, no sound) quiet=2 (no sound, no words)
666 }
667 }
668 }
669
670 new smap[32];
671 get_cvar_string("amx_nextmap", smap, 31);
672 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_CHOOSING_FINISHED", smap);
673 #if defined DEDICATED_LOG_ENABLED
674 log_to_file(logfilename, "Vote: Voting for the nextmap finished. The nextmap will be %s", smap);
675 #endif
676 inprogress = waited = 0;
677 isend = 1;
678 //WE ARE near END OF MAP; time to invoke Round mode ALgorithm
679 //set_task(2.0, "endofround", DMAP_TASKID_END_OF_ROUND, "", 0, "b");
680 new waituntilready = timeleft;
681 if (waituntilready > 60) {
682 waituntilready = 60;
683 }
684 if (waituntilready <= 0 || get_cvar_num("mp_winlimit")) {
685 addthiswait = 4;
686 set_task(4.0, "RoundMode", DMAP_TASKID_ROUND_MODE);
687 } else {
688 set_task(float(waituntilready), "RoundMode", DMAP_TASKID_ROUND_MODE);
689 addthiswait = waituntilready;
690 }
691 nmaps_num = nbeforefill;
692 num_nmapsfill = before_num_nmapsfill;
693 set_task(2.18, "calculate_custom");
694 return PLUGIN_HANDLED;
695 }
696
697 public show_timer() {
698 set_task(1.0, "timedis2", DMAP_TASKID_TIME_DIS, "", 0, "b");
699 }
700
701 public timedis2() {
702 new timeleft = get_timeleft();
703 if ((timeleft % 5) == 1) {
704 new smap[32];
705 get_cvar_string("amx_nextmap", smap, 31);
706 set_hudmessage(0, 132, 255, 0.02, 0.27, 0, 5.0, 5.04, 0.0, 0.5, 4);
707 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_NEXTMAP", smap);
708 if (waited < 90) {
709 set_hudmessage(255, 215, 190, 0.02, 0.2, 0, 5.0, 5.04, 0.0, 0.5, 3);
710 } else {
711 set_hudmessage(210, 0 ,0, 0.02, 0.15, 0, 5.0, 5.04, 0.0, 0.5, 3);
712 //Flashing red:set_hudmessage(210, 0 ,0, 0.02, 0.2, 1, 1.0, 1.04, 0.0, 0.05, 3);
713 }
714 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_LAST_ROUND");
715 }
716 return PLUGIN_HANDLED;
717 }
718
719 public timedis3() {
720 new timeleft = get_timeleft();
721 if ((timeleft % 5) == 1) {
722 new smap[32];
723 get_cvar_string("amx_nextmap", smap, 31);
724 set_hudmessage(0, 132, 255, 0.02, 0.27, 0, 5.0, 5.04, 0.0, 0.5, 4);
725 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_NEXTMAP", smap);
726 if (timeleft > 30) {
727 set_hudmessage(255, 215, 190, 0.02, 0.2, 0, 5.0, 5.04, 0.0, 0.5, 3);
728 } else {
729 set_hudmessage(210, 0 ,0, 0.02, 0.15, 0, 5.0, 5.04, 0.0, 0.5, 3);
730 //Flashing red:set_hudmessage(210, 0, 0, 0.02, 0.2, 1, 5.0, 5.04, 0.0, 0.5, 3);
731 }
732 //countdown when "Enforcing timelimit"
733 new seconds = timeleft % 60;
734 new minutes = floatround((timeleft - seconds) / 60.0);
735 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_TIME_LEFT", minutes, seconds);
736 }
737 return PLUGIN_HANDLED;
738 }
739
740 public RoundMode() {
741 if (get_cvar_float("mp_timelimit") > 0.1 && get_pcvar_num(pEnforceTimelimit)) {
742 remove_task(DMAP_TASKID_ROUND_MODE);
743 remove_task(DMAP_TASKID_TIME_DIS);
744 new timeleft = get_timeleft();
745 if (timeleft < 200) {
746 set_task(float(timeleft) - 5.8, "endofround");
747 set_task(1.0, "timedis3", DMAP_TASKID_TIME_DIS, "", 0, "b");
748 }
749 return PLUGIN_HANDLED;
750 } else {
751 if (waited == 0) {
752 set_task(1.0, "show_timer");
753 }
754 if (isbetween || isbuytime || (waited + addthiswait) > 190 || (!bIsCstrike && (waited + addthiswait) >= 30) || activeplayers < 2) { //Time to switch maps!!!!!!!!
755 remove_task(DMAP_TASKID_ROUND_MODE);
756 remove_task(DMAP_TASKID_TIME_DIS);
757 if (isbetween) {
758 set_task(3.9, "endofround");
759 } else {
760 endofround(); //switching very soon!
761 }
762 } else {
763 waited += 5;
764 //if (waited >= 15 && waited <= 150 && get_timeleft() < 7) {
765 if ((waited + addthiswait) <= 190 && get_timeleft() >= 0 && get_timeleft() <= 15) {
766 istimeset2 = 1;
767 set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + 2.0);
768 if (bIsCstrike) {
769 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_FINISHING_CUR_ROUND");
770 }
771 }
772 set_task(5.0, "RoundMode", DMAP_TASKID_ROUND_MODE);
773 }
774 }
775 return PLUGIN_HANDLED;
776 }
777
778 public vote_count(id, key) {
779 if (get_cvar_float("amx_vote_answers")) {
780 new name[32];
781 get_user_name(id, name, 31);
782 if (key == maps_to_select) {
783 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_CHOSE_MAPEXTENDING", name);
784 } else if (key < maps_to_select) {
785 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_CHOSE_MAP", name, nmaps[nnextmaps[key]]);
786 }
787 }
788 nvotes[key] += 1;
789 g_TotalVotes += 1;
790 g_AlreadyVoted[id] = true;
791 show_vote_menu(false);
792
793 return PLUGIN_HANDLED;
794 }
795
796 bool:isinmenu(id) {
797 new a;
798 for (a = 0; a < nmapstoch; ++a) {
799 if (id == nnextmaps[a]) {
800 return true;
801 }
802 }
803 return false;
804 }
805
806 public dmapcancelvote(id, level, cid) {
807 if (!cmd_access(id, level, cid, 0)) {
808 return PLUGIN_HANDLED ;
809 }
810 if (task_exists(DMAP_TASKID_ROCK_IT_NOW, 1)) {
811 new authid[32], name[32];
812
813 get_user_authid(id, authid, 31) ;
814 get_user_name(id, name, 31);
815 #if defined DEDICATED_LOG_ENABLED
816 log_to_file(logfilename, "ADMIN <%s> cancelled the map vote.", name);
817 #endif
818 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_ADMIN_CANCELLED", name);
819 remove_task(DMAP_TASKID_ROCK_IT_NOW, 1);
820 set_hudmessage(222, 70,0, -1.0, 0.3, 1, 10.0, 10.0, 2.0, 4.0, 8);
821 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_ADMIN_CANCELLED", name);
822 hasbeenrocked = 0;
823 inprogress = 0;
824 mselected = true;
825
826 return PLUGIN_CONTINUE;
827 } else {
828 client_print(id, print_chat, "%L", id, "DMAP_NO_CURRENT_VOTE");
829 }
830 return PLUGIN_HANDLED;
831 }
832
833 public dmapnominate(id, level, cid) {
834 if (!cmd_access(id, level, cid, 2)) {
835 return PLUGIN_HANDLED;
836 }
837
838 new sArg1[32];
839 read_argv(1, sArg1, 31);
840
841 handle_andchange(id, sArg1, true); // Force nomination
842
843 return PLUGIN_HANDLED;
844 }
845
846 public levelchange() {
847 if (istimeset2 == 1) { //Allow automatic map change to take place.
848 set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 2.0);
849 istimeset2 = 0;
850 } else {
851 if (get_cvar_float("mp_timelimit") >= 4.0) { //Allow automatic map change to take place.
852 if (!istimeset) {
853 oldtimelimit = get_cvar_float("mp_timelimit");
854 }
855 set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 3);
856 istimeset = 1;
857 } else {
858 if (get_cvar_num("mp_winlimit")) { //Allow automatic map change based on teamscores
859 new largerscore;
860 largerscore = (teamscore[0] > teamscore[1]) ? teamscore[0] : teamscore[1];
861 iswinlimitset = 1;
862 oldwinlimit = get_cvar_num("mp_winlimit");
863 set_cvar_num("mp_winlimit", largerscore);
864 }
865 }
866 }
867 //If we are unable to achieve automatic level change, FORCE it.
868 set_task(2.1, "DelayedChange", DMAP_TASKID_DELAYED_CHANGE);
869 }
870
871 public changeMap() { //Default event copied from nextmap.amx, and changed around.
872 set_cvar_float("mp_chattime", 3.0); // make sure mp_chattime is long
873 remove_task(DMAP_TASKID_DELAYED_CHANGE);
874 set_task(1.85, "DelayedChange");
875 }
876
877 public DelayedChange() {
878 new smap[32];
879 get_cvar_string("amx_nextmap", smap, 31);
880 server_cmd("changelevel %s", smap);
881 }
882
883 public endofround() { //Call when ready to switch maps in (?) seconds
884 remove_task(DMAP_TASKID_END_OF_ROUND);
885 remove_task(DMAP_TASKID_LOOP_MESSAGES);
886 remove_task(DMAP_TASKID_ROUND_MODE);
887 remove_task(DMAP_TASKID_TIME_DISPLAY);
888 remove_task(DMAP_TASKID_TIME_DIS);
889 new smap[32];
890 get_cvar_string("amx_nextmap", smap, 31);
891 set_task(6.0, "levelchange"); //used to be 7.0
892 if (quiet != 2) {
893 countnum = 0;
894 set_task(1.0, "countdown", DMAP_TASKID_COUNTDOWN, "", 0, "a", 6);
895 if (quiet != 1) {
896 client_cmd(0, "speak ^"loading environment on to your computer^"");
897 }
898 } else {
899 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_MAP_ABOUT_CHANGE");
900 }
901 ///////////////////////////////////////////////
902 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NEXTMAP2", smap);
903 if ((containi(mapsurl, "www") != -1 || containi(mapsurl, "http") != -1) && iscustommap(smap)) {
904 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_DOWNLOAD_MAPS_URL2", smap, mapsurl);
905 }
906 ///////////////////////////////////////////////
907 if (dofreeze) {
908 isspeedset = 1;
909 thespeed = get_cvar_float("sv_maxspeed");
910 set_cvar_float("sv_maxspeed", 0.0);
911 new players[32], inum, i;
912 get_players(players, inum, "c");
913 for (i = 0; i < inum; ++i) {
914 client_cmd(players[i], "drop");
915 client_cmd(players[i], "+showscores");
916 }
917 }
918 if (dofreeze) {
919 set_task(1.1, "stopperson", DMAP_TASKID_FREEZE, "", 0, "a", 2);
920 }
921 return PLUGIN_HANDLED;
922 }
923
924 public countdown() {
925 new smap[32];
926 get_cvar_string("amx_nextmap", smap, 31);
927 countnum++;
928 set_hudmessage(150, 120, 0, -1.0, 0.3, 0, 0.5, 1.1, 0.1, 0.1, 4);
929 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_MAP_CHANGING_IN", smap, 7 - countnum);
930 return PLUGIN_HANDLED;
931 }
932
933 public stopperson() {
934 new players[32], inum, i;
935 get_players(players, inum, "c");
936 if (isspeedset >= 0 && isspeedset < 2) {
937 thespeed = get_cvar_float("sv_maxspeed");
938 isspeedset++;
939 set_cvar_float("sv_maxspeed", 0.0);
940 }
941 for (i = 0; i < inum; ++i) {
942 client_cmd(players[i], "drop");
943 }
944 return PLUGIN_HANDLED;
945 }
946
947 public display_message() {
948 new timeleft = get_timeleft();
949 new parttime = timeleft % (frequency * 60 * 2); //460//period(minutes/cycle) * 60 seconds/minute = period in seconds
950 //if frequency = 2 (every 2 minutes one message will appear) THIS FUNCTION COVERS 2 MESSAGES WHICH MAKES ONE CYCLE
951 //parttime=timeleft%240;
952 new addition = frequency * 60;
953 if (mselected || inprogress || cycle) {
954 return PLUGIN_CONTINUE;
955 }
956 //if (parttime > 310 && parttime < 326 && timeleft > 132)
957 if (parttime > (40 + addition) && parttime < (56 + addition) && timeleft > 132) {
958 set_task(3.0, "messagenominated", DMAP_TASKID_MSG_NOMINATED); //, "", 0, "a", 4)
959 } else {
960 //if (parttime > 155 && parttime < 171 && timeleft > 132)
961 if (parttime > 30 && parttime < 46 && timeleft > 132) {
962 set_task(10.0, "messagemaps", DMAP_TASKID_MSG_MAPS, "", 0, "a", 1);
963 } else if (timeleft >= 117 && timeleft < 132) {
964 messagefifteen();
965 }
966 }
967 return PLUGIN_CONTINUE;
968 }
969
970 // THIS IS UNTESTED, BUT SHOULD WORK
971 /* 1.6 hudtext function
972 Arguments:
973 textblock: a string containing the text to print, not more than 512 chars (a small calc shows that the max number of letters to be displayed is around 270 btw)
974 colr, colg, colb: color to print text in (RGB format)
975 posx, posy: position on screen * 1000 (if you want text to be displayed centered, enter -1000 for both, text on top will be posx=-1000 & posy=20
976 screen: the screen to write to, hl supports max 4 screens at a time, do not use screen+0 to screen+3 for other hudstrings while displaying this one
977 time: how long the text shoud be displayed (in seconds)
978 */
979
980 public hudtext16(textblock[] ,colr, colg, colb, posx, posy, screen, time, id) {
981 new y;
982 if (contain(textblock, "^n") == -1) { // if there is no linebreak in the text, we can just show it as it is
983 set_hudmessage(colr, colg, colb, float(posx) / 1000.0, float(posy) / 1000.0, 0, 6.0, float(time), 0.2, 0.2, screen);
984 show_hudmessage(id, textblock);
985 } else { // more than one line
986 new out[128], rowcounter = 0, tmp[512], textremain = true;
987 y = screen;
988 new i = contain(textblock, "^n");
989 copy(out, i, textblock); // we need to get the first line of text before the loop
990 do { // this is the main print loop
991 setc(tmp, 511, 0); // reset string
992 copy(tmp, 511, textblock[i + 1]); // copy everything AFTER the first linebreak (hence the +1, we don't want the linebreak in our new string)
993 setc(textblock, 511, 0); // reset string
994 copy(textblock, 511, tmp); // copy back remaining text
995 i = contain(textblock, "^n"); // get next linebreak position
996 if ((strlen(out) + i < 64) && (i != -1)) { // we can add more lines to the outstring if total letter count don't exceed 64 chars (decrease if you have a lot of short lines since the leading linbreaks for following lines also take up one char in the string)
997 add(out, 127, "^n"); // add a linebreak before next row
998 add(out, strlen(out) + i, textblock);
999 rowcounter++; // we now have one more row in the outstring
1000 } else { // no more lines can be added
1001 set_hudmessage(colr, colg, colb, float(posx) / 1000.0, float(posy) / 1000.0, 0, 6.0, float(time), 0.2, 0.2, screen); // format our hudmsg
1002 if ((i == -1) && (strlen(out) + strlen(textblock) < 64)) {
1003 add(out, 127, "^n"); // if i == -1 we are on the last line, this line is executed if the last line can be added to the current string (total chars < 64)
1004 } else { // not the last line or last line must have it's own screen
1005 if (screen-y < 4) {
1006 show_hudmessage(id, out); // we will only print the hudstring if we are under the 4 screen limit
1007 }
1008 screen++; // go to next screen after printing this one
1009 rowcounter++; // one more row
1010 setc(out, 127, 0); // reset string
1011 for (new j = 0; j < rowcounter; j++) {
1012 add(out, 127, "^n"); // add leading linebreaks equal to the number of rows we already printed
1013 }
1014 if (i == -1) {
1015 set_hudmessage(colr, colg, colb, float(posx) / 1000.0, float(posy) / 1000.0, 0, 6.0, float(time), 0.2, 0.2, screen); // format our hudmsg if we are on the last line
1016 } else {
1017 add(out, strlen(out) + i, textblock); // else add the next line to the outstring, before this, out is empty (or have some leading linebreaks)
1018 }
1019 }
1020 if (i == -1) { // apparently we are on the last line here
1021 add(out, strlen(out) + strlen(textblock), textblock); // add the last line to out
1022 if (screen - y < 4) show_hudmessage(id, out); // we will only print the hudstring if we are under the 4 screen limit
1023 textremain = false; // we have no more text to print
1024 }
1025 }
1026 } while (textremain);
1027 }
1028 return screen - y; // we will return how many screens of text we printed
1029 }
1030
1031 public messagenominated() {
1032 if (quiet == 2) {
1033 return PLUGIN_CONTINUE;
1034 }
1035
1036 new string[256], string2[256], string3[512];
1037 if (nmaps_num < 1) {
1038 formatex(string3, 511, "%L", LANG_SERVER, "DMAP_NO_MAPS_NOMINATED");
1039 } else {
1040 new n = 0, foundone = 0;
1041 formatex(string, 255, "%L", LANG_SERVER, "DMAP_NOMINATIONS");
1042 while (n < 3 && n < nmaps_num) {
1043 formatex(string, 255, "%s %s", string, nmaps[n++]);
1044 }
1045 while (n < 6 && n < nmaps_num) {
1046 foundone = 1;
1047 format(string2, 255, "%s %s", string2, nmaps[n++]);
1048 }
1049 if (foundone) {
1050 formatex(string3, 511, "%s^n%s", string, string2);
1051 } else {
1052 formatex(string3, 511, "%s", string);
1053 }
1054 }
1055 hudtext16(string3, random_num(0, 222), random_num(0, 111), random_num(111, 222), -1000, 50, random_num(1, 4), 10, 0);
1056 return PLUGIN_CONTINUE;
1057 }
1058
1059 public listnominations(id) {
1060 if (get_pcvar_num(pNominationsAllowed) == 1) {
1061 new a = 0, string3[512], string1[96], name1[33];
1062 if (a < nmaps_num) {
1063 //show_hudmessage(id, "The following maps have been nominated for the next map vote:");
1064 formatex(string3, 255, "%L", id, "DMAP_NOMINATED_MAPS");
1065 }
1066 while (a < nmaps_num) {
1067 get_user_name(whonmaps_num[a], name1, 32);
1068 //set_hudmessage(255, 0, 0, 0.12, 0.3 + 0.08 * float(a), 0, 15.0, 15.04, 1.5, 3.75, 2 + a);
1069 //show_hudmessage(id, "%s by: %s", nmaps[a], name1);
1070 formatex(string1, 95, "%L", id, "DMAP_MAP_BY", nmaps[a], name1);
1071 add(string3, 511, string1, 95);
1072 a++;
1073 }
1074 hudtext16(string3, random_num(0, 222), random_num(0, 111), random_num(111, 222), 300, 10, random_num(1, 4), 15, id);
1075 }
1076 }
1077
1078 public messagemaps() {
1079 if (quiet == 2) {
1080 return PLUGIN_CONTINUE;
1081 }
1082
1083 new string[256], string2[256], string3[512];
1084 new n = 0;
1085 new total = 0;
1086
1087 if ((totalmaps - 6) > 0) {
1088 n = random_num(0, totalmaps - 6);
1089 }
1090 while (total < 3 && total < totalmaps && is_map_valid(listofmaps[n]) && n < totalmaps) {
1091 if (!islastmaps(listofmaps[n]) && !isbanned(listofmaps[n]) && !isnominated(listofmaps[n])) {
1092 format(string, 255, "%s %s", string, listofmaps[n]);
1093 total++;
1094 }
1095 n++;
1096 }
1097 while (total < 6 && n < totalmaps && is_map_valid(listofmaps[n]) && !isnominated(listofmaps[n])) {
1098 if (!islastmaps(listofmaps[n]) && !isbanned(listofmaps[n])) {
1099 format(string2, 255, "%s %s", string2, listofmaps[n]);
1100 total++;
1101 }
1102 n++;
1103 }
1104 if (total > 0) {
1105 //show_hudmessage(0, "The following maps are available to nominate:^n%s", string);
1106 new temp[256];
1107 formatex(temp, 255, "%L", LANG_SERVER, "DMAP_AVAILABLE_MAPS");
1108 add(string3, 511, temp, 100);
1109 add(string3, 511, string, 100);
1110 add(string3, 511, "^n");
1111 }
1112 if (total > 3) {
1113 add(string3, 511, string2, 100);
1114 }
1115
1116 hudtext16(string3, random_num(0, 222), random_num(0, 111), random_num(111, 222), -1000, 50, random_num(1, 4), 10, 0);
1117 return PLUGIN_CONTINUE;
1118 }
1119
1120 public messagefifteen() {
1121 if (quiet == 2) {
1122 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_VOTING_IN_15SEC");
1123 return PLUGIN_HANDLED;
1124 }
1125 set_hudmessage(0, 222, 50, -1.0, 0.23, 1, 6.5, 6.5, 1.0, 3.0, 4);
1126 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_VOTING_IN_15SEC");
1127 if (quiet == 0) {
1128 client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use bay(s18) mass(e42) cap(s50)^"");
1129 }
1130 set_task(8.7, "getready", DMAP_TASKID_GET_READY);
1131 return PLUGIN_HANDLED;
1132 }
1133
1134 public getready() {
1135 if (!cycle) {
1136 set_task(0.93, "timetovote", DMAP_TASKID_TIME_TO_VOTE, "", 0, "a", 5);
1137 }
1138 }
1139
1140 public timetovote() {
1141 counttovote++;
1142 new speak[5][] = {"one", "two", "three", "four", "five"};
1143
1144 if (get_timeleft() > 132 || counttovote > 5 || cycle || isbuytime) {
1145 counttovote = 0;
1146 remove_task(DMAP_TASKID_TIME_TO_VOTE);
1147 remove_task(DMAP_TASKID_GET_READY);
1148 return PLUGIN_HANDLED;
1149 } else {
1150 if (counttovote > 0 && counttovote <= 5) {
1151 set_hudmessage(0, 222, 50, -1.0, 0.13, 0, 1.0, 0.94, 0.0, 0.0, 4);
1152 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_VOTING_IN_XSEC", 6 - counttovote);
1153 if (quiet != 1) {
1154 client_cmd(0, "spk ^"fvox/%s^"", speak[5 - counttovote]);
1155 }
1156 }
1157 }
1158 return PLUGIN_HANDLED;
1159 }
1160
1161 available_maps() { //return number of maps that havent that have been added yet
1162 new num = 0, isinlist;
1163 new current_map[32], a, i;
1164 get_mapname(current_map, 31);
1165 for (a = 0; a < num_nmapsfill; a++) {
1166 if (is_map_valid(nmapsfill[a])) {
1167 isinlist = 0;
1168 for (i = 0; i < nmaps_num; i++) {
1169 if (equali(nmapsfill[a], nmaps[i])) {
1170 isinlist = 1;
1171 }
1172 }
1173 if (!isinlist) {
1174 num++;
1175 }
1176 }
1177 }
1178 return num;
1179 }
1180
1181 public askfornextmap() {
1182 display_message();
1183 new timeleft = get_timeleft();
1184
1185 if (isspeedset && timeleft > 30) {
1186 isspeedset = 0;
1187 set_cvar_float("sv_maxspeed", thespeed);
1188 }
1189 if (waited > 0) {
1190 return PLUGIN_HANDLED;
1191 }
1192 if (timeleft > 300) {
1193 isend = 0;
1194 remove_task(DMAP_TASKID_END_OF_ROUND);
1195 }
1196 new mp_winlimit = get_cvar_num("mp_winlimit");
1197 if (mp_winlimit) {
1198 new s = mp_winlimit - 2;
1199 if ((s > teamscore[0] && s > teamscore[1]) && (timeleft > 114 || timeleft < 1)) {
1200 remove_task(DMAP_TASKID_TIME_DIS);
1201 mselected = false;
1202 return PLUGIN_HANDLED;
1203 }
1204 } else {
1205 if (timeleft > 114 || timeleft < 1) {
1206 remove_task(DMAP_TASKID_TIME_DIS);
1207 if (timeleft > 135) {
1208 remove_task(DMAP_TASKID_TIME_DISPLAY);
1209 }
1210 mselected = false;
1211 return PLUGIN_HANDLED;
1212 }
1213 }
1214 if (inprogress || mselected || cycle) {
1215 return PLUGIN_HANDLED;
1216 }
1217 mselected = false;
1218 inprogress = 1;
1219 if (mp_winlimit && !(timeleft >= 115 && timeleft < 134)) {
1220 if (quiet != 2) {
1221 set_hudmessage(0, 222, 50, -1.0, 0.13, 1, 6.0, 6.0, 1.0, 1.0, 4);
1222 show_hudmessage(0, "%L", LANG_PLAYER, "DMAP_START_MAPVOTE");
1223 if (quiet != 1) {
1224 client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use bay(s18) mass(e42) cap(s50)^"");
1225 }
1226 set_task(4.2, "getready", DMAP_TASKID_GET_READY);
1227 set_task(10.0, "startthevote");
1228 } else {
1229 set_task(1.0, "startthevote");
1230 }
1231 } else {
1232 set_task(0.5, "startthevote");
1233 }
1234 return PLUGIN_HANDLED;
1235 }
1236
1237 public startthevote() {
1238 new j;
1239 if (cycle) {
1240 inprogress = 0;
1241 mselected = false;
1242 remove_task(DMAP_TASKID_TIME_TO_VOTE);
1243 remove_task(DMAP_TASKID_GET_READY);
1244 new smap[32];
1245 get_cvar_string("amx_nextmap", smap, 31);
1246 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NEXTMAP2", smap);
1247 return PLUGIN_HANDLED;
1248 }
1249 for (j = 0; j < maps_to_select + 2; j++) {
1250 nvotes[j] = 0;
1251 }
1252 mselected = true;
1253 inprogress = 1;
1254 counttovote = 0;
1255 if ((isbuytime || isbetween) && get_timeleft() && get_timeleft() > 54 && get_pcvar_num(pWeaponDelay)) {
1256 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_VOTING_DELAYED");
1257 if (isbetween) {
1258 set_task(15.0, "getready", DMAP_TASKID_GET_READY);
1259 set_task(21.0, "startthevote");
1260 } else {
1261 set_task(8.0, "getready", DMAP_TASKID_GET_READY);
1262 set_task(14.0, "startthevote");
1263 }
1264 return PLUGIN_HANDLED;
1265 } //else startthevote anyways..., regardless of buytime
1266
1267 remove_task(DMAP_TASKID_TIME_TO_VOTE);
1268 remove_task(DMAP_TASKID_GET_READY);
1269
1270 if (quiet != 2) {
1271 if (bIsCstrike) {
1272 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_POSSIBLE_NOMINATIONS", nmaps_num, maps_to_select);
1273 }
1274 }
1275
1276 #if defined DEDICATED_LOG_ENABLED
1277 log_to_file(logfilename, "Nominations for the map vote: %d out of %d possible nominations", nmaps_num, maps_to_select);
1278 #endif
1279
1280 before_num_nmapsfill = num_nmapsfill;
1281 new available = available_maps();
1282
1283 if ((nmaps_num + available) < (maps_to_select + 1)) { //Loads maps from mapcycle.txt/allmaps.txt if not enough are in in mapchoice.ini
1284
1285 new current_map[32];
1286 get_mapname(current_map,31);
1287 new overflowprotect = 0;
1288 new used[MAX_MAPS_AMOUNT];
1289 new k = num_nmapsfill;
1290 new totalfilled = 0;
1291 new alreadyused;
1292 new tryfill, custfill = 0;
1293 new q;
1294 new listpossible = totalmaps;
1295 while (((available_maps() + nmaps_num - custfill) < (maps_to_select + 7)) && listpossible > 0) {
1296 alreadyused = 0;
1297 q = 0;
1298 tryfill = random_num(0, totalmaps - 1);
1299 overflowprotect = 0;
1300 while (used[tryfill] && overflowprotect++ <= totalmaps * 15) {
1301 tryfill = random_num(0, totalmaps - 1);
1302 }
1303 if (overflowprotect >= totalmaps * 15) {
1304 alreadyused = 1;
1305 #if defined DEDICATED_LOG_ENABLED
1306 log_to_file(logfilename, "Overflow detected in Map Nominate plugin, there might not be enough maps in the current vote");
1307 #endif
1308 listpossible -= 1;
1309 } else {
1310 while (q < num_nmapsfill && !alreadyused) {
1311 if (equali(listofmaps[tryfill], nmapsfill[q])) {
1312 alreadyused = used[tryfill] = 1;
1313 listpossible--;
1314 }
1315 q++;
1316 }
1317 q = 0;
1318 while (q < nmaps_num && !alreadyused) {
1319 if (equali(listofmaps[tryfill], nmaps[q])) {
1320 alreadyused = used[tryfill] = 1;
1321 listpossible--;
1322 }
1323 q++;
1324 }
1325 }
1326
1327 if (!alreadyused) {
1328 if (equali(listofmaps[tryfill], current_map) || equali(listofmaps[tryfill], last_map)||
1329 islastmaps(listofmaps[tryfill]) || isbanned(listofmaps[tryfill])) {
1330 listpossible--;
1331 used[tryfill] = 1;
1332 } else {
1333 if (iscustommap(listofmaps[tryfill])) {
1334 custfill++;
1335 }
1336 nmapsfill[k] = listofmaps[tryfill];
1337 num_nmapsfill++;
1338 listpossible--;
1339 used[tryfill] = 1;
1340 k++;
1341 totalfilled++;
1342 }
1343 }
1344 }
1345 #if defined DEDICATED_LOG_ENABLED
1346 log_to_file(logfilename, "Filled %d slots in the fill maps array with maps from mapcycle.txt, %d are custom", totalfilled, custfill);
1347 #endif
1348 }
1349
1350 nbeforefill = nmaps_num; //extra maps do not act as "nominations" they are additions
1351
1352 if (nmaps_num < maps_to_select) {
1353
1354 new need = maps_to_select - nmaps_num;
1355 console_print(0, "%L", LANG_PLAYER, "DMAP_RANDOM_MAPSELECTION", need);
1356 #if defined DEDICATED_LOG_ENABLED
1357 log_to_file(logfilename, "Randomly Filling slots for the vote with %d out of %d", need, num_nmapsfill);
1358 #endif
1359 new fillpossible = num_nmapsfill;
1360 new k = nmaps_num;
1361 new overflowprotect = 0;
1362 new used[MAX_MAPS_AMOUNT];
1363 new totalfilled = 0, custchoice = 0, full = ((amt_custom + custchoice) >= maxcustnom);
1364 new alreadyused;
1365 new tryfill;
1366 if (num_nmapsfill < 1) {
1367 if (quiet != 2) {
1368 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NOMORE_RANDOM_DEFINED");
1369 }
1370 #if defined DEDICATED_LOG_ENABLED
1371 log_to_file(logfilename, "ERROR: Unable to fill any more voting slots with random maps, none defined in mapchoice.ini/allmaps.txt/mapcycle.txt");
1372 #endif
1373 } else {
1374 while (fillpossible > 0 && k < maps_to_select) {
1375 alreadyused = 0;
1376 new q = 0;
1377 tryfill = random_num(0, num_nmapsfill - 1);
1378 overflowprotect = 0;
1379 while (used[tryfill] && overflowprotect++ <= num_nmapsfill * 10) {
1380 tryfill = random_num(0, num_nmapsfill - 1);
1381 }
1382 if (overflowprotect >= num_nmapsfill * 15) {
1383 alreadyused = 1;
1384 #if defined DEDICATED_LOG_ENABLED
1385 log_to_file(logfilename, "Overflow detected in Map Nominate plugin, there might not be enough maps in the current vote");
1386 #endif
1387 fillpossible -= 2;
1388 } else {
1389 while (q < nmaps_num && !alreadyused) {
1390 if (equali(nmapsfill[tryfill], nmaps[q])) {
1391 alreadyused = used[tryfill] = 1;
1392 fillpossible--;
1393 }
1394 q++;
1395 }
1396 if (!alreadyused) {
1397 if (iscustommap(nmapsfill[tryfill]) && full) {
1398 alreadyused = used[tryfill] = 1;
1399 fillpossible--;
1400 }
1401 }
1402 }
1403
1404 if (!alreadyused) {
1405 if (iscustommap(nmapsfill[tryfill])) {
1406 custchoice++;
1407 full = ((amt_custom + custchoice) >= maxcustnom);
1408 }
1409 nmaps[k] = nmapsfill[tryfill];
1410 nmaps_num++;
1411 fillpossible--;
1412 used[tryfill] = 1;
1413 k++;
1414 totalfilled++;
1415 }
1416 }
1417
1418 if (totalfilled == 0) {
1419 console_print(0, "%L", LANG_PLAYER, "DMAP_NO_DEFAULTMAPS_FOUND");
1420 } else {
1421 if (quiet != 2) {
1422 console_print(0, "%L", LANG_PLAYER, "DMAP_FILLED_RANDOM_MAPS", totalfilled);
1423 }
1424 }
1425 #if defined DEDICATED_LOG_ENABLED
1426 log_to_file(logfilename, "Filled %d vote slots with random maps, %d are custom", totalfilled, custchoice);
1427 #endif
1428 }
1429 }
1430
1431 show_vote_menu(true);
1432 return PLUGIN_HANDLED;
1433 }
1434
1435 show_vote_menu(bool:bFirstTime) {
1436
1437 new menu[512], a, mkeys = (1 << maps_to_select + 1);
1438 new steptime = get_pcvar_num(pExtendmapStep);
1439
1440 new pos;
1441
1442 new mp_winlimit = get_cvar_num("mp_winlimit");
1443 if (bFirstTime == true) {
1444 g_TotalVotes = 0;
1445 for (a = 0; a <= 32; a++) {
1446 g_AlreadyVoted[a] = false;
1447 }
1448 }
1449
1450 if (bIsCstrike) {
1451 pos = formatex(menu, 511, "%L", LANG_SERVER, "DMAP_CS_MENU_TITLE");
1452 } else {
1453 pos = formatex(menu, 511, "%L", LANG_SERVER, "DMAP_MENU_TITLE");
1454 }
1455
1456 new dmax = (nmaps_num > maps_to_select) ? maps_to_select : nmaps_num;
1457
1458 new tagpath[64], sMenuOption[64]; // If size of sMenuOption is changed, change maxlength in append_vote_percent as well
1459 formatex(tagpath, 63, "%s/dmaptags.ini", custompath);
1460
1461 for (nmapstoch = 0; nmapstoch < dmax; ++nmapstoch) {
1462 if (bFirstTime == true) {
1463 a = random_num(0, nmaps_num - 1); // Randomize order of maps in vote
1464 while (isinmenu(a)) {
1465 if (++a >= nmaps_num) {
1466 a = 0;
1467 }
1468 }
1469 nnextmaps[nmapstoch] = a;
1470 nvotes[nmapstoch] = 0; // Reset votes for each map
1471 }
1472
1473 if (iscustommap(nmaps[nnextmaps[nmapstoch]]) && usestandard) {
1474 if (bIsCstrike) {
1475 formatex(sMenuOption, 63, "%L", LANG_SERVER, "DMAP_CS_MENU_CUSTOM", nmapstoch + 1, nmaps[nnextmaps[nmapstoch]]);
1476 } else {
1477 formatex(sMenuOption, 63, "%L", LANG_SERVER, "DMAP_MENU_CUSTOM", nmapstoch + 1, nmaps[nnextmaps[nmapstoch]]);
1478 }
1479 } else { // Don't show (Custom)
1480 formatex(sMenuOption, 63, "%d. %s", nmapstoch + 1, nmaps[nnextmaps[nmapstoch]]);
1481 }
1482
1483 if (file_exists(tagpath)) { // If the tag file is there, check for the extra tag
1484 new iLine, sFullLine[64], sTagMap[32], sTagText[32], txtLen;
1485
1486 while (read_file(tagpath, iLine, sFullLine, 63, txtLen)) {
1487 if (sFullLine[0] == ';') {
1488 iLine++;
1489 continue; // Ignore comments
1490 }
1491
1492 strbreak(sFullLine, sTagMap, 31, sTagText, 31); // Split the map name and tag apart
1493
1494 // TODO: Wildcard (regex) matching
1495 // I pulled this code for the v3.24 release.
1496 // Sorry! Expect it to return in the future.
1497
1498 if (equali(nmaps[nnextmaps[nmapstoch]], sTagMap)) {
1499 format(sMenuOption, 63, "%s [%s]", sMenuOption, sTagText);
1500 break; // Quit reading the file
1501 }
1502 iLine++;
1503 }
1504 }
1505
1506 append_vote_percent(sMenuOption, nmapstoch, true);
1507 pos += formatex(menu[pos], 511, sMenuOption);
1508
1509 mkeys |= (1 << nmapstoch);
1510 }
1511
1512 menu[pos++] = '^n';
1513 if (bFirstTime == true) {
1514 nvotes[maps_to_select] = 0;
1515 nvotes[maps_to_select + 1] = 0;
1516 }
1517 new mapname[32];
1518 get_mapname(mapname, 31);
1519 if (!mp_winlimit && get_cvar_float("mp_timelimit") < get_pcvar_float(pExtendmapMax)) {
1520 formatex(sMenuOption, 63, "%L", LANG_SERVER, "DMAP_MENU_EXTEND", maps_to_select + 1, mapname, steptime);
1521 append_vote_percent(sMenuOption, maps_to_select, true);
1522 pos += formatex(menu[pos], 511, sMenuOption);
1523
1524 mkeys |= (1 << maps_to_select);
1525 }
1526
1527 formatex(sMenuOption, 63, "%L", LANG_SERVER, "DMAP_MENU_NONE", maps_to_select + 2);
1528 append_vote_percent(sMenuOption, maps_to_select + 1);
1529 formatex(menu[pos], 511, sMenuOption);
1530
1531 if (bFirstTime == true) {
1532 g_VoteTimeRemaining = DMAP_VOTE_TIME;
1533 set_task(float(g_VoteTimeRemaining), "check_votes");
1534 show_menu(0, mkeys, menu, --g_VoteTimeRemaining, DMAP_MENU_TITLE);
1535 set_task(1.0, "update_vote_time_remaining", DMAP_TASKID_VTR, "", 0, "a", g_VoteTimeRemaining);
1536 if (bIsCstrike) {
1537 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_TIME_TO_CHOOSE");
1538 }
1539 if (quiet == 0) {
1540 client_cmd(0, "spk Gman/Gman_Choose%d", random_num(1, 2));
1541 }
1542 #if defined DEDICATED_LOG_ENABLED
1543 log_to_file(logfilename, "Vote: Voting for the nextmap started");
1544 #endif
1545 } else {
1546 new players[32], iNum, id;
1547 get_players(players, iNum, "ch");
1548 for (new iPlayer = 0; iPlayer < iNum; iPlayer++) {
1549 id = players[iPlayer];
1550 if (g_AlreadyVoted[id] == false) {
1551 show_menu(players[iPlayer], mkeys, menu, g_VoteTimeRemaining, DMAP_MENU_TITLE);
1552 }
1553 }
1554
1555 }
1556 return PLUGIN_HANDLED;
1557 }
1558
1559 stock percent(iIs, iOf) {
1560 return (iOf != 0) ? floatround(floatmul(float(iIs) / float(iOf), 100.0)) : 0;
1561 }
1562
1563 append_vote_percent(sMenuOption[], iChoice, bool:bNewLine = false) {
1564
1565 new iPercent = percent(nvotes[iChoice], g_TotalVotes);
1566 new sPercent[16];
1567 if (iPercent > 0) { // Don't show 0%
1568 if (bIsCstrike) {
1569 formatex(sPercent, 15, " \d(%d%s)\w", iPercent, "%%");
1570 } else {
1571 formatex(sPercent, 15, " (%d%s)", iPercent, "%%");
1572 }
1573 strcat(sMenuOption, sPercent, 63);
1574 }
1575
1576 if (bNewLine == true) { // Do this even if vote is 0%
1577 strcat(sMenuOption, "^n", 63);
1578 }
1579
1580 return PLUGIN_HANDLED;
1581 }
1582
1583 public update_vote_time_remaining() {
1584 if (--g_VoteTimeRemaining <= 0) {
1585 remove_task(DMAP_TASKID_VTR);
1586 }
1587 return PLUGIN_HANDLED;
1588 }
1589
1590 handle_andchange(id, map2[], bool:bForce = false) {
1591 new tester[32];
1592 if (is_map_valid(map2) == 1) {
1593 handle_nominate(id, map2, bForce);
1594 } else {
1595 formatex(tester, 31, "cs_%s", map2);
1596 if (is_map_valid(tester) == 1) {
1597 handle_nominate(id, tester, bForce);
1598 } else {
1599 formatex(tester, 31, "de_%s", map2);
1600 if (is_map_valid(tester) == 1) {
1601 handle_nominate(id, tester, bForce);
1602 } else {
1603 formatex(tester, 31, "as_%s", map2);
1604 if (is_map_valid(tester) == 1) {
1605 handle_nominate(id, tester, bForce);
1606 } else {
1607 formatex(tester, 31, "dod_%s", map2);
1608 if (is_map_valid(tester) == 1) {
1609 handle_nominate(id, tester, bForce);
1610 } else {
1611 formatex(tester, 31, "fy_%s", map2);
1612 if (is_map_valid(tester) == 1) {
1613 handle_nominate(id, tester, bForce);
1614 } else { // Send invalid map. handle_nominate() handles the error.
1615 handle_nominate(id, map2, bForce);
1616 }
1617 }
1618 }
1619 }
1620 }
1621 }
1622 }
1623
1624 public HandleSay(id) {
1625
1626 new chat[256];
1627 read_args(chat, 255);
1628 new saymap[256];
1629 saymap = chat;
1630 remove_quotes(saymap);
1631 new saymap2[29];
1632 read_args(saymap2, 28);
1633 remove_quotes(saymap2);
1634 new chat2[32];
1635
1636 if (containi(chat, "<") != -1 || containi(chat, "?") != -1 || containi(chat, ">") != -1 || containi(chat, "*") != -1 || containi(chat, "&") != -1 || containi(chat, ".") != -1) {
1637 return PLUGIN_CONTINUE;
1638 }
1639 if (containi(chat, "nominations") != -1) {
1640 if (get_pcvar_num(pNominationsAllowed) == 0) {
1641 client_print(id, print_chat, "%L", id, "DMAP_NOMINATIONS_DISABLED");
1642 return PLUGIN_HANDLED;
1643 }
1644 if (mselected) {
1645 client_print(id, print_chat, "%L", id, "DMAP_VOTE_IN_PROGRESS");
1646 } else {
1647 if (nmaps_num == 0) {
1648 client_print(id, print_chat, "%L", id, "DMAP_NO_NOMINATIONS");
1649 } else {
1650 listnominations(id);
1651 }
1652 }
1653 } else {
1654 if (containi(chat, "nominate ") == 1) {
1655 new mycommand[41];
1656 read_args(mycommand, 40);
1657 remove_quotes(mycommand);
1658 handle_andchange(id, mycommand[9]);
1659 } else {
1660 if (containi(chat, "vote ") == 1) {
1661 new mycommand[37];
1662 read_args(mycommand, 36);
1663 remove_quotes(mycommand);
1664 handle_andchange(id, mycommand[5]);
1665 } else {
1666 if (is_map_valid(saymap) == 1) {
1667 handle_nominate(id, saymap, false);
1668 } else {
1669 formatex(chat2, 31, "cs_%s", saymap2);
1670 if (is_map_valid(chat2) == 1) {
1671 handle_nominate(id, chat2, false);
1672 } else {
1673 formatex(chat2, 31, "de_%s", saymap2);
1674 if (is_map_valid(chat2) == 1) {
1675 handle_nominate(id, chat2, false);
1676 } else {
1677 formatex(chat2, 31, "as_%s", saymap2);
1678 if (is_map_valid(chat2) == 1) {
1679 handle_nominate(id, chat2, false);
1680 } else {
1681 formatex(chat2, 31, "dod_%s", saymap2);
1682 if (is_map_valid(chat2) == 1) {
1683 handle_nominate(id, chat2, false);
1684 } else {
1685 formatex(chat2, 31, "fy_%s", saymap2);
1686 if (is_map_valid(chat2) == 1) {
1687 handle_nominate(id, chat2, false);
1688 }
1689 }
1690 }
1691 }
1692 }
1693 }
1694 }
1695 }
1696 }
1697 return PLUGIN_CONTINUE;
1698 }
1699
1700 public calculate_custom() {
1701 //New optional protection against "too many" custom maps being nominated.
1702 amt_custom = 0;
1703 new i;
1704 for (i = 0; i < nmaps_num; i++) {
1705 if (iscustommap(nmaps[i])) {
1706 amt_custom++;
1707 }
1708 }
1709 }
1710
1711 public handle_nominate(id, map[], bool:bForce) {
1712 if ((get_pcvar_num(pNominationsAllowed) == 0) && (bForce == false)) {
1713 client_print(id, print_chat, "%L", id, "DMAP_NOMINATIONS_DISABLED");
1714 return PLUGIN_HANDLED;
1715 }
1716 strtolower(map);
1717 new current_map[32], iscust = 0, iscust_t = 0, full;
1718 full = (amt_custom >= maxcustnom);
1719 new n = 0, i, done = 0, isreplacement = 0; //0: (not a replacement), 1: (replacing his own), 2: (replacing others)
1720 new tempnmaps = nmaps_num;
1721 get_mapname(current_map, 31);
1722 if (maxnom == 0) {
1723 client_print(id, print_chat, "%L", id, "DMAP_NOMINATIONS_DISABLED");
1724 return PLUGIN_HANDLED;
1725 }
1726 if (inprogress && mselected) {
1727 client_print(id, print_chat, "%L", id, "DMAP_VOTING_IN_PROGRESS");
1728 return PLUGIN_HANDLED;
1729 }
1730 if (mselected) {
1731 new smap[32];
1732 get_cvar_string("amx_nextmap", smap, 31);
1733 client_print(id, print_chat, "%L", id, "DMAP_VOTING_OVER", smap);
1734 return PLUGIN_HANDLED;
1735 }
1736 if (!is_map_valid(map) || is_map_valid(map[1])) {
1737 client_print(id, print_chat, "%L", id, "DMAP_MAP_NOTFOUND", map);
1738 return PLUGIN_HANDLED;
1739 }
1740 if (isbanned(map) && (bForce == false)) {
1741 client_print(id, print_chat, "%L", id, "DMAP_MAPVOTE_NOT_AVAILABLE");
1742 return PLUGIN_HANDLED;
1743 }
1744 if (islastmaps(map) && !equali(map, current_map) && (bForce == false)) {
1745 client_print(id, print_chat, "%L", id, "DMAP_CANT_NOMINATE_LASTMAP", ban_last_maps);
1746 return PLUGIN_HANDLED;
1747 }
1748 if (equali(map, current_map)) {
1749 client_print(id, print_chat, "%L", id, "DMAP_EXTEND_MAP", map);
1750 return PLUGIN_HANDLED;
1751 }
1752 //Insert Strict Style code here, for pcvar dmap_strict 1
1753 if (get_pcvar_num(pDmapStrict) && (bForce == false)) {
1754 new isinthelist = 0;
1755 for (new a = 0; a < totalmaps; a++) {
1756 if (equali(map, listofmaps[a]))
1757 isinthelist = 1;
1758 }
1759 if (!isinthelist) {
1760 client_print(id, print_chat, "%L", id, "DMAP_ALLOWED_MAPS");
1761 return PLUGIN_HANDLED;
1762 }
1763 }
1764 iscust = iscustommap(map);
1765 if (nmaps_num >= maps_to_select || Nominated[id] >= maxnom) { //3 (1,2,3)
1766 if (Nominated[id] > maxnom) { //3
1767 client_print(id, print_chat, "%L", id, "DMAP_MAX_MAPS_REACHED"); //Possible to reach here!
1768 //only if the command dmap_nominations is used to lower amount of maps that can be nominated
1769 return PLUGIN_HANDLED;
1770 }
1771
1772 for (i = 0; i < nmaps_num; i++) {
1773 if (equali(map, nmaps[i])) {
1774
1775 new name[32];
1776 get_user_name(whonmaps_num[i], name, 31);
1777 if (quiet == 2) {
1778 client_print(id, print_chat, "%L", id, "DMAP_ALREADY_NOMINATED", map, name);
1779 } else {
1780 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_ALREADY_NOMINATED", map, name);
1781 }
1782 return PLUGIN_HANDLED;
1783 }
1784 }
1785
1786 while (n < nmaps_num && !done && Nominated[id] > 1) { //If the person has nominated 2 or 3 maps, he can replace his own
1787 if (whonmaps_num[n] == id) { //If a map is found that he has nominated, replace his own nomination.
1788 iscust_t = iscustommap(nmaps[n]);
1789 if (!(full && iscust && !iscust_t)) {
1790 Nominated[id] = Nominated[id] - 1;
1791 nmaps_num = n;
1792 done = 1;
1793 isreplacement = 1;
1794 }
1795 }
1796 n++;
1797 }
1798
1799 if (!done) {
1800 n = 0;
1801 while (n < nmaps_num && !done && Nominated[id] < 2) { //If the person has nom only 1 or no maps, he can replace ppl who nominated 3
1802 if (Nominated[whonmaps_num[n]] > 2) { //Replace the "greedy person's" nomination
1803 iscust_t = iscustommap(nmaps[n]);
1804 if (!(full && iscust && !iscust_t)) {
1805 done = 1;
1806 Nominated[whonmaps_num[n]] = Nominated[whonmaps_num[n]] - 1;
1807 nmaps_num = n;
1808 isreplacement = 2;
1809 }
1810 }
1811 n++;
1812 }
1813 }
1814 if (!done) {
1815 n = 0;
1816
1817 while (n < nmaps_num && !done && Nominated[id] < 1) { //If the person has not nom any maps, he can replace those with more than one
1818 //he cannot replace those with only one nomination, that would NOT be fair
1819
1820 if (Nominated[whonmaps_num[n]] > 1) { //Replace the "greedy person's" nomination
1821 iscust_t = iscustommap(nmaps[n]);
1822 if (!(full && iscust && !iscust_t)) {
1823 done = 1;
1824 Nominated[whonmaps_num[n]] = Nominated[whonmaps_num[n]] - 1;
1825 nmaps_num = n;
1826 isreplacement = 2;
1827 }
1828 }
1829 n++;
1830 }
1831 }
1832
1833 if (!done) {
1834 n = 0;
1835
1836 while (n < nmaps_num && !done && Nominated[id] > 0) { //If the person has nominated a map, he can replace his own
1837 if (whonmaps_num[n] == id) { //If a map is found that he has nominated, replace his own nomination.
1838 iscust_t = iscustommap(nmaps[n]);
1839 if (!(full && iscust && !iscust_t)) { //Check to see if too many custom maps are nominated
1840 Nominated[id] = Nominated[id] - 1;
1841 nmaps_num = n;
1842 done = 1;
1843 isreplacement = 1;
1844 }
1845 }
1846 n++;
1847 }
1848 }
1849 if (!done) {
1850 client_print(id, print_chat, "%L", id, "DMAP_MAX_NOMINATIONS_REACHED", nmaps_num);
1851 return PLUGIN_HANDLED;
1852 }
1853 }
1854
1855 for (i = 0; i < nmaps_num; i++) {
1856 if (equali(map, nmaps[i])) {
1857 new name[32];
1858 get_user_name(whonmaps_num[i], name, 31);
1859
1860 client_print(id, print_chat, "%L", id, "DMAP_ALREADY_NOMINATED", map, name);
1861
1862 nmaps_num = tempnmaps;
1863
1864 return PLUGIN_HANDLED;
1865 }
1866 }
1867
1868 if (!isreplacement && iscust && full) {
1869 client_print(id, print_chat, "%L", id, "DMAP_MAX_CUSTOMMAPS_REACHED", maxcustnom);
1870 return PLUGIN_HANDLED;
1871 }
1872
1873 new name[32];
1874 get_user_name(id, name, 31);
1875 if (isreplacement == 1) { //They are replacing their old map
1876 if (quiet == 2) {
1877 client_print(id, print_chat, "%L", id, "DMAP_REPLACE_PREVIOUS_NOMINATION", nmaps[nmaps_num]);
1878 } else {
1879 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_PLAYER_REPLACED_NOMINATION", name, nmaps[nmaps_num]);
1880 }
1881 } else {
1882 if (isreplacement == 2) {
1883 if (quiet == 2) {
1884 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NOMINATION_REPLACED", nmaps[nmaps_num]);
1885 } else {
1886 new name21[32];
1887 get_user_name(whonmaps_num[nmaps_num], name21, 31);
1888 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NOMINATION_REPLACED2", name21, nmaps[nmaps_num]);
1889 }
1890 }
1891 }
1892
1893 Nominated[id]++;
1894
1895 console_print(id, "%L", id, "DMAP_ADD_NOMINATION", map, nmaps_num + 1);
1896
1897 set_task(0.18, "calculate_custom");
1898 copy(nmaps[nmaps_num], 31, map);
1899 whonmaps_num[nmaps_num] = id;
1900
1901 if (isreplacement) {
1902 nmaps_num = tempnmaps;
1903 } else {
1904 nmaps_num = tempnmaps + 1;
1905 }
1906 if ((bForce == true) && (get_pcvar_num(pShowActivity) > 0)) {
1907 switch(get_pcvar_num(pShowActivity)) {
1908 case 1: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_ADMIN_NOMINATED_MAP1", map);
1909 case 2: client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_ADMIN_NOMINATED_MAP2", name, map);
1910 }
1911 } else {
1912 client_print(0, print_chat, "%L", LANG_PLAYER, "DMAP_NOMINATED_MAP", name, map);
1913 }
1914
1915 return PLUGIN_HANDLED;
1916 }
1917
1918 public team_score() {
1919
1920 new team[2];
1921 read_data(1, team, 1);
1922 teamscore[(team[0] == 'C') ? 0 : 1] = read_data(2);
1923
1924 return PLUGIN_CONTINUE;
1925 }
1926
1927 public plugin_end() {
1928 new current_map[32];
1929 get_mapname(current_map, 31);
1930 set_localinfo("amx_lastmap", current_map);
1931
1932 if (istimeset) {
1933 set_cvar_float("mp_timelimit", oldtimelimit);
1934 } else {
1935 if (istimeset2) {
1936 set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 2.0);
1937 }
1938 }
1939 if (isspeedset) {
1940 set_cvar_float("sv_maxspeed", thespeed);
1941 }
1942 if (iswinlimitset) {
1943 set_cvar_num("mp_winlimit", oldwinlimit);
1944 }
1945 return PLUGIN_CONTINUE;
1946 }
1947
1948 public get_listing() {
1949 new i = 0, iavailable = 0;
1950 new line = 0, p;
1951 new stextsize = 0, isinthislist = 0, found_a_match = 0, done = 0;
1952 new linestr[256];
1953 new maptext[32];
1954 new current_map[32];
1955 get_mapname(current_map, 31);
1956 //pathtomaps = "mapcycle.txt";
1957 get_cvar_string("mapcyclefile", pathtomaps, 63);
1958 new smap[32];
1959 get_cvar_string("amx_nextmap", smap, 31);
1960 if (file_exists(pathtomaps)) {
1961 while (read_file(pathtomaps, line, linestr, 255, stextsize) && !done) {
1962 formatex(maptext, 31, "%s", linestr);
1963 if (is_map_valid(maptext) && !is_map_valid(maptext[1]) && equali(maptext, current_map)) {
1964 done = found_a_match = 1;
1965 line++;
1966 if (read_file(pathtomaps, line, linestr, 255, stextsize)) {
1967 formatex(maptext, 31, "%s", linestr);
1968 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
1969 //////////////////////////////////////////
1970 if (equali(smap, "")) {
1971 register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);
1972 }
1973 set_cvar_string("amx_nextmap", maptext);
1974 } else {
1975 found_a_match = 0;
1976 }
1977 } else {
1978 found_a_match = 0;
1979 }
1980 } else {
1981 line++;
1982 }
1983 }
1984 /*
1985 if (!found_a_match) {
1986 line = 0;
1987 while (read_file(pathtomaps, line, linestr, 255, stextsize) && !found_a_match && line < 1024) {
1988 formatex(maptext, 31, "%s", linestr);
1989 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
1990 if (equali(smap, "")) {
1991 register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);
1992 }
1993 set_cvar_string("amx_nextmap", maptext);
1994 found_a_match = 1;
1995 } else {
1996 line++;
1997 }
1998 }
1999 }
2000 */
2001 /* CODE TO RANDOMIZE NEXTMAP VARIABLE!*/
2002 if (!found_a_match) {
2003 line = random_num(0, 50);
2004 new tries = 0;
2005
2006 while ((read_file(pathtomaps, line, linestr, 255, stextsize) || !found_a_match) && (tries < 1024 && !found_a_match)) {
2007 formatex(maptext, 31, "%s", linestr);
2008 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
2009 if (equali(smap, "")) {
2010 register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY);
2011 }
2012 set_cvar_string("amx_nextmap", maptext);
2013 found_a_match = 1;
2014 } else {
2015 line = random_num(0, 50);
2016 tries++;
2017 }
2018 }
2019 }
2020 }
2021
2022 line = 0;
2023 formatex(pathtomaps, 63, "%s/allmaps.txt", custompath);
2024 if (!file_exists(pathtomaps)) {
2025 new mapsadded = 0;
2026 while ((line = read_dir("maps", line, linestr, 255, stextsize)) != 0) {
2027 stextsize -= 4;
2028
2029 if (stextsize > 0) {
2030 if (!equali(linestr[stextsize], ".bsp")) {
2031 continue; // skip non map files
2032 }
2033 linestr[stextsize] = 0; // remove .bsp
2034 }
2035
2036 if (is_map_valid(linestr)) {
2037 write_file(pathtomaps, linestr);
2038 mapsadded++;
2039 }
2040 }
2041 #if defined DEDICATED_LOG_ENABLED
2042 log_to_file(logfilename, "Found %d maps in your <mod>/MAPS folder, and added these to the addons/amxmodx/allmaps.txt file", mapsadded);
2043 #endif
2044 line = 0;
2045 }
2046
2047 if (get_pcvar_float(pDmapStrict) == 1.0) {
2048 get_cvar_string("mapcyclefile", pathtomaps, 63);
2049 //pathtomaps = "mapcycle.txt";
2050 }
2051
2052 if (file_exists(pathtomaps)) {
2053 while (read_file(pathtomaps, line, linestr, 255, stextsize) && i < MAX_MAPS_AMOUNT) {
2054 formatex(maptext, 31, "%s", linestr);
2055 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
2056 isinthislist = 0;
2057 for (p = 0; p < i; p++) {
2058 if (equali(maptext, listofmaps[p])) {
2059 isinthislist = 1;
2060 }
2061 }
2062 if (!isinthislist) {
2063 listofmaps[i++] = maptext;
2064 }
2065 }
2066 line++;
2067 }
2068 }
2069
2070 line = 0;
2071 for (p = 0; p < i; p++) {
2072 if (!isbanned(listofmaps[p]) && !islastmaps(listofmaps[p])) {
2073 iavailable++;
2074 }
2075 }
2076 new dummy_str[64];
2077 get_cvar_string("mapcyclefile", dummy_str, 63);
2078 //if (iavailable < maps_to_select && !equali(pathtomaps, "mapcycle.txt"))
2079 if (iavailable < maps_to_select && !equali(pathtomaps, dummy_str)) {
2080 //pathtomaps = "mapcycle.txt";
2081 get_cvar_string("mapcyclefile", pathtomaps, 63);
2082 if (file_exists(pathtomaps)) {
2083 while (read_file(pathtomaps, line, linestr, 255, stextsize) && i < MAX_MAPS_AMOUNT) {
2084 formatex(maptext, 31, "%s", linestr);
2085 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
2086 isinthislist = 0;
2087 for (p = 0; p < i; p++) {
2088 if (equali(maptext, listofmaps[p])) {
2089 isinthislist = 1;
2090 }
2091 }
2092 if (!isinthislist) {
2093 listofmaps[i++] = maptext;
2094 }
2095 }
2096 line++;
2097 }
2098 }
2099 }
2100 totalmaps = i;
2101 iavailable = 0;
2102 for (p = 0; p < i; p++) {
2103 if (!isbanned(listofmaps[p]) && !islastmaps(listofmaps[p])) {
2104 iavailable++;
2105 }
2106 }
2107 #if defined DEDICATED_LOG_ENABLED
2108 log_to_file(logfilename, "Found %d Maps in your mapcycle.txt/allmaps.txt file, %d are available for filling slots", i, iavailable);
2109 #endif
2110 }
2111
2112 public ban_some_maps() {
2113 //BAN MAPS FROM CONFIG FILE
2114 new banpath[64];
2115 formatex(banpath, 63, "%s/mapstoban.ini", custompath);
2116 new i = 0;
2117 new line = 0;
2118 new stextsize = 0;
2119 new linestr[256];
2120 new maptext[32];
2121
2122 if (file_exists(banpath)) {
2123 while (read_file(banpath, line, linestr, 255, stextsize) && i < MAX_MAPS_AMOUNT) {
2124 formatex(maptext, 31, "%s", linestr);
2125 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
2126 banthesemaps[i++] = maptext;
2127 }
2128 line++;
2129 }
2130 }
2131 totalbanned = i;
2132 #if defined DEDICATED_LOG_ENABLED
2133 if (totalbanned > 0) {
2134 log_to_file(logfilename, "Banned %d Maps in your mapstoban.ini file", totalbanned);
2135 } else {
2136 log_to_file(logfilename, "Did not ban any maps from mapstoban.ini file");
2137 }
2138 #endif
2139 //BAN RECENT MAPS PLAYED
2140 new lastmapspath[64];
2141 formatex(lastmapspath, 63, "%s/lastmapsplayed.txt", custompath);
2142 line = stextsize = 0;
2143 new current_map[32];
2144 get_mapname(current_map, 31);
2145 lastmaps[0] = current_map;
2146 bannedsofar++;
2147 currentplayers = activeplayers = rocks = 0;
2148 if (file_exists(lastmapspath)) {
2149 while(read_file(lastmapspath, line, linestr, 255, stextsize) && bannedsofar <= ban_last_maps) {
2150 if ((strlen(linestr) > 0) && (is_map_valid(linestr))) {
2151 formatex(lastmaps[bannedsofar++], 31, "%s", linestr);
2152 }
2153 line++;
2154 }
2155 }
2156 write_lastmaps(); //deletes and writes to lastmapsplayed.txt
2157 }
2158
2159 public write_lastmaps() {
2160 new lastmapspath[64];
2161 formatex(lastmapspath, 63, "%s/lastmapsplayed.txt", custompath);
2162 if (file_exists(lastmapspath)) {
2163 delete_file(lastmapspath);
2164 }
2165 new text[256], p;
2166 for (p = 0; p < bannedsofar; p++) {
2167 formatex(text, 255, "%s", lastmaps[p]);
2168 write_file(lastmapspath, text);
2169 }
2170 write_file(lastmapspath, "Generated by map_nominate plugin,");
2171 write_file(lastmapspath, "these are most recent maps played");
2172
2173 load_maps();
2174 }
2175
2176 public load_maps() {
2177 new choicepath[64];
2178 formatex(choicepath, 63, "%s/mapchoice.ini", custompath);
2179 new line = 0;
2180 new stextsize = 0, isinlist, unable = 0, i;
2181 new linestr[256];
2182 new maptext[32];
2183 new current_map[32];
2184 get_mapname(current_map, 31);
2185 if (file_exists(choicepath)) {
2186 while (read_file(choicepath, line, linestr, 255, stextsize) && (num_nmapsfill < MAX_MAPS_AMOUNT)) {
2187 formatex(maptext, 31, "%s", linestr);
2188 if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
2189 isinlist = 0;
2190 if (isbanned(maptext) || islastmaps(maptext)) {
2191 isinlist = 1;
2192 } else {
2193 if (equali(maptext, current_map) || equali(maptext, last_map)) {
2194 isinlist = 1;
2195 } else {
2196 for (i = 0; i < num_nmapsfill; i++) {
2197 if (equali(maptext, nmapsfill[i])) {
2198 #if defined DEDICATED_LOG_ENABLED
2199 log_to_file(logfilename, "Map ^"%s^" is already in list! It is defined it twice", maptext);
2200 #endif
2201 isinlist = 1;
2202 }
2203 }
2204 }
2205 }
2206 if (!isinlist) {
2207 copy(nmapsfill[num_nmapsfill++], 31, maptext);
2208 } else {
2209 unable++;
2210 }
2211 }
2212 line++;
2213 }
2214 #if defined DEDICATED_LOG_ENABLED
2215 log_to_file(logfilename, "Loaded %d Maps into the maps that will be picked for the vote", num_nmapsfill);
2216 log_to_file(logfilename, "%d Maps were not loaded because they were the last maps played, or defined twice, or banned", unable);
2217 } else {
2218 log_to_file(logfilename, "Unable to open file %s, In order to get maps: your mapcycle.txt file will be searched", choicepath);
2219 #endif
2220 }
2221 get_listing();
2222 }
2223
2224 public load_defaultmaps() {
2225 new standardpath[64];
2226 formatex(standardpath, 63, "%s/standardmaps.ini", custompath);
2227 new i = 0;
2228 new line = 0;
2229 new stextsize = 0;
2230 new linestr[256];
2231 new maptext[32];
2232 usestandard = 1;
2233 if (!file_exists(standardpath)) {
2234 usestandard = standardtotal = 0;
2235 } else {
2236 while(read_file(standardpath, line, linestr, 255, stextsize) && i < 40) {
2237 formatex(maptext, 31, "%s", linestr);
2238 if (is_map_valid(maptext)) {
2239 standard[i++] = maptext;
2240 }
2241 line++;
2242 }
2243 standardtotal = i;
2244 }
2245 if (standardtotal < 5) {
2246 usestandard = 0;
2247 #if defined DEDICATED_LOG_ENABLED
2248 log_to_file(logfilename, "Attention, %d Maps were found in the standardmaps.ini file. This is no problem, but the words Custom will not be used", standardtotal);
2249 #endif
2250 }
2251 }
2252
2253 bool:iscustommap(map[]) {
2254 new a;
2255 for (a = 0; a < standardtotal; a++) {
2256 if (equali(map, standard[a])) {
2257 return false;
2258 }
2259 }
2260 if (usestandard) {
2261 return true;
2262 }
2263 return false;
2264 }
2265
2266 bool:islastmaps(map[]) {
2267 new a;
2268 for (a = 0; a < bannedsofar; a++) {
2269 if (equali(map, lastmaps[a])) {
2270 return true;
2271 }
2272 }
2273 return false;
2274 }
2275
2276 bool:isnominated(map[]) {
2277 new a;
2278 for (a = 0; a < nmaps_num; a++) {
2279 if (equali(map, nmaps[a])) {
2280 return true;
2281 }
2282 }
2283 return false;
2284 }
2285
2286 bool:isbanned(map[]) {
2287 new a;
2288 for (a = 0; a < totalbanned; a++) {
2289 if (equali(map, banthesemaps[a])) {
2290 return true;
2291 }
2292 }
2293 return false;
2294 }
2295
2296 loadsettings(filename[]) {
2297 if (!file_exists(filename)) {
2298 return 0;
2299 }
2300
2301 new text[256], percent[5], strban[4], strplay[3], strwait[3], strwait2[3], strurl[64], strnum[3], strnum2[3];
2302 new len, pos = 0;
2303 new Float:numpercent;
2304 new banamount, nplayers, waittime, mapsnum;
2305 while (read_file(filename, pos++, text, 255, len)) {
2306 if (text[0] == ';') {
2307 continue;
2308 }
2309 switch(text[0]) {
2310 case 'r': {
2311 formatex(percent, 4, "%s", text[2]);
2312 numpercent = float(str_to_num(percent)) / 100.0;
2313 if (numpercent >= 0.03 && numpercent <= 1.0) {
2314 rtvpercent = numpercent;
2315 }
2316 }
2317 case 'q': {
2318 if (text[1] == '2') {
2319 quiet = 2;
2320 } else {
2321 quiet = 1;
2322 }
2323 }
2324 case 'c': {
2325 cycle = 1;
2326 }
2327 case 'd': {
2328 enabled = 0;
2329 }
2330 case 'f': {
2331 if (text[1] == 'r') {
2332 formatex(strwait2, 2, "%s", text[2]);
2333 waittime = str_to_num(strwait2);
2334 if (waittime >= 2 && waittime <= 20) {
2335 frequency = waittime;
2336 }
2337 } else {
2338 dofreeze = 0;
2339 }
2340 }
2341 case 'b': {
2342 formatex(strban, 3, "%s", text[2]);
2343 banamount = str_to_num(strban);
2344 if (banamount >= 0 && banamount <= 100) {
2345 if ((banamount == 0 && text[2] == '0') || banamount > 0) {
2346 ban_last_maps = banamount;
2347 }
2348 }
2349 }
2350 case 'm': {
2351 if (atstart) {
2352 formatex(strnum, 2, "%s", text[2]);
2353 mapsnum = str_to_num(strnum);
2354 if (mapsnum >= 2 && mapsnum <= 8) {
2355 maps_to_select = mapssave = mapsnum;
2356 }
2357 }
2358 }
2359 case 'p': {
2360 formatex(strplay, 2, "%s", text[2]);
2361 nplayers = str_to_num(strplay);
2362 if (nplayers > 0 && nplayers <= 32) {
2363 minimum = nplayers;
2364 }
2365 }
2366 case 'u': {
2367 formatex(strurl, 63, "%s", text[2]);
2368 if ((containi(strurl, "www") != -1 || containi(strurl, "http") != -1) && !equali(strurl, "http")) {
2369 mapsurl = strurl;
2370 }
2371 }
2372 case 'w': {
2373 formatex(strwait, 2, "%s", text[2]);
2374 waittime = str_to_num(strwait);
2375 if (waittime >= 0 && waittime <= 60) {
2376 minimumwait = waittime;
2377 }
2378 }
2379 case 'x': {
2380 formatex(strnum2, 2, "%s", text[2]);
2381 mapsnum = str_to_num(strnum2);
2382 if (mapsnum >= 1 && mapsnum <= 3) {
2383 maxnom = mapsnum;
2384 }
2385 }
2386 case 'y': {
2387 formatex(strnum2, 2, "%s", text[2]);
2388 mapsnum = str_to_num(strnum2);
2389 if (mapsnum >= 0 && mapsnum <= mapssave) {
2390 maxcustnom = mapsnum;
2391 }
2392 }
2393 }
2394 }
2395 return 1;
2396 }
2397
2398 set_defaults(myid) {
2399
2400 rtvpercent = 0.6;
2401 ban_last_maps = 4;
2402 maxnom = frequency = 3;
2403 quiet = cycle = 0;
2404 minimum = enabled = 1;
2405 minimumwait = 10;
2406 mapssave = maxcustnom = 5;
2407 mapsurl = "";
2408 dofreeze = bIsCstrike;
2409
2410 if (myid < 0) {
2411 savesettings(-1);
2412 } else {
2413 savesettings(myid);
2414 showsettings(myid);
2415 console_print(myid, "================== DEFAULTS SET =========================");
2416 }
2417 }
2418
2419 public dmaprtvpercent(id, level, cid) {
2420 if (!cmd_access(id, level, cid, 2)) {
2421 return PLUGIN_HANDLED;
2422 }
2423
2424 if (id == 0) {
2425 announce_config_error("dmap_rtvpercent");
2426 return PLUGIN_HANDLED;
2427 }
2428
2429 new arg[32];
2430 read_argv(1, arg, 3);
2431 new Float:percentage = float(str_to_num(arg)) / 100.0;
2432 if (percentage >= 0.03 && percentage <= 1.0) {
2433 rtvpercent = percentage;
2434 savesettings(id);
2435 showsettings(id);
2436 } else {
2437 console_print(id, "You must specify a value between 3 and 100 for dmap_rtvpercent");
2438 console_print(id, "This sets minimum percent of players that must say rockthevote to rockit");
2439 }
2440 return PLUGIN_HANDLED;
2441 }
2442
2443 public dmaprtvplayers(id, level, cid) {
2444 if (!cmd_access(id, level, cid, 2)) {
2445 return PLUGIN_HANDLED;
2446 }
2447
2448 if (id == 0) {
2449 announce_config_error("dmap_rtvplayers");
2450 return PLUGIN_HANDLED;
2451 }
2452
2453 new arg[32];
2454 read_argv(1, arg, 3);
2455 new players = str_to_num(arg);
2456 if (players >= 1 && players <= 32) {
2457 minimum = players;
2458 savesettings(id);
2459 showsettings(id);
2460 } else {
2461 console_print(id, "You must specify a value between 1 and 32 for dmap_rtvplayers");
2462 console_print(id, "This sets minimum num of players that must say rockthevote to rockit");
2463 }
2464 return PLUGIN_HANDLED;
2465 }
2466
2467 public dmaprtvwait(id, level, cid) {
2468 if (!cmd_access(id, level, cid, 2)) {
2469 return PLUGIN_HANDLED;
2470 }
2471
2472 if (id == 0) {
2473 announce_config_error("dmap_rtvwait");
2474 return PLUGIN_HANDLED;
2475 }
2476
2477 new arg[32];
2478 read_argv(1, arg, 3);
2479 new wait = str_to_num(arg);
2480 if (wait >= 0 && wait <= 60) {
2481 minimumwait = wait;
2482 savesettings(id);
2483 showsettings(id);
2484 } else {
2485 console_print(id, "You must specify a value between 0 and 60 for dmap_rtvwait");
2486 console_print(id, "This sets how long must pass from the start of map before players may rockthevote");
2487 }
2488 return PLUGIN_HANDLED;
2489 }
2490
2491 public dmapmessages(id, level, cid) {
2492 if (!cmd_access(id, level, cid, 2)) {
2493 return PLUGIN_HANDLED;
2494 }
2495
2496 if (id == 0) {
2497 announce_config_error("dmap_messages");
2498 return PLUGIN_HANDLED;
2499 }
2500
2501 new arg[32];
2502 read_argv(1, arg, 3);
2503 new wait = str_to_num(arg);
2504 if (wait >= 2 && wait <= 20) {
2505 frequency = wait;
2506 savesettings(id);
2507 showsettings(id);
2508 } else {
2509 console_print(id, "You must specify a value between 2 and 20 minutes for dmap_messages");
2510 console_print(id, "This sets how many minutes will pass between messages for nominations for available maps");
2511 }
2512 return PLUGIN_HANDLED;
2513 }
2514
2515 public dmapmapsnum(id, level, cid) {
2516 if (!cmd_access(id, level, cid, 2)) {
2517 return PLUGIN_HANDLED;
2518 }
2519
2520 if (id == 0) {
2521 announce_config_error("dmap_mapsnum");
2522 return PLUGIN_HANDLED;
2523 }
2524
2525 new arg[32];
2526 read_argv(1, arg, 3);
2527 new maps = str_to_num(arg);
2528 if (maps >= 2 && maps <= 8) {
2529 mapssave = maps;
2530 savesettings(id);
2531 showsettings(id);
2532 console_print(id, "***** Settings for dmap_mapsnum do NOT take effect until the next map!!! ******");
2533 } else {
2534 console_print(id, "You must specify a value between 2 and 8 for dmap_mapsnum");
2535 console_print(id, "This sets the # of maps in the vote, changing this doesn't take effect until the next map");
2536 }
2537 return PLUGIN_HANDLED;
2538 }
2539
2540 public dmapnominations(id, level, cid) {
2541 if (!cmd_access(id, level, cid, 2)) {
2542 return PLUGIN_HANDLED;
2543 }
2544
2545 if (id == 0) {
2546 announce_config_error("dmap_nominations");
2547 return PLUGIN_HANDLED;
2548 }
2549
2550 new arg[32];
2551 read_argv(1, arg, 3);
2552 new thisnumber = str_to_num(arg);
2553 if (thisnumber >= 0 && thisnumber <= 3) {
2554 maxnom = thisnumber;
2555 savesettings(id);
2556 showsettings(id);
2557 console_print(id, "***** Settings for dmap_nominations do NOT take effect until the next map!!! ******");
2558 } else {
2559 console_print(id, "You must specify a value between 0 and 3 for dmap_nominations");
2560 console_print(id, "This sets the maximum number of maps a person can nominate");
2561 }
2562 return PLUGIN_HANDLED;
2563 }
2564
2565 public dmapmaxcustom(id, level, cid) {
2566 if (!cmd_access(id, level, cid, 2)) {
2567 return PLUGIN_HANDLED;
2568 }
2569
2570 if (id == 0) {
2571 announce_config_error("dmap_maxcustom");
2572 return PLUGIN_HANDLED;
2573 }
2574
2575 new arg[32];
2576 read_argv(1, arg, 3);
2577 new thisnumber = str_to_num(arg);
2578 if (thisnumber >= 0 && thisnumber <= mapssave) {
2579 maxcustnom = thisnumber;
2580 savesettings(id);
2581 showsettings(id);
2582 } else {
2583 console_print(id, "You must specify a value between {0} and maximum maps in the vote, which is {%d}, for dmap_maxcustom", mapssave);
2584 console_print(id, "This sets the maximum number of custom maps that may be nominated by the players");
2585 }
2586 return PLUGIN_HANDLED;
2587 }
2588
2589 public dmapquietmode(id, level, cid) {
2590 if (!cmd_access(id, level, cid, 2)) {
2591 return PLUGIN_HANDLED;
2592 }
2593
2594 if (id == 0) {
2595 announce_config_error("dmap_quietmode");
2596 return PLUGIN_HANDLED;
2597 }
2598
2599 new arg[32];
2600 read_argv(1, arg, 31);
2601 if (containi(arg, "off") != -1) {
2602 console_print(id, "======Quiet mode is now OFF, messages pertaining to maps will be shown=====");
2603 quiet = 0;
2604 } else if (containi(arg, "silent") != -1) {
2605 console_print(id, "======Quiet mode is now set to SILENT, A minimal amount of messages will be shown!=====");
2606 quiet = 2;
2607 } else if (containi(arg, "nosound") != -1) {
2608 console_print(id, "======Quiet mode is now set to NOSOUND, messages pertaining to maps will be shown, with no sound=====");
2609 quiet = 1;
2610 } else {
2611 console_print(id, "USAGE: dmap_quietmode <OFF|NOSOUND|SILENT>");
2612 return PLUGIN_HANDLED;
2613 }
2614 savesettings(id);
2615 showsettings(id);
2616 return PLUGIN_HANDLED;
2617 }
2618
2619 public dmaprtvtoggle(id, level, cid) {
2620 if (!cmd_access(id, level, cid, 1)) {
2621 return PLUGIN_HANDLED;
2622 }
2623
2624 if (id == 0) {
2625 announce_config_error("dmap_rtvtoggle");
2626 return PLUGIN_HANDLED;
2627 }
2628
2629 if (enabled == 0) {
2630 console_print(id, "=========Rockthevote is now enabled=========");
2631 } else {
2632 console_print(id, "=========Rockthevote is now disabled=========");
2633 }
2634 enabled = !enabled;
2635 savesettings(id);
2636 showsettings(id);
2637 return PLUGIN_HANDLED;
2638 }
2639
2640 public dmapfreeze(id, level, cid) {
2641 if (!cmd_access(id, level, cid, 1)) {
2642 return PLUGIN_HANDLED;
2643 }
2644
2645 if (id == 0) {
2646 announce_config_error("dmap_freeze");
2647 return PLUGIN_HANDLED;
2648 }
2649
2650 if (!bIsCstrike) {
2651 console_print(id, "Freeze is always off on non-Counter Strike Servers");
2652 return PLUGIN_HANDLED;
2653 }
2654
2655 new arg[32];
2656 read_argv(1, arg, 31);
2657 if (containi(arg, "off") != -1) {
2658 console_print(id, "=========FREEZE/Weapon Drop at end of round is now disabled==============");
2659 dofreeze = 0;
2660 } else {
2661 if (containi(arg, "on") != -1) {
2662 console_print(id, "=========FREEZE/Weapon Drop at end of round is now enabled==============");
2663 dofreeze = 1;
2664 } else {
2665 console_print(id, "========= USAGE of dmap_freeze: dmap_freeze on|off (this will turn freeze/weapons drop at end of round on/off");
2666 return PLUGIN_HANDLED;
2667 }
2668 }
2669 savesettings(id);
2670 showsettings(id);
2671 return PLUGIN_HANDLED;
2672 }
2673
2674 public dmapcyclemode(id, level, cid) {
2675 if (!cmd_access(id, level, cid, 1)) {
2676 return PLUGIN_HANDLED;
2677 }
2678
2679 if (id == 0) {
2680 announce_config_error("dmap_cyclemode");
2681 return PLUGIN_HANDLED;
2682 }
2683
2684 if (!cycle) {
2685 console_print(id, "========= Cycle mode is now ON, NO VOTE will take place! =========");
2686 } else {
2687 console_print(id, "========= Cycle Mode is already on, no change is made =========");
2688 console_print(id, "========= If you are trying to enable voting, use command dmap_votemode");
2689 return PLUGIN_HANDLED;
2690 }
2691 cycle = 1;
2692 savesettings(id);
2693 showsettings(id);
2694 if (inprogress) {
2695 console_print(id, "========= The Vote In Progress cannot be terminated, unless it hasn't started! =========");
2696 }
2697 return PLUGIN_HANDLED;
2698 }
2699
2700 public dmapvotemode(id, level, cid) {
2701 if (!cmd_access(id, level, cid, 1)) {
2702 return PLUGIN_HANDLED;
2703 }
2704
2705 if (id == 0) {
2706 announce_config_error("dmap_votemode");
2707 return PLUGIN_HANDLED;
2708 }
2709
2710 if (cycle) {
2711 console_print(id, "========= Voting mode is now ON, Votes WILL take place =========");
2712 } else {
2713 console_print(id, "========= Voting mode is already ON, no change is made =========");
2714 console_print(id, "========= If you are trying to disable voting, use command dmap_cyclemode");
2715 return PLUGIN_HANDLED;
2716 }
2717 cycle = 0;
2718 savesettings(id);
2719 showsettings(id);
2720 return PLUGIN_HANDLED;
2721 }
2722
2723 public dmapbanlastmaps(id, level, cid) {
2724 if (!cmd_access(id, level, cid, 2)) {
2725 return PLUGIN_HANDLED;
2726 }
2727
2728 if (id == 0) {
2729 announce_config_error("dmap_banlastmaps");
2730 return PLUGIN_HANDLED;
2731 }
2732
2733 new arg[32];
2734 read_argv(1, arg, 4);
2735 new banamount;
2736 banamount = str_to_num(arg);
2737 if (banamount >= 0 && banamount <= 99) {
2738 if (banamount > ban_last_maps) {
2739 console_print(id, "You have choosen to increase the number of banned maps");
2740 console_print(id, "Changes will not take affect until the nextmap; maps played more than %d maps ago will not be included in the ban", ban_last_maps);
2741 } else {
2742 if (banamount < ban_last_maps) {
2743 console_print(id, "You have choosen to decrease the number of banned maps");
2744 }
2745 }
2746 ban_last_maps = banamount;
2747 savesettings(id);
2748 showsettings(id);
2749 } else {
2750 console_print(id, "You must specify a value between 0 and 99 for dmap_banlastmaps");
2751 console_print(id, "dmap_banlastmaps <n> will ban the last <n> maps from being voted/nominated");
2752 }
2753 return PLUGIN_HANDLED;
2754 }
2755
2756 public dmaphelp(id) {
2757 if (!(get_user_flags(id) & ADMIN_MAP)) {
2758 new myversion[32];
2759 get_cvar_string("Deags_Map_Manage", myversion, 31);
2760 console_print(id, "*****This server uses the plugin Deagles' Map Manager %s *****", myversion);
2761 console_print(id, "");
2762 if (cycle) {
2763 console_print(id, "=================== The plugin is set to cycle mode. No vote will take place =================");
2764 return PLUGIN_HANDLED;
2765 }
2766 console_print(id, "Say ^"vote mapname^" ^"nominate mapname^" or just simply ^"mapname^" to nominate a map");
2767 console_print(id, "");
2768 console_print(id, "Say ^"nominations^" to see a list of maps already nominated.");
2769 console_print(id, "Say ^"listmaps^" for a list of maps you can nominate");
2770 console_print(id, "Number of maps for the vote at the end of this map will be: %d", maps_to_select);
2771 console_print(id, "Players may nominate up to %d maps for the vote (dmap_nominations)", maxnom);
2772 console_print(id, "Players may nominate up to %d **Custom** maps for the vote (dmap_maxcustom)", maxcustnom);
2773 if (enabled) {
2774 console_print(id, "Say ^"rockthevote^" to rockthevote");
2775 console_print(id, "In order to rockthevote the following 3 conditions need to be true:");
2776 console_print(id, "%d percent of players must rockthevote, and at least %d players must rockthevote", floatround(rtvpercent * 100.0), minimum);
2777 console_print(id, "Vote may not be rocked before %d minutes have elapsed on the map", minimumwait);
2778 }
2779 if (containi(mapsurl, "www") != -1 || containi(mapsurl, "http") != -1) {
2780 console_print(id, "You can download Custom maps at %s (dmap_mapsurl)", mapsurl);
2781 }
2782 return PLUGIN_HANDLED;
2783 }
2784 console_print(id, "%L", id, "DMAP_MOTD_LOADING");
2785 client_print(id, print_chat, "%L", id, "DMAP_MOTD_LOADING");
2786 showmotdhelp(id);
2787
2788 return PLUGIN_HANDLED;
2789 }
2790
2791 public gen_maphelphtml() {
2792 new path[64], text[128];
2793 formatex(path, 63, "%s/map_manage_help.htm", custompath);
2794 if (file_exists(path)) {
2795 delete_file(path);
2796 }
2797 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP");
2798 write_file(path, text);
2799 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP2");
2800 write_file(path, text);
2801 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP3");
2802 write_file(path, text);
2803 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP4");
2804 write_file(path, text);
2805 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP5");
2806 write_file(path, text);
2807 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP6");
2808 write_file(path, text);
2809 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP7");
2810 write_file(path, text);
2811 formatex(text, 127, "%L", LANG_SERVER, "DMAP_HELP8");
2812 write_file(path, text);
2813 }
2814
2815 public showmotdhelp(id) {
2816 new header[80];
2817 new myversion[32];
2818 new helpfile[64];
2819 formatex(helpfile, 63, "%s/map_manage_help.htm", custompath);
2820 get_cvar_string("Deags_Map_Manage", myversion, 31);
2821 formatex(header, 79, "%L", id, "DMAP_HELP9", myversion);
2822 if (!file_exists(helpfile)) {
2823 gen_maphelphtml();
2824 }
2825 show_motd(id, helpfile, header);
2826 }
2827
2828 public dmapstatus(id, level, cid) {
2829 if (!cmd_access(id, level, cid, 1)) {
2830 return PLUGIN_HANDLED;
2831 }
2832
2833 showsettings(id);
2834 return PLUGIN_CONTINUE;
2835 }
2836
2837 showsettings(id) {
2838
2839 console_print(id, "-----------------------------------------------------------------------------------------------");
2840 console_print(id, " Status of Deagles' Map Manager Version %s", VERSION);
2841
2842 if (cycle) {
2843 console_print(id, "=================== Mode is Cycle Mode NO vote will take place =================");
2844 console_print(id, "=================== To enable voting use command dmap_votemode ===================");
2845 } else {
2846 console_print(id, "======================= Current Mode is Voting Mode ===============================");
2847 if (quiet == 2) {
2848 console_print(id, "Quiet Mode is set to SILENT. Minimal text messages will be shown, no sound will be played (dmap_quietmode)");
2849 } else {
2850 if (quiet == 1) {
2851 console_print(id, "Quiet Mode is set to NOSOUND. Text messages will be shown, with no sound. (dmap_quietmode)");
2852 } else {
2853 console_print(id, "Quiet Mode is OFF, messages will be shown with sound (dmap_quietmode)");
2854 }
2855 console_print(id, "The time between messages about maps is %d minutes (dmap_messages)", frequency);
2856 }
2857
2858 console_print(id, "The last %d Maps played will not be in the vote (changing this will not start until the Next Map)", ban_last_maps);
2859
2860 if (maps_to_select != mapssave) {
2861 console_print(id, "Number of maps for the vote on this map is: %d (Next Map it will be: %d)", maps_to_select, mapssave);
2862 } else {
2863 console_print(id, "Number of maps for the vote at the end of this map will be: %d (dmap_mapsnum)", maps_to_select);
2864 }
2865
2866 console_print(id, "Players may nominate up to %d maps each for the vote (dmap_nominations)", maxnom);
2867
2868 console_print(id, "Players may nominate up to %d **Custom** maps each for the vote (dmap_maxcustom)", maxcustnom);
2869
2870 if (get_pcvar_num(pEnforceTimelimit)) {
2871 console_print(id, "^"Timeleft^" will be followed to change the maps, not allowing players to finish the round");
2872 console_print(id, "To change this, ask your server admin to set the cvar ^"enforce_timelimit^" to 0");
2873 }
2874
2875 if (enabled == 0) {
2876 if (!get_cvar_num("mp_timelimit")) {
2877 console_print(id, "rockthevote is disabled since mp_timelimit is set to 0");
2878 } else {
2879 console_print(id, "rockthevote is disabled; (dmap_rtvtoggle)");
2880 }
2881 }
2882 console_print(id, "In order to rockthevote the following 3 conditions need to be met:");
2883 console_print(id, "%d percent of players must rockthevote, and at least %d players must rockthevote", floatround(rtvpercent * 100.0), minimum);
2884 console_print(id, "Vote may not be rocked before %d minutes have elapsed on the map (10 is recommended)", minimumwait);
2885 }
2886
2887 console_print(id, "The Freeze/Weapons Drop at the end of the round is %s (dmap_freeze)", dofreeze ? "ENABLED" : "DISABLED");
2888
2889 if (!usestandard) {
2890 console_print(id, "Custom will not be shown by any maps, since file standardmaps.ini is not on the server");
2891 } else {
2892 console_print(id, "The word ^"Custom^" will be shown by custom maps");
2893 }
2894 if (containi(mapsurl, "www") != -1 || containi(mapsurl, "http") != -1) {
2895 console_print(id, "URL to download Custom maps is %s (dmap_mapsurl)", mapsurl);
2896 } else {
2897 console_print(id, "URL to download maps from will not be shown (dmap_mapsurl)");
2898 }
2899 console_print(id, "------------------------------------------------------------------------------------------------");
2900 console_print(id, "Commands: dmap_banlastmaps <n>; dmap_cyclemode; dmap_default; dmap_freeze <ON|OFF>; dmap_mapsnum <n>;");
2901 console_print(id, "Commands: dmap_mapsurl <url>; dmap_maxcustom <n>; dmap_messages <n(minutes)>; dmap_nominate <map>;");
2902 console_print(id, "Commands: dmap_nominations <n>; dmap_quietmode <OFF|NOSOUND|SILENT>; dmap_rockthevote; dmap_rtvpercent <n>;");
2903 console_print(id, "Commands: dmap_rtvplayers <n>; dmap_rtvtoggle; dmap_rtvwait <n>; dmap_status; dmap_votemode;");
2904 console_print(id, "Cvars: amx_emptymap <map>; amx_idletime <n>; amx_staytime <n>; dmap_strict <0|1>;");
2905 console_print(id, "Cvars: emptymap_allowed <0|1>; enforce_timelimit <0|1>; amx_extendmap_max <n>; amx_extendmap_step <n>;");
2906 console_print(id, "Cvars: nominations_allowed <0|1>; weapon_delay <0|1>");
2907 console_print(id, "------------------------- use command dmap_help for more information -----------------------");
2908 }
2909
2910 change_custom_path() {
2911 new temp[64];
2912 formatex(temp, 63, "%s/dmap", custompath);
2913 if (dir_exists(temp)) {
2914 copy(custompath, 48, temp);
2915 }
2916 }
2917
2918 savesettings(myid) {
2919
2920 new settings[64];
2921 formatex(settings, 63, "%s/mapvault.dat", custompath);
2922
2923 if (file_exists(settings)) {
2924 delete_file(settings);
2925 }
2926 new text[32], text2[128], percent, success = 1, usedany = 0;
2927 formatex(text2, 127, ";To use comments simply use ;");
2928 if (!write_file(settings,text2)) {
2929 success = 0;
2930 }
2931 formatex(text2, 127, ";Do not modify these variables; they are used by the Deagles' Map Manager plugin to save settings");
2932
2933 if (!write_file(settings, text2)) {
2934 success = 0;
2935 }
2936 formatex(text2, 127, ";If you delete this file, defaults will be restored.");
2937 if (!write_file(settings, text2)) {
2938 success = 0;
2939 }
2940 formatex(text2, 127, ";If you make an invalid setting, that specific setting will restore to the default");
2941 if (!write_file(settings, text2)) {
2942 success = 0;
2943 }
2944 if (!enabled) {
2945 formatex(text, 31, "d"); //d for disabled
2946 usedany = 1;
2947 if (!write_file(settings, text)) {
2948 success = 0;
2949 }
2950 }
2951 if (quiet != 0) {
2952 if (quiet == 1) {
2953 formatex(text, 31, "q1"); //q1 for NOSOUND
2954 } else {
2955 formatex(text, 31, "q2"); //q2 for SILENT
2956 }
2957 usedany = 1;
2958 if (!write_file(settings, text)) {
2959 success = 0;
2960 }
2961 }
2962 if (!dofreeze || !bIsCstrike) {
2963 formatex(text, 31, "f");
2964 if (!write_file(settings, text)) {
2965 success = 0;
2966 }
2967 }
2968 if (cycle) {
2969 formatex(text, 31, "c"); //c for Cycle mode=on
2970 usedany = 1;
2971 if (!write_file(settings, text)) {
2972 success = 0;
2973 }
2974 }
2975 percent = floatround(rtvpercent * 100.0);
2976 if (percent >= 3 && percent <= 100) {
2977 formatex(text, 31, "r %d", percent);
2978 usedany = 1;
2979 if (!write_file(settings, text)) {
2980 success = 0;
2981 }
2982 }
2983 if (ban_last_maps >= 0 && ban_last_maps <= 100) {
2984 formatex(text, 31, "b %d", ban_last_maps);
2985 usedany = 1;
2986 if (!write_file(settings, text)) {
2987 success = 0;
2988 }
2989 }
2990 if (mapssave >= 2 && mapssave <= 8) {
2991 formatex(text, 31, "m %d", mapssave);
2992 usedany = 1;
2993 if (!write_file(settings, text)) {
2994 success = 0;
2995 }
2996 }
2997 if (maxnom >= 0 && maxnom <= 3) {
2998 formatex(text, 31, "x %d", maxnom);
2999 usedany = 1;
3000 if (!write_file(settings, text)) {
3001 success = 0;
3002 }
3003 }
3004 if (maxcustnom >= 0 && maxcustnom <= mapssave) {
3005 formatex(text, 31, "y %d", maxcustnom);
3006 usedany = 1;
3007 if (!write_file(settings, text)) {
3008 success = 0;
3009 }
3010 }
3011 if (minimum > 0 && minimum <= 32) {
3012 formatex(text, 31, "p %d", minimum);
3013 usedany = 1;
3014 if (!write_file(settings, text)) {
3015 success = 0;
3016 }
3017 }
3018 if (minimumwait >= 0 && minimumwait <= 60) {
3019 formatex(text, 31, "w %d", minimumwait);
3020 usedany = 1;
3021 if (!write_file(settings, text)) {
3022 success = 0;
3023 }
3024 }
3025 if (frequency >= 2 && frequency <= 20) {
3026 formatex(text, 31, "fr %d", frequency);
3027 usedany = 1;
3028 if (!write_file(settings, text)) {
3029 success = 0;
3030 }
3031 }
3032 if (containi(mapsurl, "www") != -1 || containi(mapsurl, "http") != -1) {
3033 formatex(text2, 75, "u %s", mapsurl);
3034 usedany = 1;
3035 if (!write_file(settings, text2)) {
3036 success = 0;
3037 }
3038 }
3039 if (usedany) {
3040 if (myid >= 0) {
3041 if (success) {
3042 console_print(myid, "********* Settings saved successfully *********");
3043 } else {
3044 console_print(myid, "Unable to write to file %s", settings);
3045 }
3046 }
3047 if (!success) {
3048 #if defined DEDICATED_LOG_ENABLED
3049 log_to_file(logfilename, "Unable to write to file %s", settings);
3050 #endif
3051 return 0;
3052 }
3053 } else {
3054 if (myid >= 0) {
3055 console_print(myid, "Variables not valid, not saving to %s", settings);
3056 }
3057 #if defined DEDICATED_LOG_ENABLED
3058 log_to_file(logfilename, "Warning: Variables not valid, not saving to %s", settings);
3059 #endif
3060 return 0;
3061 }
3062 return 1;
3063 }
3064
3065 public dmapmapsurl(id, level, cid) {
3066 if (!cmd_access(id, level, cid, 2)) {
3067 return PLUGIN_HANDLED;
3068 }
3069
3070 if (id == 0) {
3071 announce_config_error("dmap_mapsurl");
3072 return PLUGIN_HANDLED;
3073 }
3074
3075 new arg[64];
3076 read_argv(1, arg, 63);
3077 if (equali(arg, "http")) {
3078 console_print(id, "You must specify a url that contains www or http (do not use any colons)(use ^"none^" to disable)");
3079 return PLUGIN_HANDLED;
3080 }
3081 if (containi(arg, "www") != -1 || containi(arg, "http") != -1) {
3082 console_print(id, "You have changed the mapsurl to %s", arg);
3083 mapsurl = arg;
3084 savesettings(id);
3085 showsettings(id);
3086 } else {
3087 if (containi(arg, "none") != -1) {
3088 console_print(id, "You have choosen to disable your mapsurl, none will be used");
3089 mapsurl = "";
3090 savesettings(id);
3091 showsettings(id);
3092 } else {
3093 console_print(id, "You must specify a url that contains www or http (do not use any colons)(use ^"none^" to disable)");
3094 }
3095 }
3096 return PLUGIN_HANDLED;
3097 }
3098
3099 public dmapdefaults(id, level, cid) {
3100 if (!cmd_access(id, level, cid, 1)) {
3101 return PLUGIN_HANDLED;
3102 }
3103
3104 set_defaults(id);
3105 return PLUGIN_HANDLED;
3106 }
3107
3108 public event_RoundStart() {
3109 isbetween = 0;
3110 isbuytime = 1;
3111 set_task(10.0, "now_safe_to_vote");
3112
3113 currounds++;
3114 new players[32], playernum;
3115 get_players(players, playernum, "c");
3116 curplayers += playernum;
3117 }
3118
3119 public event_RoundEnd() {
3120 isbetween = 1;
3121 }
3122
3123 public now_safe_to_vote() {
3124 //client_print(0, print_chat, "Now it is safe to vote");
3125 isbuytime = 0;
3126 }
3127
3128 public listmaps_override(id) {
3129 //TODO: if some cvar = 0 then return
3130 list_maps(id);
3131 return PLUGIN_HANDLED;
3132 }
3133
3134 public votemap_override(id) {
3135 console_print(id, "%L", id, "DMAP_COMMAND_DISABLED");
3136 return PLUGIN_HANDLED;
3137 }
3138
3139 public say_currentmap(id) {
3140 new mapname[32];
3141 get_mapname(mapname, 31);
3142 client_print(id, print_chat, "%L", id, "DMAP_CURRENT_MAP", mapname);
3143 return PLUGIN_HANDLED;
3144 }
3145
3146 public say_recentmaps(id) {
3147 if (bannedsofar <= 1) {
3148 client_print(id, print_chat, "%L", id, "DMAP_RECENT_NONE");
3149 return PLUGIN_HANDLED;
3150 }
3151
3152 new sMaps[192];
3153 for (new i=1; i < bannedsofar; i++) { // Start at 1 to skip current map
3154 if (i == 1) {
3155 formatex(sMaps, 31, "%s", lastmaps[i]);
3156 } else {
3157 format(sMaps, 191, "%s, %s", sMaps, lastmaps[i]);
3158 }
3159 }
3160 client_print(id, print_chat, "%L", id, "DMAP_RECENT_MAPS", sMaps);
3161
3162 return PLUGIN_HANDLED;
3163 }
3164
3165
3166 public check_conflict() {
3167 new sDV[8], iDV, bRepeat;
3168
3169 //repeat error over and over..
3170 if (is_plugin_loaded("Nextmap Chooser") > -1) {
3171 bRepeat = true;
3172 announce_conflict("mapchooser.amxx");
3173 }
3174 if (is_plugin_loaded("NextMap") > -1) {
3175 bRepeat = true;
3176 announce_conflict("nextmap.amxx");
3177 }
3178 if (is_plugin_loaded("Galileo") > -1) {
3179 bRepeat = true;
3180 announce_conflict("galileo.amxx");
3181 }
3182 if (is_plugin_loaded("Crab'sMapManager") > -1) {
3183 bRepeat = true;
3184 announce_conflict("crabmapmanager.amxx");
3185 }
3186
3187 // Using -2 for the language key seems to default to en, even with amx_mldebug set.
3188 // This is a hack, but it works.
3189 // ML_NOTFOUND will return 0 for version, so additional error handling isn't needed.
3190 formatex(sDV, 7, "%L", -2, "DV");
3191 iDV = str_to_num(sDV);
3192
3193 // Allow for 9 newer version of dictionary file before plugin recompile is needed.
3194 if ((iDV < DMAP_EXPECTED_DV) || (iDV > (DMAP_EXPECTED_DV + 9))) {
3195 bRepeat = true;
3196 console_print(0, "[DMM] INVALID DICTIONARY FILE! Current version: %d. Expected version: %d to %d.", iDV, DMAP_EXPECTED_DV, DMAP_EXPECTED_DV + 9);
3197 client_print(0, print_chat, "[DMM] INVALID DICTIONARY FILE! Current version: %d. Expected version: %d to %d.", iDV, DMAP_EXPECTED_DV, DMAP_EXPECTED_DV + 9);
3198 }
3199
3200 if (bRepeat) {
3201 set_task(5.0, "check_conflict", DMAP_TASKID_CONFLICT);
3202 }
3203 return PLUGIN_HANDLED;
3204 }
3205
3206 announce_conflict(sPlugin[]) {
3207 console_print(0, "[DMM] CONFLICT DETECTED! Disable %s in plugins.ini.", sPlugin);
3208 client_print(0, print_chat, "[DMM] CONFLICT DETECTED! Disable %s in plugins.ini.", sPlugin);
3209 }
3210
3211 announce_config_error(sCommand[]) {
3212 console_print(0, "[DMM] ERROR: The %s command does not belong in any config file.", sCommand);
3213 console_print(0, "[DMM] If you really want to run this command, do it from a client console.");
3214 }
3215
3216 public say_ff(id) {
3217 client_print(id, print_chat, "%L: %L", LANG_PLAYER, "DMAP_FRIEND_FIRE", LANG_PLAYER, get_cvar_num("mp_friendlyfire") ? "ON" : "OFF");
3218 return PLUGIN_CONTINUE;
3219 }
3220
3221
3222 public plugin_init() {
3223
3224 register_plugin(PLUGIN, VERSION, AUTHOR);
3225 register_dictionary("common.txt");
3226 register_dictionary("deagsmapmanager.txt");
3227
3228 get_configsdir(custompath, 49);
3229 change_custom_path();
3230
3231 check_conflict(); // Check for problems immediately
3232
3233 register_clcmd("say", "HandleSay", 0, "Say: vote mapname, nominate mapname, or just mapname to nominate a map, say: nominations");
3234 register_clcmd("say rockthevote", "rock_the_vote", 0, "Rocks the Vote");
3235 register_clcmd("say rtv", "rock_the_vote", 0, "Rocks the Vote");
3236 register_clcmd("say ff", "say_ff", 0, "Displays friendly fire status");
3237 register_clcmd("say listmaps", "list_maps", 0, "Lists all maps in the console");
3238 register_clcmd("say nextmap", "say_nextmap", 0, "Shows next map information to players");
3239 register_clcmd("say currentmap", "say_currentmap", 0, "Shows name of the current map");
3240 register_clcmd("say recentmaps", "say_recentmaps", 0, "Shows names of recently played maps");
3241 register_clcmd("votemap", "votemap_override", 0, "Override for votemap command in GoldSrc engine");
3242 register_concmd("dmap_help", "dmaphelp", 0, "Shows on-screen help information about Map Plugin");
3243 register_concmd("dmap_status", "dmapstatus", ADMIN_DMAP, "Shows settings/status/help of the map management variables");
3244 register_concmd("dmap_votemode", "dmapvotemode", ADMIN_SUPER_DMAP, "Enables Voting (This is default mode)");
3245 register_concmd("dmap_cyclemode", "dmapcyclemode", ADMIN_SUPER_DMAP, "Disables Voting (To restore voting use dmap_votemode)");
3246 register_concmd("dmap_banlastmaps", "dmapbanlastmaps", ADMIN_SUPER_DMAP, "Bans the last <n> maps played from being voted (0-99)");
3247 register_concmd("dmap_quietmode", "dmapquietmode", ADMIN_SUPER_DMAP, "Usage: <OFF|NOSOUND|SILENT>");
3248 register_concmd("dmap_freeze", "dmapfreeze", ADMIN_SUPER_DMAP, "Toggles Freeze/Drop at end of round ON|off");
3249 register_concmd("dmap_messages", "dmapmessages", ADMIN_SUPER_DMAP, "Sets the time interval in minutes between messages");
3250 register_concmd("dmap_rtvtoggle", "dmaprtvtoggle", ADMIN_SUPER_DMAP, "Toggles on|off Ability of players to use rockthevote");
3251 register_concmd("dmap_rockthevote", "admin_rockit", ADMIN_DMAP, "Allows admins to force a vote");
3252 register_concmd("amx_rockthevote", "admin_rockit", ADMIN_DMAP, "Allows admins to force a vote");
3253 register_concmd("amx_rtv", "admin_rockit", ADMIN_DMAP, "Allows admins to force a vote");
3254 register_concmd("dmap_rtvpercent", "dmaprtvpercent", ADMIN_SUPER_DMAP, "Set the percent (3-100) of players for a rtv");
3255 register_concmd("dmap_rtvplayers", "dmaprtvplayers", ADMIN_SUPER_DMAP, "Sets the minimum number of players needed to rockthevote");
3256 register_concmd("dmap_rtvwait", "dmaprtvwait", ADMIN_SUPER_DMAP, "Sets the minimum time before rockthevote can occur (0-60)");
3257 register_concmd("dmap_default", "dmapdefaults", ADMIN_SUPER_DMAP, "Will restore settings to default");
3258 register_concmd("dmap_mapsurl", "dmapmapsurl", ADMIN_SUPER_DMAP, "Specify what website to get custom maps from");
3259 register_concmd("dmap_mapsnum", "dmapmapsnum", ADMIN_SUPER_DMAP, "Set number of maps in vote (will not take effect until next map");
3260 register_concmd("dmap_nominations", "dmapnominations", ADMIN_SUPER_DMAP, "Set maximum number of nominations for each person");
3261 register_concmd("dmap_maxcustom", "dmapmaxcustom", ADMIN_SUPER_DMAP, "Set maximum number of custom nominations that may be made");
3262 register_concmd("dmap_cancelvote", "dmapcancelvote", ADMIN_DMAP, "Cancels the rocked vote");
3263 register_concmd("dmap_nominate", "dmapnominate", ADMIN_DMAP, "<mapname> - Force nomination of a map by an admin");
3264 register_concmd("listmaps", "listmaps_override", 0, "Lists all maps in the console");
3265
3266 register_logevent("event_RoundStart", 2, "0=World triggered", "1=Round_Start");
3267 register_logevent("event_RoundEnd", 2, "0=World triggered", "1=Round_End");
3268
3269 register_event("30", "changeMap", "a");
3270 #if defined DEDICATED_LOG_ENABLED
3271 get_time("dmaplog%m%d.log", logfilename, 255);
3272 #endif
3273
3274 pDmapStrict = register_cvar("dmap_strict", "0");
3275 pEmptyMap = register_cvar("amx_emptymap", "de_dust2");
3276 pEmptymapAllowed = register_cvar("emptymap_allowed", "0");
3277 pEnforceTimelimit = register_cvar("enforce_timelimit", "0");
3278 pExtendmapMax = register_cvar("amx_extendmap_max", "90");
3279 pExtendmapStep = register_cvar("amx_extendmap_step", "15");
3280 pIdleTime = register_cvar("amx_idletime", "5");
3281 pNominationsAllowed = register_cvar("nominations_allowed", "1");
3282 pShowActivity = register_cvar("amx_show_activity", "2");
3283 register_cvar("amx_staytime", "300"); // No pointer; only used once
3284 pWeaponDelay = register_cvar("weapon_delay", "1");
3285
3286 staytime = get_cvar_num("amx_staytime");
3287
3288 bIsCstrike = (cstrike_running() == 1);
3289 nmaps_num = num_nmapsfill = 0;
3290
3291 register_cvar("Deags_Map_Manage", VERSION, FCVAR_SERVER|FCVAR_SPONLY);
3292 if (bIsCstrike) {
3293 register_event("TeamScore", "team_score", "a");
3294 dofreeze = 1;
3295 }
3296 rtvpercent = 0.6;
3297 ban_last_maps = 4;
3298 atstart = enabled = minimum = 1;
3299 quiet = cycle = isend = 0;
3300 mapsurl = "";
3301 set_task(3.0, "ban_some_maps"); //reads from lastmapsplayed.txt and stores into global array
3302 //set_task(8.0, "write_lastmaps"); //deletes and writes to lastmapsplayed.txt
3303 //set_task(2.0, "get_listing"); //loads mapcycle / allmaps.txt
3304 set_task(14.0, "load_defaultmaps"); //loads standardmaps.ini
3305 //set_task(17.0, "load_maps"); //loads mapchoice.ini
3306 set_task(15.0, "askfornextmap", DMAP_TASKID_ASK_FOR_NEXT, "", 0, "b");
3307 set_task(5.0, "loopmessages", DMAP_TASKID_LOOP_MESSAGES, "", 0, "b");
3308 set_task(34.0, "gen_maphelphtml"); //Writes to help file, which is read every time that dmap_help is called by ANY player
3309 oldtimelimit = get_cvar_float("mp_timelimit");
3310 get_localinfo("amx_lastmap", last_map, 31);
3311 set_localinfo("amx_lastmap", "");
3312 set_task(1.0, "timer", DMAP_TASKID_TIMER, "curtime", 0, "b", 1);
3313 maps_to_select = mapssave = 5;
3314 new temparray[64];
3315 formatex(temparray, 63, "%s/mapvault.dat", custompath);
3316 if (!loadsettings(temparray)) {
3317 set_defaults(-1);
3318 }
3319 atstart = 0;
3320 register_menucmd(register_menuid(DMAP_MENU_TITLE), (-1 ^ (-1 << (maps_to_select + 2))), "vote_count");
3321 }

Contact webmaster
ViewVC Help
Powered by ViewVC RSS 2.0 feed