1.1 --- a/plugins/rockthevote.sp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,526 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Rock The Vote Plugin
1.8 - * Creates a map vote when the required number of players have requested one.
1.9 - *
1.10 - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.11 - * =============================================================================
1.12 - *
1.13 - * This program is free software; you can redistribute it and/or modify it under
1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
1.15 - * Free Software Foundation.
1.16 - *
1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 - * details.
1.21 - *
1.22 - * You should have received a copy of the GNU General Public License along with
1.23 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 - *
1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 - * by the Valve Corporation. You must obey the GNU General Public License in
1.29 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 - * this exception to all derivative works. AlliedModders LLC defines further
1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 - * or <http://www.sourcemod.net/license.php>.
1.33 - *
1.34 - * Version: $Id$
1.35 - */
1.36 -
1.37 -#include <sourcemod>
1.38 -
1.39 -#pragma semicolon 1
1.40 -
1.41 -public Plugin:myinfo =
1.42 -{
1.43 - name = "Rock The Vote",
1.44 - author = "AlliedModders LLC",
1.45 - description = "Provides RTV Map Voting",
1.46 - version = SOURCEMOD_VERSION,
1.47 - url = "http://www.sourcemod.net/"
1.48 -};
1.49 -
1.50 -new Handle:g_Cvar_Needed = INVALID_HANDLE;
1.51 -new Handle:g_Cvar_File = INVALID_HANDLE;
1.52 -new Handle:g_Cvar_Maps = INVALID_HANDLE;
1.53 -new Handle:g_Cvar_Nominate = INVALID_HANDLE;
1.54 -new Handle:g_Cvar_MinPlayers = INVALID_HANDLE;
1.55 -
1.56 -new Handle:g_MapList = INVALID_HANDLE;
1.57 -new Handle:g_RTVMapList = INVALID_HANDLE;
1.58 -new Handle:g_MapMenu = INVALID_HANDLE;
1.59 -new Handle:g_RetryTimer = INVALID_HANDLE;
1.60 -new g_mapFileTime;
1.61 -
1.62 -new bool:g_CanRTV = false; // True if RTV loaded maps and is active.
1.63 -new bool:g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
1.64 -new bool:g_RTVStarted = false; // Indicates that the actual map vote has started
1.65 -new bool:g_RTVEnded = false; // Indicates that the actual map vote has concluded
1.66 -new g_Voters = 0; // Total voters connected. Doesn't include fake clients.
1.67 -new g_Votes = 0; // Total number of "say rtv" votes
1.68 -new g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed)
1.69 -new bool:g_Voted[MAXPLAYERS+1] = {false, ...};
1.70 -new bool:g_Nominated[MAXPLAYERS+1] = {false, ...};
1.71 -
1.72 -public OnPluginStart()
1.73 -{
1.74 - LoadTranslations("common.phrases");
1.75 - LoadTranslations("rockthevote.phrases");
1.76 -
1.77 - new arraySize = ByteCountToCells(33);
1.78 - g_MapList = CreateArray(arraySize);
1.79 - g_RTVMapList = CreateArray(arraySize);
1.80 -
1.81 - g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0);
1.82 - g_Cvar_File = CreateConVar("sm_rtv_file", "configs/maps.ini", "Map file to use. (Def configs/maps.ini)");
1.83 - g_Cvar_Maps = CreateConVar("sm_rtv_maps", "4", "Number of maps to be voted on. 2 to 6. (Def 4)", 0, true, 2.0, true, 6.0);
1.84 - g_Cvar_Nominate = CreateConVar("sm_rtv_nominate", "1", "Enables nomination system.", 0, true, 0.0, true, 1.0);
1.85 - g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS));
1.86 -
1.87 - RegConsoleCmd("say", Command_Say);
1.88 - RegConsoleCmd("say_team", Command_Say);
1.89 -
1.90 - RegAdminCmd("sm_rtv_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_rtv_addmap <mapname> - Forces a map to be on the RTV, and lowers the allowed nominations.");
1.91 -
1.92 - AutoExecConfig(true, "rtv");
1.93 -}
1.94 -
1.95 -public OnMapStart()
1.96 -{
1.97 - g_Voters = 0;
1.98 - g_Votes = 0;
1.99 - g_VotesNeeded = 0;
1.100 - g_RTVStarted = false;
1.101 - g_RTVEnded = false;
1.102 -}
1.103 -
1.104 -public OnMapEnd()
1.105 -{
1.106 - g_CanRTV = false;
1.107 - g_RTVAllowed = false;
1.108 -}
1.109 -
1.110 -public OnConfigsExecuted()
1.111 -{
1.112 - if (g_RTVMapList != INVALID_HANDLE)
1.113 - {
1.114 - ClearArray(g_RTVMapList);
1.115 - }
1.116 -
1.117 - if (LoadMaps(g_MapList, g_mapFileTime, g_Cvar_File))
1.118 - {
1.119 - BuildMapMenu();
1.120 - g_CanRTV = true;
1.121 - CreateTimer(30.0, Timer_DelayRTV);
1.122 - }
1.123 -}
1.124 -
1.125 -public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
1.126 -{
1.127 - if(!g_CanRTV || IsFakeClient(client))
1.128 - return true;
1.129 -
1.130 - g_Voted[client] = false;
1.131 - g_Nominated[client] = false;
1.132 -
1.133 - g_Voters++;
1.134 - g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
1.135 -
1.136 - return true;
1.137 -}
1.138 -
1.139 -public OnClientDisconnect(client)
1.140 -{
1.141 - if(!g_CanRTV || IsFakeClient(client))
1.142 - return;
1.143 -
1.144 - if(g_Voted[client])
1.145 - {
1.146 - g_Votes--;
1.147 - }
1.148 -
1.149 - g_Voters--;
1.150 -
1.151 - g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
1.152 -
1.153 - if (g_Votes && g_Voters && g_Votes >= g_VotesNeeded && g_RTVAllowed && !g_RTVStarted)
1.154 - {
1.155 - g_RTVStarted = true;
1.156 - CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
1.157 - }
1.158 -}
1.159 -
1.160 -public Action:Command_Addmap(client, args)
1.161 -{
1.162 - if (args < 1)
1.163 - {
1.164 - ReplyToCommand(client, "[SM] Usage: sm_rtv_addmap <mapname>");
1.165 - return Plugin_Handled;
1.166 - }
1.167 -
1.168 - if (!g_CanRTV)
1.169 - {
1.170 - ReplyToCommand(client, "[SM] RockTheVote is not available.");
1.171 - return Plugin_Handled;
1.172 - }
1.173 -
1.174 - decl String:mapname[64];
1.175 - GetCmdArg(1, mapname, sizeof(mapname));
1.176 -
1.177 - if (FindStringInArray(g_MapList, mapname) == -1)
1.178 - {
1.179 - ReplyToCommand(client, "%t", "Map was not found", mapname);
1.180 - return Plugin_Handled;
1.181 - }
1.182 -
1.183 - if (GetArraySize(g_RTVMapList) > 0)
1.184 - {
1.185 - if (FindStringInArray(g_RTVMapList, mapname) != -1)
1.186 - {
1.187 - ReplyToCommand(client, "%t", "Map Already In Vote", mapname);
1.188 - return Plugin_Handled;
1.189 - }
1.190 -
1.191 - ShiftArrayUp(g_RTVMapList, 0);
1.192 - SetArrayString(g_RTVMapList, 0, mapname);
1.193 -
1.194 - while (GetArraySize(g_RTVMapList) > GetConVarInt(g_Cvar_Maps))
1.195 - {
1.196 - RemoveFromArray(g_RTVMapList, GetConVarInt(g_Cvar_Maps));
1.197 - }
1.198 - }
1.199 - else
1.200 - {
1.201 - PushArrayString(g_RTVMapList, mapname);
1.202 - }
1.203 -
1.204 - decl String:item[64];
1.205 - for (new i = 0; i < GetMenuItemCount(g_MapMenu); i++)
1.206 - {
1.207 - GetMenuItem(g_MapMenu, i, item, sizeof(item));
1.208 - if (strcmp(item, mapname) == 0)
1.209 - {
1.210 - RemoveMenuItem(g_MapMenu, i);
1.211 - break;
1.212 - }
1.213 - }
1.214 -
1.215 - ReplyToCommand(client, "%t", "Map Inserted", mapname);
1.216 - LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
1.217 -
1.218 - return Plugin_Handled;
1.219 -}
1.220 -
1.221 -public Action:Command_Say(client, args)
1.222 -{
1.223 - if (!g_CanRTV || !client)
1.224 - {
1.225 - return Plugin_Continue;
1.226 - }
1.227 -
1.228 - decl String:text[192];
1.229 - if (!GetCmdArgString(text, sizeof(text)))
1.230 - {
1.231 - return Plugin_Continue;
1.232 - }
1.233 -
1.234 - new startidx = 0;
1.235 - if(text[strlen(text)-1] == '"')
1.236 - {
1.237 - text[strlen(text)-1] = '\0';
1.238 - startidx = 1;
1.239 - }
1.240 -
1.241 - if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
1.242 - {
1.243 - if (!g_RTVAllowed)
1.244 - {
1.245 - PrintToChat(client, "[SM] %t", "RTV Not Allowed");
1.246 - return Plugin_Continue;
1.247 - }
1.248 -
1.249 - if (g_RTVEnded)
1.250 - {
1.251 - PrintToChat(client, "[SM] %t", "RTV Ended");
1.252 - return Plugin_Continue;
1.253 - }
1.254 -
1.255 - if (g_RTVStarted)
1.256 - {
1.257 - PrintToChat(client, "[SM] %t", "RTV Started");
1.258 - return Plugin_Continue;
1.259 - }
1.260 -
1.261 - if (GetClientCount(true) < GetConVarInt(g_Cvar_MinPlayers) && g_Votes == 0) // Should we keep checking g_Votes here?
1.262 - {
1.263 - PrintToChat(client, "[SM] %t", "Minimal Players Not Met");
1.264 - return Plugin_Continue;
1.265 - }
1.266 -
1.267 - if (g_Voted[client])
1.268 - {
1.269 - PrintToChat(client, "[SM] %t", "Already Voted");
1.270 - return Plugin_Continue;
1.271 - }
1.272 -
1.273 - new String:name[64];
1.274 - GetClientName(client, name, sizeof(name));
1.275 -
1.276 - g_Votes++;
1.277 - g_Voted[client] = true;
1.278 -
1.279 - PrintToChatAll("[SM] %t", "RTV Requested", name, g_Votes, g_VotesNeeded);
1.280 -
1.281 - if (g_Votes >= g_VotesNeeded)
1.282 - {
1.283 - g_RTVStarted = true;
1.284 - CreateTimer(2.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
1.285 - }
1.286 - }
1.287 - else if (GetConVarBool(g_Cvar_Nominate) && strcmp(text[startidx], "nominate", false) == 0)
1.288 - {
1.289 - if (g_RTVEnded)
1.290 - {
1.291 - PrintToChat(client, "[SM] %t", "RTV Ended");
1.292 - return Plugin_Continue;
1.293 - }
1.294 -
1.295 - if (g_RTVStarted)
1.296 - {
1.297 - PrintToChat(client, "[SM] %t", "RTV Started");
1.298 - return Plugin_Continue;
1.299 - }
1.300 -
1.301 - if (g_Nominated[client])
1.302 - {
1.303 - PrintToChat(client, "[SM] %t", "Already Nominated");
1.304 - return Plugin_Continue;
1.305 - }
1.306 -
1.307 - if (GetArraySize(g_RTVMapList) >= GetConVarInt(g_Cvar_Maps))
1.308 - {
1.309 - PrintToChat(client, "[SM] %t", "Max Nominations");
1.310 - return Plugin_Continue;
1.311 - }
1.312 -
1.313 - DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);
1.314 - }
1.315 -
1.316 - return Plugin_Continue;
1.317 -}
1.318 -
1.319 -public Action:Timer_DelayRTV(Handle:timer)
1.320 -{
1.321 - g_RTVAllowed = true;
1.322 -}
1.323 -
1.324 -public Action:Timer_StartRTV(Handle:timer)
1.325 -{
1.326 - if (timer == g_RetryTimer)
1.327 - {
1.328 - g_RetryTimer = INVALID_HANDLE;
1.329 - }
1.330 -
1.331 - if (g_RetryTimer != INVALID_HANDLE)
1.332 - {
1.333 - return;
1.334 - }
1.335 -
1.336 - if (IsVoteInProgress())
1.337 - {
1.338 - // Can't start a vote, try again in 5 seconds.
1.339 - g_RetryTimer = CreateTimer(5.0, Timer_StartRTV, TIMER_FLAG_NO_MAPCHANGE);
1.340 - return;
1.341 - }
1.342 -
1.343 - PrintToChatAll("[SM] %t", "RTV Vote Ready");
1.344 -
1.345 - new Handle:MapVoteMenu = CreateMenu(Handler_MapMapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
1.346 - SetMenuTitle(MapVoteMenu, "Rock The Vote");
1.347 -
1.348 - new Handle:tempMaps = CloneArray(g_MapList);
1.349 - decl String:map[32];
1.350 -
1.351 - // We assume that g_RTVMapList is within the correct limits, based on the logic for nominations
1.352 - for (new i = 0; i < GetArraySize(g_RTVMapList); i++)
1.353 - {
1.354 - GetArrayString(g_RTVMapList, i, map, sizeof(map));
1.355 - AddMenuItem(MapVoteMenu, map, map);
1.356 -
1.357 - new index = FindStringInArray(tempMaps, map);
1.358 - if (index != -1)
1.359 - {
1.360 - RemoveFromArray(tempMaps, index);
1.361 - }
1.362 - }
1.363 -
1.364 - new limit = GetConVarInt(g_Cvar_Maps) - GetArraySize(g_RTVMapList);
1.365 - if (limit > GetArraySize(tempMaps))
1.366 - {
1.367 - limit = GetArraySize(tempMaps);
1.368 - }
1.369 -
1.370 - for (new i = 0; i < limit; i++)
1.371 - {
1.372 - new b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
1.373 - GetArrayString(tempMaps, b, map, sizeof(map));
1.374 - PushArrayString(g_RTVMapList, map);
1.375 - AddMenuItem(MapVoteMenu, map, map);
1.376 - RemoveFromArray(tempMaps, b);
1.377 - }
1.378 -
1.379 - CloseHandle(tempMaps);
1.380 -
1.381 - AddMenuItem(MapVoteMenu, "Don't Change", "Don't Change");
1.382 -
1.383 - SetMenuExitButton(MapVoteMenu, false);
1.384 - VoteMenuToAll(MapVoteMenu, 20);
1.385 -
1.386 - LogMessage("[SM] Rockthevote was successfully started.");
1.387 -}
1.388 -
1.389 -public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
1.390 -{
1.391 - new String:map[65];
1.392 -
1.393 - ResetPack(dp);
1.394 - ReadPackString(dp, map, sizeof(map));
1.395 -
1.396 - ServerCommand("changelevel \"%s\"", map);
1.397 -
1.398 - return Plugin_Stop;
1.399 -}
1.400 -
1.401 -public Handler_MapMapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
1.402 -{
1.403 - switch (action)
1.404 - {
1.405 - case MenuAction_End:
1.406 - {
1.407 - CloseHandle(menu);
1.408 - }
1.409 -
1.410 - case MenuAction_Display:
1.411 - {
1.412 - decl String:oldTitle[255], String:buffer[255];
1.413 - GetMenuTitle(menu, oldTitle, sizeof(oldTitle));
1.414 - Format(buffer, sizeof(buffer), "%T", oldTitle, param1);
1.415 -
1.416 - new Handle:panel = Handle:param2;
1.417 - SetPanelTitle(panel, buffer);
1.418 - }
1.419 -
1.420 - case MenuAction_DisplayItem:
1.421 - {
1.422 - if (GetMenuItemCount(menu) - 1 == param2)
1.423 - {
1.424 - decl String:buffer[255];
1.425 - Format(buffer, sizeof(buffer), "%T", "Don't Change", param1);
1.426 - return RedrawMenuItem(buffer);
1.427 - }
1.428 - }
1.429 -
1.430 - // Why am I commented out? Because BAIL hasn't decided yet if
1.431 - // vote notification will be built into the Vote API.
1.432 - /*case MenuAction_Select:
1.433 - {
1.434 - decl String:Name[32], String:Map[32];
1.435 - GetClientName(param1, Name, sizeof(Name));
1.436 - GetMenuItem(menu, param2, Map, sizeof(Map));
1.437 -
1.438 - PrintToChatAll("[SM] %s has voted for map '%s'", Name, Map);
1.439 - }*/
1.440 -
1.441 - case MenuAction_VoteCancel:
1.442 - {
1.443 - if (param1 == VoteCancel_NoVotes)
1.444 - {
1.445 - PrintToChatAll("[SM] %t", "No Votes");
1.446 - g_RTVEnded = true;
1.447 - }
1.448 - }
1.449 -
1.450 - case MenuAction_VoteEnd:
1.451 - {
1.452 - new String:map[64];
1.453 -
1.454 - GetMenuItem(menu, param1, map, sizeof(map));
1.455 -
1.456 - if (GetMenuItemCount(menu) - 1 == param1) // This should always match the "Keep Current" option
1.457 - {
1.458 - PrintToChatAll("[SM] %t", "Current Map Stays");
1.459 - LogMessage("[SM] Rockthevote has ended, current map kept.");
1.460 - }
1.461 - else
1.462 - {
1.463 - PrintToChatAll("[SM] %t", "Changing Maps", map);
1.464 - LogMessage("[SM] Rockthevote has ended, changing to map %s.", map);
1.465 - new Handle:dp;
1.466 - CreateDataTimer(5.0, Timer_ChangeMap, dp);
1.467 - WritePackString(dp, map);
1.468 - }
1.469 -
1.470 - g_RTVEnded = true;
1.471 - }
1.472 - }
1.473 -
1.474 - return 0;
1.475 -}
1.476 -
1.477 -public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
1.478 -{
1.479 - switch (action)
1.480 - {
1.481 - case MenuAction_Select:
1.482 - {
1.483 - if (GetArraySize(g_RTVMapList) >= GetConVarInt(g_Cvar_Maps))
1.484 - {
1.485 - PrintToChat(param1, "[SM] %t", "Max Nominations");
1.486 - return;
1.487 - }
1.488 -
1.489 - decl String:map[64], String:name[64];
1.490 - GetMenuItem(menu, param2, map, sizeof(map));
1.491 -
1.492 - if (FindStringInArray(g_RTVMapList, map) != -1)
1.493 - {
1.494 - PrintToChat(param1, "[SM] %t", "Map Already Nominated");
1.495 - return;
1.496 - }
1.497 -
1.498 - GetClientName(param1, name, 64);
1.499 -
1.500 - PushArrayString(g_RTVMapList, map);
1.501 - RemoveMenuItem(menu, param2);
1.502 -
1.503 - g_Nominated[param1] = true;
1.504 -
1.505 - PrintToChatAll("[SM] %t", "Map Nominated", name, map);
1.506 - }
1.507 - }
1.508 -}
1.509 -
1.510 -BuildMapMenu()
1.511 -{
1.512 - if (g_MapMenu != INVALID_HANDLE)
1.513 - {
1.514 - CloseHandle(g_MapMenu);
1.515 - g_MapMenu = INVALID_HANDLE;
1.516 - }
1.517 -
1.518 - g_MapMenu = CreateMenu(Handler_MapSelectMenu);
1.519 - SetMenuTitle(g_MapMenu, "%t", "Nominate Title");
1.520 -
1.521 - decl String:map[64];
1.522 - for (new i = 0; i < GetArraySize(g_MapList); i++)
1.523 - {
1.524 - GetArrayString(g_MapList, i, map, sizeof(map));
1.525 - AddMenuItem(g_MapMenu, map, map);
1.526 - }
1.527 -
1.528 - SetMenuExitButton(g_MapMenu, false);
1.529 -}
1.530 \ No newline at end of file