Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.
(This day shall henceforth be known as the Eighty Column Massacre of '07)
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>.
39 public Plugin:myinfo =
42 author = "AlliedModders LLC",
43 description = "Fun Vote Commands",
44 version = SOURCEMOD_VERSION,
45 url = "http://www.sourcemod.net/"
48 #define VOTE_NO "###no###"
49 #define VOTE_YES "###yes###"
51 new Handle:g_hVoteMenu = INVALID_HANDLE;
53 new Handle:g_Cvar_Limits[5] = {INVALID_HANDLE, ...};
54 new Handle:g_Cvar_Gravity = INVALID_HANDLE;
55 new Handle:g_Cvar_Alltalk = INVALID_HANDLE;
56 new Handle:g_Cvar_FF = INVALID_HANDLE;
58 // new Handle:g_Cvar_Show = INVALID_HANDLE;
69 new voteType:g_voteType = voteType:gravity;
71 // Menu API does not provide us with a way to pass multiple peices of data with a single
72 // choice, so some globals are used to hold stuff.
74 #define VOTE_CLIENTID 0
76 new g_voteClient[2]; /* Holds the target's client id and user id */
81 new String:g_voteInfo[3][65]; /* Holds the target's name, authid, and IP */
83 public OnPluginStart()
85 LoadTranslations("common.phrases");
86 LoadTranslations("basevotes.phrases");
87 LoadTranslations("basefunvotes.phrases");
89 RegAdminCmd("sm_votegravity", Command_VoteGravity, ADMFLAG_VOTE, "sm_votegravity <amount> [amount2] ... [amount5]");
90 RegAdminCmd("sm_voteburn", Command_VoteBurn, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteburn <player>");
91 RegAdminCmd("sm_voteslay", Command_VoteSlay, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteslay <player>");
92 RegAdminCmd("sm_votealltalk", Command_VoteAlltalk, ADMFLAG_VOTE, "sm_votealltalk");
93 RegAdminCmd("sm_voteff", Command_VoteFF, ADMFLAG_VOTE, "sm_voteff");
95 g_Cvar_Limits[0] = CreateConVar("sm_vote_gravity", "0.60", "percent required for successful gravity vote.", 0, true, 0.05, true, 1.0);
96 g_Cvar_Limits[1] = CreateConVar("sm_vote_burn", "0.60", "percent required for successful burn vote.", 0, true, 0.05, true, 1.0);
97 g_Cvar_Limits[2] = CreateConVar("sm_vote_slay", "0.60", "percent required for successful slay vote.", 0, true, 0.05, true, 1.0);
98 g_Cvar_Limits[3] = CreateConVar("sm_vote_alltalk", "0.60", "percent required for successful alltalk vote.", 0, true, 0.05, true, 1.0);
99 g_Cvar_Limits[4] = CreateConVar("sm_vote_ff", "0.60", "percent required for successful friendly fire vote.", 0, true, 0.05, true, 1.0);
101 g_Cvar_Gravity = FindConVar("sv_gravity");
102 g_Cvar_Alltalk = FindConVar("sv_alltalk");
103 g_Cvar_FF = FindConVar("mp_friendlyfire");
106 g_Cvar_Show = FindConVar("sm_vote_show");
107 if (g_Cvar_Show == INVALID_HANDLE)
109 g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
114 public Action:Command_VoteGravity(client, args)
118 ReplyToCommand(client, "[SM] Usage: sm_votegravity <amount> [amount2] ... [amount5]");
119 return Plugin_Handled;
122 if (IsVoteInProgress())
124 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
125 return Plugin_Handled;
128 if (!TestVoteDelay(client))
130 return Plugin_Handled;
133 decl String:text[256];
134 GetCmdArgString(text, sizeof(text));
136 decl String:items[5][64];
140 while (pos != -1 && count < 5)
142 pos = BreakString(text[len], items[count], sizeof(items[]));
145 if (StringToFloatEx(items[count], temp) == 0)
147 ReplyToCommand(client, "[SM] %t", "Invalid Amount");
148 return Plugin_Handled;
159 ShowActivity(client, "%t", "Initiated Vote Gravity");
161 g_voteType = voteType:gravity;
163 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
167 strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), items[0]);
169 SetMenuTitle(g_hVoteMenu, "Change Gravity To");
170 AddMenuItem(g_hVoteMenu, items[0], "Yes");
171 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
175 g_voteInfo[VOTE_NAME][0] = '\0';
177 SetMenuTitle(g_hVoteMenu, "Gravity Vote");
178 for (new i = 0; i < count; i++)
180 AddMenuItem(g_hVoteMenu, items[i], items[i]);
184 SetMenuExitButton(g_hVoteMenu, false);
185 VoteMenuToAll(g_hVoteMenu, 20);
187 return Plugin_Handled;
190 public Action:Command_VoteBurn(client, args)
194 ReplyToCommand(client, "[SM] Usage: sm_voteburn <player>");
195 return Plugin_Handled;
198 if (IsVoteInProgress())
200 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
201 return Plugin_Handled;
204 if (!TestVoteDelay(client))
206 return Plugin_Handled;
209 decl String:text[256], String:arg[64];
210 GetCmdArgString(text, sizeof(text));
212 BreakString(text, arg, sizeof(arg));
214 new target = FindTarget(client, arg);
217 return Plugin_Handled;
220 if (!IsPlayerAlive(target))
222 ReplyToCommand(client, "[SM] %t", "Cannot performed on dead", arg);
223 return Plugin_Handled;
226 g_voteClient[VOTE_CLIENTID] = target;
227 GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
229 ShowActivity(client, "%t", "Initiated Vote Burn", g_voteInfo[VOTE_NAME]);
231 g_voteType = voteType:burn;
233 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
234 SetMenuTitle(g_hVoteMenu, "Voteburn Player");
235 AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
236 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
237 SetMenuExitButton(g_hVoteMenu, false);
238 VoteMenuToAll(g_hVoteMenu, 20);
240 return Plugin_Handled;
243 public Action:Command_VoteSlay(client, args)
247 ReplyToCommand(client, "[SM] Usage: sm_voteslay <player>");
248 return Plugin_Handled;
251 if (IsVoteInProgress())
253 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
254 return Plugin_Handled;
257 if (!TestVoteDelay(client))
259 return Plugin_Handled;
262 decl String:text[256], String:arg[64];
263 GetCmdArgString(text, sizeof(text));
265 BreakString(text, arg, sizeof(arg));
267 new target = FindTarget(client, arg);
270 return Plugin_Handled;
273 if (!IsPlayerAlive(target))
275 ReplyToCommand(client, "[SM] %t", "Cannot performed on dead", arg);
276 return Plugin_Handled;
279 g_voteClient[VOTE_CLIENTID] = target;
280 GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
282 ShowActivity(client, "%t", "Initiated Vote Slay", g_voteInfo[VOTE_NAME]);
284 g_voteType = voteType:slay;
286 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
287 SetMenuTitle(g_hVoteMenu, "Voteslay Player");
288 AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
289 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
290 SetMenuExitButton(g_hVoteMenu, false);
291 VoteMenuToAll(g_hVoteMenu, 20);
293 return Plugin_Handled;
296 public Action:Command_VoteAlltalk(client, args)
300 ReplyToCommand(client, "[SM] Usage: sm_votealltalk");
301 return Plugin_Handled;
304 if (IsVoteInProgress())
306 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
307 return Plugin_Handled;
310 if (!TestVoteDelay(client))
312 return Plugin_Handled;
315 ShowActivity(client, "%t", "Initiated Vote Alltalk");
317 g_voteType = voteType:alltalk;
318 g_voteInfo[VOTE_NAME][0] = '\0';
320 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
322 if (GetConVarBool(g_Cvar_Alltalk))
324 SetMenuTitle(g_hVoteMenu, "Votealltalk Off");
328 SetMenuTitle(g_hVoteMenu, "Votealltalk On");
331 AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
332 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
333 SetMenuExitButton(g_hVoteMenu, false);
334 VoteMenuToAll(g_hVoteMenu, 20);
336 return Plugin_Handled;
339 public Action:Command_VoteFF(client, args)
343 ReplyToCommand(client, "[SM] Usage: sm_voteff");
344 return Plugin_Handled;
347 if (IsVoteInProgress())
349 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
350 return Plugin_Handled;
353 if (!TestVoteDelay(client))
355 return Plugin_Handled;
358 ShowActivity(client, "%t", "Initiated Vote FF");
360 g_voteType = voteType:ff;
361 g_voteInfo[VOTE_NAME][0] = '\0';
363 g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
365 if (GetConVarBool(g_Cvar_Alltalk))
367 SetMenuTitle(g_hVoteMenu, "Voteff Off");
371 SetMenuTitle(g_hVoteMenu, "Voteff On");
374 AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
375 AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
376 SetMenuExitButton(g_hVoteMenu, false);
377 VoteMenuToAll(g_hVoteMenu, 20);
379 return Plugin_Handled;
382 public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)
384 if (action == MenuAction_End)
388 else if (action == MenuAction_Display)
390 decl String:title[64];
391 GetMenuTitle(g_hVoteMenu, title, sizeof(title));
393 decl String:buffer[255];
394 Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
396 SetMenuTitle(g_hVoteMenu, buffer);
398 else if (action == MenuAction_DisplayItem)
400 decl String:display[64];
401 GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
403 if (strcmp(display, VOTE_NO) == 0 || strcmp(display, VOTE_YES) == 0)
405 decl String:buffer[255];
406 Format(buffer, sizeof(buffer), "%T", display, param1);
408 return RedrawMenuItem(buffer);
411 /* else if (action == MenuAction_Select)
413 VoteSelect(menu, param1, param2);
415 else if (action == VoteCancel_NoVotes)
417 PrintToChatAll("[SM] %t", "No Votes Cast");
419 else if (action == MenuAction_VoteEnd)
421 decl String:item[64];
422 new Float:percent, Float:limit, votes, totalVotes;
424 GetMenuVoteInfo(param2, votes, totalVotes);
425 GetMenuItem(menu, param1, item, sizeof(item));
427 if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
429 votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
432 percent = GetVotePercent(votes, totalVotes);
434 limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
436 // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
437 if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
439 LogMessage("Vote failed.");
440 PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
444 PrintToChatAll("[SM] %t", "Vote Successful", RoundToNearest(100.0*percent), totalVotes);
448 case (voteType:gravity):
450 PrintToChatAll("[SM] %t", "Cvar changed", "sv_gravity", item);
451 LogMessage("Changing gravity to %s due to vote.", item);
452 SetConVarInt(g_Cvar_Gravity, StringToInt(item));
455 case (voteType:burn):
457 PrintToChatAll("[SM] %t", "Ignited player", g_voteInfo[VOTE_NAME]);
458 LogMessage("Vote burn successful, igniting \"%L\"", g_voteClient[VOTE_CLIENTID]);
460 IgniteEntity(g_voteClient[VOTE_CLIENTID], 19.8);
463 case (voteType:slay):
465 PrintToChatAll("[SM] %t", "Slayed player", g_voteInfo[VOTE_NAME]);
466 LogMessage("Vote slay successful, slaying \"%L\"", g_voteClient[VOTE_CLIENTID]);
468 ExtinguishEntity(g_voteClient[VOTE_CLIENTID]);
469 ForcePlayerSuicide(g_voteClient[VOTE_CLIENTID]);
472 case (voteType:alltalk):
474 PrintToChatAll("[SM] %t", "Cvar changed", "sv_alltalk", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
475 LogMessage("Changing alltalk to %s due to vote.", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
476 SetConVarBool(g_Cvar_Alltalk, !GetConVarBool(g_Cvar_Alltalk));
481 PrintToChatAll("[SM] %t", "Cvar changed", "mp_friendlyfire", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
482 LogMessage("Changing friendly fire to %s due to vote.", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
483 SetConVarBool(g_Cvar_FF, !GetConVarBool(g_Cvar_FF));
493 VoteSelect(Handle:menu, param1, param2 = 0)
495 if (GetConVarInt(g_Cvar_VoteShow) == 1)
497 decl String:voter[64], String:junk[64], String:choice[64];
498 GetClientName(param1, voter, sizeof(voter));
499 GetMenuItem(menu, param2, junk, sizeof(junk), _, choice, sizeof(choice));
500 PrintToChatAll("[SM] %T", "Vote Select", LANG_SERVER, voter, choice);
507 CloseHandle(g_hVoteMenu);
508 g_hVoteMenu = INVALID_HANDLE;
511 Float:GetVotePercent(votes, totalVotes)
513 return FloatDiv(float(votes),float(totalVotes));
516 bool:TestVoteDelay(client)
518 new delay = CheckVoteDelay();
524 ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
528 ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);