1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/funvotes/votegravity.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,139 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basefunvotes Plugin
1.8 + * Provides votegravity functionality
1.9 + *
1.10 + * SourceMod (C)2004-2008 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: admin-flatfile.sp 1438 2007-09-16 03:45:06Z dvander $
1.35 + */
1.36 +
1.37 +
1.38 +DisplayVoteGravityMenu(client,count,String:items[5][])
1.39 +{
1.40 + LogAction(client, -1, "\"%L\" initiated a gravity vote.", client);
1.41 + ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Gravity");
1.42 +
1.43 + g_voteType = voteType:gravity;
1.44 +
1.45 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.46 +
1.47 + if (count == 1)
1.48 + {
1.49 + strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), items[0]);
1.50 +
1.51 + SetMenuTitle(g_hVoteMenu, "Change Gravity To");
1.52 + AddMenuItem(g_hVoteMenu, items[0], "Yes");
1.53 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.54 + }
1.55 + else
1.56 + {
1.57 + g_voteInfo[VOTE_NAME][0] = '\0';
1.58 +
1.59 + SetMenuTitle(g_hVoteMenu, "Gravity Vote");
1.60 + for (new i = 0; i < count; i++)
1.61 + {
1.62 + AddMenuItem(g_hVoteMenu, items[i], items[i]);
1.63 + }
1.64 + }
1.65 +
1.66 + SetMenuExitButton(g_hVoteMenu, false);
1.67 + VoteMenuToAll(g_hVoteMenu, 20);
1.68 +}
1.69 +
1.70 +public AdminMenu_VoteGravity(Handle:topmenu,
1.71 + TopMenuAction:action,
1.72 + TopMenuObject:object_id,
1.73 + param,
1.74 + String:buffer[],
1.75 + maxlength)
1.76 +{
1.77 + if (action == TopMenuAction_DisplayOption)
1.78 + {
1.79 + Format(buffer, maxlength, "%T", "Gravity vote", param);
1.80 + }
1.81 + else if (action == TopMenuAction_SelectOption)
1.82 + {
1.83 + /* Might need a better way of selecting the list of pre-defined gravity choices */
1.84 + new String:items[5][5] ={"200","400","800","1600","3200"};
1.85 + DisplayVoteGravityMenu(param,5, items);
1.86 + }
1.87 + else if (action == TopMenuAction_DrawOption)
1.88 + {
1.89 + /* disable this option if a vote is already running */
1.90 + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
1.91 + }
1.92 +}
1.93 +
1.94 +public Action:Command_VoteGravity(client, args)
1.95 +{
1.96 + if (args < 1)
1.97 + {
1.98 + ReplyToCommand(client, "[SM] Usage: sm_votegravity <amount> [amount2] ... [amount5]");
1.99 + return Plugin_Handled;
1.100 + }
1.101 +
1.102 + if (IsVoteInProgress())
1.103 + {
1.104 + ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.105 + return Plugin_Handled;
1.106 + }
1.107 +
1.108 + if (!TestVoteDelay(client))
1.109 + {
1.110 + return Plugin_Handled;
1.111 + }
1.112 +
1.113 + decl String:text[256];
1.114 + GetCmdArgString(text, sizeof(text));
1.115 +
1.116 + decl String:items[5][64];
1.117 + new count;
1.118 + new len, pos;
1.119 +
1.120 + while (pos != -1 && count < 5)
1.121 + {
1.122 + pos = BreakString(text[len], items[count], sizeof(items[]));
1.123 +
1.124 + decl Float:temp;
1.125 + if (StringToFloatEx(items[count], temp) == 0)
1.126 + {
1.127 + ReplyToCommand(client, "[SM] %t", "Invalid Amount");
1.128 + return Plugin_Handled;
1.129 + }
1.130 +
1.131 + count++;
1.132 +
1.133 + if (pos != -1)
1.134 + {
1.135 + len += pos;
1.136 + }
1.137 + }
1.138 +
1.139 + DisplayVoteGravityMenu(client, count, items);
1.140 +
1.141 + return Plugin_Handled;
1.142 +}
1.143 \ No newline at end of file