3 * =============================================================================
4 * SourceMod Fun Votes Plugin
5 * Implements extra fun vote commands.
7 * SourceMod (C)2004-2007 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>.
42 public Plugin:myinfo =
44 name = "Basic Fun Votes",
45 author = "AlliedModders LLC",
46 description = "Fun Vote Commands",
47 version = SOURCEMOD_VERSION,
48 url = "http://www.sourcemod.net/"
51 #define VOTE_NO "###no###"
52 #define VOTE_YES "###yes###"
54 new Handle:g_hVoteMenu = INVALID_HANDLE;
56 new Handle:g_Cvar_Limits[5] = {INVALID_HANDLE, ...};
57 new Handle:g_Cvar_Gravity = INVALID_HANDLE;
58 new Handle:g_Cvar_Alltalk = INVALID_HANDLE;
59 new Handle:g_Cvar_FF = INVALID_HANDLE;
61 // new Handle:g_Cvar_Show = INVALID_HANDLE;
72 new voteType:g_voteType = voteType:gravity;
74 // Menu API does not provide us with a way to pass multiple peices of data with a single
75 // choice, so some globals are used to hold stuff.
77 #define VOTE_CLIENTID 0
79 new g_voteClient[2]; /* Holds the target's client id and user id */
84 new String:g_voteInfo[3][65]; /* Holds the target's name, authid, and IP */
86 new Handle:hTopMenu = INVALID_HANDLE;
88 #include "basefunvotes/votegravity.sp"
89 #include "basefunvotes/voteburn.sp"
90 #include "basefunvotes/voteslay.sp"
91 #include "basefunvotes/votealltalk.sp"
92 #include "basefunvotes/voteff.sp"
94 public OnPluginStart()
96 LoadTranslations("common.phrases");
97 LoadTranslations("basevotes.phrases");
98 LoadTranslations("basefunvotes.phrases");
99 LoadTranslations("basefuncommands.phrases");
101 RegAdminCmd("sm_votegravity", Command_VoteGravity, ADMFLAG_VOTE, "sm_votegravity <amount> [amount2] ... [amount5]");
102 RegAdminCmd("sm_voteburn", Command_VoteBurn, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteburn <player>");
103 RegAdminCmd("sm_voteslay", Command_VoteSlay, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteslay <player>");
104 RegAdminCmd("sm_votealltalk", Command_VoteAlltalk, ADMFLAG_VOTE, "sm_votealltalk");
105 RegAdminCmd("sm_voteff", Command_VoteFF, ADMFLAG_VOTE, "sm_voteff");
107 g_Cvar_Limits[0] = CreateConVar("sm_vote_gravity", "0.60", "percent required for successful gravity vote.", 0, true, 0.05, true, 1.0);
108 g_Cvar_Limits[1] = CreateConVar("sm_vote_burn", "0.60", "percent required for successful burn vote.", 0, true, 0.05, true, 1.0);
109 g_Cvar_Limits[2] = CreateConVar("sm_vote_slay", "0.60", "percent required for successful slay vote.", 0, true, 0.05, true, 1.0);
110 g_Cvar_Limits[3] = CreateConVar("sm_vote_alltalk", "0.60", "percent required for successful alltalk vote.", 0, true, 0.05, true, 1.0);
111 g_Cvar_Limits[4] = CreateConVar("sm_vote_ff", "0.60", "percent required for successful friendly fire vote.", 0, true, 0.05, true, 1.0);
113 g_Cvar_Gravity = FindConVar("sv_gravity");
114 g_Cvar_Alltalk = FindConVar("sv_alltalk");
115 g_Cvar_FF = FindConVar("mp_friendlyfire");
118 g_Cvar_Show = FindConVar("sm_vote_show");
119 if (g_Cvar_Show == INVALID_HANDLE)
121 g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
125 /* Account for late loading */
127 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
129 OnAdminMenuReady(topmenu);
133 public OnAdminMenuReady(Handle:topmenu)
135 /* Block us from being called twice */
136 if (topmenu == hTopMenu)
141 /* Save the Handle */
144 /* Build the "Voting Commands" category */
145 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
147 if (voting_commands != INVALID_TOPMENUOBJECT)
149 AddToTopMenu(hTopMenu,
152 AdminMenu_VoteGravity,
157 AddToTopMenu(hTopMenu,
163 ADMFLAG_VOTE|ADMFLAG_SLAY);
165 AddToTopMenu(hTopMenu,
171 ADMFLAG_VOTE|ADMFLAG_SLAY);
173 AddToTopMenu(hTopMenu,
176 AdminMenu_VoteAllTalk,
181 AddToTopMenu(hTopMenu,
191 public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)
193 if (action == MenuAction_End)
197 else if (action == MenuAction_Display)
199 decl String:title[64];
200 GetMenuTitle(menu, title, sizeof(title));
202 decl String:buffer[255];
203 Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
205 new Handle:panel = Handle:param2;
206 SetPanelTitle(panel, buffer);
208 else if (action == MenuAction_DisplayItem)
210 decl String:display[64];
211 GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
213 if (strcmp(display, VOTE_NO) == 0 || strcmp(display, VOTE_YES) == 0)
215 decl String:buffer[255];
216 Format(buffer, sizeof(buffer), "%T", display, param1);
218 return RedrawMenuItem(buffer);
221 /* else if (action == MenuAction_Select)
223 VoteSelect(menu, param1, param2);
225 else if (action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
227 PrintToChatAll("[SM] %t", "No Votes Cast");
229 else if (action == MenuAction_VoteEnd)
231 decl String:item[64];
232 new Float:percent, Float:limit, votes, totalVotes;
234 GetMenuVoteInfo(param2, votes, totalVotes);
235 GetMenuItem(menu, param1, item, sizeof(item));
237 if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
239 votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
242 percent = GetVotePercent(votes, totalVotes);
244 limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
246 /* :TODO: g_voteClient[userid] needs to be checked.
249 // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
250 if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
252 /* :TODO: g_voteClient[userid] should be used here and set to -1 if not applicable.
254 LogAction(-1, -1, "Vote failed.");
255 PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
259 PrintToChatAll("[SM] %t", "Vote Successful", RoundToNearest(100.0*percent), totalVotes);
263 case (voteType:gravity):
265 PrintToChatAll("[SM] %t", "Cvar changed", "sv_gravity", item);
266 LogAction(-1, -1, "Changing gravity to %s due to vote.", item);
267 SetConVarInt(g_Cvar_Gravity, StringToInt(item));
270 case (voteType:burn):
272 PrintToChatAll("[SM] %t", "Set target on fire", "_s", g_voteInfo[VOTE_NAME]);
273 LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote burn successful, igniting \"%L\"", g_voteClient[VOTE_CLIENTID]);
275 IgniteEntity(g_voteClient[VOTE_CLIENTID], 19.8);
278 case (voteType:slay):
280 PrintToChatAll("[SM] %t", "Slayed player", g_voteInfo[VOTE_NAME]);
281 LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote slay successful, slaying \"%L\"", g_voteClient[VOTE_CLIENTID]);
283 ExtinguishEntity(g_voteClient[VOTE_CLIENTID]);
284 ForcePlayerSuicide(g_voteClient[VOTE_CLIENTID]);
287 case (voteType:alltalk):
289 PrintToChatAll("[SM] %t", "Cvar changed", "sv_alltalk", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
290 LogAction(-1, -1, "Changing alltalk to %s due to vote.", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
291 SetConVarBool(g_Cvar_Alltalk, !GetConVarBool(g_Cvar_Alltalk));
296 PrintToChatAll("[SM] %t", "Cvar changed", "mp_friendlyfire", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
297 LogAction(-1, -1, "Changing friendly fire to %s due to vote.", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
298 SetConVarBool(g_Cvar_FF, !GetConVarBool(g_Cvar_FF));
308 VoteSelect(Handle:menu, param1, param2 = 0)
310 if (GetConVarInt(g_Cvar_VoteShow) == 1)
312 decl String:voter[64], String:junk[64], String:choice[64];
313 GetClientName(param1, voter, sizeof(voter));
314 GetMenuItem(menu, param2, junk, sizeof(junk), _, choice, sizeof(choice));
315 PrintToChatAll("[SM] %T", "Vote Select", LANG_SERVER, voter, choice);
322 CloseHandle(g_hVoteMenu);
323 g_hVoteMenu = INVALID_HANDLE;
326 Float:GetVotePercent(votes, totalVotes)
328 return FloatDiv(float(votes),float(totalVotes));
331 bool:TestVoteDelay(client)
333 new delay = CheckVoteDelay();
339 ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
343 ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);