From 5cd37b4e7d9a578b32980b1ed308038f20e5873a Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 19 Dec 2016 08:34:52 +0100 Subject: [PATCH] Added search/filter to nominate and nominate_addmap Refactor rockthevote --- .../scripting/nominations_extended.sp | 158 +++++++++------ .../scripting/rockthevote_extended.sp | 191 ++++++++---------- 2 files changed, 172 insertions(+), 177 deletions(-) diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index a76d42eb..1be284c4 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -56,8 +56,8 @@ Handle g_Cvar_ExcludeCurrent = INVALID_HANDLE; Handle g_MapList = INVALID_HANDLE; Handle g_AdminMapList = INVALID_HANDLE; -Handle g_MapMenu = INVALID_HANDLE; -Handle g_AdminMapMenu = INVALID_HANDLE; +Menu g_MapMenu; +Menu g_AdminMapMenu; int g_mapFileSerial = -1; int g_AdminMapFileSerial = -1; @@ -129,6 +129,7 @@ public void OnConfigsExecuted() SetFailState("Unable to create a valid map list."); } } + if(ReadMapList(g_AdminMapList, g_AdminMapFileSerial, "sm_nominate_addmap menu", @@ -155,8 +156,54 @@ public void OnConfigsExecuted() g_NominationDelay = GetTime() + GetConVarInt(g_Cvar_InitialDelay); - BuildMapMenu(); - BuildAdminMapMenu(); + if(g_MapMenu != INVALID_HANDLE) + delete g_MapMenu; + + g_MapMenu = BuildMapMenu(""); + + static char map[PLATFORM_MAX_PATH]; + static char currentMap[PLATFORM_MAX_PATH]; + ArrayList excludeMaps; + + if(GetConVarBool(g_Cvar_ExcludeOld)) + { + excludeMaps = CreateArray(ByteCountToCells(PLATFORM_MAX_PATH)); + GetExcludeMapList(excludeMaps); + } + + if(GetConVarBool(g_Cvar_ExcludeCurrent)) + GetCurrentMap(currentMap, sizeof(currentMap)); + + ClearTrie(g_mapTrie); + for(int i = 0; i < GetArraySize(g_MapList); i++) + { + int status = MAPSTATUS_ENABLED; + + GetArrayString(g_MapList, i, map, sizeof(map)); + + if(GetConVarBool(g_Cvar_ExcludeCurrent)) + { + if(StrEqual(map, currentMap)) + status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_CURRENT; + } + + /* Dont bother with this check if the current map check passed */ + if(GetConVarBool(g_Cvar_ExcludeOld) && status == MAPSTATUS_ENABLED) + { + if(FindStringInArray(excludeMaps, map) != -1) + status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS; + } + + SetTrieValue(g_mapTrie, map, status); + } + + if(excludeMaps) + delete excludeMaps; + + if(g_AdminMapMenu != INVALID_HANDLE) + delete g_AdminMapMenu; + + g_AdminMapMenu = BuildAdminMapMenu(""); } public void OnNominationRemoved(const char[] map, int owner) @@ -194,6 +241,7 @@ public Action Command_Addmap(int client, int args) if(!IsMapValid(mapname)) { CReplyToCommand(client, "%t", "Map was not found", mapname); + AttemptAdminNominate(client, mapname); return Plugin_Handled; } @@ -393,6 +441,7 @@ public Action Command_Nominate(int client, int args) if(!GetTrieValue(g_mapTrie, mapname, status)) { CPrintToChat(client, "%t", "Map was not found", mapname); + AttemptNominate(client, mapname); return Plugin_Handled; } @@ -484,7 +533,7 @@ public Action Command_NominateList(int client, int args) return Plugin_Handled; } -public int Handler_NominateListMenu(Handle menu, MenuAction action, int param1, int param2) +public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, int param2) { switch(action) { @@ -497,86 +546,52 @@ public int Handler_NominateListMenu(Handle menu, MenuAction action, int param1, return 0; } -void AttemptNominate(int client) +void AttemptNominate(int client, const char[] filter = "") { - SetMenuTitle(g_MapMenu, "%T", "Nominate Title", client); - DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER); + 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) +void AttemptAdminNominate(int client, const char[] filter = "") { - SetMenuTitle(g_AdminMapMenu, "%T", "Nominate Title", client); - DisplayMenu(g_AdminMapMenu, client, MENU_TIME_FOREVER); + Menu menu = g_AdminMapMenu; + if(filter[0]) + menu = BuildAdminMapMenu(filter); + + SetMenuTitle(menu, "%T", "Nominate Title", client); + DisplayMenu(menu, client, MENU_TIME_FOREVER); return; } -void BuildMapMenu() +Menu BuildMapMenu(const char[] filter) { - if(g_MapMenu != INVALID_HANDLE) - { - CloseHandle(g_MapMenu); - g_MapMenu = INVALID_HANDLE; - } - - ClearTrie(g_mapTrie); - - g_MapMenu = 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]; - ArrayList excludeMaps; - static char currentMap[32]; - - if(GetConVarBool(g_Cvar_ExcludeOld)) - { - excludeMaps = CreateArray(ByteCountToCells(PLATFORM_MAX_PATH)); - GetExcludeMapList(excludeMaps); - } - - if(GetConVarBool(g_Cvar_ExcludeCurrent)) - GetCurrentMap(currentMap, sizeof(currentMap)); - for(int i = 0; i < GetArraySize(g_MapList); i++) { - int status = MAPSTATUS_ENABLED; - GetArrayString(g_MapList, i, map, sizeof(map)); - if(GetConVarBool(g_Cvar_ExcludeCurrent)) - { - if(StrEqual(map, currentMap)) - status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_CURRENT; - } - - /* Dont bother with this check if the current map check passed */ - if(GetConVarBool(g_Cvar_ExcludeOld) && status == MAPSTATUS_ENABLED) - { - if(FindStringInArray(excludeMaps, map) != -1) - status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS; - } - - AddMenuItem(g_MapMenu, map, map); - SetTrieValue(g_mapTrie, map, status); + if(!filter[0] || StrContains(map, filter, false) != -1) + AddMenuItem(menu, map, map); } - SetMenuExitButton(g_MapMenu, true); + SetMenuExitButton(menu, true); - if(excludeMaps) - delete excludeMaps; + return menu; } -void BuildAdminMapMenu() +Menu BuildAdminMapMenu(const char[] filter) { - if(g_AdminMapMenu != INVALID_HANDLE) - { - CloseHandle(g_AdminMapMenu); - g_AdminMapMenu = INVALID_HANDLE; - } - - g_AdminMapMenu = CreateMenu(Handler_AdminMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); + Menu menu = CreateMenu(Handler_AdminMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); static char map[PLATFORM_MAX_PATH]; @@ -584,16 +599,24 @@ void BuildAdminMapMenu() { GetArrayString(g_AdminMapList, i, map, sizeof(map)); - AddMenuItem(g_AdminMapMenu, map, map); + if(!filter[0] || StrContains(map, filter, false) != -1) + AddMenuItem(menu, map, map); } - SetMenuExitButton(g_AdminMapMenu, true); + SetMenuExitButton(menu, true); + + return menu; } -public int Handler_MapSelectMenu(Handle menu, MenuAction action, int param1, int param2) +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()) @@ -770,10 +793,15 @@ stock bool IsNominateAllowed(int client) return true; } -public int Handler_AdminMapSelectMenu(Handle menu, MenuAction action, int param1, int param2) +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]; diff --git a/mapchooser_extended/scripting/rockthevote_extended.sp b/mapchooser_extended/scripting/rockthevote_extended.sp index 5f1188a2..b2d19c0e 100644 --- a/mapchooser_extended/scripting/rockthevote_extended.sp +++ b/mapchooser_extended/scripting/rockthevote_extended.sp @@ -41,10 +41,11 @@ #include #pragma semicolon 1 +#pragma newdecls required #define MCE_VERSION "1.11.0" -public Plugin:myinfo = +public Plugin myinfo = { name = "Rock The Vote Extended", author = "Powerlord and AlliedModders LLC", @@ -53,23 +54,24 @@ public Plugin:myinfo = url = "https://forums.alliedmods.net/showthread.php?t=156974" }; -new Handle:g_Cvar_Needed = INVALID_HANDLE; -new Handle:g_Cvar_MinPlayers = INVALID_HANDLE; -new Handle:g_Cvar_InitialDelay = INVALID_HANDLE; -new Handle:g_Cvar_Interval = INVALID_HANDLE; -new Handle:g_Cvar_ChangeTime = INVALID_HANDLE; -new Handle:g_Cvar_RTVPostVoteAction = INVALID_HANDLE; +Handle g_Cvar_Needed = INVALID_HANDLE; +Handle g_Cvar_MinPlayers = INVALID_HANDLE; +Handle g_Cvar_InitialDelay = INVALID_HANDLE; +Handle g_Cvar_Interval = INVALID_HANDLE; +Handle g_Cvar_ChangeTime = INVALID_HANDLE; +Handle g_Cvar_RTVPostVoteAction = INVALID_HANDLE; -new bool:g_CanRTV = false; // True if RTV loaded maps and is active. -new bool:g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes. -new g_Voters = 0; // Total voters connected. Doesn't include fake clients. -new g_Votes = 0; // Total number of "say rtv" votes -new g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) -new bool:g_Voted[MAXPLAYERS+1] = {false, ...}; +bool g_CanRTV = false; // True if RTV loaded maps and is active. +bool g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes. +int g_Voters = 0; // Total voters connected. Doesn't include fake clients. +int g_Votes = 0; // Total number of "say rtv" votes +int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) +bool g_Voted[MAXPLAYERS+1] = {false, ...}; -new bool:g_InChange = false; +bool g_InChange = false; +bool g_bLate = false; -public OnPluginStart() +public void OnPluginStart() { LoadTranslations("common.phrases"); LoadTranslations("rockthevote.phrases"); @@ -96,39 +98,43 @@ public OnPluginStart() CreateConVar("rtve_version", MCE_VERSION, "Rock The Vote Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); AutoExecConfig(true, "rtv"); + + /* Handle late load */ + g_bLate = true; } -public OnMapStart() +public void OnMapStart() { g_Voters = 0; g_Votes = 0; g_VotesNeeded = 0; g_InChange = false; - /* Handle late load */ - for (new i=1; i<=MaxClients; i++) + if(g_bLate) { - if (IsClientConnected(i)) + for(int client = 1; client <= MaxClients; client++) { - OnClientConnected(i); + if(IsClientConnected(client)) + OnClientConnected(client); } + g_bLate = false; } } -public OnMapEnd() +public void OnMapEnd() { g_CanRTV = false; g_RTVAllowed = false; } -public OnConfigsExecuted() +public void OnConfigsExecuted() { g_CanRTV = true; g_RTVAllowed = false; CreateTimer(GetConVarFloat(g_Cvar_InitialDelay), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE); } -public OnClientConnected(client) +public void OnClientConnected(int client) { if(IsFakeClient(client)) return; @@ -141,145 +147,117 @@ public OnClientConnected(client) return; } -public OnClientDisconnect(client) +public void OnClientDisconnect(int client) { if(IsFakeClient(client)) return; if(g_Voted[client]) - { g_Votes--; - } g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3); - g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed)); - if (!g_CanRTV) - { + if(!g_CanRTV) return; - } - if (g_Votes && + if(g_Votes && g_Voters && g_Votes >= g_VotesNeeded && g_RTVAllowed ) { - if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()) - { + if(GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()) return; - } StartRTV(); } } -public OnPlayerChangedTeam(Handle:event, const String:name[], bool:dontBroadcast) +public void OnPlayerChangedTeam(Handle event, const char[] name, bool dontBroadcast) { - new Client = GetClientOfUserId(GetEventInt(event, "userid")); - - if(IsFakeClient(Client)) + int client = GetClientOfUserId(GetEventInt(event, "userid")); + if(client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || IsFakeClient(client) || + GetClientTeam(client) == 0 || GetClientTeam(client) == 1) return; - if(Client == 0) + g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3); + g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed)); + + if(g_Votes && + g_Voters && + g_Votes >= g_VotesNeeded && + g_RTVAllowed ) { - return; - } + if(GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()) + return; - if (IsClientInGame(Client) && IsClientConnected(Client)) - { - if (GetClientTeam(Client) == 1) - { - g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3); - g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed)); - - if (g_Votes && - g_Voters && - g_Votes >= g_VotesNeeded && - g_RTVAllowed ) - { - if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()) - { - return; - } - - StartRTV(); - } - } + StartRTV(); } } -public Action:Command_RTV(client, args) +public Action Command_RTV(int client, int args) { - if (!g_CanRTV || !client) - { + if(!g_CanRTV || !client) return Plugin_Handled; - } AttemptRTV(client); return Plugin_Handled; } -public Action:Command_Say(client, args) +public Action Command_Say(int client, int args) { - if (!g_CanRTV || !client) - { + if(!g_CanRTV || !client) return Plugin_Continue; - } - decl String:text[192]; - if (!GetCmdArgString(text, sizeof(text))) - { + static char text[192]; + if(!GetCmdArgString(text, sizeof(text))) return Plugin_Continue; - } - new startidx = 0; + int startidx = 0; if(text[strlen(text)-1] == '"') { text[strlen(text)-1] = '\0'; startidx = 1; } - new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT); + ReplySource old = SetCmdReplySource(SM_REPLY_TO_CHAT); - if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0) - { + if(strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0) AttemptRTV(client); - } SetCmdReplySource(old); return Plugin_Continue; } -AttemptRTV(client) +void AttemptRTV(int client) { - if (!g_RTVAllowed || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())) + if(!g_RTVAllowed || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())) { CReplyToCommand(client, "[SM] %t", "RTV Not Allowed"); return; } - if (!CanMapChooserStartVote()) + if(!CanMapChooserStartVote()) { CReplyToCommand(client, "[SM] %t", "RTV Started"); return; } - if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers)) + if(GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers)) { CReplyToCommand(client, "[SM] %t", "Minimal Players Not Met"); return; } - if (g_Voted[client]) + if(g_Voted[client]) { CReplyToCommand(client, "[SM] %t", "Already Voted", g_Votes, g_VotesNeeded); return; } - new String:name[MAX_NAME_LENGTH]; + char name[MAX_NAME_LENGTH]; GetClientName(client, name, sizeof(name)); g_Votes++; @@ -287,29 +265,25 @@ AttemptRTV(client) CPrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded); - if (g_Votes >= g_VotesNeeded) - { + if(g_Votes >= g_VotesNeeded) StartRTV(); - } } -public Action:Timer_DelayRTV(Handle:timer) +public Action Timer_DelayRTV(Handle timer) { g_RTVAllowed = true; } -StartRTV() +void StartRTV() { - if (g_InChange) - { + if(g_InChange) return; - } - if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished()) + if(EndOfMapVoteEnabled() && HasEndOfMapVoteFinished()) { /* Change right now then */ - new String:map[PLATFORM_MAX_PATH]; - if (GetNextMap(map, sizeof(map))) + char map[PLATFORM_MAX_PATH]; + if(GetNextMap(map, sizeof(map))) { CPrintToChatAll("[SM] %t", "Changing Maps", map); CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE); @@ -319,12 +293,13 @@ StartRTV() g_RTVAllowed = false; } + return; } - if (CanMapChooserStartVote()) + if(CanMapChooserStartVote()) { - new MapChange:when = MapChange:GetConVarInt(g_Cvar_ChangeTime); + MapChange when = view_as(GetConVarInt(g_Cvar_ChangeTime)); InitiateMapChooserVote(when); ResetRTV(); @@ -334,39 +309,33 @@ StartRTV() } } -ResetRTV() +void ResetRTV() { g_Votes = 0; - for (new i=1; i<=MAXPLAYERS; i++) - { + for(int i = 1; i <= MAXPLAYERS; i++) g_Voted[i] = false; - } } -public Action:Timer_ChangeMap(Handle:hTimer) +public Action Timer_ChangeMap(Handle hTimer) { g_InChange = false; LogMessage("RTV changing map manually"); - new String:map[PLATFORM_MAX_PATH]; - if (GetNextMap(map, sizeof(map))) - { + char map[PLATFORM_MAX_PATH]; + if(GetNextMap(map, sizeof(map))) ForceChangeLevel(map, "RTV after mapvote"); - } return Plugin_Stop; } // Rock The Vote Extended functions -public Action:Command_ForceRTV(client, args) +public Action Command_ForceRTV(int client, int args) { - if (!g_CanRTV || !client) - { + if(!g_CanRTV || !client) return Plugin_Handled; - } ShowActivity2(client, "[RTVE] ", "%t", "Initiated Vote Map"); @@ -374,5 +343,3 @@ public Action:Command_ForceRTV(client, args) return Plugin_Handled; } - -