Updated some CS:GO gamedata.
3 * =============================================================================
4 * SourceMod Basic Votes Plugin
5 * Implements basic vote commands.
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 =
43 author = "AlliedModders LLC",
44 description = "Basic Vote Commands",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
49 #define VOTE_NO "###no###"
50 #define VOTE_YES "###yes###"
52 new Handle:g_hVoteMenu = INVALID_HANDLE;
54 new Handle:g_Cvar_Limits[3] = {INVALID_HANDLE, ...};
55 //new Handle:g_Cvar_VoteSay = INVALID_HANDLE;
65 new voteType:g_voteType = voteType:question;
67 // Menu API does not provide us with a way to pass multiple peices of data with a single
68 // choice, so some globals are used to hold stuff.
70 #define VOTE_CLIENTID 0
72 new g_voteClient[2]; /* Holds the target's client id and user id */
77 new String:g_voteInfo[3][65]; /* Holds the target's name, authid, and IP */
79 new String:g_voteArg[256]; /* Used to hold ban/kick reasons or vote questions */
82 new Handle:hTopMenu = INVALID_HANDLE;
84 #include "basevotes/votekick.sp"
85 #include "basevotes/voteban.sp"
86 #include "basevotes/votemap.sp"
88 public OnPluginStart()
90 LoadTranslations("common.phrases");
91 LoadTranslations("basevotes.phrases");
92 LoadTranslations("plugin.basecommands");
93 LoadTranslations("basebans.phrases");
95 RegAdminCmd("sm_votemap", Command_Votemap, ADMFLAG_VOTE|ADMFLAG_CHANGEMAP, "sm_votemap <mapname> [mapname2] ... [mapname5] ");
96 RegAdminCmd("sm_votekick", Command_Votekick, ADMFLAG_VOTE|ADMFLAG_KICK, "sm_votekick <player> [reason]");
97 RegAdminCmd("sm_voteban", Command_Voteban, ADMFLAG_VOTE|ADMFLAG_BAN, "sm_voteban <player> [reason]");
98 RegAdminCmd("sm_vote", Command_Vote, ADMFLAG_VOTE, "sm_vote <question> [Answer1] [Answer2] ... [Answer5]");
101 g_Cvar_Show = FindConVar("sm_vote_show");
102 if (g_Cvar_Show == INVALID_HANDLE)
104 g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
108 g_Cvar_Limits[0] = CreateConVar("sm_vote_map", "0.60", "percent required for successful map vote.", 0, true, 0.05, true, 1.0);
109 g_Cvar_Limits[1] = CreateConVar("sm_vote_kick", "0.60", "percent required for successful kick vote.", 0, true, 0.05, true, 1.0);
110 g_Cvar_Limits[2] = CreateConVar("sm_vote_ban", "0.60", "percent required for successful ban vote.", 0, true, 0.05, true, 1.0);
112 /* Account for late loading */
114 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
116 OnAdminMenuReady(topmenu);
119 g_SelectedMaps = CreateArray(33);
121 g_MapList = CreateMenu(MenuHandler_Map, MenuAction_DrawItem|MenuAction_Display);
122 SetMenuTitle(g_MapList, "%T", "Please select a map", LANG_SERVER);
123 SetMenuExitBackButton(g_MapList, true);
125 decl String:mapListPath[PLATFORM_MAX_PATH];
126 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
127 SetMapListCompatBind("sm_votemap menu", mapListPath);
130 public OnConfigsExecuted()
132 g_mapCount = LoadMapList(g_MapList);
135 public OnAdminMenuReady(Handle:topmenu)
137 /* Block us from being called twice */
138 if (topmenu == hTopMenu)
143 /* Save the Handle */
146 /* Build the "Voting Commands" category */
147 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
149 if (voting_commands != INVALID_TOPMENUOBJECT)
151 AddToTopMenu(hTopMenu,
157 ADMFLAG_VOTE|ADMFLAG_KICK);
159 AddToTopMenu(hTopMenu,
165 ADMFLAG_VOTE|ADMFLAG_BAN);
167 AddToTopMenu(hTopMenu,
173 ADMFLAG_VOTE|ADMFLAG_CHANGEMAP);
177 public Action:Command_Vote(client, args)
181 ReplyToCommand(client, "[SM] Usage: sm_vote <question> [Answer1] [Answer2] ... [Answer5]");
182 return Plugin_Handled;
185 if (IsVoteInProgress())
187 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
188 return Plugin_Handled;
191 if (!TestVoteDelay(client))
193 return Plugin_Handled;
196 decl String:text[256];
197 GetCmdArgString(text, sizeof(text));
199 decl String:answers[5][64];
201 new len = BreakString(text, g_voteArg, sizeof(g_voteArg));
204 while (args > 1 && pos != -1 && answerCount < 5)
206 pos = BreakString(text[len], answers[answerCount], sizeof(answers[]));
215 LogAction(client, -1, "\"%L\" initiated a generic vote.", client);
216 ShowActivity2(client, "[SM] ", "%t", "Initiate Vote", g_voteArg);
218 g_voteType = voteType:question;
220 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
221 SetMenuTitle(g_hVoteMenu, "%s?", g_voteArg);
225 AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
226 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
230 for (new i = 0; i < answerCount; i++)
232 AddMenuItem(g_hVoteMenu, answers[i], answers[i]);
236 SetMenuExitButton(g_hVoteMenu, false);
237 VoteMenuToAll(g_hVoteMenu, 20);
239 return Plugin_Handled;
242 public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)
244 if (action == MenuAction_End)
248 else if (action == MenuAction_Display)
250 if (g_voteType != voteType:question)
252 decl String:title[64];
253 GetMenuTitle(menu, title, sizeof(title));
255 decl String:buffer[255];
256 Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
258 new Handle:panel = Handle:param2;
259 SetPanelTitle(panel, buffer);
262 else if (action == MenuAction_DisplayItem)
264 decl String:display[64];
265 GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
267 if (strcmp(display, "No") == 0 || strcmp(display, "Yes") == 0)
269 decl String:buffer[255];
270 Format(buffer, sizeof(buffer), "%T", display, param1);
272 return RedrawMenuItem(buffer);
275 /* else if (action == MenuAction_Select)
277 VoteSelect(menu, param1, param2);
279 else if (action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
281 PrintToChatAll("[SM] %t", "No Votes Cast");
283 else if (action == MenuAction_VoteEnd)
285 decl String:item[64], String:display[64];
286 new Float:percent, Float:limit, votes, totalVotes;
288 GetMenuVoteInfo(param2, votes, totalVotes);
289 GetMenuItem(menu, param1, item, sizeof(item), _, display, sizeof(display));
291 if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
293 votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
296 percent = GetVotePercent(votes, totalVotes);
298 if (g_voteType != voteType:question)
300 limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
303 /* :TODO: g_voteClient[userid] needs to be checked */
305 // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
306 if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
308 /* :TODO: g_voteClient[userid] should be used here and set to -1 if not applicable.
310 LogAction(-1, -1, "Vote failed.");
311 PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
315 PrintToChatAll("[SM] %t", "Vote Successful", RoundToNearest(100.0*percent), totalVotes);
319 case (voteType:question):
321 if (strcmp(item, VOTE_NO) == 0 || strcmp(item, VOTE_YES) == 0)
323 strcopy(item, sizeof(item), display);
326 PrintToChatAll("[SM] %t", "Vote End", g_voteArg, item);
331 LogAction(-1, -1, "Changing map to %s due to vote.", item);
332 PrintToChatAll("[SM] %t", "Changing map", item);
334 CreateDataTimer(5.0, Timer_ChangeMap, dp);
335 WritePackString(dp, item);
338 case (voteType:kick):
340 if (g_voteArg[0] == '\0')
342 strcopy(g_voteArg, sizeof(g_voteArg), "Votekicked");
345 PrintToChatAll("[SM] %t", "Kicked target", "_s", g_voteInfo[VOTE_NAME]);
346 LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote kick successful, kicked \"%L\" (reason \"%s\")", g_voteClient[VOTE_CLIENTID], g_voteArg);
348 ServerCommand("kickid %d \"%s\"", g_voteClient[VOTE_USERID], g_voteArg);
353 if (g_voteArg[0] == '\0')
355 strcopy(g_voteArg, sizeof(g_voteArg), "Votebanned");
358 PrintToChatAll("[SM] %t", "Banned player", g_voteInfo[VOTE_NAME], 30);
359 LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote ban successful, banned \"%L\" (minutes \"30\") (reason \"%s\")", g_voteClient[VOTE_CLIENTID], g_voteArg);
361 BanClient(g_voteClient[VOTE_CLIENTID],
376 VoteSelect(Handle:menu, param1, param2 = 0)
378 if (GetConVarInt(g_Cvar_VoteShow) == 1)
380 decl String:voter[64], String:junk[64], String:choice[64];
381 GetClientName(param1, voter, sizeof(voter));
382 GetMenuItem(menu, param2, junk, sizeof(junk), _, choice, sizeof(choice));
383 PrintToChatAll("[SM] %T", "Vote Select", LANG_SERVER, voter, choice);
390 CloseHandle(g_hVoteMenu);
391 g_hVoteMenu = INVALID_HANDLE;
394 Float:GetVotePercent(votes, totalVotes)
396 return FloatDiv(float(votes),float(totalVotes));
399 bool:TestVoteDelay(client)
401 new delay = CheckVoteDelay();
407 ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
411 ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);
420 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
422 decl String:mapname[65];
425 ReadPackString(dp, mapname, sizeof(mapname));
427 ForceChangeLevel(mapname, "sm_votemap Result");