plugins/mapchooser.sp
author Matt Woodrow <pred@alliedmods.net>
Mon Jul 07 23:12:21 2008 +0000 (2008-07-07)
changeset 2179 e36379b15572
parent 2178 7769e1d56f64
child 2185 1ae3a4151376
permissions -rw-r--r--
Fixed build
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Mapchooser Plugin
ds@1952
     5
 * Creates a map vote at appropriate times, setting sm_nextmap to the winning
ds@1952
     6
 * vote
ds@1952
     7
 *
pred@2032
     8
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1952
     9
 * =============================================================================
ds@1952
    10
 *
ds@1952
    11
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    12
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    13
 * Free Software Foundation.
ds@1952
    14
 * 
ds@1952
    15
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    16
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    17
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    18
 * details.
ds@1952
    19
 *
ds@1952
    20
 * You should have received a copy of the GNU General Public License along with
ds@1952
    21
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    22
 *
ds@1952
    23
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    24
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    25
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    26
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    27
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    28
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    29
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    30
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    31
 *
ds@1952
    32
 * Version: $Id$
ds@1952
    33
 */
ds@1952
    34
ds@1952
    35
#pragma semicolon 1
ds@1952
    36
#include <sourcemod>
pred@2133
    37
#include <mapchooser>
pred@2133
    38
#include <nextmap>
pred@2133
    39
#undef REQUIRE_EXTENSIONS
pred@2133
    40
#include <tf2>
pred@2133
    41
#define REQUIRE_EXTENSIONS
ds@1952
    42
ds@1952
    43
public Plugin:myinfo =
ds@1952
    44
{
ds@1952
    45
	name = "MapChooser",
ds@1952
    46
	author = "AlliedModders LLC",
ds@1952
    47
	description = "Automated Map Voting",
ds@1952
    48
	version = SOURCEMOD_VERSION,
ds@1952
    49
	url = "http://www.sourcemod.net/"
ds@1952
    50
};
ds@1952
    51
pred@2133
    52
/* Valve ConVars */
ds@1952
    53
new Handle:g_Cvar_Winlimit = INVALID_HANDLE;
ds@1952
    54
new Handle:g_Cvar_Maxrounds = INVALID_HANDLE;
ds@1952
    55
new Handle:g_Cvar_Fraglimit = INVALID_HANDLE;
pred@2133
    56
new Handle:g_Cvar_Bonusroundtime = INVALID_HANDLE;
ds@1952
    57
pred@2133
    58
/* Plugin ConVars */
ds@1952
    59
new Handle:g_Cvar_StartTime = INVALID_HANDLE;
ds@1952
    60
new Handle:g_Cvar_StartRounds = INVALID_HANDLE;
ds@1952
    61
new Handle:g_Cvar_StartFrags = INVALID_HANDLE;
ds@1952
    62
new Handle:g_Cvar_ExtendTimeStep = INVALID_HANDLE;
ds@1952
    63
new Handle:g_Cvar_ExtendRoundStep = INVALID_HANDLE;
ds@1952
    64
new Handle:g_Cvar_ExtendFragStep = INVALID_HANDLE;
ds@1952
    65
new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
ds@1952
    66
new Handle:g_Cvar_IncludeMaps = INVALID_HANDLE;
ds@1952
    67
new Handle:g_Cvar_NoVoteMode = INVALID_HANDLE;
ds@1952
    68
new Handle:g_Cvar_Extend = INVALID_HANDLE;
pred@2133
    69
new Handle:g_Cvar_DontChange = INVALID_HANDLE;
pred@2133
    70
new Handle:g_Cvar_EndOfMapVote = INVALID_HANDLE;
pred@2133
    71
new Handle:g_Cvar_VoteDuration = INVALID_HANDLE;
pred@2178
    72
ds@1952
    73
new Handle:g_VoteTimer = INVALID_HANDLE;
ds@1952
    74
new Handle:g_RetryTimer = INVALID_HANDLE;
ds@1952
    75
pred@2133
    76
/* Data Handles */
ds@1952
    77
new Handle:g_MapList = INVALID_HANDLE;
pred@2133
    78
new Handle:g_NominateList = INVALID_HANDLE;
pred@2133
    79
new Handle:g_NominateOwners = INVALID_HANDLE;
ds@1952
    80
new Handle:g_OldMapList = INVALID_HANDLE;
ds@1952
    81
new Handle:g_NextMapList = INVALID_HANDLE;
ds@1952
    82
new Handle:g_VoteMenu = INVALID_HANDLE;
ds@1952
    83
ds@1952
    84
new g_Extends;
ds@1952
    85
new g_TotalRounds;
ds@1952
    86
new bool:g_HasVoteStarted;
pred@2133
    87
new bool:g_WaitingForVote;
pred@2133
    88
new bool:g_MapVoteCompleted;
pred@2133
    89
new bool:g_ChangeMapAtRoundEnd;
ds@1952
    90
new g_mapFileSerial = -1;
ds@1952
    91
pred@2133
    92
new g_NominateCount = 0;
pred@2133
    93
new MapChange:g_ChangeTime;
pred@2133
    94
pred@2133
    95
new Handle:g_NominationsResetForward = INVALID_HANDLE;
pred@2133
    96
pred@2133
    97
/* Upper bound of how many team there could be */
pred@2133
    98
#define MAXTEAMS 10
pred@2133
    99
new g_winCount[MAXTEAMS];
pred@2133
   100
ds@1952
   101
#define VOTE_EXTEND "##extend##"
pred@2133
   102
#define VOTE_DONTCHANGE "##dontchange##"
ds@1952
   103
ds@1952
   104
public OnPluginStart()
ds@1952
   105
{
ds@1952
   106
	LoadTranslations("mapchooser.phrases");
ds@1952
   107
	
ds@1952
   108
	new arraySize = ByteCountToCells(33);
ds@1952
   109
	g_MapList = CreateArray(arraySize);
pred@2133
   110
	g_NominateList = CreateArray(arraySize);
pred@2133
   111
	g_NominateOwners = CreateArray(1);
ds@1952
   112
	g_OldMapList = CreateArray(arraySize);
ds@1952
   113
	g_NextMapList = CreateArray(arraySize);
pred@2133
   114
	
pred@2133
   115
	g_Cvar_EndOfMapVote = CreateConVar("sm_mapvote_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0);
pred@2133
   116
	HookConVarChange(g_Cvar_EndOfMapVote, EndVoteChanged);
ds@1952
   117
ds@1952
   118
	g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0);
pred@2133
   119
	g_Cvar_StartRounds = CreateConVar("sm_mapvote_startround", "2.0", "Specifies when to start the vote based on rounds remaining. Use 0 on TF2 to start vote during bonus round time", _, true, 0.0);
ds@1952
   120
	g_Cvar_StartFrags = CreateConVar("sm_mapvote_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0);
ds@1952
   121
	g_Cvar_ExtendTimeStep = CreateConVar("sm_extendmap_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0);
pred@2133
   122
	g_Cvar_ExtendRoundStep = CreateConVar("sm_extendmap_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
ds@1952
   123
	g_Cvar_ExtendFragStep = CreateConVar("sm_extendmap_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);	
ds@1952
   124
	g_Cvar_ExcludeMaps = CreateConVar("sm_mapvote_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
ds@1952
   125
	g_Cvar_IncludeMaps = CreateConVar("sm_mapvote_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 6.0);
ds@1952
   126
	g_Cvar_NoVoteMode = CreateConVar("sm_mapvote_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
ds@1952
   127
	g_Cvar_Extend = CreateConVar("sm_mapvote_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
pred@2133
   128
	g_Cvar_DontChange = CreateConVar("sm_mapvote_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0);
pred@2133
   129
	g_Cvar_VoteDuration = CreateConVar("sm_mapvote_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0, true, 25.0);
ds@1952
   130
	RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
ds@1952
   131
ds@1952
   132
	g_Cvar_Winlimit = FindConVar("mp_winlimit");
ds@1952
   133
	g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
ds@1952
   134
	g_Cvar_Fraglimit = FindConVar("mp_fraglimit");
pred@2133
   135
	g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
ds@1952
   136
	
ds@1952
   137
	if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   138
	{
ds@1952
   139
		HookEvent("round_end", Event_RoundEnd);
pred@2133
   140
		HookEventEx("teamplay_win_panel", Event_TeamPlayWinPanel);
pred@2133
   141
		HookEventEx("teamplay_restart_round", Event_TFRestartRound);
ds@1952
   142
	}
ds@1952
   143
	
ds@1952
   144
	if (g_Cvar_Fraglimit != INVALID_HANDLE)
ds@1952
   145
	{
ds@1952
   146
		HookEvent("player_death", Event_PlayerDeath);		
ds@1952
   147
	}
ds@1952
   148
	
ds@1952
   149
	AutoExecConfig(true, "mapchooser");
pred@2133
   150
	
pred@2133
   151
	//Change the mp_bonusroundtime max so that we have time to display the vote
pred@2133
   152
	//If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
pred@2133
   153
	if (g_Cvar_Bonusroundtime != INVALID_HANDLE)
pred@2133
   154
	{
pred@2133
   155
		SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);		
pred@2133
   156
	}
pred@2133
   157
	
pred@2165
   158
pred@2133
   159
	
pred@2133
   160
	g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
pred@2133
   161
}
pred@2133
   162
pred@2133
   163
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
pred@2133
   164
{
pred@2165
   165
	RegPluginLibrary("mapchooser");	
pred@2165
   166
	
pred@2133
   167
	CreateNative("NominateMap", Native_NominateMap);
pred@2133
   168
	CreateNative("InitiateMapChooserVote", Native_InitiateVote);
pred@2133
   169
	CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
pred@2133
   170
	CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
pred@2133
   171
	CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
pred@2133
   172
pred@2133
   173
	return true;
pred@2133
   174
}
pred@2133
   175
ds@1952
   176
public OnConfigsExecuted()
ds@1952
   177
{
ds@1952
   178
	if (ReadMapList(g_MapList,
ds@1952
   179
					 g_mapFileSerial, 
ds@1952
   180
					 "mapchooser",
ds@1952
   181
					 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
ds@1952
   182
		!= INVALID_HANDLE)
ds@1952
   183
		
ds@1952
   184
	{
ds@1952
   185
		if (g_mapFileSerial == -1)
ds@1952
   186
		{
ds@1952
   187
			LogError("Unable to create a valid map list.");
ds@1952
   188
		}
ds@1952
   189
	}
ds@1952
   190
	
ds@1952
   191
	CreateNextVote();
ds@1952
   192
	SetupTimeleftTimer();
ds@1952
   193
	
ds@1952
   194
	g_TotalRounds = 0;
ds@1952
   195
	
ds@1952
   196
	g_Extends = 0;
pred@2133
   197
	
pred@2133
   198
	g_MapVoteCompleted = false;
pred@2133
   199
	
pred@2133
   200
	g_NominateCount = 0;
pred@2133
   201
	ClearArray(g_NominateList);
pred@2133
   202
	ClearArray(g_NominateOwners);
pred@2133
   203
	
pred@2133
   204
	for (new i=0; i<MAXTEAMS; i++)
pred@2133
   205
	{
pred@2133
   206
		g_winCount[i] = 0;	
pred@2133
   207
	}
pred@2133
   208
	
pred@2133
   209
pred@2133
   210
	/* Check if mapchooser will attempt to start mapvote during bonus round time - TF2 Only */
pred@2133
   211
	if ((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
pred@2133
   212
	{
pred@2133
   213
		if (GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
pred@2133
   214
		{
pred@2133
   215
			LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
pred@2133
   216
		}
pred@2133
   217
	}
ds@1952
   218
}
ds@1952
   219
ds@1952
   220
public OnMapEnd()
ds@1952
   221
{
ds@1952
   222
	g_HasVoteStarted = false;
pred@2133
   223
	g_WaitingForVote = false;
ds@1952
   224
	
pred@2178
   225
	g_VoteTimer = INVALID_HANDLE;
pred@2178
   226
	g_RetryTimer = INVALID_HANDLE;
pred@2133
   227
	
pred@2133
   228
	decl String:map[32];
pred@2133
   229
	GetCurrentMap(map, sizeof(map));
pred@2133
   230
	PushArrayString(g_OldMapList, map);
pred@2133
   231
				
pred@2133
   232
	if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
pred@2133
   233
	{
pred@2133
   234
		RemoveFromArray(g_OldMapList, 0);
pred@2133
   235
	}	
pred@2133
   236
}
pred@2133
   237
pred@2133
   238
public OnClientDisconnect(client)
pred@2133
   239
{
pred@2133
   240
	new index = FindValueInArray(g_NominateOwners, client);
pred@2133
   241
	
pred@2133
   242
	if (index == -1)
pred@2133
   243
	{
pred@2133
   244
		return;
pred@2133
   245
	}
pred@2133
   246
	
pred@2133
   247
	new String:oldmap[33];
pred@2133
   248
	GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
pred@2133
   249
	Call_StartForward(g_NominationsResetForward);
pred@2133
   250
	Call_PushString(oldmap);
pred@2133
   251
	Call_PushCell(GetArrayCell(g_NominateOwners, index));
pred@2133
   252
	Call_Finish();
pred@2133
   253
	
pred@2133
   254
	RemoveFromArray(g_NominateOwners, index);
pred@2133
   255
	RemoveFromArray(g_NominateList, index);
pred@2133
   256
	g_NominateCount--;
pred@2133
   257
}
pred@2133
   258
pred@2133
   259
public EndVoteChanged(Handle:convar, const String:oldValue[], const String:newValue[])
pred@2133
   260
{
pred@2133
   261
	if (newValue[0] == '1')
pred@2133
   262
	{
pred@2133
   263
		SetNextMap("Pending Vote");
pred@2133
   264
	}
pred@2133
   265
	else
pred@2133
   266
	{
pred@2133
   267
		SetNextMap("");	
pred@2133
   268
	}
ds@1952
   269
}
ds@1952
   270
ds@1952
   271
public OnMapTimeLeftChanged()
ds@1952
   272
{
ds@1952
   273
	if (GetArraySize(g_MapList))
ds@1952
   274
	{
ds@1952
   275
		SetupTimeleftTimer();
ds@1952
   276
	}
ds@1952
   277
}
ds@1952
   278
ds@1952
   279
SetupTimeleftTimer()
ds@1952
   280
{
ds@1952
   281
	new time;
ds@1952
   282
	if (GetMapTimeLeft(time) && time > 0)
ds@1952
   283
	{
ds@1952
   284
		new startTime = GetConVarInt(g_Cvar_StartTime) * 60;
pred@2133
   285
		if (time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
ds@1952
   286
		{
pred@2133
   287
			InitiateVote(MapChange_MapEnd, INVALID_HANDLE);		
ds@1952
   288
		}
ds@1952
   289
		else
ds@1952
   290
		{
ds@1952
   291
			if (g_VoteTimer != INVALID_HANDLE)
ds@1952
   292
			{
ds@1952
   293
				KillTimer(g_VoteTimer);
ds@1952
   294
				g_VoteTimer = INVALID_HANDLE;
ds@1952
   295
			}	
ds@1952
   296
			
pred@2178
   297
			g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   298
		}		
ds@1952
   299
	}
ds@1952
   300
}
ds@1952
   301
ds@1952
   302
public Action:Timer_StartMapVote(Handle:timer)
ds@1952
   303
{
pred@2133
   304
	if (!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted)
ds@1952
   305
	{
ds@1952
   306
		return Plugin_Stop;
ds@1952
   307
	}		
ds@1952
   308
	
ds@1952
   309
	if (timer == g_RetryTimer)
ds@1952
   310
	{
ds@1952
   311
		g_RetryTimer = INVALID_HANDLE;
ds@1952
   312
	}
ds@1952
   313
	else
ds@1952
   314
	{
ds@1952
   315
		g_VoteTimer = INVALID_HANDLE;
ds@1952
   316
	}
pred@2133
   317
	
pred@2133
   318
	InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   319
ds@1952
   320
	return Plugin_Stop;
ds@1952
   321
}
ds@1952
   322
pred@2133
   323
public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast)
pred@2133
   324
{
pred@2133
   325
	/* Game got restarted - reset our round count tracking */
pred@2133
   326
	g_TotalRounds = 0;	
pred@2133
   327
}
pred@2133
   328
pred@2133
   329
public Event_TeamPlayWinPanel(Handle:event, const String:name[], bool:dontBroadcast)
pred@2032
   330
{
pred@2133
   331
	if (g_ChangeMapAtRoundEnd)
pred@2133
   332
	{
pred@2133
   333
		g_ChangeMapAtRoundEnd = false;
pred@2179
   334
		CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
pred@2133
   335
	}
pred@2133
   336
	
pred@2133
   337
	if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !GetConVarBool(g_Cvar_EndOfMapVote))
pred@2133
   338
	{
pred@2133
   339
		return;
pred@2133
   340
	}
pred@2133
   341
	
pred@2133
   342
	new bluescore = GetEventInt(event, "blue_score");
pred@2133
   343
	new redscore = GetEventInt(event, "red_score");
pred@2032
   344
	
pred@2133
   345
	if(GetEventInt(event, "round_complete") == 1)
pred@2133
   346
	{	
pred@2133
   347
		switch(GetEventInt(event, "winning_team"))
pred@2133
   348
		{
pred@2133
   349
			case TFTeam_Blue:
pred@2133
   350
			{
pred@2133
   351
				CheckWinLimit(bluescore);
pred@2133
   352
			}
pred@2133
   353
			case TFTeam_Red:
pred@2133
   354
			{
pred@2133
   355
				CheckWinLimit(redscore);				
pred@2133
   356
			}			
pred@2133
   357
			//We need to do nothing on winning_team == 0 this indicates stalemate.
pred@2133
   358
			default:
pred@2133
   359
			{
pred@2133
   360
				return;
pred@2133
   361
			}			
pred@2133
   362
		}
pred@2133
   363
		
pred@2133
   364
		g_TotalRounds++;
pred@2133
   365
		CheckMaxRounds(g_TotalRounds);
pred@2032
   366
	}
pred@2032
   367
}
ds@1952
   368
/* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */
ds@1952
   369
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   370
{
pred@2133
   371
	if (g_ChangeMapAtRoundEnd)
pred@2133
   372
	{
pred@2133
   373
		g_ChangeMapAtRoundEnd = false;
pred@2179
   374
		CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
pred@2133
   375
	}
pred@2133
   376
	
pred@2133
   377
	if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted)
ds@1952
   378
	{
ds@1952
   379
		return;
ds@1952
   380
	}
ds@1952
   381
ds@1952
   382
	new winner = GetEventInt(event, "winner");
ds@1952
   383
	
pred@2133
   384
	if (winner == 0 || winner == 1 || !GetConVarBool(g_Cvar_EndOfMapVote))
ds@1952
   385
	{
ds@1952
   386
		return;
ds@1952
   387
	}
pred@2133
   388
	
pred@2133
   389
	if (winner >= MAXTEAMS)
pred@2133
   390
	{
pred@2133
   391
		SetFailState("Mod exceed maximum team count - Please file a bug report.");	
pred@2133
   392
	}
ds@1952
   393
ds@1952
   394
	g_TotalRounds++;
ds@1952
   395
	
pred@2133
   396
	g_winCount[winner]++;
ds@1952
   397
	
pred@2133
   398
	CheckWinLimit(g_winCount[winner]);
pred@2133
   399
	CheckMaxRounds(g_TotalRounds);
pred@2133
   400
}
pred@2133
   401
pred@2133
   402
public CheckWinLimit(winner_score)
pred@2133
   403
{	
ds@1952
   404
	if (g_Cvar_Winlimit != INVALID_HANDLE)
ds@1952
   405
	{
ds@1952
   406
		new winlimit = GetConVarInt(g_Cvar_Winlimit);
ds@1952
   407
		if (winlimit)
pred@2133
   408
		{			
pred@2133
   409
			if (winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   410
			{
pred@2133
   411
				InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   412
			}
ds@1952
   413
		}
ds@1952
   414
	}
pred@2133
   415
}
pred@2133
   416
pred@2133
   417
public CheckMaxRounds(roundcount)
pred@2133
   418
{		
ds@1952
   419
	if (g_Cvar_Maxrounds != INVALID_HANDLE)
ds@1952
   420
	{
ds@1952
   421
		new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
ds@1952
   422
		if (maxrounds)
ds@1952
   423
		{
pred@2133
   424
			if (roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds)))
ds@1952
   425
			{
pred@2133
   426
				InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   427
			}			
ds@1952
   428
		}
ds@1952
   429
	}
ds@1952
   430
}
ds@1952
   431
ds@1952
   432
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952
   433
{
ds@1952
   434
	if (!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
ds@1952
   435
	{
ds@1952
   436
		return;
ds@1952
   437
	}
ds@1952
   438
	
pred@2133
   439
	if (!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
ds@1952
   440
	{
ds@1952
   441
		return;
ds@1952
   442
	}
ds@1952
   443
ds@1952
   444
	new fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
ds@1952
   445
	if (fragger && GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
ds@1952
   446
	{
pred@2133
   447
		InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   448
	}
ds@1952
   449
}
ds@1952
   450
ds@1952
   451
public Action:Command_Mapvote(client, args)
ds@1952
   452
{
pred@2133
   453
	InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
ds@1952
   454
ds@1952
   455
	return Plugin_Handled;	
ds@1952
   456
}
ds@1952
   457
pred@2133
   458
InitiateVote(MapChange:when, Handle:inputlist)
ds@1952
   459
{
pred@2133
   460
	if (!CanVoteStart())
ds@1952
   461
	{
ds@1952
   462
		return;
ds@1952
   463
	}
ds@1952
   464
	
pred@2133
   465
	g_WaitingForVote = true;
pred@2133
   466
	
ds@1952
   467
	if (IsVoteInProgress())
ds@1952
   468
	{
ds@1952
   469
		// Can't start a vote, try again in 5 seconds.
pred@2178
   470
		g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
ds@1952
   471
		return;
pred@2133
   472
	}
ds@1952
   473
	
pred@2133
   474
	g_ChangeTime = when;
pred@2133
   475
	
pred@2133
   476
	g_WaitingForVote = false;
pred@2133
   477
		
ds@1952
   478
	g_HasVoteStarted = true;
ds@1952
   479
	g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
ds@1952
   480
	SetMenuTitle(g_VoteMenu, "Vote Nextmap");
pred@2133
   481
	SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished);
pred@2133
   482
	
pred@2133
   483
	/**
pred@2133
   484
	 * TODO: Make a proper decision on when to clear the nominations list.
pred@2133
   485
	 * Currently it clears when used, and stays if an external list is provided.
pred@2133
   486
	 * Is this the right thing to do? External lists will probably come from places
pred@2133
   487
	 * like sm_mapvote from the adminmenu in the future.
pred@2133
   488
	 */
pred@2133
   489
	 
ds@1952
   490
	decl String:map[32];
pred@2133
   491
	
pred@2133
   492
	/* No input given - User our internal nominations and maplist */
pred@2133
   493
	if (inputlist == INVALID_HANDLE)
ds@1952
   494
	{
pred@2133
   495
		new nominateCount = GetArraySize(g_NominateList);
pred@2133
   496
		new voteSize = GetConVarInt(g_Cvar_IncludeMaps);
pred@2133
   497
		
pred@2133
   498
		/* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
pred@2133
   499
		new nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
pred@2133
   500
		
pred@2133
   501
		
pred@2133
   502
		for (new i=0; i<nominationsToAdd; i++)
pred@2133
   503
		{
pred@2133
   504
			GetArrayString(g_NominateList, i, map, sizeof(map));
pred@2133
   505
			AddMenuItem(g_VoteMenu, map, map);
pred@2133
   506
			
pred@2133
   507
			/* Notify Nominations that this map is now free */
pred@2133
   508
			Call_StartForward(g_NominationsResetForward);
pred@2133
   509
			Call_PushString(map);
pred@2133
   510
			Call_PushCell(GetArrayCell(g_NominateOwners, i));
pred@2133
   511
			Call_Finish();
pred@2133
   512
		}
pred@2133
   513
		
pred@2133
   514
		/* Clear out the rest of the nominations array */
pred@2133
   515
		for (new i=nominationsToAdd; i<nominateCount; i++)
pred@2133
   516
		{
pred@2133
   517
			GetArrayString(g_NominateList, i, map, sizeof(map));
pred@2133
   518
			
pred@2133
   519
			/* Notify Nominations that this map is now free */
pred@2133
   520
			Call_StartForward(g_NominationsResetForward);
pred@2133
   521
			Call_PushString(map);
pred@2133
   522
			Call_PushCell(GetArrayCell(g_NominateOwners, i));
pred@2133
   523
			Call_Finish();			
pred@2133
   524
		}
pred@2133
   525
		
pred@2133
   526
		/* There should currently be 'nominationsToAdd' unique maps in the vote */
pred@2133
   527
		
pred@2133
   528
		new i = nominationsToAdd;
pred@2133
   529
		new count = 0;
pred@2133
   530
		new availableMaps = GetArraySize(g_NextMapList);
pred@2133
   531
		
pred@2133
   532
		while (i < voteSize)
pred@2133
   533
		{
pred@2133
   534
			GetArrayString(g_NextMapList, count, map, sizeof(map));
pred@2133
   535
			count++;
pred@2133
   536
			
pred@2133
   537
			//Check if this map is in the nominate list (and thus already in the vote) */
pred@2133
   538
			if (FindStringInArray(g_NominateList, map) == -1)
pred@2133
   539
			{
pred@2133
   540
				/* Insert the map and increment our count */
pred@2133
   541
				AddMenuItem(g_VoteMenu, map, map);
pred@2133
   542
				i++;
pred@2133
   543
			}
pred@2133
   544
			
pred@2133
   545
			if (count >= availableMaps)
pred@2133
   546
			{
pred@2133
   547
				//Run out of maps, this will have to do.
pred@2133
   548
				break;	
pred@2133
   549
			}
pred@2133
   550
		}
pred@2133
   551
		
pred@2133
   552
		/* Wipe out our nominations list - Nominations have already been informed of this */
pred@2133
   553
		ClearArray(g_NominateOwners);
pred@2133
   554
		ClearArray(g_NominateList);
ds@1952
   555
	}
pred@2133
   556
	else //We were given a list of maps to start the vote with
pred@2133
   557
	{
pred@2133
   558
		new size = GetArraySize(inputlist);
pred@2133
   559
		
pred@2133
   560
		for (new i=0; i<size; i++)
pred@2133
   561
		{
pred@2133
   562
			GetArrayString(inputlist, i, map, sizeof(map));
pred@2133
   563
			
pred@2133
   564
			if (IsMapValid(map))
pred@2133
   565
			{
pred@2133
   566
				AddMenuItem(g_VoteMenu, map, map);
pred@2133
   567
			}	
pred@2133
   568
		}
pred@2133
   569
	}
pred@2133
   570
	
pred@2133
   571
	/* Do we add any special items? */
pred@2133
   572
	if ((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
pred@2133
   573
	{
pred@2133
   574
		AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
pred@2133
   575
	}
pred@2133
   576
	else if (GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
ds@1952
   577
	{
ds@1952
   578
		AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map");
ds@1952
   579
	}
pred@2133
   580
	
pred@2133
   581
	new voteDuration = GetConVarInt(g_Cvar_VoteDuration);
ds@1952
   582
ds@1952
   583
	SetMenuExitButton(g_VoteMenu, false);
pred@2133
   584
	VoteMenuToAll(g_VoteMenu, voteDuration);
ds@1952
   585
ds@1952
   586
	LogMessage("Voting for next map has started.");
ds@1952
   587
	PrintToChatAll("[SM] %t", "Nextmap Voting Started");
ds@1952
   588
}
ds@1952
   589
pred@2133
   590
public Handler_MapVoteFinished(Handle:menu,
pred@2133
   591
						   num_votes, 
pred@2133
   592
						   num_clients,
pred@2133
   593
						   const client_info[][2], 
pred@2133
   594
						   num_items,
pred@2133
   595
						   const item_info[][2])
pred@2133
   596
{
pred@2133
   597
	if (num_votes == 0)
pred@2133
   598
	{
pred@2133
   599
		LogError("No Votes recorded yet Advanced callback fired - Tell pRED* to fix this");
pred@2133
   600
		return;	
pred@2133
   601
	}
pred@2133
   602
	
pred@2133
   603
	decl String:map[32];
pred@2133
   604
	GetMenuItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map));
pred@2133
   605
pred@2133
   606
	if (strcmp(map, VOTE_EXTEND, false) == 0)
pred@2133
   607
	{
pred@2133
   608
		g_Extends++;
pred@2133
   609
		
pred@2133
   610
		new time;
pred@2133
   611
		if (GetMapTimeLimit(time))
pred@2133
   612
		{
pred@2133
   613
			if (time > 0)
pred@2133
   614
			{
pred@2133
   615
				ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);						
pred@2133
   616
			}
pred@2133
   617
		}
pred@2133
   618
		
pred@2133
   619
		if (g_Cvar_Winlimit != INVALID_HANDLE)
pred@2133
   620
		{
pred@2133
   621
			new winlimit = GetConVarInt(g_Cvar_Winlimit);
pred@2133
   622
			if (winlimit)
pred@2133
   623
			{
pred@2133
   624
				SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
pred@2133
   625
			}					
pred@2133
   626
		}
pred@2133
   627
		
pred@2133
   628
		if (g_Cvar_Maxrounds != INVALID_HANDLE)
pred@2133
   629
		{
pred@2133
   630
			new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
pred@2133
   631
			if (maxrounds)
pred@2133
   632
			{
pred@2133
   633
				SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
pred@2133
   634
			}
pred@2133
   635
		}
pred@2133
   636
		
pred@2133
   637
		if (g_Cvar_Fraglimit != INVALID_HANDLE)
pred@2133
   638
		{
pred@2133
   639
			new fraglimit = GetConVarInt(g_Cvar_Fraglimit);
pred@2133
   640
			if (fraglimit)
pred@2133
   641
			{
pred@2133
   642
				SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));						
pred@2133
   643
			}
pred@2133
   644
		}
pred@2133
   645
pred@2133
   646
		PrintToChatAll("[SM] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   647
		LogMessage("Voting for next map has finished. The current map has been extended.");
pred@2133
   648
		
pred@2133
   649
		// We extended, so we'll have to vote again.
pred@2133
   650
		g_HasVoteStarted = false;
pred@2133
   651
		CreateNextVote();
pred@2133
   652
		SetupTimeleftTimer();
pred@2133
   653
		
pred@2133
   654
	}
pred@2133
   655
	else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
pred@2133
   656
	{
pred@2133
   657
		PrintToChatAll("[SM] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   658
		LogMessage("Voting for next map has finished. 'No Change' was the winner");
pred@2133
   659
		
pred@2133
   660
		g_HasVoteStarted = false;
pred@2133
   661
		CreateNextVote();
pred@2133
   662
		SetupTimeleftTimer();
pred@2133
   663
	}
pred@2133
   664
	else
pred@2133
   665
	{
pred@2133
   666
		if (g_ChangeTime == MapChange_MapEnd)
pred@2133
   667
		{
pred@2133
   668
			SetNextMap(map);
pred@2133
   669
		}
pred@2133
   670
		else if (g_ChangeTime == MapChange_Instant)
pred@2133
   671
		{
pred@2133
   672
			new Handle:data;
pred@2133
   673
			CreateDataTimer(2.0, Timer_ChangeMap, data);
pred@2133
   674
			WritePackString(data, map);
pred@2133
   675
		}
pred@2133
   676
		else // MapChange_RoundEnd
pred@2133
   677
		{
pred@2133
   678
			SetNextMap(map);
pred@2133
   679
			g_ChangeMapAtRoundEnd = true;
pred@2133
   680
		}
pred@2133
   681
		
pred@2133
   682
		g_HasVoteStarted = false;
pred@2133
   683
		g_MapVoteCompleted = true;
pred@2133
   684
		
pred@2133
   685
		PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100), num_votes);
pred@2133
   686
		LogMessage("Voting for next map has finished. Nextmap: %s.", map);
pred@2133
   687
	}	
pred@2133
   688
}
pred@2133
   689
ds@1952
   690
public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   691
{
ds@1952
   692
	switch (action)
ds@1952
   693
	{
ds@1952
   694
		case MenuAction_End:
ds@1952
   695
		{
ds@1952
   696
			g_VoteMenu = INVALID_HANDLE;
ds@1952
   697
			CloseHandle(menu);
ds@1952
   698
		}
ds@1952
   699
		
ds@1952
   700
		case MenuAction_Display:
ds@1952
   701
		{
ds@1952
   702
	 		decl String:buffer[255];
ds@1952
   703
			Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1);
ds@1952
   704
ds@1952
   705
			new Handle:panel = Handle:param2;
ds@1952
   706
			SetPanelTitle(panel, buffer);
ds@1952
   707
		}		
ds@1952
   708
		
ds@1952
   709
		case MenuAction_DisplayItem:
ds@1952
   710
		{
ds@1952
   711
			if (GetMenuItemCount(menu) - 1 == param2)
ds@1952
   712
			{
ds@1952
   713
				decl String:map[64], String:buffer[255];
ds@1952
   714
				GetMenuItem(menu, param2, map, sizeof(map));
ds@1952
   715
				if (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   716
				{
ds@1952
   717
					Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
ds@1952
   718
					return RedrawMenuItem(buffer);
ds@1952
   719
				}
pred@2133
   720
				else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
pred@2133
   721
				{
pred@2133
   722
					Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
pred@2133
   723
					return RedrawMenuItem(buffer);					
pred@2133
   724
				}
ds@1952
   725
			}
ds@1952
   726
		}		
pred@2133
   727
	
ds@1952
   728
		case MenuAction_VoteCancel:
ds@1952
   729
		{
ds@1952
   730
			// If we receive 0 votes, pick at random.
ds@1952
   731
			if (param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode))
ds@1952
   732
			{
ds@1952
   733
				new count = GetMenuItemCount(menu);
ds@1952
   734
				new item = GetRandomInt(0, count - 1);
ds@1952
   735
				decl String:map[32];
ds@1952
   736
				GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   737
				
ds@1952
   738
				while (strcmp(map, VOTE_EXTEND, false) == 0)
ds@1952
   739
				{
ds@1952
   740
					item = GetRandomInt(0, count - 1);
ds@1952
   741
					GetMenuItem(menu, item, map, sizeof(map));
ds@1952
   742
				}
ds@1952
   743
				
ds@1952
   744
				SetNextMap(map);			
ds@1952
   745
			}
ds@1952
   746
			else
ds@1952
   747
			{
ds@1952
   748
				// We were actually cancelled. What should we do?
ds@1952
   749
				g_HasVoteStarted = false;
ds@1952
   750
				CreateNextVote();
ds@1952
   751
				SetupTimeleftTimer();
ds@1952
   752
			}
ds@1952
   753
		}
ds@1952
   754
	}
ds@1952
   755
	
ds@1952
   756
	return 0;
ds@1952
   757
}
ds@1952
   758
pred@2133
   759
public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
ds@1952
   760
{
pred@2133
   761
	new String:map[65];
pred@2133
   762
	
pred@2133
   763
	if (dp == INVALID_HANDLE)
ds@1952
   764
	{
pred@2133
   765
		if (!GetNextMap(map, sizeof(map)))
pred@2133
   766
		{
pred@2133
   767
			//No passed map and no set nextmap. fail!
pred@2133
   768
			return Plugin_Stop;	
pred@2133
   769
		}
ds@1952
   770
	}
pred@2133
   771
	else
pred@2133
   772
	{
pred@2133
   773
		ResetPack(dp);
pred@2133
   774
		ReadPackString(dp, map, sizeof(map));		
pred@2133
   775
	}
pred@2133
   776
	
pred@2133
   777
	ServerCommand("changelevel \"%s\"", map);
pred@2133
   778
	
pred@2133
   779
	return Plugin_Stop;
ds@1952
   780
}
ds@1952
   781
ds@1952
   782
CreateNextVote()
ds@1952
   783
{
ds@1952
   784
	if(g_NextMapList != INVALID_HANDLE)
ds@1952
   785
	{
ds@1952
   786
		ClearArray(g_NextMapList);
ds@1952
   787
	}
ds@1952
   788
	
ds@1952
   789
	decl String:map[32];
ds@1952
   790
	new index, Handle:tempMaps  = CloneArray(g_MapList);
ds@1952
   791
	
ds@1952
   792
	GetCurrentMap(map, sizeof(map));
ds@1952
   793
	index = FindStringInArray(tempMaps, map);
ds@1952
   794
	if (index != -1)
ds@1952
   795
	{
ds@1952
   796
		RemoveFromArray(tempMaps, index);
ds@1952
   797
	}	
ds@1952
   798
	
ds@1952
   799
	if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
ds@1952
   800
	{
ds@1952
   801
		for (new i = 0; i < GetArraySize(g_OldMapList); i++)
ds@1952
   802
		{
ds@1952
   803
			GetArrayString(g_OldMapList, i, map, sizeof(map));
ds@1952
   804
			index = FindStringInArray(tempMaps, map);
ds@1952
   805
			if (index != -1)
ds@1952
   806
			{
ds@1952
   807
				RemoveFromArray(tempMaps, index);
ds@1952
   808
			}
ds@1952
   809
		}	
ds@1952
   810
	}
ds@1952
   811
ds@1952
   812
	new limit = (GetConVarInt(g_Cvar_IncludeMaps) < GetArraySize(tempMaps) ? GetConVarInt(g_Cvar_IncludeMaps) : GetArraySize(tempMaps));
ds@1952
   813
	for (new i = 0; i < limit; i++)
ds@1952
   814
	{
ds@1952
   815
		new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
ds@1952
   816
		GetArrayString(tempMaps, b, map, sizeof(map));		
ds@1952
   817
		PushArrayString(g_NextMapList, map);
ds@1952
   818
		RemoveFromArray(tempMaps, b);
ds@1952
   819
	}
ds@1952
   820
	
ds@1952
   821
	CloseHandle(tempMaps);
pred@2133
   822
}
pred@2133
   823
pred@2133
   824
bool:CanVoteStart()
pred@2133
   825
{
pred@2133
   826
	if (g_WaitingForVote || g_HasVoteStarted)
pred@2133
   827
	{
pred@2133
   828
		return false;	
pred@2133
   829
	}
pred@2133
   830
	
pred@2133
   831
	return true;
pred@2133
   832
}
pred@2133
   833
pred@2133
   834
NominateResult:InternalNominateMap(String:map[], bool:force, owner)
pred@2133
   835
{
pred@2133
   836
	if (!IsMapValid(map))
pred@2133
   837
	{
pred@2133
   838
		return Nominate_InvalidMap;
pred@2133
   839
	}
pred@2133
   840
	
pred@2133
   841
	new index;
pred@2133
   842
pred@2133
   843
	if ((index = FindValueInArray(g_NominateOwners, owner)) != -1)
pred@2133
   844
	{
pred@2133
   845
		new String:oldmap[33];
pred@2133
   846
		GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap));
pred@2133
   847
		Call_StartForward(g_NominationsResetForward);
pred@2133
   848
		Call_PushString(oldmap);
pred@2133
   849
		Call_PushCell(owner);
pred@2133
   850
		Call_Finish();
pred@2133
   851
		
pred@2133
   852
		
pred@2133
   853
		SetArrayString(g_NominateList, index, map);
pred@2133
   854
		return Nominate_Replaced;
pred@2133
   855
	}
pred@2133
   856
	
pred@2133
   857
	/* Too many nominated maps. */
pred@2133
   858
	if (g_NominateCount >= GetConVarInt(g_Cvar_IncludeMaps) && !force)
pred@2133
   859
	{
pred@2133
   860
		return Nominate_VoteFull;
pred@2133
   861
	}
pred@2133
   862
	
pred@2133
   863
	/* Map already in the vote */
pred@2133
   864
	if (FindStringInArray(g_NominateList, map) != -1)
pred@2133
   865
	{
pred@2133
   866
		return Nominate_AlreadyInVote;	
pred@2133
   867
	}
pred@2133
   868
	
pred@2133
   869
	
pred@2133
   870
	PushArrayString(g_NominateList, map);
pred@2133
   871
	PushArrayCell(g_NominateOwners, owner);
pred@2133
   872
	g_NominateCount++;
pred@2133
   873
	
pred@2133
   874
	while (GetArraySize(g_NominateList) > GetConVarInt(g_Cvar_IncludeMaps))
pred@2133
   875
	{
pred@2133
   876
		new String:oldmap[33];
pred@2133
   877
		GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap));
pred@2133
   878
		Call_StartForward(g_NominationsResetForward);
pred@2133
   879
		Call_PushString(oldmap);
pred@2133
   880
		Call_PushCell(GetArrayCell(g_NominateOwners, 0));
pred@2133
   881
		Call_Finish();
pred@2133
   882
		
pred@2133
   883
		RemoveFromArray(g_NominateList, 0);
pred@2133
   884
		RemoveFromArray(g_NominateOwners, 0);
pred@2133
   885
	}
pred@2133
   886
	
pred@2133
   887
	return Nominate_Added;
pred@2133
   888
}
pred@2133
   889
pred@2133
   890
/* Add natives to allow nominate and initiate vote to be call */
pred@2133
   891
pred@2133
   892
/* native  bool:NominateMap(const String:map[], bool:force, &NominateError:error); */
pred@2133
   893
public Native_NominateMap(Handle:plugin, numParams)
pred@2133
   894
{
pred@2133
   895
	new len;
pred@2133
   896
	GetNativeStringLength(1, len);
pred@2133
   897
	
pred@2133
   898
	if (len <= 0)
pred@2133
   899
	{
pred@2133
   900
	  return false;
pred@2133
   901
	}
pred@2133
   902
	
pred@2133
   903
	new String:map[len+1];
pred@2133
   904
	GetNativeString(1, map, len+1);
pred@2133
   905
	
pred@2133
   906
	return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3));
pred@2133
   907
}
pred@2133
   908
pred@2133
   909
/* native InitiateMapChooserVote(); */
pred@2133
   910
public Native_InitiateVote(Handle:plugin, numParams)
pred@2133
   911
{
pred@2133
   912
	new MapChange:when = MapChange:GetNativeCell(1);
pred@2133
   913
	new Handle:inputarray = Handle:GetNativeCell(2);
pred@2133
   914
	
pred@2133
   915
	LogMessage("Starting map vote because outside request");
pred@2133
   916
	InitiateVote(when, inputarray);
pred@2133
   917
}
pred@2133
   918
pred@2133
   919
public Native_CanVoteStart(Handle:plugin, numParams)
pred@2133
   920
{
pred@2133
   921
	return CanVoteStart();	
pred@2133
   922
}
pred@2133
   923
pred@2133
   924
public Native_CheckVoteDone(Handle:plugin, numParams)
pred@2133
   925
{
pred@2133
   926
	return g_MapVoteCompleted;
pred@2133
   927
}
pred@2133
   928
pred@2133
   929
public Native_GetExcludeMapList(Handle:plugin, numParams)
pred@2133
   930
{
pred@2133
   931
	new Handle:array = Handle:GetNativeCell(1);
pred@2133
   932
	
pred@2133
   933
	if (array == INVALID_HANDLE)
pred@2133
   934
	{
pred@2133
   935
		return;	
pred@2133
   936
	}
pred@2133
   937
	
pred@2133
   938
	
pred@2133
   939
	new size = GetArraySize(g_OldMapList);
pred@2133
   940
	decl String:map[33];
pred@2133
   941
	
pred@2133
   942
	for (new i=0; i<size; i++)
pred@2133
   943
	{
pred@2133
   944
		GetArrayString(g_OldMapList, i, map, sizeof(map));
pred@2133
   945
		PushArrayString(array, map);	
pred@2133
   946
	}
pred@2133
   947
	
pred@2133
   948
	return;
ds@1952
   949
}