plugins/funvotes/votegravity.sp
author David Anderson <dvander@alliedmods.net>
Mon Aug 12 00:22:41 2013 +0100 (2013-08-12)
changeset 3989 b73dae36a0da
parent 2289 44045ead61cd
permissions -rw-r--r--
Eliminate InfoVars::rval (bug 5844 part 6, r=ds).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefunvotes Plugin
     5  * Provides votegravity functionality
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    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.
    13  * 
    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
    17  * details.
    18  *
    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/>.
    21  *
    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>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 
    35 DisplayVoteGravityMenu(client,count,String:items[5][])
    36 {
    37 	LogAction(client, -1, "\"%L\" initiated a gravity vote.", client);
    38 	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Gravity");
    39 	
    40 	g_voteType = voteType:gravity;
    41 	
    42 	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
    43 	
    44 	if (count == 1)
    45 	{
    46 		strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), items[0]);
    47 			
    48 		SetMenuTitle(g_hVoteMenu, "Change Gravity To");
    49 		AddMenuItem(g_hVoteMenu, items[0], "Yes");
    50 		AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
    51 	}
    52 	else
    53 	{
    54 		g_voteInfo[VOTE_NAME][0] = '\0';
    55 		
    56 		SetMenuTitle(g_hVoteMenu, "Gravity Vote");
    57 		for (new i = 0; i < count; i++)
    58 		{
    59 			AddMenuItem(g_hVoteMenu, items[i], items[i]);
    60 		}	
    61 	}
    62 	
    63 	SetMenuExitButton(g_hVoteMenu, false);
    64 	VoteMenuToAll(g_hVoteMenu, 20);
    65 }
    66 
    67 public AdminMenu_VoteGravity(Handle:topmenu, 
    68 							  TopMenuAction:action,
    69 							  TopMenuObject:object_id,
    70 							  param,
    71 							  String:buffer[],
    72 							  maxlength)
    73 {
    74 	if (action == TopMenuAction_DisplayOption)
    75 	{
    76 		Format(buffer, maxlength, "%T", "Gravity vote", param);
    77 	}
    78 	else if (action == TopMenuAction_SelectOption)
    79 	{
    80 		/* Might need a better way of selecting the list of pre-defined gravity choices */
    81 		new String:items[5][5] ={"200","400","800","1600","3200"};
    82 		DisplayVoteGravityMenu(param,5, items);
    83 	}
    84 	else if (action == TopMenuAction_DrawOption)
    85 	{	
    86 		/* disable this option if a vote is already running */
    87 		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
    88 	}
    89 }
    90 
    91 public Action:Command_VoteGravity(client, args)
    92 {
    93 	if (args < 1)
    94 	{
    95 		ReplyToCommand(client, "[SM] Usage: sm_votegravity <amount> [amount2] ... [amount5]");
    96 		return Plugin_Handled;	
    97 	}
    98 	
    99 	if (IsVoteInProgress())
   100 	{
   101 		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   102 		return Plugin_Handled;
   103 	}
   104 	
   105 	if (!TestVoteDelay(client))
   106 	{
   107 		return Plugin_Handled;
   108 	}
   109 	
   110 	decl String:text[256];
   111 	GetCmdArgString(text, sizeof(text));
   112 
   113 	decl String:items[5][64];
   114 	new count;	
   115 	new len, pos;
   116 	
   117 	while (pos != -1 && count < 5)
   118 	{	
   119 		pos = BreakString(text[len], items[count], sizeof(items[]));
   120 		
   121 		decl Float:temp;
   122 		if (StringToFloatEx(items[count], temp) == 0)
   123 		{
   124 			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
   125 			return Plugin_Handled;
   126 		}		
   127 
   128 		count++;
   129 		
   130 		if (pos != -1)
   131 		{
   132 			len += pos;
   133 		}	
   134 	}
   135 	
   136 	DisplayVoteGravityMenu(client, count, items);
   137 	
   138 	return Plugin_Handled;	
   139 }