pred@2133: /** pred@2133: * vim: set ts=4 : pred@2133: * ============================================================================= pred@2133: * SourceMod Rock The Vote Plugin pred@2133: * Creates a map vote when the required number of players have requested one. pred@2133: * pred@2133: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. pred@2133: * ============================================================================= pred@2133: * pred@2133: * This program is free software; you can redistribute it and/or modify it under pred@2133: * the terms of the GNU General Public License, version 3.0, as published by the pred@2133: * Free Software Foundation. pred@2133: * pred@2133: * This program is distributed in the hope that it will be useful, but WITHOUT pred@2133: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS pred@2133: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more pred@2133: * details. pred@2133: * pred@2133: * You should have received a copy of the GNU General Public License along with pred@2133: * this program. If not, see . pred@2133: * pred@2133: * As a special exception, AlliedModders LLC gives you permission to link the pred@2133: * code of this program (as well as its derivative works) to "Half-Life 2," the pred@2133: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software pred@2133: * by the Valve Corporation. You must obey the GNU General Public License in pred@2133: * all respects for all other code used. Additionally, AlliedModders LLC grants pred@2133: * this exception to all derivative works. AlliedModders LLC defines further pred@2133: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), pred@2133: * or . pred@2133: * pred@2133: * Version: $Id$ pred@2133: */ pred@2133: pred@2133: #include pred@2133: #include pred@2133: pred@2133: #pragma semicolon 1 pred@2133: pred@2133: public Plugin:myinfo = pred@2133: { pred@2133: name = "Map Nominations", pred@2133: author = "AlliedModders LLC", pred@2133: description = "Provides Map Nominations", pred@2133: version = SOURCEMOD_VERSION, pred@2133: url = "http://www.sourcemod.net/" pred@2133: }; pred@2133: pred@2133: new Handle:g_Cvar_ExcludeOld = INVALID_HANDLE; pred@2133: new Handle:g_Cvar_ExcludeCurrent = INVALID_HANDLE; pred@2133: pred@2133: new Handle:g_MapList = INVALID_HANDLE; pred@2133: new Handle:g_MapMenu = INVALID_HANDLE; pred@2133: new g_mapFileSerial = -1; pred@2133: pred@2350: #define MAPSTATUS_ENABLED (1<<0) pred@2350: #define MAPSTATUS_DISABLED (1<<1) pred@2350: #define MAPSTATUS_EXCLUDE_CURRENT (1<<2) pred@2350: #define MAPSTATUS_EXCLUDE_PREVIOUS (1<<3) pred@2350: #define MAPSTATUS_EXCLUDE_NOMINATED (1<<4) pred@2350: pred@2350: new Handle:g_mapTrie; pred@2350: pred@2133: public OnPluginStart() pred@2133: { pred@2133: LoadTranslations("common.phrases"); pred@2133: LoadTranslations("nominations.phrases"); pred@2133: pred@2133: new arraySize = ByteCountToCells(33); pred@2133: g_MapList = CreateArray(arraySize); pred@2133: pred@2133: g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0); pred@2133: g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0); pred@2133: pred@2133: RegConsoleCmd("say", Command_Say); pred@2133: RegConsoleCmd("say_team", Command_Say); pred@2133: pred@2133: RegConsoleCmd("sm_nominate", Command_Nominate); pred@2133: pred@2133: RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap - Forces a map to be on the next mapvote."); pred@2350: pred@2350: g_mapTrie = CreateTrie(); pred@2133: } pred@2133: pred@2133: public OnConfigsExecuted() pred@2133: { pred@2133: if (ReadMapList(g_MapList, pred@2133: g_mapFileSerial, pred@2133: "nominations", pred@2133: MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) pred@2133: == INVALID_HANDLE) pred@2133: { pred@2133: if (g_mapFileSerial == -1) pred@2133: { pred@2133: SetFailState("Unable to create a valid map list."); pred@2133: } pred@2133: } pred@2133: pred@2133: BuildMapMenu(); pred@2133: } pred@2133: pred@2350: public OnNominationRemoved(const String:map[], owner) pred@2133: { pred@2350: new status; pred@2350: pred@2350: /* Is the map in our list? */ pred@2350: if (!GetTrieValue(g_mapTrie, map, status)) pred@2350: { pred@2350: return; pred@2350: } pred@2350: pred@2350: /* Was the map disabled due to being nominated */ pred@2350: if ((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED) pred@2350: { pred@2350: return; pred@2350: } pred@2350: pred@2350: SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED); pred@2133: } pred@2133: pred@2133: public Action:Command_Addmap(client, args) pred@2133: { pred@2133: if (args < 1) pred@2133: { pred@2133: ReplyToCommand(client, "[SM] Usage: sm_nominate_addmap "); pred@2133: return Plugin_Handled; pred@2133: } pred@2133: pred@2133: decl String:mapname[64]; pred@2133: GetCmdArg(1, mapname, sizeof(mapname)); pred@2133: pred@2350: pred@2350: new status; pred@2350: if (!GetTrieValue(g_mapTrie, mapname, status)) pred@2133: { pred@2133: ReplyToCommand(client, "%t", "Map was not found", mapname); pred@2350: return Plugin_Handled; pred@2133: } pred@2133: pred@2133: new NominateResult:result = NominateMap(mapname, true, 0); pred@2133: pred@2133: if (result > Nominate_Replaced) pred@2133: { pred@2133: /* 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 */ pred@2133: ReplyToCommand(client, "%t", "Map Already In Vote", mapname); pred@2133: pred@2133: return Plugin_Handled; pred@2133: } pred@2133: pred@2350: pred@2350: SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); pred@2350: pred@2133: pred@2133: ReplyToCommand(client, "%t", "Map Inserted", mapname); pred@2133: LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname); pred@2133: pred@2133: return Plugin_Handled; pred@2133: } pred@2133: pred@2133: public Action:Command_Say(client, args) pred@2133: { pred@2133: if (!client) pred@2133: { pred@2133: return Plugin_Continue; pred@2133: } pred@2133: pred@2133: decl String:text[192]; pred@2133: if (!GetCmdArgString(text, sizeof(text))) pred@2133: { pred@2133: return Plugin_Continue; pred@2133: } pred@2133: pred@2133: new startidx = 0; pred@2133: if(text[strlen(text)-1] == '"') pred@2133: { pred@2133: text[strlen(text)-1] = '\0'; pred@2133: startidx = 1; pred@2133: } pred@2133: pred@2133: new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT); pred@2133: pred@2133: if (strcmp(text[startidx], "nominate", false) == 0) pred@2133: { pred@2133: AttemptNominate(client); pred@2133: } pred@2133: pred@2133: SetCmdReplySource(old); pred@2133: pred@2133: return Plugin_Continue; pred@2133: } pred@2133: pred@2133: public Action:Command_Nominate(client, args) pred@2133: { pred@2133: if (!client) pred@2133: { erik@3187: return Plugin_Handled; pred@2133: } pred@2133: pred@2133: if (args == 0) pred@2133: { pred@2133: AttemptNominate(client); erik@3187: return Plugin_Handled; pred@2133: } pred@2133: pred@2133: decl String:mapname[64]; pred@2133: GetCmdArg(1, mapname, sizeof(mapname)); pred@2133: pred@2350: new status; pred@2350: if (!GetTrieValue(g_mapTrie, mapname, status)) pred@2133: { pred@2350: ReplyToCommand(client, "%t", "Map was not found", mapname); pred@2350: return Plugin_Handled; pred@2133: } pred@2133: pred@2350: if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) pred@2350: { pred@2350: if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) pred@2350: { pred@2350: ReplyToCommand(client, "[SM] %t", "Can't Nominate Current Map"); pred@2350: } pred@2350: pred@2350: if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) pred@2350: { pred@2350: ReplyToCommand(client, "[SM] %t", "Map in Exclude List"); pred@2350: } pred@2350: pred@2350: if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) pred@2350: { pred@2350: ReplyToCommand(client, "[SM] %t", "Map Already Nominated"); pred@2350: } pred@2350: pred@2350: return Plugin_Handled; pred@2350: } pred@2350: pred@2350: new NominateResult:result = NominateMap(mapname, false, client); pred@2350: pred@2350: if (result > Nominate_Replaced) pred@2350: { pred@2350: if (result == Nominate_AlreadyInVote) pred@2350: { pred@2350: ReplyToCommand(client, "%t", "Map Already In Vote", mapname); pred@2350: } pred@2350: else pred@2350: { pred@2350: ReplyToCommand(client, "[SM] %t", "Map Already Nominated"); pred@2350: } pred@2350: pred@2350: return Plugin_Handled; pred@2350: } pred@2350: pred@2350: /* Map was nominated! - Disable the menu item and update the trie */ pred@2350: pred@2350: SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); pred@2350: pred@2350: decl String:name[64]; pred@2350: GetClientName(client, name, sizeof(name)); pred@2350: PrintToChatAll("[SM] %t", "Map Nominated", name, mapname); pred@2350: pred@2350: return Plugin_Continue; pred@2133: } pred@2133: pred@2133: AttemptNominate(client) pred@2133: { pred@2133: SetMenuTitle(g_MapMenu, "%t", "Nominate Title", client); pred@2133: DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER); pred@2133: pred@2133: return; pred@2133: } pred@2133: pred@2133: BuildMapMenu() pred@2133: { pred@2133: if (g_MapMenu != INVALID_HANDLE) pred@2133: { pred@2133: CloseHandle(g_MapMenu); pred@2133: g_MapMenu = INVALID_HANDLE; pred@2133: } pred@2133: pred@2350: ClearTrie(g_mapTrie); pred@2350: pred@2350: g_MapMenu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); pred@2133: pred@2133: decl String:map[64]; pred@2133: fyrenmoo@2865: new Handle:excludeMaps = INVALID_HANDLE; pred@2133: decl String:currentMap[32]; pred@2133: pred@2133: if (GetConVarBool(g_Cvar_ExcludeOld)) pred@2133: { pred@2133: excludeMaps = CreateArray(ByteCountToCells(33)); pred@2133: GetExcludeMapList(excludeMaps); pred@2133: } pred@2133: pred@2133: if (GetConVarBool(g_Cvar_ExcludeCurrent)) pred@2133: { pred@2133: GetCurrentMap(currentMap, sizeof(currentMap)); pred@2133: } pred@2133: pred@2350: pred@2133: for (new i = 0; i < GetArraySize(g_MapList); i++) pred@2133: { pred@2350: new status = MAPSTATUS_ENABLED; pred@2133: pred@2350: GetArrayString(g_MapList, i, map, sizeof(map)); pred@2133: pred@2133: if (GetConVarBool(g_Cvar_ExcludeCurrent)) pred@2133: { pred@2133: if (StrEqual(map, currentMap)) pred@2133: { pred@2350: status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_CURRENT; pred@2350: } pred@2350: } pred@2350: pred@2350: /* Dont bother with this check if the current map check passed */ pred@2350: if (GetConVarBool(g_Cvar_ExcludeOld) && status == MAPSTATUS_ENABLED) pred@2350: { pred@2350: if (FindStringInArray(excludeMaps, map) != -1) pred@2350: { pred@2350: status = MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS; pred@2133: } pred@2133: } pred@2133: pred@2133: AddMenuItem(g_MapMenu, map, map); pred@2350: SetTrieValue(g_mapTrie, map, status); pred@2133: } pred@2133: pred@2133: SetMenuExitButton(g_MapMenu, true); fyrenmoo@2865: fyrenmoo@2865: if (excludeMaps != INVALID_HANDLE) fyrenmoo@2865: { fyrenmoo@2865: CloseHandle(excludeMaps); fyrenmoo@2865: } pred@2133: } pred@2133: pred@2133: public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2) pred@2133: { pred@2133: switch (action) pred@2133: { pred@2133: case MenuAction_Select: pred@2133: { pred@2133: decl String:map[64], String:name[64]; pred@2350: GetMenuItem(menu, param2, map, sizeof(map)); pred@2133: pred@2133: GetClientName(param1, name, 64); pred@2133: pred@2133: new NominateResult:result = NominateMap(map, false, param1); pred@2133: pred@2133: /* Don't need to check for InvalidMap because the menu did that already */ pred@2133: if (result == Nominate_AlreadyInVote) pred@2133: { pred@2133: PrintToChat(param1, "[SM] %t", "Map Already Nominated"); pred@2350: return 0; pred@2133: } pred@2133: else if (result == Nominate_VoteFull) pred@2133: { pred@2133: PrintToChat(param1, "[SM] %t", "Max Nominations"); pred@2350: return 0; pred@2133: } pred@2350: pred@2350: SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); pred@2347: pred@2133: if (result == Nominate_Replaced) pred@2133: { pred@2133: PrintToChatAll("[SM] %t", "Map Nomination Changed", name, map); pred@2350: return 0; pred@2133: } pred@2133: pred@2133: PrintToChatAll("[SM] %t", "Map Nominated", name, map); pred@2133: } pred@2350: pred@2350: case MenuAction_DrawItem: pred@2350: { pred@2350: decl String:map[64]; pred@2350: GetMenuItem(menu, param2, map, sizeof(map)); pred@2350: pred@2350: new status; pred@2350: pred@2350: if (!GetTrieValue(g_mapTrie, map, status)) pred@2350: { pred@2350: LogError("Menu selection of item not in trie. Major logic problem somewhere."); pred@2350: return ITEMDRAW_DEFAULT; pred@2350: } pred@2350: pred@2350: if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) pred@2350: { pred@2350: return ITEMDRAW_DISABLED; pred@2350: } pred@2350: pred@2350: return ITEMDRAW_DEFAULT; pred@2350: pred@2350: } pred@2350: pred@2350: case MenuAction_DisplayItem: pred@2350: { pred@2350: decl String:map[64]; pred@2350: GetMenuItem(menu, param2, map, sizeof(map)); pred@2350: pred@2350: new status; pred@2350: pred@2350: if (!GetTrieValue(g_mapTrie, map, status)) pred@2350: { pred@2350: LogError("Menu selection of item not in trie. Major logic problem somewhere."); pred@2350: return 0; pred@2350: } pred@2350: pred@2350: decl String:display[100]; pred@2350: pred@2350: if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) pred@2350: { pred@2350: if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) pred@2350: { pred@2350: Format(display, sizeof(display), "%s (%T)", map, "Current Map", param1); pred@2350: return RedrawMenuItem(display); pred@2350: } pred@2350: pred@2350: if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) pred@2350: { pred@2350: Format(display, sizeof(display), "%s (%T)", map, "Recently Played", param1); pred@2350: return RedrawMenuItem(display); pred@2350: } pred@2350: pred@2350: if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) pred@2350: { pred@2350: Format(display, sizeof(display), "%s (%T)", map, "Nominated", param1); pred@2350: return RedrawMenuItem(display); pred@2350: } pred@2350: } pred@2350: pred@2350: return 0; pred@2350: } pred@2133: } pred@2350: pred@2350: return 0; fyrenmoo@2865: }