From 987c6438384954e17426262ee76726ddc8a647b0 Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 27 Jan 2023 21:07:48 +0100 Subject: [PATCH] rehawl of mapchooser so clients can have multiple nominations where the maps with most nominations get into the vote --- .../scripting/mapchooser_extended.sp | 1659 +++++++++-------- .../scripting/nominations_extended.sp | 774 ++++---- 2 files changed, 1288 insertions(+), 1145 deletions(-) mode change 100644 => 100755 mapchooser_extended/scripting/mapchooser_extended.sp mode change 100644 => 100755 mapchooser_extended/scripting/nominations_extended.sp diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp old mode 100644 new mode 100755 index 9e8f4b8..f2a8a9a --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -92,8 +92,6 @@ ConVar g_Cvar_Winlimit; ConVar g_Cvar_Maxrounds; ConVar g_Cvar_Fraglimit; ConVar g_Cvar_Bonusroundtime; -ConVar g_Cvar_MatchClinch; -ConVar g_Cvar_VoteNextLevel; ConVar g_Cvar_GameType; ConVar g_Cvar_GameMode; @@ -120,7 +118,7 @@ Handle g_WarningTimer = INVALID_HANDLE; /* Data Handles */ Handle g_MapList = INVALID_HANDLE; -Handle g_NominateList = INVALID_HANDLE; +Handle g_NominateList[MAXPLAYERS + 1]; Handle g_NominateOwners = INVALID_HANDLE; StringMap g_OldMapList; StringMap g_TimeMapList; @@ -215,173 +213,188 @@ enum WarningType #define LINE_SPACER "##linespacer##" #define FAILURE_TIMER_LENGTH 5 +//call forward to reset all nominations +public void OnPluginEnd() +{ + for (int i = 0; i < MaxClients; i++) + { + int index = FindValueInArray(g_NominateOwners, i); + if (index == -1) continue; + for (int j = 0; j < GetArraySize(g_NominateList[i]); j++) + { + char oldmap[PLATFORM_MAX_PATH]; + Call_StartForward(g_NominationsResetForward); + GetArrayString(g_NominateList[i], j, oldmap, PLATFORM_MAX_PATH); + Call_PushString(oldmap); + Call_PushCell(GetArrayCell(g_NominateOwners, index)); + Call_Finish(); + } + } +} + public void OnPluginStart() { - LoadTranslations("mapchooser_extended.phrases"); - LoadTranslations("basevotes.phrases"); - LoadTranslations("common.phrases"); + LoadTranslations("mapchooser_extended.phrases"); + LoadTranslations("basevotes.phrases"); + LoadTranslations("common.phrases"); - int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); - g_MapList = CreateArray(arraySize); - g_NominateList = CreateArray(arraySize); - g_NominateOwners = CreateArray(1); - g_OldMapList = new StringMap(); - g_TimeMapList = new StringMap(); - g_NextMapList = CreateArray(arraySize); - g_OfficialList = CreateArray(arraySize); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + g_MapList = CreateArray(arraySize); + g_NominateOwners = CreateArray(1); + g_OldMapList = new StringMap(); + g_TimeMapList = new StringMap(); + g_NextMapList = CreateArray(arraySize); + g_OfficialList = CreateArray(arraySize); - GetGameFolderName(g_GameModName, sizeof(g_GameModName)); + for (int i = 0; i < MaxClients; i++) + { + g_NominateList[i] = CreateArray(arraySize); + } - g_Cvar_EndOfMapVote = CreateConVar("mce_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0); + GetGameFolderName(g_GameModName, sizeof(g_GameModName)); - g_Cvar_StartTime = CreateConVar("mce_starttime", "10.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0); - g_Cvar_StartRounds = CreateConVar("mce_startround", "2.0", "Specifies when to start the vote based on rounds remaining. Use 0 on DoD:S, CS:S, and TF2 to start vote during bonus round time", _, true, 0.0); - g_Cvar_StartFrags = CreateConVar("mce_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0); - g_Cvar_ExtendTimeStep = CreateConVar("mce_extend_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0); - g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0); - g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); - g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); - g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5h", "Specifies how long in minutes an old map is excluded from the vote."); - g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0); - g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0); - g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); - g_Cvar_Extend = CreateConVar("mce_extend", "0", "Number of extensions allowed each map.", _, true, 0.0); - g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0); - g_Cvar_VoteDuration = CreateConVar("mce_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0); + g_Cvar_EndOfMapVote = CreateConVar("mce_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0); - // MapChooser Extended cvars - CreateConVar("mce_version", MCE_VERSION, "MapChooser Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); + g_Cvar_StartTime = CreateConVar("mce_starttime", "10.0", "Specifies when to start the vote based on time remaining.", _, true, 1.0); + g_Cvar_StartRounds = CreateConVar("mce_startround", "2.0", "Specifies when to start the vote based on rounds remaining. Use 0 on DoD:S, CS:S, and TF2 to start vote during bonus round time", _, true, 0.0); + g_Cvar_StartFrags = CreateConVar("mce_startfrags", "5.0", "Specifies when to start the vote base on frags remaining.", _, true, 1.0); + g_Cvar_ExtendTimeStep = CreateConVar("mce_extend_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0); + g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0); + g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); + g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); + g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5h", "Specifies how long in minutes an old map is excluded from the vote."); + g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0); + g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0); + g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); + g_Cvar_Extend = CreateConVar("mce_extend", "0", "Number of extensions allowed each map.", _, true, 0.0); + g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change option should be added to early votes", _, true, 0.0); + g_Cvar_VoteDuration = CreateConVar("mce_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0); - g_Cvar_RunOff = CreateConVar("mce_runoff", "1", "Hold run off votes if winning choice has less than a certain percentage of votes", _, true, 0.0, true, 1.0); - g_Cvar_RunOffPercent = CreateConVar("mce_runoffpercent", "50", "If winning choice has less than this percent of votes, hold a runoff", _, true, 0.0, true, 100.0); - g_Cvar_BlockSlots = CreateConVar("mce_blockslots", "0", "Block slots to prevent accidental votes. Only applies when Voice Command style menus are in use.", _, true, 0.0, true, 1.0); - //g_Cvar_BlockSlotsCount = CreateConVar("mce_blockslots_count", "2", "Number of slots to block.", _, true, 1.0, true, 3.0); - g_Cvar_MaxRunOffs = CreateConVar("mce_maxrunoffs", "1", "Number of run off votes allowed each map.", _, true, 0.0); - g_Cvar_StartTimePercent = CreateConVar("mce_start_percent", "35.0", "Specifies when to start the vote based on percents.", _, true, 0.0, true, 100.0); - g_Cvar_StartTimePercentEnable = CreateConVar("mce_start_percent_enable", "0", "Enable or Disable percentage calculations when to start vote.", _, true, 0.0, true, 1.0); - g_Cvar_WarningTime = CreateConVar("mce_warningtime", "15.0", "Warning time in seconds.", _, true, 0.0, true, 60.0); - g_Cvar_RunOffWarningTime = CreateConVar("mce_runoffvotewarningtime", "5.0", "Warning time for runoff vote in seconds.", _, true, 0.0, true, 30.0); - g_Cvar_TimerLocation = CreateConVar("mce_warningtimerlocation", "0", "Location for the warning timer text. 0 is HintBox, 1 is Center text, 2 is Chat. Defaults to HintBox.", _, true, 0.0, true, 2.0); - g_Cvar_MarkCustomMaps = CreateConVar("mce_markcustommaps", "1", "Mark custom maps in the vote list. 0 = Disabled, 1 = Mark with *, 2 = Mark with phrase.", _, true, 0.0, true, 2.0); - g_Cvar_ExtendPosition = CreateConVar("mce_extendposition", "0", "Position of Extend/Don't Change options. 0 = at end, 1 = at start.", _, true, 0.0, true, 1.0); - g_Cvar_RandomizeNominations = CreateConVar("mce_randomizeorder", "0", "Randomize map order?", _, true, 0.0, true, 1.0); - g_Cvar_HideTimer = CreateConVar("mce_hidetimer", "0", "Hide the MapChooser Extended warning timer", _, true, 0.0, true, 1.0); - g_Cvar_NoVoteOption = CreateConVar("mce_addnovote", "1", "Add \"No Vote\" to vote menu?", _, true, 0.0, true, 1.0); - g_Cvar_ShufflePerClient = CreateConVar("mce_shuffle_per_client", "1", "Random shuffle map vote menu per client?", _, true, 0.0, true, 1.0); - g_Cvar_NoRestrictionTimeframeEnable = CreateConVar("mce_no_restriction_timeframe_enable", "1", "Enable timeframe where all nomination restrictions and cooldowns are disabled?", _, true, 0.0, true, 1.0); - g_Cvar_NoRestrictionTimeframeMinTime = CreateConVar("mce_no_restriction_timeframe_mintime", "0100", "Start of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0); - g_Cvar_NoRestrictionTimeframeMaxTime = CreateConVar("mce_no_restriction_timeframe_maxtime", "0700", "End of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0); + // MapChooser Extended cvars + CreateConVar("mce_version", MCE_VERSION, "MapChooser Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); - RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now."); - RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap "); + g_Cvar_RunOff = CreateConVar("mce_runoff", "1", "Hold run off votes if winning choice has less than a certain percentage of votes", _, true, 0.0, true, 1.0); + g_Cvar_RunOffPercent = CreateConVar("mce_runoffpercent", "50", "If winning choice has less than this percent of votes, hold a runoff", _, true, 0.0, true, 100.0); + g_Cvar_BlockSlots = CreateConVar("mce_blockslots", "0", "Block slots to prevent accidental votes. Only applies when Voice Command style menus are in use.", _, true, 0.0, true, 1.0); + //g_Cvar_BlockSlotsCount = CreateConVar("mce_blockslots_count", "2", "Number of slots to block.", _, true, 1.0, true, 3.0); + g_Cvar_MaxRunOffs = CreateConVar("mce_maxrunoffs", "1", "Number of run off votes allowed each map.", _, true, 0.0); + g_Cvar_StartTimePercent = CreateConVar("mce_start_percent", "35.0", "Specifies when to start the vote based on percents.", _, true, 0.0, true, 100.0); + g_Cvar_StartTimePercentEnable = CreateConVar("mce_start_percent_enable", "0", "Enable or Disable percentage calculations when to start vote.", _, true, 0.0, true, 1.0); + g_Cvar_WarningTime = CreateConVar("mce_warningtime", "15.0", "Warning time in seconds.", _, true, 0.0, true, 60.0); + g_Cvar_RunOffWarningTime = CreateConVar("mce_runoffvotewarningtime", "5.0", "Warning time for runoff vote in seconds.", _, true, 0.0, true, 30.0); + g_Cvar_TimerLocation = CreateConVar("mce_warningtimerlocation", "0", "Location for the warning timer text. 0 is HintBox, 1 is Center text, 2 is Chat. Defaults to HintBox.", _, true, 0.0, true, 2.0); + g_Cvar_MarkCustomMaps = CreateConVar("mce_markcustommaps", "1", "Mark custom maps in the vote list. 0 = Disabled, 1 = Mark with *, 2 = Mark with phrase.", _, true, 0.0, true, 2.0); + g_Cvar_ExtendPosition = CreateConVar("mce_extendposition", "0", "Position of Extend/Dont Change options. 0 = at end, 1 = at start.", _, true, 0.0, true, 1.0); + g_Cvar_RandomizeNominations = CreateConVar("mce_randomizeorder", "0", "Randomize map order?", _, true, 0.0, true, 1.0); + g_Cvar_HideTimer = CreateConVar("mce_hidetimer", "0", "Hide the MapChooser Extended warning timer", _, true, 0.0, true, 1.0); + g_Cvar_NoVoteOption = CreateConVar("mce_addnovote", "1", "Add \"No Vote\" to vote menu?", _, true, 0.0, true, 1.0); + g_Cvar_ShufflePerClient = CreateConVar("mce_shuffle_per_client", "1", "Random shuffle map vote menu per client?", _, true, 0.0, true, 1.0); + g_Cvar_NoRestrictionTimeframeEnable = CreateConVar("mce_no_restriction_timeframe_enable", "1", "Enable timeframe where all nomination restrictions and cooldowns are disabled?", _, true, 0.0, true, 1.0); + g_Cvar_NoRestrictionTimeframeMinTime = CreateConVar("mce_no_restriction_timeframe_mintime", "0100", "Start of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0); + g_Cvar_NoRestrictionTimeframeMaxTime = CreateConVar("mce_no_restriction_timeframe_maxtime", "0700", "End of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0); - // Mapchooser Extended Commands - RegAdminCmd("mce_reload_maplist", Command_ReloadMaps, ADMFLAG_CHANGEMAP, "mce_reload_maplist - Reload the Official Maplist file."); + RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now."); + RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap "); - RegConsoleCmd("sm_extends", Command_ExtendsLeft, "sm_extends - Shows how many extends are left on the current map."); - RegConsoleCmd("sm_extendsleft", Command_ExtendsLeft, "sm_extendsleft - Shows how many extends are left on the current map."); + // Mapchooser Extended Commands + RegAdminCmd("mce_reload_maplist", Command_ReloadMaps, ADMFLAG_CHANGEMAP, "mce_reload_maplist - Reload the Official Maplist file."); - g_Cvar_Winlimit = FindConVar("mp_winlimit"); - g_Cvar_Maxrounds = FindConVar("mp_maxrounds"); - g_Cvar_Fraglimit = FindConVar("mp_fraglimit"); + RegConsoleCmd("sm_extends", Command_ExtendsLeft, "sm_extends - Shows how many extends are left on the current map."); + RegConsoleCmd("sm_extendsleft", Command_ExtendsLeft, "sm_extendsleft - Shows how many extends are left on the current map."); - EngineVersion version = GetEngineVersion(); + g_Cvar_Winlimit = FindConVar("mp_winlimit"); + g_Cvar_Maxrounds = FindConVar("mp_maxrounds"); + g_Cvar_Fraglimit = FindConVar("mp_fraglimit"); - static char mapListPath[PLATFORM_MAX_PATH]; + EngineVersion version = GetEngineVersion(); - BuildPath(Path_SM, mapListPath, PLATFORM_MAX_PATH, "configs/mapchooser_extended/maps/%s.txt", g_GameModName); - SetMapListCompatBind("official", mapListPath); + static char mapListPath[PLATFORM_MAX_PATH]; - switch(version) - { - case Engine_TF2: - { - g_Cvar_VoteNextLevel = FindConVar("sv_vote_issue_nextlevel_allowed"); - g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime"); - } + BuildPath(Path_SM, mapListPath, PLATFORM_MAX_PATH, "configs/mapchooser_extended/maps/%s.txt", g_GameModName); + SetMapListCompatBind("official", mapListPath); - case Engine_CSGO: - { - g_Cvar_VoteNextLevel = FindConVar("mp_endmatch_votenextmap"); - g_Cvar_GameType = FindConVar("game_type"); - g_Cvar_GameMode = FindConVar("game_mode"); - g_Cvar_Bonusroundtime = FindConVar("mp_round_restart_delay"); - } + switch(version) + { + case Engine_TF2: + { + g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime"); + } - case Engine_DODS: - { - g_Cvar_Bonusroundtime = FindConVar("dod_bonusroundtime"); - } + case Engine_CSGO: + { + g_Cvar_GameType = FindConVar("game_type"); + g_Cvar_GameMode = FindConVar("game_mode"); + g_Cvar_Bonusroundtime = FindConVar("mp_round_restart_delay"); + } - case Engine_CSS: - { - g_Cvar_Bonusroundtime = FindConVar("mp_round_restart_delay"); - } + case Engine_DODS: + { + g_Cvar_Bonusroundtime = FindConVar("dod_bonusroundtime"); + } - default: - { - g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime"); - } - } + case Engine_CSS: + { + g_Cvar_Bonusroundtime = FindConVar("mp_round_restart_delay"); + } - if(g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE) - { - switch(version) - { - case Engine_TF2: - { - HookEvent("teamplay_win_panel", Event_TeamPlayWinPanel); - HookEvent("teamplay_restart_round", Event_TFRestartRound); - HookEvent("arena_win_panel", Event_TeamPlayWinPanel); - HookEvent("pve_win_panel", Event_MvMWinPanel); - } + default: + { + g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime"); + } + } - case Engine_NuclearDawn: - { - HookEvent("round_win", Event_RoundEnd); - } + switch(version) + { + case Engine_TF2: + { + HookEvent("teamplay_win_panel", Event_TeamPlayWinPanel); + HookEvent("teamplay_restart_round", Event_TFRestartRound); + HookEvent("arena_win_panel", Event_TeamPlayWinPanel); + HookEvent("pve_win_panel", Event_MvMWinPanel); + } - case Engine_CSGO: - { - HookEvent("round_end", Event_RoundEnd); - HookEvent("cs_intermission", Event_Intermission); - HookEvent("announce_phase_end", Event_PhaseEnd); - g_Cvar_MatchClinch = FindConVar("mp_match_can_clinch"); - } + case Engine_NuclearDawn: + { + HookEvent("round_win", Event_RoundEnd); + } - case Engine_DODS: - { - HookEvent("dod_round_win", Event_RoundEnd); - } + case Engine_CSGO: + { + HookEvent("round_end", Event_RoundEnd); + HookEvent("cs_intermission", Event_Intermission); + HookEvent("announce_phase_end", Event_PhaseEnd); + } - default: - { - HookEvent("round_end", Event_RoundEnd); - } - } - } + case Engine_DODS: + { + HookEvent("dod_round_win", Event_RoundEnd); + } - if(g_Cvar_Fraglimit != INVALID_HANDLE) - HookEvent("player_death", Event_PlayerDeath); + default: + { + HookEvent("round_end", Event_RoundEnd); + } + } - AutoExecConfig(true, "mapchooser_extended"); + HookEvent("player_death", Event_PlayerDeath); - //Change the mp_bonusroundtime max so that we have time to display the vote - //If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime - if(g_Cvar_Bonusroundtime != INVALID_HANDLE) - SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0); + AutoExecConfig(true, "mapchooser_extended"); - g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell); - g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore); + //Change the mp_bonusroundtime max so that we have time to display the vote + //If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime + SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0); - //MapChooser Extended Forwards - g_MapVoteStartForward = CreateGlobalForward("OnMapVoteStart", ET_Ignore); // Deprecated - g_MapVoteEndForward = CreateGlobalForward("OnMapVoteEnd", ET_Ignore, Param_String); - g_MapVoteWarningStartForward = CreateGlobalForward("OnMapVoteWarningStart", ET_Ignore); - g_MapVoteWarningTickForward = CreateGlobalForward("OnMapVoteWarningTick", ET_Ignore, Param_Cell); - g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore); + g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell); + g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore); - InternalRestoreMapCooldowns(); + //MapChooser Extended Forwards + g_MapVoteStartForward = CreateGlobalForward("OnMapVoteStart", ET_Ignore); // Deprecated + g_MapVoteEndForward = CreateGlobalForward("OnMapVoteEnd", ET_Ignore, Param_String); + g_MapVoteWarningStartForward = CreateGlobalForward("OnMapVoteWarningStart", ET_Ignore); + g_MapVoteWarningTickForward = CreateGlobalForward("OnMapVoteWarningTick", ET_Ignore, Param_Cell); + g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore); + + InternalRestoreMapCooldowns(); } public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) @@ -477,47 +490,49 @@ public void OnMapStart() public void OnConfigsExecuted() { - if(ReadMapList(g_MapList, - g_mapFileSerial, - "mapchooser", - MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) - != INVALID_HANDLE) + if(ReadMapList(g_MapList, + g_mapFileSerial, + "mapchooser", + MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) + != INVALID_HANDLE) - { - if(g_mapFileSerial == -1) - LogError("Unable to create a valid map list."); - } + { + if(g_mapFileSerial == -1) + LogError("Unable to create a valid map list."); + } - // Disable the next level vote in TF2 and CS:GO - // In TF2, this has two effects: 1. Stop the next level vote (which overlaps rtv functionality). - // 2. Stop the built-in end level vote. This is the only thing that happens in CS:GO - if(g_Cvar_VoteNextLevel != INVALID_HANDLE) - SetConVarBool(g_Cvar_VoteNextLevel, false); - SetupTimeleftTimer(); + SetupTimeleftTimer(); - g_TotalRounds = 0; + g_TotalRounds = 0; - g_Extends = 0; + g_Extends = 0; - g_MapVoteCompleted = false; + g_MapVoteCompleted = false; - g_NominateCount = 0; - g_NominateReservedCount = 0; - ClearArray(g_NominateList); - ClearArray(g_NominateOwners); + g_NominateCount = 0; + g_NominateReservedCount = 0; + for (int i = 0; i < MaxClients; i++) + { + if (g_NominateList[i] != INVALID_HANDLE) + { + ClearArray(g_NominateList[i]); + } + } - for(int i = 0; i < MAXTEAMS; i++) - g_winCount[i] = 0; + ClearArray(g_NominateOwners); - /* Check if mapchooser will attempt to start mapvote during bonus round time */ - if((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds)) - { - if(!GetConVarInt(g_Cvar_StartTime) && GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration)) - LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete"); - } + for(int i = 0; i < MAXTEAMS; i++) + g_winCount[i] = 0; - InitializeOfficialMapList(); + /* Check if mapchooser will attempt to start mapvote during bonus round time */ + if (!GetConVarInt(g_Cvar_StartRounds)) + { + if(!GetConVarInt(g_Cvar_StartTime) && GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration)) + LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete"); + } + + InitializeOfficialMapList(); } public void OnMapEnd() @@ -576,7 +591,11 @@ public void OnMapEnd() public void OnClientPutInServer(int client) { - CheckMapRestrictions(false, true); + if (g_NominateList[client] != INVALID_HANDLE) + { + ClearArray(g_NominateList[client]); + } + CheckMapRestrictions(false, true); } public void OnClientDisconnect_Post(int client) @@ -586,21 +605,30 @@ public void OnClientDisconnect_Post(int client) public void OnClientDisconnect(int client) { - int index = FindValueInArray(g_NominateOwners, client); + int index = FindValueInArray(g_NominateOwners, client); - if(index == -1) - return; + if(index == -1) + return; - char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); - Call_StartForward(g_NominationsResetForward); - Call_PushString(oldmap); - Call_PushCell(GetArrayCell(g_NominateOwners, index)); - Call_Finish(); + //2023 edit for handling multiple nominations -jenz + for (int i = 0; i < GetArraySize(g_NominateList[client]); i++) + { + Call_StartForward(g_NominationsResetForward); + char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[client], i, oldmap, PLATFORM_MAX_PATH); + Call_PushString(oldmap); + Call_PushCell(GetArrayCell(g_NominateOwners, index)); + Call_Finish(); + } - RemoveFromArray(g_NominateOwners, index); - RemoveFromArray(g_NominateList, index); - g_NominateCount--; + RemoveFromArray(g_NominateOwners, index); + for (int i = 0; i < GetArraySize(g_NominateList[client]); i++) + { + RemoveFromArray(g_NominateList[client], i); + } + + ClearArray(g_NominateList[client]); + g_NominateCount--; } public Action Command_SetNextmap(int client, int args) @@ -898,8 +926,6 @@ public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast) public void CheckWinLimit(int winner_score) { - if(g_Cvar_Winlimit != INVALID_HANDLE) - { int winlimit = GetConVarInt(g_Cvar_Winlimit); if(winlimit) { @@ -912,27 +938,6 @@ public void CheckWinLimit(int winner_score) } } } - } - - if(g_Cvar_MatchClinch != INVALID_HANDLE && g_Cvar_Maxrounds != INVALID_HANDLE) - { - bool clinch = GetConVarBool(g_Cvar_MatchClinch); - - if(clinch) - { - int maxrounds = GetConVarInt(g_Cvar_Maxrounds); - int winlimit = RoundFloat(maxrounds / 2.0); - - if(winner_score == winlimit - 1) - { - if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) - { - SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); - //InitiateVote(MapChange_MapEnd, INVALID_HANDLE); - } - } - } - } } public void CheckMaxRounds(int roundcount) @@ -943,8 +948,6 @@ public void CheckMaxRounds(int roundcount) maxrounds = GameRules_GetProp("m_iNumGunGameProgressiveWeaponsCT"); else if(g_RoundCounting == RoundCounting_MvM) maxrounds = GetEntProp(g_ObjectiveEnt, Prop_Send, "m_nMannVsMachineMaxWaveCount"); - else if(g_Cvar_Maxrounds != INVALID_HANDLE) - maxrounds = GetConVarInt(g_Cvar_Maxrounds); else return; @@ -961,30 +964,31 @@ public void CheckMaxRounds(int roundcount) } } -public void Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) +public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) { - if(!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted) - return; + if(!GetArraySize(g_MapList) || g_HasVoteStarted) + return Plugin_Continue; - if(!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote)) - return; + if(!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote)) + return Plugin_Continue; - if(g_MapVoteCompleted) - return; + if(g_MapVoteCompleted) + return Plugin_Continue; - int fragger = GetClientOfUserId(GetEventInt(event, "attacker")); + int fragger = GetClientOfUserId(GetEventInt(event, "attacker")); - if(!fragger) - return; + if(!fragger) + return Plugin_Continue; - if(GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags))) - { - if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) - { - SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); - //InitiateVote(MapChange_MapEnd, INVALID_HANDLE); - } - } + if(GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags))) + { + if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) + { + SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); + //InitiateVote(MapChange_MapEnd, INVALID_HANDLE); + } + } + return Plugin_Continue; } public Action Command_Mapvote(int client, int args) @@ -998,6 +1002,68 @@ public Action Command_Mapvote(int client, int args) return Plugin_Handled; } +public Handle get_most_nominated_maps() +{ + int voteSize = GetVoteSize(2); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + Handle most_nominated_maps = CreateArray(arraySize); + StringMap sm = new StringMap(); + + for (int i = 0; i < MaxClients; i++) + { + for (int j = 0; j < GetArraySize(g_NominateList[i]); j++) + { + char map_iteration[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[i], j, map_iteration, PLATFORM_MAX_PATH); + //PrintToChatAll("map_iteration: %s", map_iteration); + int nominate_count_for_particular_map = 0; + sm.GetValue(map_iteration, nominate_count_for_particular_map); + nominate_count_for_particular_map++; + sm.SetValue(map_iteration, nominate_count_for_particular_map, true); + } + } + + for (int i = 0; i < voteSize; i++) + { + int max_count = 0; + char picked_map[PLATFORM_MAX_PATH]; + StringMapSnapshot keys = sm.Snapshot(); + for (int j = 0; j < keys.Length; j++) + { + int size = keys.KeyBufferSize(j); + char[] buffer = new char[size]; + keys.GetKey(j, buffer, size); + //PrintToChatAll("buffer: %s", buffer); + if (StrEqual(buffer, "nominated_maps")) + { + continue; + } + int value = 0; + sm.GetValue(buffer, value); + //PrintToChatAll("value: %i", value); + + //first selection has most nominates, second selection second most etc etc + if (value >= max_count) + { + max_count = value; + strcopy(picked_map, sizeof(picked_map), buffer); + } + } + + delete keys; + if (strlen(picked_map) == 0) + { + continue; + } + sm.Remove(picked_map); + PushArrayString(most_nominated_maps, picked_map); + //PrintToChatAll("picked_map: %s", picked_map); + } + + delete sm; + return most_nominated_maps; +} + /** * Starts a new map vote * @@ -1006,261 +1072,271 @@ public Action Command_Mapvote(int client, int args) */ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) { - g_WaitingForVote = true; - g_WarningInProgress = false; - int MenuRandomShuffleStart = 0; - int MenuRandomShuffleStop = 0; + g_WaitingForVote = true; + g_WarningInProgress = false; + int MenuRandomShuffleStart = 0; + int MenuRandomShuffleStop = 0; - // Check if a vote is in progress first - if(IsVoteInProgress()) - { - // Can't start a vote, try again in 5 seconds. - //g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); + // Check if a vote is in progress first + if(IsVoteInProgress()) + { + // Cant start a vote, try again in 5 seconds. + //g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); - CPrintToChatAll("[MCE] %t", "Cannot Start Vote", FAILURE_TIMER_LENGTH); - Handle data; - g_RetryTimer = CreateDataTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); + CPrintToChatAll("[MCE] %t", "Cannot Start Vote", FAILURE_TIMER_LENGTH); + Handle data; + g_RetryTimer = CreateDataTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); - /* Mapchooser Extended */ - WritePackCell(data, FAILURE_TIMER_LENGTH); + /* Mapchooser Extended */ + WritePackCell(data, FAILURE_TIMER_LENGTH); - if(GetConVarBool(g_Cvar_RunOff) && g_RunoffCount > 0) - WritePackString(data, "Revote Warning"); - else - WritePackString(data, "Vote Warning"); - /* End Mapchooser Extended */ + if(GetConVarBool(g_Cvar_RunOff) && g_RunoffCount > 0) + WritePackString(data, "Revote Warning"); + else + WritePackString(data, "Vote Warning"); + /* End Mapchooser Extended */ - WritePackCell(data, view_as(when)); - WritePackCell(data, view_as(inputlist)); - ResetPack(data); - return; - } + WritePackCell(data, view_as(when)); + WritePackCell(data, view_as(inputlist)); + ResetPack(data); + return; + } - /* If the main map vote has completed (and chosen result) and its currently changing (not a delayed change) we block further attempts */ - if(g_MapVoteCompleted && g_ChangeMapInProgress) - return; + /* If the main map vote has completed (and chosen result) and its currently changing (not a delayed change) we block further attempts */ + if(g_MapVoteCompleted && g_ChangeMapInProgress) + return; - CheckMapRestrictions(true, true); - CreateNextVote(); + CheckMapRestrictions(true, true); + CreateNextVote(); - g_ChangeTime = when; + g_ChangeTime = when; - g_WaitingForVote = false; + g_WaitingForVote = false; - g_HasVoteStarted = true; + g_HasVoteStarted = true; - g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction_End | MenuAction_Display | MenuAction_DisplayItem | MenuAction_VoteCancel); + g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction_End | MenuAction_Display | MenuAction_DisplayItem | MenuAction_VoteCancel); - g_AddNoVote = GetConVarBool(g_Cvar_NoVoteOption); + g_AddNoVote = GetConVarBool(g_Cvar_NoVoteOption); - // Block Vote Slots - if(GetConVarBool(g_Cvar_BlockSlots)) - { - Handle radioStyle = GetMenuStyleHandle(MenuStyle_Radio); + // Block Vote Slots + if(GetConVarBool(g_Cvar_BlockSlots)) + { + Handle radioStyle = GetMenuStyleHandle(MenuStyle_Radio); - if(GetMenuStyle(g_VoteMenu) == radioStyle) - { - g_BlockedSlots = true; - AddMenuItem(g_VoteMenu, LINE_ONE, "Choose something...", ITEMDRAW_DISABLED); - AddMenuItem(g_VoteMenu, LINE_TWO, "...will ya?", ITEMDRAW_DISABLED); - MenuRandomShuffleStart += 2; + if(GetMenuStyle(g_VoteMenu) == radioStyle) + { + g_BlockedSlots = true; + AddMenuItem(g_VoteMenu, LINE_ONE, "Choose something...", ITEMDRAW_DISABLED); + AddMenuItem(g_VoteMenu, LINE_TWO, "...will ya?", ITEMDRAW_DISABLED); + MenuRandomShuffleStart += 2; - if(!g_AddNoVote) { - AddMenuItem(g_VoteMenu, LINE_SPACER, "", ITEMDRAW_SPACER); - MenuRandomShuffleStart++; - } - } - else - g_BlockedSlots = false; - } + if(!g_AddNoVote) { + AddMenuItem(g_VoteMenu, LINE_SPACER, "", ITEMDRAW_SPACER); + MenuRandomShuffleStart++; + } + } + else + g_BlockedSlots = false; + } - if(g_AddNoVote) - SetMenuOptionFlags(g_VoteMenu, MENUFLAG_BUTTON_NOVOTE); + if(g_AddNoVote) + SetMenuOptionFlags(g_VoteMenu, MENUFLAG_BUTTON_NOVOTE); - SetMenuTitle(g_VoteMenu, "Vote Nextmap"); - SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished); + SetMenuTitle(g_VoteMenu, "Vote Nextmap"); + SetVoteResultCallback(g_VoteMenu, Handler_MapVoteFinished); - /* Call OnMapVoteStarted() Forward */ + /* Call OnMapVoteStarted() Forward */ // Call_StartForward(g_MapVoteStartedForward); // Call_Finish(); - /** - * TODO: Make a proper decision on when to clear the nominations list. - * Currently it clears when used, and stays if an external list is provided. - * Is this the right thing to do? External lists will probably come from places - * like sm_mapvote from the adminmenu in the future. - */ + /** + * TODO: Make a proper decision on when to clear the nominations list. + * Currently it clears when used, and stays if an external list is provided. + * Is this the right thing to do? External lists will probably come from places + * like sm_mapvote from the adminmenu in the future. + */ - static char map[PLATFORM_MAX_PATH]; + static char map[PLATFORM_MAX_PATH]; - /* No input given - User our internal nominations and maplist */ - if(inputlist == INVALID_HANDLE) - { - Handle randomizeList = INVALID_HANDLE; - if(GetConVarBool(g_Cvar_RandomizeNominations)) - randomizeList = CloneArray(g_NominateList); + /* No input given - User our internal nominations and maplist */ + if(inputlist == INVALID_HANDLE) + { + Handle randomizeList = INVALID_HANDLE; + //2023 edit to allow multiple nominations per player + Handle most_nominated_maps = get_most_nominated_maps(); - int nominateCount = GetArraySize(g_NominateList); + int voteSize = GetVoteSize(2); //voteSize wrong size probably for my for loop - int voteSize = GetVoteSize(2); + if(GetConVarBool(g_Cvar_RandomizeNominations)) + randomizeList = CloneArray(most_nominated_maps); - /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */ - int nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount; + int nominateCount = GetArraySize(most_nominated_maps); - bool extendFirst = GetConVarBool(g_Cvar_ExtendPosition); - if(extendFirst) { - AddExtendToMenu(g_VoteMenu, when); - MenuRandomShuffleStart++; - } + /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */ + int nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount; - for(int i = 0; i < nominationsToAdd; i++) - { - GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH); + bool extendFirst = GetConVarBool(g_Cvar_ExtendPosition); - if(randomizeList == INVALID_HANDLE) - AddMapItem(map); + if(extendFirst) { + AddExtendToMenu(g_VoteMenu, when); + MenuRandomShuffleStart++; + } - RemoveStringFromArray(g_NextMapList, map); + for(int i = 0; i < nominationsToAdd; i++) + { + GetArrayString(most_nominated_maps, i, map, PLATFORM_MAX_PATH); - /* Notify Nominations that this map is now free */ - Call_StartForward(g_NominationsResetForward); - Call_PushString(map); - Call_PushCell(GetArrayCell(g_NominateOwners, i)); - Call_Finish(); - } + if(randomizeList == INVALID_HANDLE) + AddMapItem(map); - /* Clear out the rest of the nominations array */ - for(int i = nominationsToAdd; i < nominateCount; i++) - { - GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH); - /* These maps shouldn't be excluded from the vote as they weren't really nominated at all */ + RemoveStringFromArray(g_NextMapList, map); - /* Notify Nominations that this map is now free */ - Call_StartForward(g_NominationsResetForward); - Call_PushString(map); - Call_PushCell(GetArrayCell(g_NominateOwners, i)); - Call_Finish(); - } + /* Notify Nominations that this map is now free */ + Call_StartForward(g_NominationsResetForward); + Call_PushString(map); + Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_Finish(); + } - /* There should currently be 'nominationsToAdd' unique maps in the vote */ + /* Clear out the rest of the nominations array */ + for(int i = nominationsToAdd; i < nominateCount; i++) + { + //2023 edit: might need to run all g_NominateList[client] through this instead + GetArrayString(most_nominated_maps, i, map, PLATFORM_MAX_PATH); + /* These maps shouldn't be excluded from the vote as they weren't really nominated at all */ - int i = nominationsToAdd; - int count = 0; - int availableMaps = GetArraySize(g_NextMapList); + /* Notify Nominations that this map is now free */ + Call_StartForward(g_NominationsResetForward); + Call_PushString(map); + Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_Finish(); + } - if(i < voteSize && availableMaps == 0) - { - if(i == 0) - { - LogError("No maps available for vote."); - return; - } - else - { - LogMessage("Not enough maps to fill map list, reducing map count. Adjust mce_include and mce_exclude to avoid this warning."); - voteSize = i; - } - } + /* There should currently be 'nominationsToAdd' unique maps in the vote */ - while(i < voteSize) - { - GetArrayString(g_NextMapList, count, map, PLATFORM_MAX_PATH); - count++; + int i = nominationsToAdd; + int count = 0; + int availableMaps = GetArraySize(g_NextMapList); - if(randomizeList == INVALID_HANDLE) - { - /* Insert the map and increment our count */ - AddMapItem(map); - } - else - PushArrayString(randomizeList, map); - i++; + if(i < voteSize && availableMaps == 0) + { + if(i == 0) + { + LogError("No maps available for vote."); + return; + } + else + { + LogMessage("Not enough maps to fill map list, reducing map count. Adjust mce_include and mce_exclude to avoid this warning."); + voteSize = i; + } + } - //Run out of maps, this will have to do. - if(count >= availableMaps) - break; - } + while(i < voteSize) + { + GetArrayString(g_NextMapList, count, map, PLATFORM_MAX_PATH); + count++; - if(randomizeList != INVALID_HANDLE) - { - // Fisher-Yates Shuffle - for(int j = GetArraySize(randomizeList) - 1; j >= 1; j--) - { - int k = GetRandomInt(0, j); - SwapArrayItems(randomizeList, j, k); - } + if(randomizeList == INVALID_HANDLE) + { + /* Insert the map and increment our count */ + AddMapItem(map); + } + else + PushArrayString(randomizeList, map); + i++; - for(int j = 0; j < GetArraySize(randomizeList); j++) - { - GetArrayString(randomizeList, j, map, PLATFORM_MAX_PATH); - AddMapItem(map); - } + //Run out of maps, this will have to do. + if(count >= availableMaps) + break; + } - delete randomizeList; - randomizeList = INVALID_HANDLE; - } + if(randomizeList != INVALID_HANDLE) + { + // Fisher-Yates Shuffle + for(int j = GetArraySize(randomizeList) - 1; j >= 1; j--) + { + int k = GetRandomInt(0, j); + SwapArrayItems(randomizeList, j, k); + } - /* Wipe out our nominations list - Nominations have already been informed of this */ - g_NominateCount = 0; - g_NominateReservedCount = 0; - ClearArray(g_NominateOwners); - ClearArray(g_NominateList); + for(int j = 0; j < GetArraySize(randomizeList); j++) + { + GetArrayString(randomizeList, j, map, PLATFORM_MAX_PATH); + AddMapItem(map); + } - if(!extendFirst) { - AddExtendToMenu(g_VoteMenu, when); - MenuRandomShuffleStop++; - } - } - else //We were given a list of maps to start the vote with - { - int size = GetArraySize(inputlist); + delete randomizeList; + randomizeList = INVALID_HANDLE; + delete most_nominated_maps; + most_nominated_maps = INVALID_HANDLE; + } - for(int i = 0; i < size; i++) - { - GetArrayString(inputlist, i, map, PLATFORM_MAX_PATH); + /* Wipe out our nominations list - Nominations have already been informed of this */ + g_NominateCount = 0; + g_NominateReservedCount = 0; + ClearArray(g_NominateOwners); + for (int j = 0; j < MaxClients; j++) + { + ClearArray(g_NominateList[j]); + } - if(IsMapValid(map)) - { - AddMapItem(map); - } - // New in Mapchooser Extended - else if(StrEqual(map, VOTE_DONTCHANGE)) - { - AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change"); - } - else if(StrEqual(map, VOTE_EXTEND)) - { - AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map"); - } - } - delete inputlist; - } + if(!extendFirst) { + AddExtendToMenu(g_VoteMenu, when); + MenuRandomShuffleStop++; + } + } + else //We were given a list of maps to start the vote with + { + int size = GetArraySize(inputlist); - int voteDuration = GetConVarInt(g_Cvar_VoteDuration); + for(int i = 0; i < size; i++) + { + GetArrayString(inputlist, i, map, PLATFORM_MAX_PATH); - //SetMenuExitButton(g_VoteMenu, false); + if(IsMapValid(map)) + { + AddMapItem(map); + } + // New in Mapchooser Extended + else if(StrEqual(map, VOTE_DONTCHANGE)) + { + AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Dont Change"); + } + else if(StrEqual(map, VOTE_EXTEND)) + { + AddMenuItem(g_VoteMenu, VOTE_EXTEND, "Extend Map"); + } + } + delete inputlist; + } - if(GetVoteSize(2) <= GetMaxPageItems(GetMenuStyle(g_VoteMenu))) - { - //This is necessary to get items 9 and 0 as usable voting items - SetMenuPagination(g_VoteMenu, MENU_NO_PAGINATION); - } + int voteDuration = GetConVarInt(g_Cvar_VoteDuration); - if(GetConVarInt(g_Cvar_ShufflePerClient)) - MenuShufflePerClient(g_VoteMenu, MenuRandomShuffleStart, GetMenuItemCount(g_VoteMenu) - MenuRandomShuffleStop); + //SetMenuExitButton(g_VoteMenu, false); - VoteMenuToAll(g_VoteMenu, voteDuration); + if(GetVoteSize(2) <= GetMaxPageItems(GetMenuStyle(g_VoteMenu))) + { + //This is necessary to get items 9 and 0 as usable voting items + SetMenuPagination(g_VoteMenu, MENU_NO_PAGINATION); + } - /* Call OnMapVoteStarted() Forward */ - Call_StartForward(g_MapVoteStartForward); // Deprecated - Call_Finish(); + if(GetConVarInt(g_Cvar_ShufflePerClient)) + MenuShufflePerClient(g_VoteMenu, MenuRandomShuffleStart, GetMenuItemCount(g_VoteMenu) - MenuRandomShuffleStop); - Call_StartForward(g_MapVoteStartedForward); - Call_Finish(); + VoteMenuToAll(g_VoteMenu, voteDuration); - LogAction(-1, -1, "Voting for next map has started."); - CPrintToChatAll("[MCE] %t", "Nextmap Voting Started"); + /* Call OnMapVoteStarted() Forward */ + Call_StartForward(g_MapVoteStartForward); // Deprecated + Call_Finish(); + + Call_StartForward(g_MapVoteStartedForward); + Call_Finish(); + + LogAction(-1, -1, "Voting for next map has started."); + CPrintToChatAll("[MCE] %t", "Nextmap Voting Started"); } public void Handler_VoteFinishedGeneric(Handle menu, @@ -1270,89 +1346,80 @@ public void Handler_VoteFinishedGeneric(Handle menu, int num_items, const int[][] item_info) { - static char map[PLATFORM_MAX_PATH]; - GetMapItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, PLATFORM_MAX_PATH); + static char map[PLATFORM_MAX_PATH]; + GetMapItem(menu, item_info[0][VOTEINFO_ITEM_INDEX], map, PLATFORM_MAX_PATH); - Call_StartForward(g_MapVoteEndForward); - Call_PushString(map); - Call_Finish(); + Call_StartForward(g_MapVoteEndForward); + Call_PushString(map); + Call_Finish(); - if(strcmp(map, VOTE_EXTEND, false) == 0) - { - g_Extends++; + if(strcmp(map, VOTE_EXTEND, false) == 0) + { + g_Extends++; - int time; - if(GetMapTimeLimit(time)) - { - if(time > 0) - ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60); - } + int time; + if(GetMapTimeLimit(time)) + { + if(time > 0) + ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60); + } - if(g_Cvar_Winlimit != INVALID_HANDLE) - { - int winlimit = GetConVarInt(g_Cvar_Winlimit); - if(winlimit) - SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep)); - } + int winlimit = GetConVarInt(g_Cvar_Winlimit); + if(winlimit) + SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep)); - if(g_Cvar_Maxrounds != INVALID_HANDLE) - { - int maxrounds = GetConVarInt(g_Cvar_Maxrounds); - if(maxrounds) - SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep)); - } + int maxrounds = GetConVarInt(g_Cvar_Maxrounds); + if(maxrounds) + SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep)); - if(g_Cvar_Fraglimit != INVALID_HANDLE) - { - int fraglimit = GetConVarInt(g_Cvar_Fraglimit); - if(fraglimit) - SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep)); - } + int fraglimit = GetConVarInt(g_Cvar_Fraglimit); + if(fraglimit) + SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep)); - CPrintToChatAll("[MCE] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); - LogAction(-1, -1, "Voting for next map has finished. The current map has been extended."); - CPrintToChatAll("[MCE] Available Extends: %d", GetConVarInt(g_Cvar_Extend) - g_Extends); + CPrintToChatAll("[MCE] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); + LogAction(-1, -1, "Voting for next map has finished. The current map has been extended."); + CPrintToChatAll("[MCE] Available Extends: %d", GetConVarInt(g_Cvar_Extend) - g_Extends); - // We extended, so we'll have to vote again. - g_RunoffCount = 0; - g_HasVoteStarted = false; - SetupTimeleftTimer(); + // We extended, so well have to vote again. + g_RunoffCount = 0; + g_HasVoteStarted = false; + SetupTimeleftTimer(); - } - else if(strcmp(map, VOTE_DONTCHANGE, false) == 0) - { - CPrintToChatAll("[MCE] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); - LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner"); + } + else if(strcmp(map, VOTE_DONTCHANGE, false) == 0) + { + CPrintToChatAll("[MCE] %t", "Current Map Stays", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); + LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner"); - g_RunoffCount = 0; - g_HasVoteStarted = false; - SetupTimeleftTimer(); - } - else - { - if(g_ChangeTime == MapChange_MapEnd) - { - SetNextMap(map); - } - else if(g_ChangeTime == MapChange_Instant) - { - Handle data; - CreateDataTimer(4.0, Timer_ChangeMap, data); - WritePackString(data, map); - g_ChangeMapInProgress = false; - } - else // MapChange_RoundEnd - { - SetNextMap(map); - g_ChangeMapAtRoundEnd = true; - } + g_RunoffCount = 0; + g_HasVoteStarted = false; + SetupTimeleftTimer(); + } + else + { + if(g_ChangeTime == MapChange_MapEnd) + { + SetNextMap(map); + } + else if(g_ChangeTime == MapChange_Instant) + { + Handle data; + CreateDataTimer(4.0, Timer_ChangeMap, data); + WritePackString(data, map); + g_ChangeMapInProgress = false; + } + else // MapChange_RoundEnd + { + SetNextMap(map); + g_ChangeMapAtRoundEnd = true; + } - g_HasVoteStarted = false; - g_MapVoteCompleted = true; + g_HasVoteStarted = false; + g_MapVoteCompleted = true; - CPrintToChatAll("[MCE] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); - LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map); - } + CPrintToChatAll("[MCE] %t", "Nextmap Voting Finished", map, RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes); + LogAction(-1, -1, "Voting for next map has finished. Nextmap: %s.", map); + } } public void Handler_MapVoteFinished(Handle menu, @@ -1579,191 +1646,206 @@ bool RemoveStringFromArray(Handle array, char[] str) void CreateNextVote() { - assert(g_NextMapList) - ClearArray(g_NextMapList); + assert(g_NextMapList) + ClearArray(g_NextMapList); - static char map[PLATFORM_MAX_PATH]; - Handle tempMaps = CloneArray(g_MapList); + static char map[PLATFORM_MAX_PATH]; + Handle tempMaps = CloneArray(g_MapList); - GetCurrentMap(map, PLATFORM_MAX_PATH); - RemoveStringFromArray(tempMaps, map); + GetCurrentMap(map, PLATFORM_MAX_PATH); + RemoveStringFromArray(tempMaps, map); - if(GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive()) - { - StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot(); - for(int i = 0; i < OldMapListSnapshot.Length; i++) - { - OldMapListSnapshot.GetKey(i, map, sizeof(map)); - RemoveStringFromArray(tempMaps, map); - } - delete OldMapListSnapshot; - } + if(GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive()) + { + StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot(); + for(int i = 0; i < OldMapListSnapshot.Length; i++) + { + OldMapListSnapshot.GetKey(i, map, sizeof(map)); + RemoveStringFromArray(tempMaps, map); + } + delete OldMapListSnapshot; + } - if(InternalAreRestrictionsActive()) - { - StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); - for(int i = 0; i < TimeMapListSnapshot.Length; i++) - { - TimeMapListSnapshot.GetKey(i, map, sizeof(map)); - int Cooldown; - g_TimeMapList.GetValue(map, Cooldown); + if(InternalAreRestrictionsActive()) + { + StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); + for(int i = 0; i < TimeMapListSnapshot.Length; i++) + { + TimeMapListSnapshot.GetKey(i, map, sizeof(map)); + int Cooldown; + g_TimeMapList.GetValue(map, Cooldown); - if(Cooldown > GetTime()) - RemoveStringFromArray(tempMaps, map); - } - delete TimeMapListSnapshot; - } + if(Cooldown > GetTime()) + RemoveStringFromArray(tempMaps, map); + } + delete TimeMapListSnapshot; + } - int voteSize = GetVoteSize(2); - int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); + int voteSize = GetVoteSize(2); + int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); - // group -> number of maps nominated from group - StringMap groupmap = new StringMap(); - char groupstr[8]; + // group -> number of maps nominated from group + StringMap groupmap = new StringMap(); + char groupstr[8]; - // populate groupmap with maps from nomination list - static char map_[PLATFORM_MAX_PATH]; - int groups_[32]; - for(int i = 0; i < GetArraySize(g_NominateList); i++) - { - GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); - int groupsfound = InternalGetMapGroups(map_, groups_, sizeof(groups_)); - for(int group = 0; group < groupsfound; group++) - { - IntToString(group, groupstr, sizeof(groupstr)); - int groupcur = 0; - groupmap.GetValue(groupstr, groupcur); - groupcur++; - groupmap.SetValue(groupstr, groupcur, true); - } - } + // populate groupmap with maps from nomination list + static char map_[PLATFORM_MAX_PATH]; + int groups_[32]; - // find random maps which honor all restrictions - for(int i = 0; i < limit; i++) - { - int b; - for(int j = 0; j < 1000; j++) - { - b = GetRandomInt(0, GetArraySize(tempMaps) - 1); - GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH); + //2023 edit + Handle most_nominated_maps = get_most_nominated_maps(); + for(int i = 0; i < GetArraySize(most_nominated_maps); i++) + { + GetArrayString(most_nominated_maps, i, map_, PLATFORM_MAX_PATH); + int groupsfound = InternalGetMapGroups(map_, groups_, sizeof(groups_)); + for(int group = 0; group < groupsfound; group++) + { + IntToString(group, groupstr, sizeof(groupstr)); + int groupcur = 0; + groupmap.GetValue(groupstr, groupcur); + groupcur++; + groupmap.SetValue(groupstr, groupcur, true); + } + } - if(!InternalAreRestrictionsActive()) - break; + // find random maps which honor all restrictions + for(int i = 0; i < limit; i++) + { + int b; + for(int j = 0; j < 1000; j++) + { + b = GetRandomInt(0, GetArraySize(tempMaps) - 1); + GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH); - if(InternalGetMapVIPRestriction(map)) - continue; + if(!InternalAreRestrictionsActive()) + break; - if(InternalGetMapTimeRestriction(map) != 0) - continue; + if(InternalGetMapVIPRestriction(map)) + continue; - if(InternalGetMapPlayerRestriction(map) != 0) - continue; + if(InternalGetMapTimeRestriction(map) != 0) + continue; - bool okay = true; + if(InternalGetMapPlayerRestriction(map) != 0) + continue; - int groups[32]; - int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); - for(int group = 0; group < groupsfound; group++) - { - IntToString(group, groupstr, sizeof(groupstr)); + bool okay = true; - int groupmax = InternalGetGroupMax(groups[group]); - if(groupmax >= 0) - { - int groupcur = 0; - groupmap.GetValue(groupstr, groupcur); + int groups[32]; + int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); + for(int group = 0; group < groupsfound; group++) + { + IntToString(group, groupstr, sizeof(groupstr)); - if(groupcur >= groupmax) - { - okay = false; - break; - } + int groupmax = InternalGetGroupMax(groups[group]); + if(groupmax >= 0) + { + int groupcur = 0; + groupmap.GetValue(groupstr, groupcur); - groupcur++; - groupmap.SetValue(groupstr, groupcur, true); - } - } + if(groupcur >= groupmax) + { + okay = false; + break; + } - if(okay) - break; - } - PushArrayString(g_NextMapList, map); - RemoveFromArray(tempMaps, b); - } + groupcur++; + groupmap.SetValue(groupstr, groupcur, true); + } + } - delete groupmap; - delete tempMaps; + if(okay) + break; + } + PushArrayString(g_NextMapList, map); + RemoveFromArray(tempMaps, b); + } + + delete groupmap; + delete tempMaps; } bool CanVoteStart() { - if(g_WaitingForVote || g_HasVoteStarted) - return false; - - return true; + if(g_WaitingForVote || g_HasVoteStarted) + return false; + return true; } -NominateResult InternalNominateMap(char[] map, bool force, int owner) +NominateResult InternalNominateMap(char[] map, int owner) { - if(!IsMapValid(map)) - { - return Nominate_InvalidMap; - } + if(!IsMapValid(map)) + { + return Nominate_InvalidMap; + } - /* Map already in the vote */ - if(FindStringInArray(g_NominateList, map) != -1) - { - return Nominate_AlreadyInVote; - } - int index; + /* Look to replace an existing nomination by this client - Nominations made with owner = 0 arent replaced */ + //2023 edit: change clients first nomination out of the clients multiple nominations, make a check if client filled all his nomination slots + //currently hard coded to 3 maps, just add a cvar to replace it with in the future + if(owner && ((FindValueInArray(g_NominateOwners, owner)) != -1) && GetArraySize(g_NominateList[owner]) > 2) + { + char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[owner], 0, oldmap, PLATFORM_MAX_PATH); + Call_StartForward(g_NominationsResetForward); + Call_PushString(oldmap); + Call_PushCell(owner); + Call_Finish(); - /* Look to replace an existing nomination by this client - Nominations made with owner = 0 aren't replaced */ - if(owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1)) - { - char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); - Call_StartForward(g_NominationsResetForward); - Call_PushString(oldmap); - Call_PushCell(owner); - Call_Finish(); + RemoveFromArray(g_NominateList[owner], 0); + PushArrayString(g_NominateList[owner], map); + return Nominate_Replaced; + } - SetArrayString(g_NominateList, index, map); - return Nominate_Replaced; - } - /* Too many nominated maps. */ - if(g_NominateCount >= GetVoteSize(0) && !force) - { - return Nominate_VoteFull; - } + /* Too many nominated maps. */ + //2023 edit: we dont want this check + /* + if(g_NominateCount >= GetVoteSize(0) && !force) + { + return Nominate_VoteFull; + } + */ - PushArrayString(g_NominateList, map); - PushArrayCell(g_NominateOwners, owner); - if(owner == 0 && g_NominateReservedCount < GetVoteSize(1)) - g_NominateReservedCount++; - else - g_NominateCount++; + if (owner != 0) + { + for (int j = 0; j < GetArraySize(g_NominateList[owner]); j++) + { + char map_iteration[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[owner], j, map_iteration, PLATFORM_MAX_PATH); + if (StrEqual(map, map_iteration, false)) + { + return Nominate_InvalidMap; + } + } + } + + PushArrayString(g_NominateList[owner], map); + PushArrayCell(g_NominateOwners, owner); //maybe i only want to do this for the first nomination of each client + if(owner == 0 && g_NominateReservedCount < GetVoteSize(1)) + g_NominateReservedCount++; + else + g_NominateCount++; - while(GetArraySize(g_NominateList) > GetVoteSize(2)) - { - char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, 0, oldmap, PLATFORM_MAX_PATH); - Call_StartForward(g_NominationsResetForward); - Call_PushString(oldmap); - int owner_ = GetArrayCell(g_NominateOwners, 0); - Call_PushCell(owner_); - Call_Finish(); + while(GetArraySize(g_NominateList[owner]) > GetVoteSize(2)) + { + char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[owner], 0, oldmap, PLATFORM_MAX_PATH); + Call_StartForward(g_NominationsResetForward); + Call_PushString(oldmap); + int owner_ = GetArrayCell(g_NominateOwners, 0); + Call_PushCell(owner_); + Call_Finish(); - RemoveFromArray(g_NominateList, 0); - RemoveFromArray(g_NominateOwners, 0); - if(owner_ == 0) - g_NominateReservedCount--; - else - g_NominateCount--; - } + RemoveFromArray(g_NominateList[owner], 0); + RemoveFromArray(g_NominateOwners, 0); + if(owner_ == 0) + g_NominateReservedCount--; + else + g_NominateCount--; + } - return Nominate_Added; + return Nominate_Added; } /* Add natives to allow nominate and initiate vote to be call */ @@ -1780,37 +1862,39 @@ public int Native_NominateMap(Handle plugin, int numParams) char[] map = new char[len+1]; GetNativeString(1, map, len+1); - return view_as(InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3))); + return view_as(InternalNominateMap(map, GetNativeCell(3))); } bool InternalRemoveNominationByMap(char[] map) { - for(int i = 0; i < GetArraySize(g_NominateList); i++) - { - char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, i, oldmap, PLATFORM_MAX_PATH); + for (int client = 0; client < MaxClients; client++) + { + for(int i = 0; i < GetArraySize(g_NominateList[client]); i++) + { + char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[client], i, oldmap, PLATFORM_MAX_PATH); - if(strcmp(map, oldmap, false) == 0) - { - Call_StartForward(g_NominationsResetForward); - Call_PushString(oldmap); - Call_PushCell(GetArrayCell(g_NominateOwners, i)); - Call_Finish(); + if(strcmp(map, oldmap, false) == 0) + { + Call_StartForward(g_NominationsResetForward); + Call_PushString(oldmap); + Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_Finish(); - int owner = GetArrayCell(g_NominateOwners, i); - if(owner) - g_NominateCount--; - else - g_NominateReservedCount--; + int owner = GetArrayCell(g_NominateOwners, i); + if(owner) + g_NominateCount--; + else + g_NominateReservedCount--; - RemoveFromArray(g_NominateList, i); - RemoveFromArray(g_NominateOwners, i); + RemoveFromArray(g_NominateList[client], i); + RemoveFromArray(g_NominateOwners, i); - return true; - } - } - - return false; + return true; + } + } + } + return false; } /* native bool RemoveNominationByMap(const char[] map); */ @@ -1835,14 +1919,15 @@ bool InternalRemoveNominationByOwner(int owner) if(owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1)) { char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); + GetArrayString(g_NominateList[owner], index, oldmap, PLATFORM_MAX_PATH); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); Call_PushCell(owner); Call_Finish(); - RemoveFromArray(g_NominateList, index); + RemoveFromArray(g_NominateList[owner], index); + //maybe only do once or change g_NominateOwners RemoveFromArray(g_NominateOwners, index); g_NominateCount--; @@ -1903,26 +1988,29 @@ public int Native_GetExcludeMapList(Handle plugin, int numParams) public int Native_GetNominatedMapList(Handle plugin, int numParams) { - Handle maparray = view_as(GetNativeCell(1)); - Handle ownerarray = view_as(GetNativeCell(2)); + Handle maparray = view_as(GetNativeCell(1)); + Handle ownerarray = view_as(GetNativeCell(2)); - if(maparray == INVALID_HANDLE) - return; + if(maparray == INVALID_HANDLE) + return; - static char map[PLATFORM_MAX_PATH]; + static char map[PLATFORM_MAX_PATH]; - for(int i = 0; i < GetArraySize(g_NominateList); i++) - { - GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH); - PushArrayString(maparray, map); + for (int client = 0; client < MaxClients; client++) + { + for(int i = 0; i < GetArraySize(g_NominateList[client]); i++) + { + GetArrayString(g_NominateList[client], i, map, PLATFORM_MAX_PATH); + PushArrayString(maparray, map); - // If the optional parameter for an owner list was passed, then we need to fill that out as well - if(ownerarray != INVALID_HANDLE) - { - int index = GetArrayCell(g_NominateOwners, i); - PushArrayCell(ownerarray, index); - } - } + // If the optional parameter for an owner list was passed, then we need to fill that out as well + if(ownerarray != INVALID_HANDLE) + { + //int index = GetArrayCell(g_NominateOwners, i); + PushArrayCell(ownerarray, client); + } + } + } } // Functions new to Mapchooser Extended @@ -2274,61 +2362,71 @@ public int Native_GetMapGroups(Handle plugin, int numParams) public int Native_GetMapGroupRestriction(Handle plugin, int numParams) { - int client = GetNativeCell(2); - int len; - GetNativeStringLength(1, len); + int client = GetNativeCell(2); + int len; + GetNativeStringLength(1, len); - if(len <= 0) - return -999; + if(len <= 0) + return -999; - char[] map = new char[len+1]; - GetNativeString(1, map, len+1); + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); - int groups[32]; - int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); + int groups[32]; + int groupsfound = InternalGetMapGroups(map, groups, sizeof(groups)); - for(int group = 0; group < groupsfound; group ++) - { - int groupcur = 0; - int groupmax = InternalGetGroupMax(groups[group]); + for(int group = 0; group < groupsfound; group ++) + { + int groupcur = 0; + int groupmax = InternalGetGroupMax(groups[group]); - if(groupmax >= 0) - { - static char map_[PLATFORM_MAX_PATH]; - int groups_[32]; - for(int i = 0; i < GetArraySize(g_NominateList); i++) - { - GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); - int tmp = InternalGetMapGroups(map_, groups_, sizeof(groups_)); - if(FindIntInArray(groups_, tmp, groups[group]) != -1) - groupcur++; - } + if(groupmax >= 0) + { + static char map_[PLATFORM_MAX_PATH]; + char kv_map[PLATFORM_MAX_PATH]; + int groups_[32]; + KeyValues kv = CreateKeyValues("cur_groups"); + for (int clienti = 0; clienti < MaxClients; clienti++) + { + for(int i = 0; i < GetArraySize(g_NominateList[clienti]); i++) + { + GetArrayString(g_NominateList[clienti], i, map_, PLATFORM_MAX_PATH); + int tmp = InternalGetMapGroups(map_, groups_, sizeof(groups_)); + kv.GetString(map_, kv_map, sizeof(kv_map), "not_found"); + if(FindIntInArray(groups_, tmp, groups[group]) != -1 && StrEqual(kv_map, "not_found")) + { + groupcur++; + kv.SetString(map_, map_); + } + } + } + delete kv; - if(groupcur >= groupmax) - { - // Check if client has nominated a map in the same group and can change their nomination - bool okay = false; - if(client >= 1 && client <= MaxClients) - { - int index = FindValueInArray(g_NominateOwners, client); - if(index != -1) - { - static char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); - static int oldgroups[32]; - int tmp = InternalGetMapGroups(oldmap, oldgroups, sizeof(oldgroups)); - if(FindIntInArray(groups_, tmp, groups[group]) != -1) - okay = true; - } - } + if(groupcur >= groupmax) + { + // Check if client has nominated a map in the same group and can change their nomination + bool okay = false; + if(client >= 1 && client <= MaxClients) + { + int index = FindValueInArray(g_NominateOwners, client); + if(index != -1) + { + static char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList[client], index, oldmap, PLATFORM_MAX_PATH); + static int oldgroups[32]; + int tmp = InternalGetMapGroups(oldmap, oldgroups, sizeof(oldgroups)); + if(FindIntInArray(groups_, tmp, groups[group]) != -1) + okay = true; + } + } - if(!okay) - return groupmax; - } - } - } + if(!okay) + return groupmax; + } + } + } - return -1; + return -1; } public int Native_GetMapVIPRestriction(Handle plugin, int numParams) @@ -2390,8 +2488,8 @@ stock void AddExtendToMenu(Handle menu, MapChange when) if((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange)) { - // Built-in votes doesn't have "Don't Change", send Extend instead - AddMenuItem(menu, VOTE_DONTCHANGE, "Don't Change"); + // Built-in votes doesnt have "Dont Change", send Extend instead + AddMenuItem(menu, VOTE_DONTCHANGE, "Dont Change"); } else if(GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend)) { @@ -2448,59 +2546,58 @@ stock int InternalGetMapCooldownTime(const char[] map) void CheckMapRestrictions(bool time = false, bool players = false) { - if(!InternalAreRestrictionsActive()) - return; + if(!InternalAreRestrictionsActive()) + return; - static char map[PLATFORM_MAX_PATH]; - for(int i = 0; i < GetArraySize(g_NominateList); i++) - { - int client = GetArrayCell(g_NominateOwners, i); - if(!client) - continue; + static char map[PLATFORM_MAX_PATH]; - if(CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) - continue; + for (int client = 0; client < MaxClients; client++) + { + if(CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) + continue; + for (int i = 0; i < GetArraySize(g_NominateList[client]); i++) + { + bool remove; + GetArrayString(g_NominateList[client], i, map, PLATFORM_MAX_PATH); - bool remove; - GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH); + if (time) + { + int TimeRestriction = InternalGetMapTimeRestriction(map); + if(TimeRestriction) + { + remove = true; - if (time) - { - int TimeRestriction = InternalGetMapTimeRestriction(map); - if(TimeRestriction) - { - remove = true; + CPrintToChat(client, "[MCE] %t", "Nomination Removed Time Error", map); + } + } - CPrintToChat(client, "[MCE] %t", "Nomination Removed Time Error", map); - } - } + if (players) + { + int PlayerRestriction = InternalGetMapPlayerRestriction(map); + if(PlayerRestriction) + { + remove = true; - if (players) - { - int PlayerRestriction = InternalGetMapPlayerRestriction(map); - if(PlayerRestriction) - { - remove = true; + if(PlayerRestriction < 0) + CPrintToChat(client, "[MCE] %t", "Nomination Removed MinPlayers Error", map); + else + CPrintToChat(client, "[MCE] %t", "Nomination Removed MaxPlayers Error", map); + } + } - if(PlayerRestriction < 0) - CPrintToChat(client, "[MCE] %t", "Nomination Removed MinPlayers Error", map); - else - CPrintToChat(client, "[MCE] %t", "Nomination Removed MaxPlayers Error", map); - } - } + if (remove) + { + Call_StartForward(g_NominationsResetForward); + Call_PushString(map); + Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_Finish(); - if (remove) - { - Call_StartForward(g_NominationsResetForward); - Call_PushString(map); - Call_PushCell(GetArrayCell(g_NominateOwners, i)); - Call_Finish(); - - RemoveFromArray(g_NominateList, i); - RemoveFromArray(g_NominateOwners, i); - g_NominateCount--; - } - } + RemoveFromArray(g_NominateList[client], i); + RemoveFromArray(g_NominateOwners, i); + g_NominateCount--; + } + } + } } stock int InternalGetMapMinTime(const char[] map) diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp old mode 100644 new mode 100755 index 0ceb433..e7374a3 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -187,14 +187,7 @@ public void OnConfigsExecuted() void UpdateMapMenus() { - if(g_MapMenu != INVALID_HANDLE) - delete g_MapMenu; - - g_MapMenu = BuildMapMenu(""); - - if(g_AdminMapMenu != INVALID_HANDLE) - delete g_AdminMapMenu; - + g_MapMenu = BuildMapMenu("", 0); g_AdminMapMenu = BuildAdminMapMenu(""); } @@ -243,17 +236,16 @@ void UpdateMapTrie() public void OnNominationRemoved(const char[] map, int owner) { - int status; + int status; + /* Is the map in our list? */ + if(!GetTrieValue(g_mapTrie, map, status)) + return; - /* Is the map in our list? */ - if(!GetTrieValue(g_mapTrie, map, status)) - return; + /* Was the map disabled due to being nominated */ + if((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED) + return; - /* Was the map disabled due to being nominated */ - if((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED) - return; - - SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED); + SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED); } public Action Command_Addmap(int client, int args) @@ -290,7 +282,7 @@ public Action Command_Addmap(int client, int args) if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) { if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) - CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map"); + CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map"); if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { @@ -345,7 +337,7 @@ public Action Command_Addmap(int client, int args) if(result > Nominate_Replaced) { - /* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it can't be full */ + /* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */ CReplyToCommand(client, "%t", "Map Already In Vote", mapname); return Plugin_Handled; @@ -388,7 +380,7 @@ public Action Command_Removemap(int client, int args) if(!RemoveNominationByMap(mapname)) { - CReplyToCommand(client, "This map isn't nominated.", mapname); + CReplyToCommand(client, "This map isnt nominated.", mapname); return Plugin_Handled; } @@ -523,130 +515,135 @@ public Action Command_Say(int client, int args) public Action Command_Nominate(int client, int args) { - if(!client || !IsNominateAllowed(client)) - return Plugin_Handled; + if(!client || !IsNominateAllowed(client)) + return Plugin_Handled; - if(g_NominationDelay > GetTime()) - { - PrintToChat(client, "[NE] Nominations will be unlocked in %d seconds", g_NominationDelay - GetTime()); - return Plugin_Handled; - } + if(g_NominationDelay > GetTime()) + { + PrintToChat(client, "[NE] Nominations will be unlocked in %d seconds", g_NominationDelay - GetTime()); + return Plugin_Handled; + } - if(args == 0) - { - AttemptNominate(client); - return Plugin_Handled; - } + if(args == 0) + { + AttemptNominate(client); + return Plugin_Handled; + } - if(g_Player_NominationDelay[client] > GetTime()) - { - PrintToChat(client, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[client] - GetTime()); - return Plugin_Handled; - } + if(g_Player_NominationDelay[client] > GetTime()) + { + PrintToChat(client, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[client] - GetTime()); + return Plugin_Handled; + } - static char mapname[PLATFORM_MAX_PATH]; - GetCmdArg(1, mapname, sizeof(mapname)); + static char mapname[PLATFORM_MAX_PATH]; + GetCmdArg(1, mapname, sizeof(mapname)); - int status; - if(!GetTrieValue(g_mapTrie, mapname, status)) - { - CPrintToChat(client, "%t", "Map was not found", mapname); - AttemptNominate(client, mapname); - return Plugin_Handled; - } + int status; + if(!GetTrieValue(g_mapTrie, mapname, status)) + { + CPrintToChat(client, "%t", "Map was not found", mapname); + AttemptNominate(client, mapname); + return Plugin_Handled; + } - bool RestrictionsActive = AreRestrictionsActive(); + bool RestrictionsActive = AreRestrictionsActive(); - if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) - { - if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) - CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map"); + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) + { + if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) + CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map"); - if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) - { - int Cooldown = GetMapCooldown(mapname); - CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); - } + if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) + { + int Cooldown = GetMapCooldown(mapname); + CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); + } - if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) - CPrintToChat(client, "[NE] %t", "Map Already Nominated"); + if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) + CPrintToChat(client, "[NE] %t", "Map Already Nominated"); - return Plugin_Handled; - } + return Plugin_Handled; + } - int Cooldown = GetMapCooldownTime(mapname); - if(RestrictionsActive && Cooldown > GetTime()) - { - int Seconds = Cooldown - GetTime(); - CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60); + int Cooldown = GetMapCooldownTime(mapname); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60); - return Plugin_Handled; - } + return Plugin_Handled; + } - bool VIPRestriction = GetMapVIPRestriction(mapname, client); - if(RestrictionsActive && VIPRestriction) - { - CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error"); + bool VIPRestriction = GetMapVIPRestriction(mapname, client); + if(RestrictionsActive && VIPRestriction) + { + CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error"); - return Plugin_Handled; - } + return Plugin_Handled; + } - int TimeRestriction = GetMapTimeRestriction(mapname); - if(RestrictionsActive && TimeRestriction) - { - CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60); + int TimeRestriction = GetMapTimeRestriction(mapname); + if(RestrictionsActive && TimeRestriction) + { + CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60); - return Plugin_Handled; - } + return Plugin_Handled; + } - int PlayerRestriction = GetMapPlayerRestriction(mapname); - if(RestrictionsActive && PlayerRestriction) - { - if(PlayerRestriction < 0) - CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1); - else - CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction); + int PlayerRestriction = GetMapPlayerRestriction(mapname); + if(RestrictionsActive && PlayerRestriction) + { + if(PlayerRestriction < 0) + CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1); + else + CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction); - return Plugin_Handled; - } + return Plugin_Handled; + } - int GroupRestriction = GetMapGroupRestriction(mapname, client); - if(RestrictionsActive && GroupRestriction >= 0) - { - CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); - return Plugin_Handled; - } + int GroupRestriction = GetMapGroupRestriction(mapname, client); + if(RestrictionsActive && GroupRestriction >= 0) + { + CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); + return Plugin_Handled; + } - NominateResult result = NominateMap(mapname, false, client); + NominateResult result = NominateMap(mapname, false, client); - if(result > Nominate_Replaced) - { - if(result == Nominate_AlreadyInVote) - CPrintToChat(client, "[NE] %t", "Map Already In Vote", mapname); - else if(result == Nominate_VoteFull) - CPrintToChat(client, "[NE] %t", "Max Nominations"); + if (result == Nominate_InvalidMap) + { + CPrintToChat(client, "[NE] %t", "You already nominated the map ", mapname); + return Plugin_Handled; + } + if(result > Nominate_Replaced) + { + if(result == Nominate_AlreadyInVote) + CPrintToChat(client, "[NE] %t", "Map Already In Vote", mapname); + else if(result == Nominate_VoteFull) + CPrintToChat(client, "[NE] %t", "Max Nominations"); - return Plugin_Handled; - } + return Plugin_Handled; + } - /* Map was nominated! - Disable the menu item and update the trie */ + /* Map was nominated! - Disable the menu item and update the trie */ - SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); + //SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); - static char name[MAX_NAME_LENGTH]; - GetClientName(client, name, sizeof(name)); + static char name[MAX_NAME_LENGTH]; + GetClientName(client, name, sizeof(name)); - if(result == Nominate_Added) - PrintToChatAll("[NE] %t", "Map Nominated", name, mapname); - else if(result == Nominate_Replaced) - PrintToChatAll("[NE] %t", "Map Nomination Changed", name, mapname); + if(result == Nominate_Added) + PrintToChatAll("[NE] %t", "Map Nominated", name, mapname); + else if(result == Nominate_Replaced) + PrintToChatAll("[NE] %t", "Map Nomination Changed", name, mapname); - LogMessage("%s nominated %s", name, mapname); + LogMessage("%s nominated %s", name, mapname); - g_Player_NominationDelay[client] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); + g_Player_NominationDelay[client] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); - return Plugin_Continue; + return Plugin_Continue; } public Action Command_NominateList(int client, int args) @@ -701,15 +698,14 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in void AttemptNominate(int client, const char[] filter = "") { - if(!client) - return; + if(!client) + return; - Menu menu = g_MapMenu; - if(filter[0]) - menu = BuildMapMenu(filter); + Menu menu = g_MapMenu; + menu = BuildMapMenu(filter, client); - SetMenuTitle(menu, "%T", "Nominate Title", client); - DisplayMenu(menu, client, MENU_TIME_FOREVER); + SetMenuTitle(menu, "%T", "Nominate Title", client); + DisplayMenu(menu, client, MENU_TIME_FOREVER); } void AttemptAdminNominate(int client, const char[] filter = "") @@ -786,25 +782,64 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "") return true; } -Menu BuildMapMenu(const char[] filter) +Menu BuildMapMenu(const char[] filter, int client) { - Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); + Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); - static char map[PLATFORM_MAX_PATH]; + static char map[PLATFORM_MAX_PATH * 2]; - for(int i = 0; i < GetArraySize(g_MapList); i++) - { - GetArrayString(g_MapList, i, map, sizeof(map)); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + ArrayList MapList = CreateArray(arraySize); + ArrayList OwnerList = CreateArray(); + StringMap sm = new StringMap(); - if(!filter[0] || StrContains(map, filter, false) != -1) - { - AddMenuItem(menu, map, map); - } - } + GetNominatedMapList(MapList, OwnerList); + bool nominated_maps = true; + if (!GetArraySize(MapList)) + { + nominated_maps = false; + } - SetMenuExitButton(menu, true); + if (client != 0 && nominated_maps) + { + for(int j = 0; j < GetArraySize(MapList); j++) + { + int owner = GetArrayCell(OwnerList, j); + if (client == owner) + { + GetArrayString(MapList, j, map, sizeof(map)); + sm.SetValue(map, 1); + } + } + } - return menu; + for(int i = 0; i < GetArraySize(g_MapList); i++) + { + GetArrayString(g_MapList, i, map, sizeof(map)); + + if(!filter[0] || StrContains(map, filter, false) != -1) + { + if (client != 0 && nominated_maps) + { + int map_present = 0; + sm.GetValue(map, map_present); + if (map_present == 1) + { + //PrintToChatAll("client %N here. map: %s", client, map); + StrCat(map, sizeof(map), " (Nominated)"); + } + } + AddMenuItem(menu, map, map); + } + } + + delete MapList; + delete OwnerList; + delete sm; + + SetMenuExitButton(menu, true); + + return menu; } Menu BuildAdminMapMenu(const char[] filter) @@ -840,218 +875,229 @@ Menu BuildAdminMapMenu(const char[] filter) public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int param2) { - switch(action) - { - case MenuAction_End: - { - if(menu != g_MapMenu) - delete menu; - } - case MenuAction_Select: - { - if(g_Player_NominationDelay[param1] > GetTime()) - { - PrintToChat(param1, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[param1] - GetTime()); - DisplayMenuAtItem(menu, param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); - return 0; - } + switch(action) + { + case MenuAction_End: + { + if (menu != g_MapMenu) + { + delete menu; + } + } + case MenuAction_Select: + { + if(g_Player_NominationDelay[param1] > GetTime()) + { + PrintToChat(param1, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[param1] - GetTime()); + DisplayMenuAtItem(menu, param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } - static char map[PLATFORM_MAX_PATH]; - char name[MAX_NAME_LENGTH]; - GetMenuItem(menu, param2, map, sizeof(map)); + static char map[PLATFORM_MAX_PATH]; + char name[MAX_NAME_LENGTH]; + GetMenuItem(menu, param2, map, sizeof(map)); - GetClientName(param1, name, MAX_NAME_LENGTH); + GetClientName(param1, name, MAX_NAME_LENGTH); - if(AreRestrictionsActive() && ( - GetMapCooldownTime(map) > GetTime() || - GetMapTimeRestriction(map) || - GetMapPlayerRestriction(map) || - GetMapGroupRestriction(map, param1) >= 0 || - GetMapVIPRestriction(map, param1))) - { - PrintToChat(param1, "[NE] You can't nominate this map right now."); - return 0; - } + if(AreRestrictionsActive() && ( + GetMapCooldownTime(map) > GetTime() || + GetMapTimeRestriction(map) || + GetMapPlayerRestriction(map) || + GetMapGroupRestriction(map, param1) >= 0 || + GetMapVIPRestriction(map, param1))) + { + PrintToChat(param1, "[NE] You cant nominate this map right now."); + return 0; + } - NominateResult result = NominateMap(map, false, param1); + NominateResult result = NominateMap(map, false, param1); - /* Don't need to check for InvalidMap because the menu did that already */ - if(result == Nominate_AlreadyInVote) - { - PrintToChat(param1, "[NE] %t", "Map Already Nominated"); - return 0; - } - else if(result == Nominate_VoteFull) - { - PrintToChat(param1, "[NE] %t", "Max Nominations"); - return 0; - } + if (result == Nominate_InvalidMap) + { + PrintToChat(param1, "[NE] You already nominated the map %s", map); + return 0; + } - SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); + /* Dont need to check for InvalidMap because the menu did that already */ + if(result == Nominate_AlreadyInVote) + { + PrintToChat(param1, "[NE] %t", "Map Already Nominated"); + return 0; + } + else if(result == Nominate_VoteFull) + { + PrintToChat(param1, "[NE] %t", "Max Nominations"); + return 0; + } - if(result == Nominate_Added) - PrintToChatAll("[NE] %t", "Map Nominated", name, map); - else if(result == Nominate_Replaced) - PrintToChatAll("[NE] %t", "Map Nomination Changed", name, map); + //SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); - LogMessage("%s nominated %s", name, map); - g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); - } + if(result == Nominate_Added) + PrintToChatAll("[NE] %t", "Map Nominated", name, map); + else if(result == Nominate_Replaced) + PrintToChatAll("[NE] %t", "Map Nomination Changed", name, map); - case MenuAction_DrawItem: - { - static char map[PLATFORM_MAX_PATH]; - GetMenuItem(menu, param2, map, sizeof(map)); + LogMessage("%s nominated %s", name, map); + g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); + } - int status; - if(GetTrieValue(g_mapTrie, map, status)) - { - if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) - { - if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) - { - return ITEMDRAW_DISABLED; - } + case MenuAction_DrawItem: + { + static char map[PLATFORM_MAX_PATH]; + GetMenuItem(menu, param2, map, sizeof(map)); - if(AreRestrictionsActive() && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) - { - return ITEMDRAW_DISABLED; - } + int status; + if(GetTrieValue(g_mapTrie, map, status)) + { + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) + { + if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) + { + return ITEMDRAW_DISABLED; + } - if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) - { - return ITEMDRAW_DISABLED; - } - } - } + if(AreRestrictionsActive() && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) + { + return ITEMDRAW_DISABLED; + } - if(AreRestrictionsActive() && ( - GetMapCooldownTime(map) > GetTime() || - GetMapTimeRestriction(map) || - GetMapPlayerRestriction(map) || - GetMapGroupRestriction(map, param1) >= 0 || - GetMapVIPRestriction(map, param1))) - { - return ITEMDRAW_DISABLED; - } + if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) + { + return ITEMDRAW_DISABLED; + } + } + } - return ITEMDRAW_DEFAULT; - } + if(AreRestrictionsActive() && ( + GetMapCooldownTime(map) > GetTime() || + GetMapTimeRestriction(map) || + GetMapPlayerRestriction(map) || + GetMapGroupRestriction(map, param1) >= 0 || + GetMapVIPRestriction(map, param1))) + { + return ITEMDRAW_DISABLED; + } - case MenuAction_DisplayItem: - { - static char map[PLATFORM_MAX_PATH]; - GetMenuItem(menu, param2, map, sizeof(map)); + return ITEMDRAW_DEFAULT; + } - int mark = GetConVarInt(g_Cvar_MarkCustomMaps); - bool official; + case MenuAction_DisplayItem: + { + static char map[PLATFORM_MAX_PATH]; + GetMenuItem(menu, param2, map, sizeof(map)); - static char buffer[100]; - static char display[150]; + int mark = GetConVarInt(g_Cvar_MarkCustomMaps); + bool official; - if(mark) - official = IsMapOfficial(map); + static char buffer[100]; + static char display[150]; - if(mark && !official) - { - switch(mark) - { - case 1: - { - Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map); - } + if(mark) + official = IsMapOfficial(map); - case 2: - { - Format(buffer, sizeof(buffer), "%T", "Custom", param1, map); - } - } - } - else - strcopy(buffer, sizeof(buffer), map); + if(mark && !official) + { + switch(mark) + { + case 1: + { + Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map); + } - bool RestrictionsActive = AreRestrictionsActive(); + case 2: + { + Format(buffer, sizeof(buffer), "%T", "Custom", param1, map); + } + } + } + else + strcopy(buffer, sizeof(buffer), map); - bool VIPRestriction = GetMapVIPRestriction(map); - if(RestrictionsActive && VIPRestriction) - { - Format(buffer, sizeof(buffer), "%s (%T)", buffer, "VIP Restriction", param1); - } + bool RestrictionsActive = AreRestrictionsActive(); - int status; - if(GetTrieValue(g_mapTrie, map, status)) - { - if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) - { - if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) - { - Format(display, sizeof(display), "%s (%T)", buffer, "Current Map", param1); - return RedrawMenuItem(display); - } + bool VIPRestriction = GetMapVIPRestriction(map); + if(RestrictionsActive && VIPRestriction) + { + Format(buffer, sizeof(buffer), "%s (%T)", buffer, "VIP Restriction", param1); + } - if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) - { - int Cooldown = GetMapCooldown(map); - Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); - return RedrawMenuItem(display); - } + int status; + if(GetTrieValue(g_mapTrie, map, status)) + { + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) + { + if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Current Map", param1); + return RedrawMenuItem(display); + } - if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) - { - Format(display, sizeof(display), "%s (%T)", buffer, "Nominated", param1); - return RedrawMenuItem(display); - } - } - } + if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) + { + int Cooldown = GetMapCooldown(map); + Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); + return RedrawMenuItem(display); + } - int Cooldown = GetMapCooldownTime(map); - if(RestrictionsActive && Cooldown > GetTime()) - { - int Seconds = Cooldown - GetTime(); - char time[16]; - CustomFormatTime(Seconds, time, sizeof(time)); - Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time); - return RedrawMenuItem(display); - } + if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Nominated", param1); + return RedrawMenuItem(display); + } + } + } - int TimeRestriction = GetMapTimeRestriction(map); - if(RestrictionsActive && TimeRestriction) - { - Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60); - return RedrawMenuItem(display); - } + int Cooldown = GetMapCooldownTime(map); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + char time[16]; + CustomFormatTime(Seconds, time, sizeof(time)); + Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time); + return RedrawMenuItem(display); + } - int PlayerRestriction = GetMapPlayerRestriction(map); - if(RestrictionsActive && PlayerRestriction) - { - if(PlayerRestriction < 0) - Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1); - else - Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "-", PlayerRestriction); + int TimeRestriction = GetMapTimeRestriction(map); + if(RestrictionsActive && TimeRestriction) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60); + return RedrawMenuItem(display); + } - return RedrawMenuItem(display); - } + int PlayerRestriction = GetMapPlayerRestriction(map); + if(RestrictionsActive && PlayerRestriction) + { + if(PlayerRestriction < 0) + Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1); + else + Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "-", PlayerRestriction); - int GroupRestriction = GetMapGroupRestriction(map, param1); - if(RestrictionsActive && GroupRestriction >= 0) - { - Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); - return RedrawMenuItem(display); - } + return RedrawMenuItem(display); + } - if(RestrictionsActive && VIPRestriction) - { - return RedrawMenuItem(buffer); - } + //2023 edit for multiple nominations + /* + int GroupRestriction = GetMapGroupRestriction(map, param1); + if(RestrictionsActive && GroupRestriction >= 0) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); + return RedrawMenuItem(display); + } + */ - if(mark && !official) - return RedrawMenuItem(buffer); + if(RestrictionsActive && VIPRestriction) + { + return RedrawMenuItem(buffer); + } - return 0; - } - } + if(mark && !official) + return RedrawMenuItem(buffer); - return 0; + return 0; + } + } + + return 0; } stock bool IsNominateAllowed(int client) @@ -1103,66 +1149,66 @@ stock bool IsNominateAllowed(int client) public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, int param2) { - switch(action) - { - case MenuAction_End: - { - if(menu != g_AdminMapMenu) - delete menu; - } - case MenuAction_Select: - { - static char map[PLATFORM_MAX_PATH]; - GetMenuItem(menu, param2, map, sizeof(map)); + switch(action) + { + case MenuAction_End: + { + if(menu != g_AdminMapMenu) + delete menu; + } + case MenuAction_Select: + { + static char map[PLATFORM_MAX_PATH]; + GetMenuItem(menu, param2, map, sizeof(map)); - if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) - { - if(AreRestrictionsActive() && ( - GetMapCooldownTime(map) > GetTime() || - GetMapTimeRestriction(map) || - GetMapPlayerRestriction(map) || - GetMapGroupRestriction(map, param1) >= 0 || - GetMapVIPRestriction(map, param1))) - { - PrintToChat(param1, "[NE] You can't nominate this map right now."); - return 0; - } - } + if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) + { + if(AreRestrictionsActive() && ( + GetMapCooldownTime(map) > GetTime() || + GetMapTimeRestriction(map) || + GetMapPlayerRestriction(map) || + GetMapGroupRestriction(map, param1) >= 0 || + GetMapVIPRestriction(map, param1))) + { + PrintToChat(param1, "[NE] You cant nominate this map right now."); + return 0; + } + } - NominateResult result = NominateMap(map, true, 0); + NominateResult result = NominateMap(map, true, 0); - if(result > Nominate_Replaced) - { - /* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it can't be full */ - PrintToChat(param1, "[NE] %t", "Map Already In Vote", map); - return 0; - } + if(result > Nominate_Replaced) + { + /* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */ + PrintToChat(param1, "[NE] %t", "Map Already In Vote", map); + return 0; + } - SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); + SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); - PrintToChat(param1, "[NE] %t", "Map Inserted", map); - LogAction(param1, -1, "\"%L\" inserted map \"%s\".", param1, map); + PrintToChat(param1, "[NE] %t", "Map Inserted", map); + LogAction(param1, -1, "\"%L\" inserted map \"%s\".", param1, map); - PrintToChatAll("[NE] %N has inserted %s into nominations", param1, map); - } + PrintToChatAll("[NE] %N has inserted %s into nominations", param1, map); + } - case MenuAction_DrawItem: - { - if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) - { - return Handler_MapSelectMenu(menu, action, param1, param2); - } + case MenuAction_DrawItem: + { + if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) + { + return Handler_MapSelectMenu(menu, action, param1, param2); + } - return ITEMDRAW_DEFAULT; - } + return ITEMDRAW_DEFAULT; + } - case MenuAction_DisplayItem: - { - return Handler_MapSelectMenu(menu, action, param1, param2); - } - } + case MenuAction_DisplayItem: + { + return Handler_MapSelectMenu(menu, action, param1, param2); + } + } - return 0; + return 0; } public int Handler_AdminRemoveMapMenu(Menu menu, MenuAction action, int param1, int param2) @@ -1180,7 +1226,7 @@ public int Handler_AdminRemoveMapMenu(Menu menu, MenuAction action, int param1, if(!RemoveNominationByMap(map)) { - CReplyToCommand(param1, "This map isn't nominated.", map); + CReplyToCommand(param1, "This map isnt nominated.", map); return 0; } @@ -1302,7 +1348,7 @@ stock int GetVIPTimeRestriction() MinTime = (MinTime <= CurTime) ? MinTime + 2400 : MinTime; MinTime = (MinTime <= MaxTime) ? MinTime + 2400 : MinTime; - // Convert our 'time' to minutes. + // Convert our time to minutes. CurTime = ((CurTime / 100) * 60) + (CurTime % 100); MinTime = ((MinTime / 100) * 60) + (MinTime % 100); MaxTime = ((MaxTime / 100) * 60) + (MaxTime % 100);