mapchooser_extended: Fix bug with full nomination when addmap and removemap. Add nominate_removemap menu.

This commit is contained in:
BotoX 2019-12-22 14:10:01 +01:00
parent d99d5f016c
commit 1915e52302
2 changed files with 129 additions and 50 deletions

View File

@ -53,7 +53,7 @@
#pragma semicolon 1
#pragma newdecls required
#define MCE_VERSION "1.3.0"
#define MCE_VERSION "1.3.1"
enum RoundCounting
{
@ -1719,7 +1719,7 @@ NominateResult InternalNominateMap(char[] map, bool force, int owner)
}
/* Too many nominated maps. */
if(g_NominateCount >= GetVoteSize() && !force)
if(g_NominateCount >= GetVoteSize(0) && !force)
{
return Nominate_VoteFull;
}
@ -1783,9 +1783,14 @@ bool InternalRemoveNominationByMap(char[] map)
Call_PushCell(GetArrayCell(g_NominateOwners, i));
Call_Finish();
int owner = GetArrayCell(g_NominateOwners, i);
if(owner)
g_NominateCount--;
else
g_NominateReservedCount--;
RemoveFromArray(g_NominateList, i);
RemoveFromArray(g_NominateOwners, i);
g_NominateCount--;
return true;
}
@ -2376,19 +2381,17 @@ stock void AddExtendToMenu(Handle menu, MapChange when)
// 0 = IncludeMaps, 1 = Reserved, 2 = IncludeMaps+Reserved
stock int GetVoteSize(int what=0)
{
int voteSize = 0;
int includeMaps = GetConVarInt(g_Cvar_IncludeMaps);
int includeMapsReserved = GetConVarInt(g_Cvar_IncludeMapsReserved);
if(what == 0 || what == 2)
voteSize += includeMaps;
if(what == 1 || what == 2)
voteSize += includeMapsReserved;
if(what == 0)
return includeMaps;
else if(what == 1)
return includeMapsReserved;
else if(what == 2)
return includeMaps + includeMapsReserved;
if(what == 1)
return voteSize - includeMaps;
return voteSize;
return 0;
}
stock int InternalGetMapCooldown(const char[] map)
@ -2431,6 +2434,9 @@ void CheckMapRestrictions(bool time = false, bool players = false)
for(int i = 0; i < GetArraySize(g_NominateList); i++)
{
int client = GetArrayCell(g_NominateOwners, i);
if(!client)
continue;
if(CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
continue;

View File

@ -41,7 +41,7 @@
#include <multicolors>
#include <basecomm>
#define MCE_VERSION "1.3.0"
#define MCE_VERSION "1.3.1"
public Plugin myinfo =
{
@ -362,6 +362,12 @@ public Action Command_Addmap(int client, int args)
public Action Command_Removemap(int client, int args)
{
if(args == 0 && client > 0)
{
AttemptAdminRemoveMap(client);
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_removemap <mapname>");
@ -375,6 +381,7 @@ public Action Command_Removemap(int client, int args)
if(/*!GetTrieValue(g_mapTrie, mapname, status)*/!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminRemoveMap(client, mapname);
return Plugin_Handled;
}
@ -643,46 +650,38 @@ public Action Command_Nominate(int client, int args)
public Action Command_NominateList(int client, int args)
{
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
ArrayList MapList = CreateArray(arraySize);
GetNominatedMapList(MapList);
if(!GetArraySize(MapList))
{
ReplyToCommand(client, "[NE] No maps have been nominated.");
delete MapList;
return Plugin_Handled;
}
static char map[PLATFORM_MAX_PATH];
if (client == 0)
{
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
ArrayList MapList = CreateArray(arraySize);
GetNominatedMapList(MapList);
char aBuf[2048];
StrCat(aBuf, sizeof(aBuf), "[NE] Nominated Maps:");
static char map[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(MapList); i++)
{
StrCat(aBuf, sizeof(aBuf), "\n");
GetArrayString(MapList, i, map, sizeof(map));
StrCat(aBuf, sizeof(aBuf), map);
}
ReplyToCommand(client, aBuf);
delete MapList;
return Plugin_Handled;
}
Handle NominateListMenu = CreateMenu(Handler_NominateListMenu, MENU_ACTIONS_DEFAULT|MenuAction_DisplayItem);
Menu NominateListMenu = CreateMenu(Handler_NominateListMenu, MENU_ACTIONS_DEFAULT|MenuAction_DisplayItem);
for(int i = 0; i < GetArraySize(MapList); i++)
if(!PopulateNominateListMenu(NominateListMenu, client))
{
GetArrayString(MapList, i, map, sizeof(map));
AddMenuItem(NominateListMenu, map, map);
ReplyToCommand(client, "[NE] No maps have been nominated.");
return Plugin_Handled;
}
SetMenuTitle(NominateListMenu, "Nominated Maps", client);
DisplayMenu(NominateListMenu, client, MENU_TIME_FOREVER);
delete MapList;
return Plugin_Handled;
}
@ -694,22 +693,6 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in
{
delete menu;
}
case MenuAction_DisplayItem:
{
static char display[150];
static char map[PLATFORM_MAX_PATH];
GetMenuItem(menu, param2, map, sizeof(map));
bool VIPRestriction = GetMapVIPRestriction(map);
if((VIPRestriction) && AreRestrictionsActive())
{
Format(display, sizeof(display), "%s (%T)", map, "VIP Nomination", param1);
return RedrawMenuItem(display);
}
return 0;
}
}
return 0;
@ -717,26 +700,87 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in
void AttemptNominate(int client, const char[] filter = "")
{
if(!client)
return;
Menu menu = g_MapMenu;
if(filter[0])
menu = BuildMapMenu(filter);
SetMenuTitle(menu, "%T", "Nominate Title", client);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return;
}
void AttemptAdminNominate(int client, const char[] filter = "")
{
if(!client)
return;
Menu menu = g_AdminMapMenu;
if(filter[0])
menu = BuildAdminMapMenu(filter);
SetMenuTitle(menu, "%T", "Nominate Title", client);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
return;
void AttemptAdminRemoveMap(int client, const char[] filter = "")
{
if(!client)
return;
Menu AdminRemoveMapMenu = CreateMenu(Handler_AdminRemoveMapMenu, MENU_ACTIONS_DEFAULT|MenuAction_DisplayItem);
if(!PopulateNominateListMenu(AdminRemoveMapMenu, client, filter))
{
ReplyToCommand(client, "[NE] No maps have been nominated.");
return;
}
SetMenuTitle(AdminRemoveMapMenu, "Remove nomination", client);
DisplayMenu(AdminRemoveMapMenu, client, MENU_TIME_FOREVER);
}
bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
{
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
ArrayList MapList = CreateArray(arraySize);
ArrayList OwnerList = CreateArray();
GetNominatedMapList(MapList, OwnerList);
if(!GetArraySize(MapList))
{
delete MapList;
delete OwnerList;
return false;
}
static char map[PLATFORM_MAX_PATH];
static char display[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(MapList); i++)
{
GetArrayString(MapList, i, map, sizeof(map));
if(!filter[0] || StrContains(map, filter, false) != -1)
{
int owner = GetArrayCell(OwnerList, i);
if(!owner)
Format(display, sizeof(display), "%s (Admin)", map);
else
Format(display, sizeof(display), "%s (%N)", map, owner);
bool VIPRestriction = GetMapVIPRestriction(map);
if((VIPRestriction) && AreRestrictionsActive())
Format(display, sizeof(display), "%s (%T)", map, "VIP Nomination", client);
AddMenuItem(menu, map, display);
}
}
delete MapList;
delete OwnerList;
return true;
}
Menu BuildMapMenu(const char[] filter)
@ -1118,6 +1162,35 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
return 0;
}
public int Handler_AdminRemoveMapMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_End:
{
delete menu;
}
case MenuAction_Select:
{
static char map[PLATFORM_MAX_PATH];
GetMenuItem(menu, param2, map, sizeof(map));
if(!RemoveNominationByMap(map))
{
CReplyToCommand(param1, "This map isn't nominated.", map);
return 0;
}
CReplyToCommand(param1, "Map '%s' removed from the nominations list.", map);
LogAction(param1, -1, "\"%L\" removed map \"%s\" from nominations.", param1, map);
PrintToChatAll("[NE] %N has removed %s from nominations", param1, map);
}
}
return 0;
}
public int Native_GetNominationPool(Handle plugin, int numArgs)
{
SetNativeCellRef(1, g_MapList);