initial commit

This commit is contained in:
BotoX
2016-01-06 02:11:56 +01:00
commit 72f7665358
106 changed files with 17675 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
../../../includes/colors.inc
@@ -0,0 +1,108 @@
/**
* vim: set ts=4 :
* =============================================================================
* MapChooser Extended
* Creates a map vote at appropriate times, setting sm_nextmap to the winning
* vote
*
* MapChooser Extended (C)2011-2013 Powerlord (Ross Bemrose)
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _mapchooser_extended_included_
#endinput
#endif
#define _mapchooser_extended_included_
#include <mapchooser>
// MCE 1.9 series
enum CanNominateResult
{
CanNominate_No_VoteFull, /** No, nominations list is full */
CanNominate_No_VoteInProgress, /** No, map vote is in progress */
CanNominate_No_VoteComplete, /** No, map vote is completed */
CanNominate_Yes, /** Yes, you can nominate */
};
/**
* Called whenever warning timer starts
*
*/
forward OnMapVoteWarningStart();
/**
* Called whenever runoff warning timer starts
*/
forward OnMapVoteRunnoffWarningStart();
/**
* Called whenever the timer ticks
*/
forward OnMapVoteWarningTick(time);
/**
* Called whenever vote starts
*
* @deprecated Will be removed in MapChooser 1.8. Use OnMapVoteStarted instead.
*/
forward OnMapVoteStart();
/**
* Called whenever vote ends
*/
forward OnMapVoteEnd(const String:map[]);
/**
* Is a map on the current game's official list?
* This should be treated as informative only.
*
* @param map Name of map to check
* @return true if it's on the list of official maps for this game
*/
native bool:IsMapOfficial(const String:map[]);
/**
* Is nominate allowed?
*
* @return A CanNominateResult corresponding to whether a vote is allowed or not
*/
native CanNominateResult:CanNominate();
native bool:ExcludeMap(const String:map[]);
public SharedPlugin:__pl_mapchooser_extended =
{
name = "mapchooser",
file = "mapchooser_extended.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
@@ -0,0 +1 @@
../../../includes/nativevotes.inc
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,703 @@
/**
* vim: set ts=4 :
* =============================================================================
* Nominations Extended
* Allows players to nominate maps for Mapchooser
*
* Nominations Extended (C)2012-2013 Powerlord (Ross Bemrose)
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include <sourcemod>
#include <mapchooser>
#include "include/mapchooser_extended"
#include <colors>
#pragma semicolon 1
#define MCE_VERSION "1.10.0"
public Plugin:myinfo =
{
name = "Map Nominations Extended",
author = "Powerlord and AlliedModders LLC",
description = "Provides Map Nominations",
version = MCE_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=156974"
};
new Handle:g_Cvar_ExcludeOld = INVALID_HANDLE;
new Handle:g_Cvar_ExcludeCurrent = INVALID_HANDLE;
new Handle:g_MapList = INVALID_HANDLE;
new Handle:g_AdminMapList = INVALID_HANDLE;
new Handle:g_MapMenu = INVALID_HANDLE;
new Handle:g_AdminMapMenu = INVALID_HANDLE;
new g_mapFileSerial = -1;
new g_AdminMapFileSerial = -1;
#define MAPSTATUS_ENABLED (1<<0)
#define MAPSTATUS_DISABLED (1<<1)
#define MAPSTATUS_EXCLUDE_CURRENT (1<<2)
#define MAPSTATUS_EXCLUDE_PREVIOUS (1<<3)
#define MAPSTATUS_EXCLUDE_NOMINATED (1<<4)
new Handle:g_mapTrie;
// Nominations Extended Convars
new Handle:g_Cvar_MarkCustomMaps = INVALID_HANDLE;
new Handle:g_Cvar_NominateDelay = INVALID_HANDLE;
new Handle:g_Cvar_InitialDelay = INVALID_HANDLE;
new g_Player_NominationDelay[MAXPLAYERS+1];
new g_NominationDelay;
public OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("nominations.phrases");
LoadTranslations("basetriggers.phrases"); // for Next Map phrase
LoadTranslations("mapchooser_extended.phrases");
new arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
g_MapList = CreateArray(arraySize);
g_AdminMapList = CreateArray(arraySize);
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);
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);
g_Cvar_InitialDelay = CreateConVar("sm_nominate_initialdelay", "60.0", "Time in seconds before first Nomination can be made", 0, true, 0.00);
g_Cvar_NominateDelay = CreateConVar("sm_nominate_delay", "3.0", "Delay between nominations", 0, true, 0.00, true, 60.00);
RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);
RegConsoleCmd("sm_nominate", Command_Nominate);
RegConsoleCmd("sm_nomlist", Command_NominateList);
RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote.");
// BotoX
RegAdminCmd("sm_nominate_exclude", Command_AddExclude, ADMFLAG_CHANGEMAP, "sm_nominate_exclude <mapname> - Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated.");
// Nominations Extended cvars
CreateConVar("ne_version", MCE_VERSION, "Nominations Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
g_mapTrie = CreateTrie();
}
public OnAllPluginsLoaded()
{
// This is an MCE cvar... this plugin requires MCE to be loaded. Granted, this plugin SHOULD have an MCE dependency.
g_Cvar_MarkCustomMaps = FindConVar("mce_markcustommaps");
}
public OnConfigsExecuted()
{
if (ReadMapList(g_MapList,
g_mapFileSerial,
"nominations",
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
== INVALID_HANDLE)
{
if (g_mapFileSerial == -1)
{
SetFailState("Unable to create a valid map list.");
}
}
if (ReadMapList(g_AdminMapList,
g_AdminMapFileSerial,
"sm_nominate_addmap menu",
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER)
== INVALID_HANDLE)
{
if (g_AdminMapFileSerial == -1)
{
SetFailState("Unable to create a valid admin map list.");
}
}
else
{
for (new i = 0; i < GetArraySize(g_MapList); i++)
{
decl String:map[PLATFORM_MAX_PATH];
GetArrayString(g_MapList, i, map, sizeof(map));
new Index = FindStringInArray(g_AdminMapList, map);
if (Index != -1)
RemoveFromArray(g_AdminMapList, Index);
}
}
g_NominationDelay = GetTime() + GetConVarInt(g_Cvar_InitialDelay);
BuildMapMenu();
BuildAdminMapMenu();
}
public OnNominationRemoved(const String:map[], owner)
{
new status;
/* 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;
}
SetTrieValue(g_mapTrie, map, MAPSTATUS_ENABLED);
}
public Action:Command_Addmap(client, args)
{
if (args == 0)
{
AttemptAdminNominate(client);
return Plugin_Handled;
}
if (args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled;
}
decl String:mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
// new status;
if (/*!GetTrieValue(g_mapTrie, mapname, status)*/!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
return Plugin_Handled;
}
new NominateResult:result = NominateMap(mapname, 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 */
CReplyToCommand(client, "%t", "Map Already In Vote", mapname);
return Plugin_Handled;
}
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
CReplyToCommand(client, "%t", "Map Inserted", mapname);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
PrintToChatAll("[NE] %N has inserted %s into nominations", client, mapname);
return Plugin_Handled;
}
public Action:Command_AddExclude(client, args)
{
if (args < 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude <mapname>");
return Plugin_Handled;
}
decl String:mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
new status;
if(!GetTrieValue(g_mapTrie, mapname, status))
{
ReplyToCommand(client, "[NE] %t", "Map was not found", mapname);
return Plugin_Handled;
}
ShowActivity(client, "Excluded map \"%s\" from nomination", mapname);
LogAction(client, -1, "\"%L\" excluded map \"%s\" from nomination", client, mapname);
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_PREVIOUS);
// native call to mapchooser_extended
ExcludeMap(mapname);
return Plugin_Handled;
}
public Action:Command_Say(client, args)
{
if (!client)
{
return Plugin_Continue;
}
decl String:text[192];
if (!GetCmdArgString(text, sizeof(text)))
{
return Plugin_Continue;
}
new startidx = 0;
if(text[strlen(text)-1] == '"')
{
text[strlen(text)-1] = '\0';
startidx = 1;
}
new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
if (strcmp(text[startidx], "nominate", false) == 0)
{
if (IsNominateAllowed(client))
{
if (g_NominationDelay > GetTime())
ReplyToCommand(client, "[NE] Nominations will be unlocked in %d seconds", g_NominationDelay - GetTime());
else
AttemptNominate(client);
}
}
SetCmdReplySource(old);
return Plugin_Continue;
}
public Action:Command_Nominate(client, args)
{
if (!client || !IsNominateAllowed(client))
{
return Plugin_Handled;
}
if (g_NominationDelay > GetTime())
{
ReplyToCommand(client, "[NE] Nominations will be unlocked in %d seconds", g_NominationDelay - GetTime());
return Plugin_Handled;
}
if (args == 0)
{
AttemptNominate(client);
return Plugin_Handled;
}
if (g_Player_NominationDelay[client] > GetTime())
{
ReplyToCommand(client, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[client] - GetTime());
return Plugin_Handled;
}
decl String:mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
new status;
if (!GetTrieValue(g_mapTrie, mapname, status))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
return Plugin_Handled;
}
if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if ((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
{
CReplyToCommand(client, "[NE] %t", "Can't Nominate Current Map");
}
if ((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
CReplyToCommand(client, "[NE] %t", "Map in Exclude List");
}
if ((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
{
CReplyToCommand(client, "[NE] %t", "Map Already Nominated");
}
return Plugin_Handled;
}
new NominateResult:result = NominateMap(mapname, false, client);
if (result > Nominate_Replaced)
{
if (result == Nominate_AlreadyInVote)
{
CReplyToCommand(client, "[NE] %t", "Map Already In Vote", mapname);
}
else if (result == Nominate_VoteFull)
{
CReplyToCommand(client, "[ME] %t", "Max Nominations");
}
return Plugin_Handled;
}
/* Map was nominated! - Disable the menu item and update the trie */
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
decl String: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);
LogMessage("%s nominated %s", name, mapname);
g_Player_NominationDelay[client] = GetTime() + GetConVarInt(g_Cvar_NominateDelay);
return Plugin_Continue;
}
public Action:Command_NominateList(client, args)
{
new arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
new Handle:MapList = CreateArray(arraySize);
GetNominatedMapList(MapList);
if (!GetArraySize(MapList))
{
CReplyToCommand(client, "[NE] No maps have been nominated.");
return Plugin_Handled;
}
new Handle:NominateListMenu = CreateMenu(Handler_NominateListMenu, MENU_ACTIONS_DEFAULT|MenuAction_DisplayItem);
decl String:map[PLATFORM_MAX_PATH];
for (new i = 0; i < GetArraySize(MapList); i++)
{
GetArrayString(MapList, i, map, sizeof(map));
AddMenuItem(NominateListMenu, map, map);
}
SetMenuTitle(NominateListMenu, "Nominated Maps", client);
DisplayMenu(NominateListMenu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Handler_NominateListMenu(Handle:menu, MenuAction:action, param1, param2)
{
return 0;
}
AttemptNominate(client)
{
SetMenuTitle(g_MapMenu, "%T", "Nominate Title", client);
DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);
return;
}
AttemptAdminNominate(client)
{
SetMenuTitle(g_AdminMapMenu, "%T", "Nominate Title", client);
DisplayMenu(g_AdminMapMenu, client, MENU_TIME_FOREVER);
return;
}
BuildMapMenu()
{
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);
decl String:map[PLATFORM_MAX_PATH];
new Handle:excludeMaps = INVALID_HANDLE;
decl String: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 (new i = 0; i < GetArraySize(g_MapList); i++)
{
new 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);
}
SetMenuExitButton(g_MapMenu, true);
if (excludeMaps != INVALID_HANDLE)
{
CloseHandle(excludeMaps);
}
}
BuildAdminMapMenu()
{
if (g_AdminMapMenu != INVALID_HANDLE)
{
CloseHandle(g_AdminMapMenu);
g_AdminMapMenu = INVALID_HANDLE;
}
g_AdminMapMenu = CreateMenu(Handler_AdminMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
decl String:map[PLATFORM_MAX_PATH];
for (new i = 0; i < GetArraySize(g_AdminMapList); i++)
{
GetArrayString(g_AdminMapList, i, map, sizeof(map));
AddMenuItem(g_AdminMapMenu, map, map);
}
SetMenuExitButton(g_AdminMapMenu, true);
}
public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
{
switch (action)
{
case MenuAction_Select:
{
decl String:map[PLATFORM_MAX_PATH], String:name[MAX_NAME_LENGTH];
GetMenuItem(menu, param2, map, sizeof(map));
GetClientName(param1, name, MAX_NAME_LENGTH);
new 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);
}
case MenuAction_DrawItem:
{
decl String:map[PLATFORM_MAX_PATH];
GetMenuItem(menu, param2, map, sizeof(map));
new 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;
}
return ITEMDRAW_DEFAULT;
}
case MenuAction_DisplayItem:
{
decl String:map[PLATFORM_MAX_PATH];
GetMenuItem(menu, param2, map, sizeof(map));
new mark = GetConVarInt(g_Cvar_MarkCustomMaps);
new bool:official;
new status;
if (!GetTrieValue(g_mapTrie, map, status))
{
LogError("Menu selection of item not in trie. Major logic problem somewhere.");
return 0;
}
decl String:buffer[100];
decl String: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)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Recently Played", 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 (mark && !official)
return RedrawMenuItem(buffer);
return 0;
}
}
return 0;
}
stock bool:IsNominateAllowed(client)
{
new CanNominateResult:result = CanNominate();
switch(result)
{
case CanNominate_No_VoteInProgress:
{
CReplyToCommand(client, "[ME] %t", "Nextmap Voting Started");
return false;
}
case CanNominate_No_VoteComplete:
{
new String:map[PLATFORM_MAX_PATH];
GetNextMap(map, sizeof(map));
CReplyToCommand(client, "[NE] %t", "Next Map", map);
return false;
}
/*
case CanNominate_No_VoteFull:
{
CReplyToCommand(client, "[ME] %t", "Max Nominations");
return false;
}
*/
}
return true;
}
public Handler_AdminMapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
{
switch (action)
{
case MenuAction_Select:
{
decl String:map[PLATFORM_MAX_PATH], String:name[MAX_NAME_LENGTH];
GetMenuItem(menu, param2, map, sizeof(map));
new NominateResult:result = NominateMap(map, false, 0);
if (result == Nominate_AlreadyInVote)
{
PrintToChat(param1, "[NE] %t", "Map Already In Vote", map);
return 0;
}
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);
PrintToChatAll("[NE] %N has inserted %s into nominations", name, map);
}
}
return 0;
}
@@ -0,0 +1,378 @@
/**
* vim: set ts=4 :
* =============================================================================
* Rock The Vote Extended
* Creates a map vote when the required number of players have requested one.
*
* Rock The Vote Extended (C)2012-2013 Powerlord (Ross Bemrose)
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <mapchooser>
#include "include/mapchooser_extended"
#include <nextmap>
#include <colors>
#pragma semicolon 1
#define MCE_VERSION "1.10.0"
public Plugin:myinfo =
{
name = "Rock The Vote Extended",
author = "Powerlord and AlliedModders LLC",
description = "Provides RTV Map Voting",
version = MCE_VERSION,
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;
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, ...};
new bool:g_InChange = false;
public OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("rockthevote.phrases");
LoadTranslations("basevotes.phrases");
g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0);
g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
g_Cvar_InitialDelay = CreateConVar("sm_rtv_initialdelay", "30.0", "Time (in seconds) before first RTV can be held", 0, true, 0.00);
g_Cvar_Interval = CreateConVar("sm_rtv_interval", "240.0", "Time (in seconds) after a failed RTV before another can be held", 0, true, 0.00);
g_Cvar_ChangeTime = CreateConVar("sm_rtv_changetime", "0", "When to change the map after a succesful RTV: 0 - Instant, 1 - RoundEnd, 2 - MapEnd", _, true, 0.0, true, 2.0);
g_Cvar_RTVPostVoteAction = CreateConVar("sm_rtv_postvoteaction", "0", "What to do with RTV's after a mapvote has completed. 0 - Allow, success = instant change, 1 - Deny", _, true, 0.0, true, 1.0);
HookEvent("player_team", OnPlayerChangedTeam);
RegConsoleCmd("say", Command_Say);
RegConsoleCmd("say_team", Command_Say);
RegConsoleCmd("sm_rtv", Command_RTV);
RegAdminCmd("sm_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote");
RegAdminCmd("mce_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote");
// Rock The Vote Extended cvars
CreateConVar("rtve_version", MCE_VERSION, "Rock The Vote Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "rtv");
}
public OnMapStart()
{
g_Voters = 0;
g_Votes = 0;
g_VotesNeeded = 0;
g_InChange = false;
/* Handle late load */
for (new i=1; i<=MaxClients; i++)
{
if (IsClientConnected(i))
{
OnClientConnected(i);
}
}
}
public OnMapEnd()
{
g_CanRTV = false;
g_RTVAllowed = false;
}
public OnConfigsExecuted()
{
g_CanRTV = true;
g_RTVAllowed = false;
CreateTimer(GetConVarFloat(g_Cvar_InitialDelay), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
}
public OnClientConnected(client)
{
if(IsFakeClient(client))
return;
g_Voted[client] = false;
g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3);
g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
return;
}
public OnClientDisconnect(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)
{
return;
}
if (g_Votes &&
g_Voters &&
g_Votes >= g_VotesNeeded &&
g_RTVAllowed )
{
if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())
{
return;
}
StartRTV();
}
}
public OnPlayerChangedTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
new Client = GetClientOfUserId(GetEventInt(event, "userid"));
if(IsFakeClient(Client))
return;
if(Client == 0)
{
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();
}
}
}
}
public Action:Command_RTV(client, args)
{
if (!g_CanRTV || !client)
{
return Plugin_Handled;
}
AttemptRTV(client);
return Plugin_Handled;
}
public Action:Command_Say(client, args)
{
if (!g_CanRTV || !client)
{
return Plugin_Continue;
}
decl String:text[192];
if (!GetCmdArgString(text, sizeof(text)))
{
return Plugin_Continue;
}
new startidx = 0;
if(text[strlen(text)-1] == '"')
{
text[strlen(text)-1] = '\0';
startidx = 1;
}
new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
{
AttemptRTV(client);
}
SetCmdReplySource(old);
return Plugin_Continue;
}
AttemptRTV(client)
{
if (!g_RTVAllowed || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
{
CReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
return;
}
if (!CanMapChooserStartVote())
{
CReplyToCommand(client, "[SM] %t", "RTV Started");
return;
}
if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers))
{
CReplyToCommand(client, "[SM] %t", "Minimal Players Not Met");
return;
}
if (g_Voted[client])
{
CReplyToCommand(client, "[SM] %t", "Already Voted", g_Votes, g_VotesNeeded);
return;
}
new String:name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
g_Votes++;
g_Voted[client] = true;
CPrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
if (g_Votes >= g_VotesNeeded)
{
StartRTV();
}
}
public Action:Timer_DelayRTV(Handle:timer)
{
g_RTVAllowed = true;
}
StartRTV()
{
if (g_InChange)
{
return;
}
if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
{
/* Change right now then */
new String:map[PLATFORM_MAX_PATH];
if (GetNextMap(map, sizeof(map)))
{
CPrintToChatAll("[SM] %t", "Changing Maps", map);
CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
g_InChange = true;
ResetRTV();
g_RTVAllowed = false;
}
return;
}
if (CanMapChooserStartVote())
{
new MapChange:when = MapChange:GetConVarInt(g_Cvar_ChangeTime);
InitiateMapChooserVote(when);
ResetRTV();
g_RTVAllowed = false;
CreateTimer(GetConVarFloat(g_Cvar_Interval), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
}
}
ResetRTV()
{
g_Votes = 0;
for (new i=1; i<=MAXPLAYERS; i++)
{
g_Voted[i] = false;
}
}
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)))
{
ForceChangeLevel(map, "RTV after mapvote");
}
return Plugin_Stop;
}
// Rock The Vote Extended functions
public Action:Command_ForceRTV(client, args)
{
if (!g_CanRTV || !client)
{
return Plugin_Handled;
}
ShowActivity2(client, "[RTVE] ", "%t", "Initiated Vote Map");
StartRTV();
return Plugin_Handled;
}