3 * =============================================================================
4 * SourceMod Rock The Vote Plugin
5 * Creates a map vote when the required number of players have requested one.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
40 public Plugin:myinfo =
42 name = "Rock The Vote",
43 author = "AlliedModders LLC",
44 description = "Provides RTV Map Voting",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
49 new Handle:g_Cvar_Needed = INVALID_HANDLE;
50 new Handle:g_Cvar_MinPlayers = INVALID_HANDLE;
51 new Handle:g_Cvar_InitialDelay = INVALID_HANDLE;
52 new Handle:g_Cvar_Interval = INVALID_HANDLE;
53 new Handle:g_Cvar_ChangeTime = INVALID_HANDLE;
54 new Handle:g_Cvar_RTVPostVoteAction = INVALID_HANDLE;
56 new bool:g_CanRTV = false; // True if RTV loaded maps and is active.
57 new bool:g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
58 new g_Voters = 0; // Total voters connected. Doesn't include fake clients.
59 new g_Votes = 0; // Total number of "say rtv" votes
60 new g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed)
61 new bool:g_Voted[MAXPLAYERS+1] = {false, ...};
63 new bool:g_InChange = false;
65 public OnPluginStart()
67 LoadTranslations("common.phrases");
68 LoadTranslations("rockthevote.phrases");
70 g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0);
71 g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
72 g_Cvar_InitialDelay = CreateConVar("sm_rtv_initialdelay", "30.0", "Time (in seconds) before first RTV can be held", 0, true, 0.00);
73 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);
74 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);
75 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);
77 RegConsoleCmd("say", Command_Say);
78 RegConsoleCmd("say_team", Command_Say);
80 RegConsoleCmd("sm_rtv", Command_RTV);
82 AutoExecConfig(true, "rtv");
92 /* Handle late load */
93 for (new i=1; i<=MaxClients; i++)
95 if (IsClientConnected(i))
105 g_RTVAllowed = false;
108 public OnConfigsExecuted()
111 g_RTVAllowed = false;
112 CreateTimer(GetConVarFloat(g_Cvar_InitialDelay), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
115 public OnClientConnected(client)
117 if(IsFakeClient(client))
120 g_Voted[client] = false;
123 g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
128 public OnClientDisconnect(client)
130 if(IsFakeClient(client))
140 g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
149 g_Votes >= g_VotesNeeded &&
152 if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())
161 public Action:Command_RTV(client, args)
163 if (!g_CanRTV || !client)
165 return Plugin_Handled;
170 return Plugin_Handled;
173 public Action:Command_Say(client, args)
175 if (!g_CanRTV || !client)
177 return Plugin_Continue;
180 decl String:text[192];
181 if (!GetCmdArgString(text, sizeof(text)))
183 return Plugin_Continue;
187 if(text[strlen(text)-1] == '"')
189 text[strlen(text)-1] = '\0';
193 new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
195 if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
200 SetCmdReplySource(old);
202 return Plugin_Continue;
207 if (!g_RTVAllowed || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
209 ReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
213 if (!CanMapChooserStartVote())
215 ReplyToCommand(client, "[SM] %t", "RTV Started");
219 if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers))
221 ReplyToCommand(client, "[SM] %t", "Minimal Players Not Met");
227 ReplyToCommand(client, "[SM] %t", "Already Voted", g_Votes, g_VotesNeeded);
232 GetClientName(client, name, sizeof(name));
235 g_Voted[client] = true;
237 PrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
239 if (g_Votes >= g_VotesNeeded)
245 public Action:Timer_DelayRTV(Handle:timer)
257 if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
259 /* Change right now then */
261 if (GetNextMap(map, sizeof(map)))
263 PrintToChatAll("[SM] %t", "Changing Maps", map);
264 CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
269 g_RTVAllowed = false;
274 if (CanMapChooserStartVote())
276 new MapChange:when = MapChange:GetConVarInt(g_Cvar_ChangeTime);
277 InitiateMapChooserVote(when);
281 g_RTVAllowed = false;
282 CreateTimer(GetConVarFloat(g_Cvar_Interval), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
290 for (new i=1; i<=MAXPLAYERS; i++)
296 public Action:Timer_ChangeMap(Handle:hTimer)
300 LogMessage("RTV changing map manually");
303 if (GetNextMap(map, sizeof(map)))
305 ForceChangeLevel(map, "RTV after mapvote");