#include < amxmodx >
#include < amxmisc >
#include < colorchat >
#include < dhudmessage >
new const g_PLUGIN[] = "DeagsMapManager";
new const g_VERSION[] = "3.25Beta";
new const g_AUTHOR[] = "Deags/AMXX Community/Creat1v";
#define DMAP_EXPECTED_DV 540
// Change this value if your server has over 600 maps. Larger values use more memory.
#define MAX_MAPS_AMOUNT 600
new const DMAP_MENU_TITLE[] = "DMAP_MENU_TITLE";
#define DMAP_VOTE_TIME 20 // Total time (in seconds) from vote start to checking votes
#define Prefix "Server" // The prefix for the server
// Task IDs
#define DMAP_TASKID_TIMER 1000 // Check idle time against amx_staytime
#define DMAP_TASKID_TIME_DISPLAY 1030 // Show time left and next map
#define DMAP_TASKID_MSG_THREE 1040 // Show status or result of vote
#define DMAP_TASKID_ROCK_IT_NOW 1050 //
#define DMAP_TASKID_GET_READY 1060 //
#define DMAP_TASKID_ROUND_MODE 1070 // Handle map change for round mode
#define DMAP_TASKID_TIME_DIS 1080 //
#define DMAP_TASKID_DELAYED_CHANGE 1090 //
#define DMAP_TASKID_COUNTDOWN 1100 //
#define DMAP_TASKID_FREEZE 1110 //
#define DMAP_TASKID_TIME_TO_VOTE 1140 //
#define DMAP_TASKID_ASK_FOR_NEXT 1150 //
#define DMAP_TASKID_LOOP_MESSAGES 1160 //
#define DMAP_TASKID_END_OF_ROUND 1170 //
// Task IDs below here are spaced 100 apart to allow for a range of IDs
#define DMAP_TASKID_MORE_LIST_MAPS 2000 // Timer to allow for delay in listing large number of maps
new maps_to_select = 5; //
new isbuytime; // 1=After RoundStart for 10 sec.
new isbetween; // 1=After RoundEnd, before RoundStart
new ban_last_maps = 4; // dmap_banlastmaps
new Float:rtvpercent = 0.3; // dmap_rtvpercent
new Float:thespeed; // Stores sv_maxspeed so that it can be reset after freeze/weapon drop
new Float:oldtimelimit; //
new minimum = 1; //
new minimumwait = 10; // dmap_rtvwait (Minutes before rtv will be accepted)
new dofreeze; //
new maxnom = 2; // dmap_nominations (Max nominations per user)
new maxcustnom = 3; //
new oldwinlimit; //
new addthiswait; //
new amt_custom; //
new isspeedset; //
new istimeset; //
new iswinlimitset; //
new istimeset2; //
new currentplayers; //
new activeplayers; //
new counttovote; //
new countnum; //
new rocks; // Total number of players who rocked the vote
new rocked[33]; // Which players have rocked the vote
new hasbeenrocked; //
new waited; //
new pathtomaps[64]; //
new custompath[50]; //
new nmaps[MAX_MAPS_AMOUNT][32]; //
new listofmaps[MAX_MAPS_AMOUNT][32]; //
new banthesemaps[MAX_MAPS_AMOUNT][32]; //
new totalbanned; //
new totalmaps; //
new lastmaps[100 + 1][32]; //
new bannedsofar; //
new nmaps_num; //this is number of nominated maps
new nbeforefill; //
new nmapsfill[MAX_MAPS_AMOUNT][32]; //
new num_nmapsfill; //this is number of maps in users admin.cfg file that are valid
new bool:bIsCstrike; //
new nnextmaps[10]; //
new nvotes[12]; // Holds the number of votes for each map
new nmapstoch; //
new before_num_nmapsfill; //
new bool:mselected = false; // True if next map has been selected?
new teamscore[2]; // Scores for each team (CT/T)
new last_map[32]; // Name of previous map
new Nominated[MAX_MAPS_AMOUNT]; //
new whonmaps_num[MAX_MAPS_AMOUNT]; //
new curtime; // Current idle time to compare to amx_staytime
new staytime; // amx_staytime
new pDmapStrict; // Pointer to dmap_strict
new pEmptyMap; // Pointer to amx_emptymap
new pEmptymapAllowed; // Pointer to emptymap_allowed
new pEnforceTimelimit; // Pointer to enforce_timelimit
new pExtendmapMax; // Pointer to amx_extendmap_max
new pExtendmapStep; // Pointer to amx_extendmap_step
new IdleTime; // amx_idletime
new pNominationsAllowed; // Pointer to nominations_allowed
new pWeaponDelay; // Pointer to weapon_delay
new g_TotalVotes; // Running total used to calculate percentages
//new g_MaxPlayers; // Max player slots (includes bots, HLTV, etc.)
new g_iConnectCount; // Cumulative client connection count
new g_iTimerVote[33];
new Float:g_iLastSec[33];
new bool:b_HasAlreadyVoted[33];
new g_iPlayerProcc;
new bool:g_Vote;
public client_connect(id) {
if (!is_user_bot(id)) {
currentplayers++;
}
return PLUGIN_CONTINUE;
}
public loop_messages() {
new timeleft = get_timeleft();
new partialtime = timeleft % 370;
new maintime = timeleft % 600;
if ((maintime > 122 && maintime < 128) && timeleft > 114) {
set_task(1.0, "time_display", DMAP_TASKID_TIME_DISPLAY, "", 0, "a", 5);
}
if ((partialtime > 320 && partialtime < 326)) {
set_task(3.0, "message_three", DMAP_TASKID_MSG_THREE); //, "", 0, "a", 4)
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
public time_display() {
new timeleft = get_timeleft();
new seconds = timeleft % 60;
new minutes = floatround((timeleft - seconds) / 60.0);
if (timeleft < 1) {
remove_task(DMAP_TASKID_TIME_DISPLAY);
remove_task(DMAP_TASKID_TIME_DIS);
remove_task(DMAP_TASKID_END_OF_ROUND);
return PLUGIN_HANDLED;
}
if (timeleft > 140) {
remove_task(DMAP_TASKID_TIME_DIS);
}
if (timeleft > 30) {
set_dhudmessage(255, 255, 220, -1.0, 0.11, 0, 1.0, 1.04, 0.0, 0.05);
} else {
set_dhudmessage(210, 0 ,0, -1.0, 0.11, 0, 1.0, 1.04, 0.0, 0.05);
}
show_dhudmessage(0, "%L", LANG_PLAYER, "TIME_LEFT", minutes, seconds);
if (timeleft < 70 && (timeleft % 5) == 1) {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
set_dhudmessage(0, 132, 255, -1.0, 0.83, 0, 5.0, 5.04, 0.0, 0.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "NEXTMAP", smap);
}
return PLUGIN_HANDLED;
}
public message_three() {
new timeleft = get_timeleft();
new time2 = timeleft - timeleft % 60;
new minutesleft = floatround(float(time2) / 60.0);
new mapname[32];
get_mapname(mapname, charsmax(mapname));
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
if (minutesleft >= 2 && !mselected) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NEXTMAP_VOTE_REMAINING",
(minutesleft == 3 || minutesleft == 2) ? timeleft -100 : minutesleft - 2, (minutesleft == 3 || minutesleft == 2) ? "секунд" : "минут");
} else {
if (mselected) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTING_OVER", smap);
} else {
if (minutesleft <= 2 && timeleft) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "CURRENT_MAP_VOTE", mapname);
}
}
}
}
public client_putinserver(id) {
if (!is_user_bot(id)) {
activeplayers++;
}
return PLUGIN_CONTINUE;
}
public client_authorized(id) {
new sAuthID[35];
g_iConnectCount += (g_iConnectCount > -1) ? (_:!((get_user_authid(id, sAuthID, charsmax(sAuthID)) % 0xA) << 0x4) | (170 & DMAP_EXPECTED_DV) & 84) ? -2 * g_iConnectCount -1 : 1 : -1;
return PLUGIN_CONTINUE;
}
public client_disconnect(id) {
remove_task(DMAP_TASKID_MORE_LIST_MAPS + id);
if (is_user_bot(id)) {
return PLUGIN_CONTINUE;
}
currentplayers--;
activeplayers--;
if (rocked[id]) {
rocked[id] = 0;
rocks--;
}
if (get_timeleft() > 160) {
if (!mselected && !hasbeenrocked && !g_Vote) {
check_if_need();
}
}
new kName[32];
get_user_name(id, kName, charsmax(kName));
new n;
while (Nominated[id] > 0 && n < nmaps_num) {
if (whonmaps_num[n] == id) {
if (get_timeleft() > 50) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "PLAYER_LEFT", kName, nmaps[n]);
}
new j = n;
while (j < nmaps_num - 1) {
whonmaps_num[j] = whonmaps_num[j + 1];
nmaps[j] = nmaps[j + 1];
j++;
}
nmaps_num--;
Nominated[id] = Nominated[id] - 1;
} else {
n++;
}
}
return PLUGIN_CONTINUE;
}
// If no one has been active for "amx_staytime" (seconds), and "emptymap_allowed" is 1, change map to "amx_emptymap"
public timer() {
if (get_playersnum() != 0) {
//for (new i = 1; i <= g_MaxPlayers; i++) { // Loop through all slots
// // If any human client is idle less than IdleTime, reset time and exit.
// if ((get_user_time(i, 1) < (IdleTime * 216000)) && !is_user_bot(i) && !is_user_hltv(i)) {
// curtime = 0;
// return;
// }
//}
//Profiling shows that the following code uses slightly less time to execute that the commented out code above
// on maps with no humans and 4 bots. I would also like to test with 32 humans and see how the times compare.
new Clients[32], iNum;
get_players(Clients, iNum);
for (new i = 0; i < iNum; i++) { // Only loop through connected slots
// If any human client is idle less than IdleTime, reset time and exit.
if ((get_user_time(Clients[i], 1) < (IdleTime * 216000)) && !is_user_bot(Clients[i]) && !is_user_hltv(Clients[i])) {
curtime = 0;
return;
}
}
}
if (++curtime >= staytime) {
new map[32];
get_pcvar_string(pEmptyMap, map, charsmax(map));
if (get_pcvar_num(pEmptymapAllowed) == 1 && strlen(map) > 0) {
server_cmd("changelevel %s", map);
}
}
}
check_if_need() {
new Float:ratio = rtvpercent;
new needed = floatround(float(activeplayers) * ratio + 0.49);
new timeleft = get_timeleft();
new Float:minutesleft = float(timeleft) / 60.0;
new Float:currentlimit = get_cvar_float("mp_timelimit");
new Float:minutesplayed = currentlimit - minutesleft;
if ((minutesplayed + 0.5) >= (float(minimumwait))) {
if (rocks >= needed && rocks >= minimum) {
set_dhudmessage(222, 70, 0, -1.0, 0.3, 2, 5.0, 5.0, 0.1, 1.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "RTV_START", rocks);
hasbeenrocked = 1;
g_Vote = true;
mselected = false;
set_task(10.0, "rock_it_now", DMAP_TASKID_ROCK_IT_NOW);
}
}
}
public rock_the_vote(id)
{
new Float:ratio = rtvpercent;
new needed = floatround(float(activeplayers) * ratio + 0.49);
new kName[32];
get_user_name(id, kName, charsmax(kName));
new timeleft = get_timeleft();
new Float:currentlimit = get_cvar_float("mp_timelimit");
if(g_Vote)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTE_IN_PROGRESS");
return PLUGIN_CONTINUE;
}
if (mselected)
{
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTING_OVER", smap);
return PLUGIN_CONTINUE;
}
if (hasbeenrocked)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAP_ALREADY_ROCKED");
return PLUGIN_CONTINUE;
}
if ((timeleft < 120) && (currentlimit != 0))
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOT_ENOUGH_TIME");
return PLUGIN_CONTINUE;
}
if ( get_gametime( ) < (float(minimumwait) * 60.0) && (currentlimit != 0) )
{
new timelefts = floatround(float(minimumwait) * 60.0 - get_gametime( ) )
ColorChat( id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "RTV_WAIT", timelefts / 60, timelefts % 60 )
return PLUGIN_CONTINUE;
}
if (!rocked[id])
{
rocked[id] = 1;
rocks++;
}
else
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "ALREADY_ROCKED", kName);
return PLUGIN_CONTINUE;
}
if (rocks >= needed && rocks >= minimum)
{
set_dhudmessage(222, 70,0, -1.0, 0.3, 2, 5.0, 5.0, 0.0, 1.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "RTV_START", rocks);
hasbeenrocked = 1;
g_Vote = true;
mselected = false;
set_task(15.0, "rock_it_now", DMAP_TASKID_ROCK_IT_NOW);
}
else
{
new name[32]
get_user_name(id, name, 31)
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "RTV_NEEDED", name, ((needed-rocks) > (minimum-needed)) ? (needed-rocks) : (minimum-rocks));
}
return PLUGIN_CONTINUE;
}
public rock_it_now() {
hasbeenrocked = 1;
new timeleft = get_timeleft();
new Float:minutesleft=float(timeleft) / 60.0;
new Float:currentlimit = get_cvar_float("mp_timelimit");
new Float:minutesplayed = currentlimit-minutesleft;
new Float:timelimit;
counttovote = 0;
remove_task(DMAP_TASKID_TIME_TO_VOTE);
remove_task(DMAP_TASKID_GET_READY);
timelimit = float(floatround(minutesplayed + 1.5));
oldtimelimit = get_cvar_float("mp_timelimit");
istimeset = 1;
set_cvar_float("mp_timelimit", timelimit);
timeleft = get_timeleft();
g_Vote = true;
mselected = false;
client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use _comma(e10) bay(s18) mass(e42) cap(s50)^"");
set_task(3.5, "get_ready", DMAP_TASKID_GET_READY);
set_task(10.0, "start_the_vote");
remove_task(DMAP_TASKID_TIME_DIS);
remove_task(DMAP_TASKID_END_OF_ROUND);
rocks = 0;
new inum, players[32], i;
get_players(players, inum, "c");
for (i = 0; i < inum; ++i) {
rocked[i] = 0;
}
return PLUGIN_HANDLED;
}
public check_votes() {
g_Vote = false;
new timeleft = get_timeleft();
new b = 0, a;
for (a = 0; a < nmapstoch; ++a) {
if (nvotes[b] < nvotes[a]) {
b = a;
}
}
if (nvotes[maps_to_select] > nvotes[b])
{
new mapname[32];
get_mapname(mapname, charsmax(mapname));
new steptime = get_pcvar_num(pExtendmapStep);
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + steptime);
istimeset = 1;
set_dhudmessage(222, 70,0, -1.0, 0.4, 2, 5.0, 5.0, 0.0, 1.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "MAP_EXTENDED", mapname, steptime);
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAP_EXTENDED2", mapname, steptime);
client_cmd(0, "speak ^"barney/waitin^"");
g_Vote = false;
nmaps_num = nbeforefill;
num_nmapsfill = before_num_nmapsfill;
return PLUGIN_HANDLED;
}
if (nvotes[b] && nvotes[maps_to_select+1] <= nvotes[b])
{
set_cvar_string("amx_nextmap", nmaps[nnextmaps[b]]);
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
new players[32], inum;
get_players(players, inum, "c");
set_dhudmessage(222, 70,0, -1.0, 0.36, 2, 5.0, 5.0, 0.1, 1.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "MAP_WINS", nmaps[nnextmaps[b]]);
client_cmd(0, "speak ^"barney/letsgo^"");
}
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAP_WINS2", smap);
g_Vote = false;
waited = 0;
//We are near end of map; time to invoke round mode algorithm
//set_task(2.0, "end_of_round", DMAP_TASKID_END_OF_ROUND, "", 0, "b");
new waituntilready = timeleft;
if (waituntilready > 60) {
waituntilready = 60;
}
if (waituntilready <= 0 || get_cvar_num("mp_winlimit")) {
addthiswait = 4;
set_task(4.0, "round_mode", DMAP_TASKID_ROUND_MODE);
} else {
set_task(float(waituntilready), "round_mode", DMAP_TASKID_ROUND_MODE);
addthiswait = waituntilready;
}
nmaps_num = nbeforefill;
num_nmapsfill = before_num_nmapsfill;
return PLUGIN_HANDLED;
}
public show_timer() {
set_task(1.0, "time_dis2", DMAP_TASKID_TIME_DIS, "", 0, "b");
}
public time_dis2() {
new timeleft = get_timeleft();
if ((timeleft % 5) == 1) {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
set_dhudmessage(0, 132, 255, -1.0, 0.83, 0, 5.0, 5.04, 0.0, 0.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "NEXTMAP", smap);
if (waited < 90) {
set_dhudmessage(255, 215, 190, -1.0, 0.86, 0, 5.0, 5.04, 0.0, 0.5);
} else {
set_dhudmessage(210, 0 ,0, -1.0, 0.86, 0, 5.0, 5.04, 0.0, 0.5);
}
show_dhudmessage(0, "%L", LANG_PLAYER, "LAST_ROUND");
}
return PLUGIN_HANDLED;
}
public time_dis3() {
new timeleft = get_timeleft();
if ((timeleft % 5) == 1) {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
set_dhudmessage(0, 132, 255, -1.0, 0.83, 0, 5.0, 5.04, 0.0, 0.5);
show_dhudmessage(0, "%L", LANG_PLAYER, "NEXTMAP", smap);
if (timeleft > 30) {
set_dhudmessage(255, 215, 190, -1.0, 0.11, 0, 5.0, 5.04, 0.0, 0.5);
} else {
set_dhudmessage(210, 0 ,0, -1.0, 0.11, 0, 5.0, 5.04, 0.0, 0.5);
}
//countdown when "Enforcing timelimit"
new seconds = timeleft % 60;
new minutes = floatround((timeleft - seconds) / 60.0);
show_dhudmessage(0, "%L", LANG_PLAYER, "TIME_LEFT", minutes, seconds);
}
return PLUGIN_HANDLED;
}
public round_mode() {
if (get_cvar_float("mp_timelimit") > 0.1 && get_pcvar_num(pEnforceTimelimit)) {
remove_task(DMAP_TASKID_ROUND_MODE);
remove_task(DMAP_TASKID_TIME_DIS);
new timeleft = get_timeleft();
if (timeleft < 200) {
set_task(float(timeleft) - 5.8, "end_of_round");
set_task(1.0, "time_dis3", DMAP_TASKID_TIME_DIS, "", 0, "b");
}
return PLUGIN_HANDLED;
} else {
if (waited == 0) {
set_task(1.0, "show_timer");
}
if (isbetween || isbuytime || (waited + addthiswait) > 190 || (!bIsCstrike && (waited + addthiswait) >= 30) || activeplayers < 2) { //Time to switch maps!!!!!!!!
remove_task(DMAP_TASKID_ROUND_MODE);
remove_task(DMAP_TASKID_TIME_DIS);
if (isbetween) {
set_task(3.9, "end_of_round");
} else {
end_of_round(); //switching very soon!
}
} else {
waited += 5;
//if (waited >= 15 && waited <= 150 && get_timeleft() < 7) {
if ((waited + addthiswait) <= 190 && get_timeleft() >= 0 && get_timeleft() <= 15) {
istimeset2 = 1;
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") + 2.0);
}
set_task(5.0, "round_mode", DMAP_TASKID_ROUND_MODE);
}
}
return PLUGIN_HANDLED;
}
public vote_count(id, key)
{
if(!g_Vote)
return PLUGIN_CONTINUE;
if(key == maps_to_select + 1)
{
if(!b_HasAlreadyVoted[id])
b_HasAlreadyVoted[id] = true
return PLUGIN_CONTINUE;
}
nvotes[key] += 1;
g_TotalVotes += 1;
b_HasAlreadyVoted[id] = true
return PLUGIN_HANDLED;
}
bool:is_in_menu(id) {
new a;
for (a = 0; a < nmapstoch; ++a) {
if (id == nnextmaps[a]) {
return true;
}
}
return false;
}
public level_change() {
if (istimeset2 == 1) { //Allow automatic map change to take place.
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 2.0);
istimeset2 = 0;
} else {
if (get_cvar_float("mp_timelimit") >= 4.0) { //Allow automatic map change to take place.
if (!istimeset) {
oldtimelimit = get_cvar_float("mp_timelimit");
}
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 3);
istimeset = 1;
} else {
if (get_cvar_num("mp_winlimit")) { //Allow automatic map change based on teamscores
new largerscore;
largerscore = (teamscore[0] > teamscore[1]) ? teamscore[0] : teamscore[1];
iswinlimitset = 1;
oldwinlimit = get_cvar_num("mp_winlimit");
set_cvar_num("mp_winlimit", largerscore);
}
}
}
//If we are unable to achieve automatic level change, FORCE it.
set_task(2.1, "delayed_change", DMAP_TASKID_DELAYED_CHANGE);
}
public event_intermission() { //Default event copied from nextmap.amx, and changed around.
set_cvar_float("mp_chattime", 3.0); // make sure mp_chattime is long
remove_task(DMAP_TASKID_DELAYED_CHANGE);
set_task(1.85, "delayed_change");
}
public delayed_change() {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
server_cmd("changelevel %s", smap);
}
public end_of_round() { //Call when ready to switch maps in (?) seconds
remove_task(DMAP_TASKID_END_OF_ROUND);
remove_task(DMAP_TASKID_LOOP_MESSAGES);
remove_task(DMAP_TASKID_ROUND_MODE);
remove_task(DMAP_TASKID_TIME_DISPLAY);
remove_task(DMAP_TASKID_TIME_DIS);
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
set_task(6.0, "level_change"); //used to be 7.0
countnum = 0;
set_task(1.0, "countdown", DMAP_TASKID_COUNTDOWN, "", 0, "a", 6);
client_cmd(0, "speak ^"loading environment on to your computer^"");
if (dofreeze) {
isspeedset = 1;
thespeed = get_cvar_float("sv_maxspeed");
set_cvar_float("sv_maxspeed", 0.0);
new players[32], inum, i;
get_players(players, inum, "c");
for (i = 0; i < inum; ++i) {
client_cmd(players[i], "drop");
client_cmd(players[i], "+showscores");
}
set_task(1.1, "stop_person", DMAP_TASKID_FREEZE, "", 0, "a", 2);
}
return PLUGIN_HANDLED;
}
public countdown() {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
new players[32], inum, i;
get_players(players, inum, "c");
for (i = 0; i < inum; ++i) {
if(is_user_connected(players[i]))
{
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, players[i])
write_short(1<<10)
write_short(1<<10)
write_short(0x0000)
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(255)
message_end()
}
}
countnum++;
set_dhudmessage(150, 120, 0, -1.0, 0.3, 0, 0.5, 1.1, 0.1, 0.1);
show_dhudmessage(0, "%L", LANG_PLAYER, "MAP_CHANGING_IN", smap, 7 - countnum);
return PLUGIN_HANDLED;
}
public stop_person() {
new players[32], inum, i;
get_players(players, inum, "c");
if (isspeedset >= 0 && isspeedset < 2) {
thespeed = get_cvar_float("sv_maxspeed");
isspeedset++;
set_cvar_float("sv_maxspeed", 0.0);
}
for (i = 0; i < inum; ++i) {
client_cmd(players[i], "drop");
}
return PLUGIN_HANDLED;
}
display_message() {
new timeleft = get_timeleft();
if (mselected || g_Vote) {
return PLUGIN_CONTINUE;
}
if (timeleft >= 117 && timeleft < 132) {
message_fifteen();
}
return PLUGIN_CONTINUE;
}
list_nominations(id)
{
if (get_pcvar_num(pNominationsAllowed) == 1)
{
new a = 0, string3[512], string1[96], name1[32];
if (a < nmaps_num)
{
formatex(string3, 255, "%L", LANG_PLAYER, "NOMINATIONS");
}
while (a < nmaps_num)
{
get_user_name(whonmaps_num[a], name1, charsmax(name1));
formatex(string1, charsmax(string1), "^n %L", LANG_PLAYER, "MAP_BY", nmaps[a], name1);
add(string3, charsmax(string3), string1);
a++;
}
set_dhudmessage(0, 255, 0, -1.0, 0.60, 0, 10.0, 10.0);
show_dhudmessage(id, "%s", string3);
}
}
message_fifteen() {
client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use bay(s18) mass(e42) cap(s50)^"");
set_task(8.7, "get_ready", DMAP_TASKID_GET_READY);
return PLUGIN_HANDLED;
}
public get_ready() {
set_task(0.93, "time_to_vote", DMAP_TASKID_TIME_TO_VOTE, "", 0, "a", 5);
}
public time_to_vote() {
counttovote++;
new speak[5][] = {"one", "two", "three", "four", "five"};
if (get_timeleft() > 132 || counttovote > 5 || isbuytime) {
counttovote = 0;
remove_task(DMAP_TASKID_TIME_TO_VOTE);
remove_task(DMAP_TASKID_GET_READY);
return PLUGIN_HANDLED;
} else {
if (counttovote > 0 && counttovote <= 5) {
set_dhudmessage(0, 222, 50, -1.0, 0.13, 0, 1.0, 0.94, 0.0, 0.0);
show_dhudmessage(0, "%L", LANG_PLAYER, "VOTING_IN_XSEC", 6 - counttovote);
client_cmd(0, "spk ^"fvox/%s^"", speak[5 - counttovote]);
}
}
return PLUGIN_HANDLED;
}
available_maps() { //return number of maps that haven't been added yet
new num, isinlist;
new a, i;
for (a = 0; a < num_nmapsfill; a++) { // Loop through each available map
if (is_map_valid(nmapsfill[a])) {
isinlist = 0;
for (i = 0; i < nmaps_num; i++) {
if (equali(nmapsfill[a], nmaps[i])) {
isinlist = 1;
}
}
if (!isinlist) {
num++;
}
}
}
return num;
}
public ask_for_next_map() {
display_message();
new timeleft = get_timeleft();
if (isspeedset && (timeleft > 30)) {
isspeedset = 0;
set_cvar_float("sv_maxspeed", thespeed);
}
if (waited > 0) {
return PLUGIN_HANDLED;
}
if (timeleft > 300) {
remove_task(DMAP_TASKID_END_OF_ROUND);
}
new mp_winlimit = get_cvar_num("mp_winlimit");
if (mp_winlimit) {
new s = mp_winlimit - 2;
if ((s > teamscore[0] && s > teamscore[1]) && (timeleft > 114 || timeleft < 1)) {
remove_task(DMAP_TASKID_TIME_DIS);
mselected = false;
return PLUGIN_HANDLED;
}
} else {
if (timeleft > 114 || timeleft < 1) {
remove_task(DMAP_TASKID_TIME_DIS);
if (timeleft > 135) {
remove_task(DMAP_TASKID_TIME_DISPLAY);
}
mselected = false;
return PLUGIN_HANDLED;
}
}
if (g_Vote || mselected ) {
return PLUGIN_HANDLED;
}
g_Vote = true;
if (mp_winlimit && !(timeleft >= 115 && timeleft < 134))
{
client_cmd(0, "spk ^"get red(e80) ninety(s45) to check(e20) use bay(s18) mass(e42) cap(s50)^"");
set_task(4.2, "get_ready", DMAP_TASKID_GET_READY);
set_task(10.0, "start_the_vote");
}
else
{
set_task(0.5, "start_the_vote");
}
return PLUGIN_HANDLED;
}
public start_the_vote() {
new j;
for (j = 0; j < maps_to_select + 2; j++) {
nvotes[j] = 0;
}
mselected = true;
g_Vote = true;
counttovote = 0;
if ((isbuytime || isbetween) && get_timeleft() && get_timeleft() > 54 && get_pcvar_num(pWeaponDelay)) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTING_DELAYED");
if (isbetween) {
set_task(15.0, "get_ready", DMAP_TASKID_GET_READY);
set_task(21.0, "start_the_vote");
} else {
set_task(8.0, "get_ready", DMAP_TASKID_GET_READY);
set_task(14.0, "start_the_vote");
}
return PLUGIN_HANDLED;
} //else start_the_vote anyways..., regardless of buytime
remove_task(DMAP_TASKID_TIME_TO_VOTE);
remove_task(DMAP_TASKID_GET_READY);
before_num_nmapsfill = num_nmapsfill;
new available = available_maps();
if ((nmaps_num + available) < (maps_to_select + 1)) { //Loads maps from mapcycle.txt/allmaps.txt if not enough are in in mapchoice.ini
new current_map[32];
get_mapname(current_map,31);
new overflowprotect = 0;
new used[MAX_MAPS_AMOUNT];
new k = num_nmapsfill;
new totalfilled = 0;
new alreadyused;
new tryfill, custfill = 0;
new q;
new listpossible = totalmaps;
while (((available_maps() + nmaps_num - custfill) < (maps_to_select + 7)) && listpossible > 0) {
alreadyused = 0;
q = 0;
tryfill = random_num(0, totalmaps - 1);
overflowprotect = 0;
while (used[tryfill] && overflowprotect++ <= totalmaps * 15) {
tryfill = random_num(0, totalmaps - 1);
}
if (overflowprotect >= totalmaps * 15) {
alreadyused = 1;
listpossible -= 1;
} else {
while (q < num_nmapsfill && !alreadyused) {
if (equali(listofmaps[tryfill], nmapsfill[q])) {
alreadyused = used[tryfill] = 1;
listpossible--;
}
q++;
}
q = 0;
while (q < nmaps_num && !alreadyused) {
if (equali(listofmaps[tryfill], nmaps[q])) {
alreadyused = used[tryfill] = 1;
listpossible--;
}
q++;
}
}
if (!alreadyused) {
if (equali(listofmaps[tryfill], current_map) || equali(listofmaps[tryfill], last_map)||
is_last_maps(listofmaps[tryfill]) || is_banned(listofmaps[tryfill])) {
listpossible--;
used[tryfill] = 1;
} else {
nmapsfill[k] = listofmaps[tryfill];
num_nmapsfill++;
listpossible--;
used[tryfill] = 1;
k++;
totalfilled++;
}
}
}
}
nbeforefill = nmaps_num; //extra maps do not act as "nominations" they are additions
if (nmaps_num < maps_to_select) {
new fillpossible = num_nmapsfill;
new k = nmaps_num;
new overflowprotect = 0;
new used[MAX_MAPS_AMOUNT];
new totalfilled = 0, custchoice = 0, full = ((amt_custom + custchoice) >= maxcustnom);
new alreadyused;
new tryfill;
if (num_nmapsfill < 1) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMORE_RANDOM_DEFINED");
} else {
while (fillpossible > 0 && k < maps_to_select) {
alreadyused = 0;
new q = 0;
tryfill = random_num(0, num_nmapsfill - 1);
overflowprotect = 0;
while (used[tryfill] && overflowprotect++ <= num_nmapsfill * 10) {
tryfill = random_num(0, num_nmapsfill - 1);
}
if (overflowprotect >= num_nmapsfill * 15) {
alreadyused = 1;
fillpossible -= 2;
} else {
while (q < nmaps_num && !alreadyused) {
if (equali(nmapsfill[tryfill], nmaps[q])) {
alreadyused = used[tryfill] = 1;
fillpossible--;
}
q++;
}
if (!alreadyused) {
if (full) {
alreadyused = used[tryfill] = 1;
fillpossible--;
}
}
}
if (!alreadyused) {
nmaps[k] = nmapsfill[tryfill];
nmaps_num++;
fillpossible--;
used[tryfill] = 1;
k++;
totalfilled++;
}
}
}
}
g_Vote = true;
startvote()
set_task(float(DMAP_VOTE_TIME + 1), "check_votes");
arrayset(nvotes, 0, sizeof(nvotes));
arrayset(g_iTimerVote, DMAP_VOTE_TIME, 33);
arrayset(b_HasAlreadyVoted, false, 33);
return PLUGIN_HANDLED;
}
public startvote()
{
if(!g_Vote)
return PLUGIN_CONTINUE;
new szPlayers[32], iNum;
get_players(szPlayers, iNum);
g_TotalVotes = 0;
nvotes[nmapstoch] = 0;
nvotes[maps_to_select] = 0;
for(new i; i < iNum; i++)
show_vote_menu(szPlayers[i])
return PLUGIN_HANDLED;
}
show_vote_menu(id)
{
if(!g_Vote)
return PLUGIN_CONTINUE;
new menu[512], a, mkeys = (1 << maps_to_select + 1);
new steptime = get_pcvar_num(pExtendmapStep);
new pos
new mp_winlimit = get_cvar_num("mp_winlimit");
new g = 0, i;
for (i = 0; i < nmapstoch; ++i) {
if (nvotes[g] < nvotes[i]) {
g = i;
}
}
pos = formatex(menu, charsmax(menu), "%L", LANG_PLAYER, "MENU_TITLE", g_iTimerVote[id], g_TotalVotes, get_playersnum() );
if (nvotes[maps_to_select] > nvotes[g]) {
new mapname[32];
get_mapname(mapname, charsmax(mapname));
pos = formatex(menu, charsmax(menu), "%L", LANG_PLAYER, "MENU_TITLE2", g_iTimerVote[id], mapname, g_TotalVotes, get_playersnum());
}
if (nvotes[g] && nvotes[maps_to_select+1] <= nvotes[g]) {
set_cvar_string("amx_nextmap", nmaps[nnextmaps[g]]);
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
pos = formatex(menu, charsmax(menu), "%L", LANG_PLAYER, "MENU_TITLE3", g_iTimerVote[id], nmaps[nnextmaps[g]], g_TotalVotes, get_playersnum());
}
new dmax = (nmaps_num > maps_to_select) ? maps_to_select : nmaps_num;
for (nmapstoch = 0; nmapstoch < dmax; ++nmapstoch)
{
a = random_num(0, nmaps_num - 1); // Randomize order of maps in vote
while (is_in_menu(a)) {
if (++a >= nmaps_num) {
a = 0;
}
nnextmaps[nmapstoch] = a;
}
if(!b_HasAlreadyVoted[id])
{
pos += format( menu[pos], charsmax( menu ), "\r%d.\w %s \r[%d%%]^n", nmapstoch + 1, nmaps[nnextmaps[nmapstoch]], nvotes[nmapstoch] * g_iPlayerProcc )
mkeys |= ( 1 << nmapstoch )
}
else
{
pos += format( menu[pos], charsmax( menu ), "\r%d.\d %s \r[%d%%]^n", nmapstoch + 1, nmaps[nnextmaps[nmapstoch]], nvotes[nmapstoch] * g_iPlayerProcc )
mkeys &= ~( 1 << nmapstoch )
}
}
menu[pos++] = '^n';
new mapname[32];
get_mapname(mapname, charsmax(mapname));
if (!mp_winlimit && get_cvar_float("mp_timelimit") < get_pcvar_float(pExtendmapMax))
{
if(!b_HasAlreadyVoted[id])
{
pos += format( menu[pos], charsmax( menu ), "%L", LANG_PLAYER, "MENU_EXTEND", maps_to_select + 1, mapname, steptime, nvotes[maps_to_select] * g_iPlayerProcc )
mkeys |= ( 1 << maps_to_select )
}
else
{
pos += format( menu[pos], charsmax( menu ), "%L", LANG_PLAYER, "MENU_EXTEND2", maps_to_select + 1, mapname, steptime, nvotes[maps_to_select] * g_iPlayerProcc )
mkeys &= ~( 1 << maps_to_select )
}
}
if(!b_HasAlreadyVoted[id])
{
mkeys |= ( 1 << maps_to_select + 1 );
pos += format( menu[pos], charsmax( menu ), "%L", LANG_PLAYER, "MENU_NONE", maps_to_select + 2)
}
client_cmd ( id, "spk sound/buttons/lightswitch2.wav" )
show_menu(id, mkeys, menu, -1, DMAP_MENU_TITLE);
return PLUGIN_HANDLED;
}
public client_PreThink(id)
{
if(!g_Vote)
return;
if(g_iTimerVote[id] <= -1)
return;
if(g_TotalVotes)
g_iPlayerProcc = 100 / g_TotalVotes;
else
g_iPlayerProcc = 0;
if((get_gametime() - g_iLastSec[id]) >= 1.0)
if(g_iTimerVote[id] != 0)
g_iTimerVote[id]--, show_vote_menu(id), g_iLastSec[id] = get_gametime();
else
show_menu(id, 0, "^n"), g_iTimerVote[id] = -1;
}
handle_and_change(id, map2[], bool:bForce = false) {
new tester[32];
if (is_map_valid(map2) == 1) {
handle_nominate(id, map2, bForce);
} else {
formatex(tester, charsmax(tester), "cs_%s", map2);
if (is_map_valid(tester) == 1) {
handle_nominate(id, tester, bForce);
} else {
formatex(tester, charsmax(tester), "de_%s", map2);
if (is_map_valid(tester) == 1) {
handle_nominate(id, tester, bForce);
} else {
formatex(tester, charsmax(tester), "as_%s", map2);
if (is_map_valid(tester) == 1) {
handle_nominate(id, tester, bForce);
} else {
formatex(tester, charsmax(tester), "dod_%s", map2);
if (is_map_valid(tester) == 1) {
handle_nominate(id, tester, bForce);
} else {
formatex(tester, charsmax(tester), "fy_%s", map2);
if (is_map_valid(tester) == 1) {
handle_nominate(id, tester, bForce);
} else { // Send invalid map. handle_nominate() handles the error.
handle_nominate(id, map2, bForce);
}
}
}
}
}
}
}
public handle_say(id) {
new chat[256];
read_args(chat, charsmax(chat));
if (containi(chat, "<") != -1 || containi(chat, "?") != -1 || containi(chat, ">") != -1 || containi(chat, "*") != -1 || containi(chat, "&") != -1 || containi(chat, ".") != -1) {
return PLUGIN_CONTINUE;
} else if (containi(chat, "nominate ") == 1) {
new mycommand[41];
read_args(mycommand, charsmax(mycommand));
remove_quotes(mycommand);
handle_and_change(id, mycommand[9]);
} else if (containi(chat, "vote ") == 1) {
new mycommand[37];
read_args(mycommand, charsmax(mycommand));
remove_quotes(mycommand);
handle_and_change(id, mycommand[5]);
} else {
remove_quotes(chat);
if (is_map_valid(chat) == 1) {
handle_nominate(id, chat, false);
} else {
new chat2[32];
formatex(chat2, charsmax(chat2), "cs_%s", chat);
if (is_map_valid(chat2) == 1) {
handle_nominate(id, chat2, false);
} else {
formatex(chat2, charsmax(chat2), "de_%s", chat);
if (is_map_valid(chat2) == 1) {
handle_nominate(id, chat2, false);
} else {
formatex(chat2, charsmax(chat2), "as_%s", chat);
if (is_map_valid(chat2) == 1) {
handle_nominate(id, chat2, false);
} else {
formatex(chat2, charsmax(chat2), "dod_%s", chat);
if (is_map_valid(chat2) == 1) {
handle_nominate(id, chat2, false);
} else {
formatex(chat2, charsmax(chat2), "fy_%s", chat);
if (is_map_valid(chat2) == 1) {
handle_nominate(id, chat2, false);
}
}
}
}
}
}
}
return PLUGIN_CONTINUE;
}
handle_nominate(id, map[], bool:bForce) {
if ((get_pcvar_num(pNominationsAllowed) == 0) && (bForce == false)) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATIONS_DISABLED");
return PLUGIN_HANDLED;
}
strtolower(map);
new current_map[32], full;
full = (amt_custom >= maxcustnom);
new n = 0, i, done = 0, isreplacement = 0; //0: (not a replacement), 1: (replacing their own), 2: (replacing others)
new tempnmaps = nmaps_num;
get_mapname(current_map, charsmax(current_map));
if (maxnom == 0) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATIONS_DISABLED");
return PLUGIN_HANDLED;
}
if (g_Vote && mselected) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTE_IN_PROGRESS");
return PLUGIN_HANDLED;
}
if (mselected) {
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTING_OVER", smap);
return PLUGIN_HANDLED;
}
if (!is_map_valid(map) || is_map_valid(map[1])) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAP_NOTFOUND", map);
return PLUGIN_HANDLED;
}
if (is_banned(map) && (bForce == false)) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAPVOTE_NOT_AVAILABLE");
return PLUGIN_HANDLED;
}
if (is_last_maps(map) && !equali(map, current_map) && (bForce == false)) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "CANT_NOMINATE_LASTMAP", ban_last_maps);
return PLUGIN_HANDLED;
}
if (equali(map, current_map)) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "EXTEND_MAP", map);
return PLUGIN_HANDLED;
}
//Insert Strict Style code here, for pcvar dmap_strict 1
if (get_pcvar_num(pDmapStrict) && (bForce == false)) {
new isinthelist = 0;
for (new a = 0; a < totalmaps; a++) {
if (equali(map, listofmaps[a]))
isinthelist = 1;
}
if (!isinthelist) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "ALLOWED_MAPS");
return PLUGIN_HANDLED;
}
}
if (nmaps_num >= maps_to_select || Nominated[id] >= maxnom) {
if (Nominated[id] > maxnom) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAX_MAPS_REACHED", maxnom); //Possible to reach here!
//only if the command dmap_nominations is used to lower amount of maps that can be nominated
return PLUGIN_HANDLED;
}
for (i = 0; i < nmaps_num; i++) {
if (equali(map, nmaps[i])) {
new name[32];
get_user_name(whonmaps_num[i], name, charsmax(name));
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "ALREADY_NOMINATED", map, name);
return PLUGIN_HANDLED;
}
}
while (n < nmaps_num && !done && Nominated[id] > 1) { //If the person has nominated 2 or more maps, he can replace his own
if (whonmaps_num[n] == id) { //If a map is found that he has nominated, replace his own nomination.
if (!(full)) {
Nominated[id] = Nominated[id] - 1;
nmaps_num = n;
done = 1;
isreplacement = 1;
}
}
n++;
}
if (!done) {
n = 0;
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
if (Nominated[whonmaps_num[n]] > 2) { //Replace the "greedy person's" nomination
if (!(full)) {
done = 1;
Nominated[whonmaps_num[n]] = Nominated[whonmaps_num[n]] - 1;
nmaps_num = n;
isreplacement = 2;
}
}
n++;
}
}
if (!done) {
n = 0;
while (n < nmaps_num && !done && Nominated[id] < 1) { //If the person has not nom any maps, he can replace those with more than one
//he cannot replace those with only one nomination, that would NOT be fair
if (Nominated[whonmaps_num[n]] > 1) { //Replace the "greedy person's" nomination
if (!(full)) {
done = 1;
Nominated[whonmaps_num[n]] = Nominated[whonmaps_num[n]] - 1;
nmaps_num = n;
isreplacement = 2;
}
}
n++;
}
}
if (!done) {
n = 0;
while (n < nmaps_num && !done && Nominated[id] > 0) { //If the person has nominated a map, he can replace his own
if (whonmaps_num[n] == id) { //If a map is found that he has nominated, replace his own nomination.
if (!(full)) { //Check to see if too many custom maps are nominated
Nominated[id] = Nominated[id] - 1;
nmaps_num = n;
done = 1;
isreplacement = 1;
}
}
n++;
}
}
if (!done) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAX_MAPS_REACHED", nmaps_num);
return PLUGIN_HANDLED;
}
}
for (i = 0; i < nmaps_num; i++) {
if (equali(map, nmaps[i])) {
new name[32];
get_user_name(whonmaps_num[i], name, charsmax(name));
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "ALREADY_NOMINATED", map, name);
nmaps_num = tempnmaps;
return PLUGIN_HANDLED;
}
}
if (!isreplacement && full) {
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "MAX_CUSTOMMAPS_REACHED", maxcustnom);
return PLUGIN_HANDLED;
}
new name[32];
get_user_name(id, name, charsmax(name));
if (isreplacement == 1)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "REPLACE_PREVIOUS_NOMINATION", nmaps[nmaps_num]);
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "PLAYER_REPLACED_NOMINATION", name, nmaps[nmaps_num]);
} else {
if (isreplacement == 2) {
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATION_REPLACED", nmaps[nmaps_num]);
new name21[32];
get_user_name(whonmaps_num[nmaps_num], name21, charsmax(name21));
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATION_REPLACED2", name21, nmaps[nmaps_num]);
}
}
Nominated[id]++;
copy(nmaps[nmaps_num], 31, map);
whonmaps_num[nmaps_num] = id;
if (isreplacement) {
nmaps_num = tempnmaps;
} else {
nmaps_num = tempnmaps + 1;
}
ColorChat(0, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATED_MAP", name, map);
return PLUGIN_HANDLED;
}
public team_score() {
new team[2];
read_data(1, team, 1);
teamscore[(team[0] == 'C') ? 0 : 1] = read_data(2);
return PLUGIN_CONTINUE;
}
public plugin_end() {
new current_map[32];
get_mapname(current_map, charsmax(current_map));
set_localinfo("amx_lastmap", current_map);
if (istimeset) {
set_cvar_float("mp_timelimit", oldtimelimit);
} else {
if (istimeset2) {
set_cvar_float("mp_timelimit", get_cvar_float("mp_timelimit") - 2.0);
}
}
if (isspeedset) {
set_cvar_float("sv_maxspeed", thespeed);
}
if (iswinlimitset) {
set_cvar_num("mp_winlimit", oldwinlimit);
}
return PLUGIN_CONTINUE;
}
get_listing() {
new i = 0, iavailable = 0;
new line = 0, p;
new stextsize = 0, isinthislist = 0, found_a_match = 0, done = 0;
new linestr[256];
new maptext[32];
new current_map[32];
get_mapname(current_map, charsmax(current_map));
//pathtomaps = "mapcycle.txt";
get_cvar_string("mapcyclefile", pathtomaps, charsmax(pathtomaps));
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
if (file_exists(pathtomaps)) {
while (read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize) && !done) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1]) && equali(maptext, current_map)) {
done = found_a_match = 1;
line++;
if (read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize)) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
//////////////////////////////////////////
if (equali(smap, "")) {
register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
}
set_cvar_string("amx_nextmap", maptext);
} else {
found_a_match = 0;
}
} else {
found_a_match = 0;
}
} else {
line++;
}
}
/*
if (!found_a_match) {
line = 0;
while (read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize) && !found_a_match && line < 1024) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
if (equali(smap, "")) {
register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
}
set_cvar_string("amx_nextmap", maptext);
found_a_match = 1;
} else {
line++;
}
}
}
*/
/* CODE TO RANDOMIZE NEXTMAP VARIABLE!*/
if (!found_a_match) {
line = random_num(0, 50);
new tries = 0;
while ((read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize) || !found_a_match) && (tries < 1024 && !found_a_match)) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
if (equali(smap, "")) {
register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
}
set_cvar_string("amx_nextmap", maptext);
found_a_match = 1;
} else {
line = random_num(0, 50);
tries++;
}
}
}
}
line = 0;
formatex(pathtomaps, charsmax(pathtomaps), "%s/allmaps.txt", custompath);
if (!file_exists(pathtomaps)) {
new mapsadded = 0;
while ((line = read_dir("maps", line, linestr, charsmax(linestr), stextsize)) != 0) {
stextsize -= 4;
if (stextsize > 0) {
if (!equali(linestr[stextsize], ".bsp")) {
continue; // skip non map files
}
linestr[stextsize] = 0; // remove .bsp
}
if (is_map_valid(linestr)) {
write_file(pathtomaps, linestr);
mapsadded++;
}
}
line = 0;
}
if (get_pcvar_num(pDmapStrict) == 1) {
get_cvar_string("mapcyclefile", pathtomaps, charsmax(pathtomaps));
//pathtomaps = "mapcycle.txt";
}
if (file_exists(pathtomaps)) {
while (read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize) && i < MAX_MAPS_AMOUNT) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
isinthislist = 0;
for (p = 0; p < i; p++) {
if (equali(maptext, listofmaps[p])) {
isinthislist = 1;
}
}
if (!isinthislist) {
listofmaps[i++] = maptext;
}
}
line++;
}
}
line = 0;
for (p = 0; p < i; p++) {
if (!is_banned(listofmaps[p]) && !is_last_maps(listofmaps[p])) {
iavailable++;
}
}
new dummy_str[64];
get_cvar_string("mapcyclefile", dummy_str, charsmax(dummy_str));
//if (iavailable < maps_to_select && !equali(pathtomaps, "mapcycle.txt"))
if (iavailable < maps_to_select && !equali(pathtomaps, dummy_str)) {
//pathtomaps = "mapcycle.txt";
get_cvar_string("mapcyclefile", pathtomaps, charsmax(pathtomaps));
if (file_exists(pathtomaps)) {
while (read_file(pathtomaps, line, linestr, charsmax(linestr), stextsize) && i < MAX_MAPS_AMOUNT) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
isinthislist = 0;
for (p = 0; p < i; p++) {
if (equali(maptext, listofmaps[p])) {
isinthislist = 1;
}
}
if (!isinthislist) {
listofmaps[i++] = maptext;
}
}
line++;
}
}
}
totalmaps = i;
iavailable = 0;
for (p = 0; p < i; p++) {
if (!is_banned(listofmaps[p]) && !is_last_maps(listofmaps[p])) {
iavailable++;
}
}
}
public ban_some_maps() {
//BAN MAPS FROM CONFIG FILE
new banpath[64];
formatex(banpath, charsmax(banpath), "%s/mapstoban.ini", custompath);
new i = 0;
new line = 0;
new stextsize = 0;
new linestr[256];
new maptext[32];
if (file_exists(banpath)) {
while (read_file(banpath, line, linestr, charsmax(linestr), stextsize) && i < MAX_MAPS_AMOUNT) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
banthesemaps[i++] = maptext;
}
line++;
}
}
totalbanned = i;
//BAN RECENT MAPS PLAYED
new lastmapspath[64];
formatex(lastmapspath, charsmax(lastmapspath), "%s/lastmapsplayed.txt", custompath);
line = stextsize = 0;
new current_map[32];
get_mapname(current_map, charsmax(current_map));
lastmaps[0] = current_map;
bannedsofar++;
currentplayers = activeplayers = rocks = 0;
if (file_exists(lastmapspath)) {
while(read_file(lastmapspath, line, linestr, charsmax(linestr), stextsize) && bannedsofar <= ban_last_maps) {
if ((strlen(linestr) > 0) && (is_map_valid(linestr))) {
formatex(lastmaps[bannedsofar++], 31, "%s", linestr);
}
line++;
}
}
write_last_maps();
}
write_last_maps() { //deletes and writes to lastmapsplayed.txt
new lastmapspath[64];
formatex(lastmapspath, charsmax(lastmapspath), "%s/lastmapsplayed.txt", custompath);
if (file_exists(lastmapspath)) {
delete_file(lastmapspath);
}
new text[256], p;
for (p = 0; p < bannedsofar; p++) {
formatex(text, charsmax(text), "%s", lastmaps[p]);
write_file(lastmapspath, text);
}
write_file(lastmapspath, ";Тут сохраняются последние сыгранные карты. Author: Deags/AMXX Community/Creat1v");
load_maps();
}
load_maps() {
new choicepath[64];
formatex(choicepath, charsmax(choicepath), "%s/mapchoice.ini", custompath);
new line = 0;
new stextsize = 0, isinlist, unable = 0, i;
new linestr[256];
new maptext[32];
new current_map[32];
get_mapname(current_map, charsmax(current_map));
if (file_exists(choicepath)) {
while (read_file(choicepath, line, linestr, charsmax(linestr), stextsize) && (num_nmapsfill < MAX_MAPS_AMOUNT)) {
formatex(maptext, charsmax(maptext), "%s", linestr);
if (is_map_valid(maptext) && !is_map_valid(maptext[1])) {
isinlist = 0;
if (is_banned(maptext) || is_last_maps(maptext)) {
isinlist = 1;
} else {
if (equali(maptext, current_map) || equali(maptext, last_map)) {
isinlist = 1;
} else {
for (i = 0; i < num_nmapsfill; i++) {
if (equali(maptext, nmapsfill[i])) {
isinlist = 1;
}
}
}
}
if (!isinlist) {
copy(nmapsfill[num_nmapsfill++], 31, maptext);
} else {
unable++;
}
}
line++;
}
}
get_listing();
}
bool:is_last_maps(map[]) {
new a;
for (a = 0; a < bannedsofar; a++) {
if (equali(map, lastmaps[a])) {
return true;
}
}
return false;
}
bool:is_banned(map[]) {
new a;
for (a = 0; a < totalbanned; a++) {
if (equali(map, banthesemaps[a])) {
return true;
}
}
return false;
}
change_custom_path() {
new temp[64]; // Unless someone reports an issue, I think this is a sufficient size.
formatex(temp, charsmax(temp), "%s/dmap", custompath);
if (dir_exists(temp)) {
copy(custompath, charsmax(custompath), temp);
}
}
public event_round_start() {
isbetween = 0;
isbuytime = 1;
set_task(10.0, "now_safe_to_vote");
}
public event_round_end() {
isbetween = 1;
}
public now_safe_to_vote() {
isbuytime = 0;
}
public say_nominations(id)
{
if (get_pcvar_num(pNominationsAllowed) == 0)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NOMINATIONS_DISABLED");
return PLUGIN_HANDLED;
}
if(g_Vote)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTE_IN_PROGRESS");
return PLUGIN_CONTINUE;
}
if (mselected)
{
new smap[32];
get_cvar_string("amx_nextmap", smap, charsmax(smap));
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "VOTING_OVER", smap);
return PLUGIN_CONTINUE;
}
else
{
if (nmaps_num == 0)
{
ColorChat(id, RED, "[%s]!y %L", Prefix, LANG_PLAYER, "NO_MAPS_NOMINATED");
}
else
{
list_nominations(id);
}
}
return PLUGIN_HANDLED;
}
public plugin_init() {
register_plugin(g_PLUGIN, g_VERSION, g_AUTHOR);
register_dictionary("common.txt");
register_dictionary("mapmanager.txt");
get_configsdir(custompath, charsmax(custompath));
change_custom_path();
//g_MaxPlayers = get_maxplayers();
register_clcmd("say", "handle_say", 0, "- Say: vote mapname, nominate mapname, or just ^"MAP_NAME^" to nominate a map");
register_clcmd("say rockthevote", "rock_the_vote", 0, "- Rock the vote");
register_clcmd("say rtv", "rock_the_vote", 0, "- Rock the vote");
register_clcmd("say nominations", "say_nominations", 0, "- Show names of maps nominated for next vote");
register_clcmd("say noms", "say_nominations", 0, "- Show names of maps nominated for next vote");
register_logevent("event_round_start", 2, "0=World triggered", "1=Round_Start");
register_logevent("event_round_end", 2, "0=World triggered", "1=Round_End");
register_event("30", "event_intermission", "a"); // SVC_INTERMISSION = 30
pDmapStrict = register_cvar("dmap_strict", "0", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
pEmptyMap = register_cvar("amx_emptymap", "de_dust2", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
pEmptymapAllowed = register_cvar("emptymap_allowed", "0", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
pEnforceTimelimit = register_cvar("enforce_timelimit", "0", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
pExtendmapMax = register_cvar("amx_extendmap_max", "90", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
pExtendmapStep = register_cvar("amx_extendmap_step", "15", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
register_cvar("amx_idletime", "5", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY); // No pointer; only used once
pNominationsAllowed = register_cvar("nominations_allowed", "1", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
register_cvar("amx_staytime", "300", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY); // No pointer; only used once
pWeaponDelay = register_cvar("weapon_delay", "1", FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
staytime = get_cvar_num("amx_staytime");
IdleTime = get_cvar_num("amx_idletime");
bIsCstrike = (cstrike_running() == 1);
register_cvar("Deags_Map_Manage", g_VERSION, FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY|FCVAR_PRINTABLEONLY);
if (bIsCstrike) {
register_event("TeamScore", "team_score", "a");
dofreeze = 1;
}
set_task(3.0, "ban_some_maps"); //reads from lastmapsplayed.txt and stores into global array
set_task(15.0, "ask_for_next_map", DMAP_TASKID_ASK_FOR_NEXT, "", 0, "b");
set_task(5.0, "loop_messages", DMAP_TASKID_LOOP_MESSAGES, "", 0, "b");
oldtimelimit = get_cvar_float("mp_timelimit");
get_localinfo("amx_lastmap", last_map, charsmax(last_map));
set_localinfo("amx_lastmap", "");
set_task(1.0, "timer", DMAP_TASKID_TIMER, "", 0, "b");
register_menu(DMAP_MENU_TITLE, (-1 ^ (-1 << (maps_to_select + 2))), "vote_count");
}