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(menu, title, sizeof(title));
393 decl String:buffer[255];
394 Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
396 new Handle:panel = Handle:param2;
397 SetPanelTitle(panel, buffer);
399 else if (action == MenuAction_DisplayItem)
401 decl String:display[64];
402 GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
404 if (strcmp(display, VOTE_NO) == 0 || strcmp(display, VOTE_YES) == 0)
406 decl String:buffer[255];
407 Format(buffer, sizeof(buffer), "%T", display, param1);
409 return RedrawMenuItem(buffer);
412 /* else if (action == MenuAction_Select)
414 VoteSelect(menu, param1, param2);
416 else if (action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
418 PrintToChatAll("[SM] %t", "No Votes Cast");
420 else if (action == MenuAction_VoteEnd)
422 decl String:item[64];
423 new Float:percent, Float:limit, votes, totalVotes;
425 GetMenuVoteInfo(param2, votes, totalVotes);
426 GetMenuItem(menu, param1, item, sizeof(item));
428 if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
430 votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
433 percent = GetVotePercent(votes, totalVotes);
435 limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
437 // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
438 if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
440 LogMessage("Vote failed.");
441 PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
445 PrintToChatAll("[SM] %t", "Vote Successful", RoundToNearest(100.0*percent), totalVotes);
449 case (voteType:gravity):
451 PrintToChatAll("[SM] %t", "Cvar changed", "sv_gravity", item);
452 LogMessage("Changing gravity to %s due to vote.", item);
453 SetConVarInt(g_Cvar_Gravity, StringToInt(item));
456 case (voteType:burn):
458 PrintToChatAll("[SM] %t", "Ignited player", g_voteInfo[VOTE_NAME]);
459 LogMessage("Vote burn successful, igniting \"%L\"", g_voteClient[VOTE_CLIENTID]);
461 IgniteEntity(g_voteClient[VOTE_CLIENTID], 19.8);
464 case (voteType:slay):
466 PrintToChatAll("[SM] %t", "Slayed player", g_voteInfo[VOTE_NAME]);
467 LogMessage("Vote slay successful, slaying \"%L\"", g_voteClient[VOTE_CLIENTID]);
469 ExtinguishEntity(g_voteClient[VOTE_CLIENTID]);
470 ForcePlayerSuicide(g_voteClient[VOTE_CLIENTID]);
473 case (voteType:alltalk):
475 PrintToChatAll("[SM] %t", "Cvar changed", "sv_alltalk", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
476 LogMessage("Changing alltalk to %s due to vote.", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
477 SetConVarBool(g_Cvar_Alltalk, !GetConVarBool(g_Cvar_Alltalk));
482 PrintToChatAll("[SM] %t", "Cvar changed", "mp_friendlyfire", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
483 LogMessage("Changing friendly fire to %s due to vote.", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
484 SetConVarBool(g_Cvar_FF, !GetConVarBool(g_Cvar_FF));
494 VoteSelect(Handle:menu, param1, param2 = 0)
496 if (GetConVarInt(g_Cvar_VoteShow) == 1)
498 decl String:voter[64], String:junk[64], String:choice[64];
499 GetClientName(param1, voter, sizeof(voter));
500 GetMenuItem(menu, param2, junk, sizeof(junk), _, choice, sizeof(choice));
501 PrintToChatAll("[SM] %T", "Vote Select", LANG_SERVER, voter, choice);
508 CloseHandle(g_hVoteMenu);
509 g_hVoteMenu = INVALID_HANDLE;
512 Float:GetVotePercent(votes, totalVotes)
514 return FloatDiv(float(votes),float(totalVotes));
517 bool:TestVoteDelay(client)
519 new delay = CheckVoteDelay();
525 ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
529 ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);