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 new maxclients = GetMaxClients();
94 for (new i=1; i<=maxclients; i++)
96 if (IsClientConnected(i))
98 OnClientConnect(i, "", 0);
106 g_RTVAllowed = false;
109 public OnConfigsExecuted()
112 g_RTVAllowed = false;
113 CreateTimer(GetConVarFloat(g_Cvar_InitialDelay), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
116 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
118 if(IsFakeClient(client))
121 g_Voted[client] = false;
124 g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
129 public OnClientDisconnect(client)
131 if(!g_CanRTV || IsFakeClient(client))
141 g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
145 g_Votes >= g_VotesNeeded &&
148 if (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished())
157 public Action:Command_RTV(client, args)
159 if (!g_CanRTV || !client)
161 return Plugin_Continue;
166 return Plugin_Continue;
169 public Action:Command_Say(client, args)
171 if (!g_CanRTV || !client)
173 return Plugin_Continue;
176 decl String:text[192];
177 if (!GetCmdArgString(text, sizeof(text)))
179 return Plugin_Continue;
183 if(text[strlen(text)-1] == '"')
185 text[strlen(text)-1] = '\0';
189 new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
191 if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
196 SetCmdReplySource(old);
198 return Plugin_Continue;
203 if (!g_RTVAllowed || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))
205 ReplyToCommand(client, "[SM] %t", "RTV Not Allowed");
209 if (!CanMapChooserStartVote())
211 ReplyToCommand(client, "[SM] %t", "RTV Started");
215 if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers))
217 ReplyToCommand(client, "[SM] %t", "Minimal Players Not Met");
223 ReplyToCommand(client, "[SM] %t", "Already Voted");
228 GetClientName(client, name, sizeof(name));
231 g_Voted[client] = true;
233 PrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
235 if (g_Votes >= g_VotesNeeded)
241 public Action:Timer_DelayRTV(Handle:timer)
253 if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
255 /* Change right now then */
257 if (GetNextMap(map, sizeof(map)))
259 PrintToChatAll("[SM] %t", "Changing Maps", map);
260 CreateTimer(5.0, Timer_ChangeMap, _, TIMER_FLAG_NO_MAPCHANGE);
265 g_RTVAllowed = false;
270 if (CanMapChooserStartVote())
272 new MapChange:when = MapChange:GetConVarInt(g_Cvar_ChangeTime);
273 InitiateMapChooserVote(when);
277 g_RTVAllowed = false;
278 CreateTimer(GetConVarFloat(g_Cvar_Interval), Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
286 for (new i=1; i<=MAXPLAYERS; i++)
292 public Action:Timer_ChangeMap(Handle:hTimer)
296 LogMessage("RTV changing map manually");
299 if (GetNextMap(map, sizeof(map)))
301 ForceChangeLevel(map, "RTV after mapvote");