mapchooser_extended: make certain maps only available for VIPs
This commit is contained in:
parent
c4ada8e92c
commit
95e8bf6475
@ -130,6 +130,8 @@ native int GetMapGroups(const char[] map, int[] groups, int size);
|
||||
// >=0 = Group _max -> Group full
|
||||
native int GetMapGroupRestriction(const char[] map, int client = 0);
|
||||
|
||||
native bool GetMapVIPRestriction(const char[] map);
|
||||
|
||||
public SharedPlugin __pl_mapchooser_extended =
|
||||
{
|
||||
name = "mapchooser",
|
||||
|
@ -411,6 +411,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
|
||||
CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction);
|
||||
CreateNative("GetMapGroups", Native_GetMapGroups);
|
||||
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
|
||||
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
|
||||
|
||||
return APLRes_Success;
|
||||
}
|
||||
@ -1691,6 +1692,9 @@ void CreateNextVote()
|
||||
b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
|
||||
GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH);
|
||||
|
||||
if(!InternalGetMapVIPRestriction(map))
|
||||
continue;
|
||||
|
||||
if(InternalGetMapTimeRestriction(map) != 0)
|
||||
continue;
|
||||
|
||||
@ -2296,6 +2300,19 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams)
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Native_GetMapVIPRestriction(Handle plugin, int numParams)
|
||||
{
|
||||
int len;
|
||||
GetNativeStringLength(1, len);
|
||||
|
||||
if(len <= 0)
|
||||
return false;
|
||||
|
||||
char[] map = new char[len+1];
|
||||
GetNativeString(1, map, len+1);
|
||||
|
||||
return InternalGetMapVIPRestriction(map);
|
||||
}
|
||||
|
||||
stock void AddMapItem(const char[] map)
|
||||
{
|
||||
@ -2594,6 +2611,18 @@ stock int FindIntInArray(int[] array, int size, int value)
|
||||
return -1;
|
||||
}
|
||||
|
||||
stock bool InternalGetMapVIPRestriction(const char[] map)
|
||||
{
|
||||
int VIP = 0;
|
||||
|
||||
if(g_Config && g_Config.JumpToKey(map))
|
||||
{
|
||||
VIP = g_Config.GetNum("VIP", VIP);
|
||||
g_Config.Rewind();
|
||||
}
|
||||
|
||||
return view_as<bool>(VIP);
|
||||
}
|
||||
|
||||
stock void InternalRestoreMapCooldowns()
|
||||
{
|
||||
|
@ -58,6 +58,7 @@ Handle g_Cvar_ExcludeCurrent = INVALID_HANDLE;
|
||||
Handle g_MapList = INVALID_HANDLE;
|
||||
Handle g_AdminMapList = INVALID_HANDLE;
|
||||
Menu g_MapMenu;
|
||||
Menu g_VIPMapMenu;
|
||||
Menu g_AdminMapMenu;
|
||||
int g_mapFileSerial = -1;
|
||||
int g_AdminMapFileSerial = -1;
|
||||
@ -190,6 +191,11 @@ void UpdateMapMenus()
|
||||
|
||||
g_MapMenu = BuildMapMenu("");
|
||||
|
||||
if(g_VIPMapMenu != INVALID_HANDLE)
|
||||
delete g_VIPMapMenu;
|
||||
|
||||
g_VIPMapMenu = BuildVIPMapMenu("");
|
||||
|
||||
if(g_AdminMapMenu != INVALID_HANDLE)
|
||||
delete g_AdminMapMenu;
|
||||
|
||||
@ -510,6 +516,14 @@ public Action Command_Nominate(int client, int args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
bool VIPRestriction = GetMapVIPRestriction(mapname);
|
||||
if((VIPRestriction) && !(CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1) || CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK)))
|
||||
{
|
||||
CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
int TimeRestriction = GetMapTimeRestriction(mapname);
|
||||
if(TimeRestriction)
|
||||
{
|
||||
@ -628,8 +642,18 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in
|
||||
void AttemptNominate(int client, const char[] filter = "")
|
||||
{
|
||||
Menu menu = g_MapMenu;
|
||||
|
||||
if(CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1) || CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
||||
{
|
||||
menu = g_VIPMapMenu;
|
||||
if(filter[0])
|
||||
menu = BuildVIPMapMenu(filter);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(filter[0])
|
||||
menu = BuildMapMenu(filter);
|
||||
}
|
||||
|
||||
SetMenuTitle(menu, "%T", "Nominate Title", client);
|
||||
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
||||
@ -670,6 +694,27 @@ Menu BuildMapMenu(const char[] filter)
|
||||
return menu;
|
||||
}
|
||||
|
||||
Menu BuildVIPMapMenu(const char[] filter)
|
||||
{
|
||||
Menu menu = CreateMenu(Handler_VIPMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
|
||||
|
||||
static char map[PLATFORM_MAX_PATH];
|
||||
|
||||
for(int i = 0; i < GetArraySize(g_MapList); i++)
|
||||
{
|
||||
GetArrayString(g_MapList, i, map, sizeof(map));
|
||||
|
||||
if(!filter[0] || StrContains(map, filter, false) != -1)
|
||||
{
|
||||
AddMenuItem(menu, map, map);
|
||||
}
|
||||
}
|
||||
|
||||
SetMenuExitButton(menu, true);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
Menu BuildAdminMapMenu(const char[] filter)
|
||||
{
|
||||
Menu menu = CreateMenu(Handler_AdminMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
|
||||
@ -750,6 +795,181 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
|
||||
g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay);
|
||||
}
|
||||
|
||||
case MenuAction_DrawItem:
|
||||
{
|
||||
static char map[PLATFORM_MAX_PATH];
|
||||
GetMenuItem(menu, param2, map, sizeof(map));
|
||||
|
||||
int status;
|
||||
|
||||
if(!GetTrieValue(g_mapTrie, map, status))
|
||||
{
|
||||
LogError("Menu selection of item not in trie. Major logic problem somewhere.");
|
||||
return ITEMDRAW_DEFAULT;
|
||||
}
|
||||
|
||||
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
|
||||
return ITEMDRAW_DISABLED;
|
||||
|
||||
if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map))
|
||||
return ITEMDRAW_DISABLED;
|
||||
|
||||
return ITEMDRAW_DEFAULT;
|
||||
}
|
||||
|
||||
case MenuAction_DisplayItem:
|
||||
{
|
||||
static char map[PLATFORM_MAX_PATH];
|
||||
GetMenuItem(menu, param2, map, sizeof(map));
|
||||
|
||||
int mark = GetConVarInt(g_Cvar_MarkCustomMaps);
|
||||
bool official;
|
||||
|
||||
int status;
|
||||
|
||||
if(!GetTrieValue(g_mapTrie, map, status))
|
||||
{
|
||||
LogError("Menu selection of item not in trie. Major logic problem somewhere.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char buffer[100];
|
||||
static char display[150];
|
||||
|
||||
if(mark)
|
||||
official = IsMapOfficial(map);
|
||||
|
||||
if(mark && !official)
|
||||
{
|
||||
switch(mark)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map);
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
Format(buffer, sizeof(buffer), "%T", "Custom", param1, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
strcopy(buffer, sizeof(buffer), map);
|
||||
|
||||
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_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
|
||||
{
|
||||
int Cooldown = GetMapCooldown(map);
|
||||
Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
|
||||
{
|
||||
Format(display, sizeof(display), "%s (%T)", buffer, "Nominated", param1);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
}
|
||||
|
||||
bool VIPRestriction = GetMapVIPRestriction(map);
|
||||
if(VIPRestriction)
|
||||
{
|
||||
Format(display, sizeof(display), "%s (%T)", buffer, "VIP Restriction", param1);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int TimeRestriction = GetMapTimeRestriction(map);
|
||||
if(TimeRestriction)
|
||||
{
|
||||
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int PlayerRestriction = GetMapPlayerRestriction(map);
|
||||
if(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);
|
||||
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
int GroupRestriction = GetMapGroupRestriction(map, param1);
|
||||
if(GroupRestriction >= 0)
|
||||
{
|
||||
Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction);
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
if(mark && !official)
|
||||
return RedrawMenuItem(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Handler_VIPMapSelectMenu(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;
|
||||
}
|
||||
|
||||
static char map[PLATFORM_MAX_PATH];
|
||||
char name[MAX_NAME_LENGTH];
|
||||
GetMenuItem(menu, param2, map, sizeof(map));
|
||||
|
||||
GetClientName(param1, name, MAX_NAME_LENGTH);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
|
||||
|
||||
if(result == Nominate_Added)
|
||||
PrintToChatAll("[NE] %t", "Map Nominated", name, map);
|
||||
else if(result == Nominate_Replaced)
|
||||
PrintToChatAll("[NE] %t", "Map Nomination Changed", name, map);
|
||||
|
||||
LogMessage("%s nominated %s", name, map);
|
||||
g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay);
|
||||
}
|
||||
|
||||
case MenuAction_DrawItem:
|
||||
{
|
||||
static char map[PLATFORM_MAX_PATH];
|
||||
@ -838,7 +1058,6 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
|
||||
if(TimeRestriction)
|
||||
{
|
||||
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
|
||||
|
||||
return RedrawMenuItem(display);
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,11 @@
|
||||
"en" "*{1}"
|
||||
}
|
||||
|
||||
"Map Nominate VIP Error"
|
||||
{
|
||||
"en" "Only VIPs can nominate this map."
|
||||
}
|
||||
|
||||
"Map Nominate Time Error"
|
||||
{
|
||||
"#format" "{1:d},{2:d}"
|
||||
@ -148,6 +153,11 @@
|
||||
"en" "Group max: {1}"
|
||||
}
|
||||
|
||||
"VIP Restriction"
|
||||
{
|
||||
"en" "VIP only"
|
||||
}
|
||||
|
||||
"Nomination Removed Time Error"
|
||||
{
|
||||
"#format" "{1:s}"
|
||||
|
Loading…
Reference in New Issue
Block a user