plugins/funvotes/votegravity.sp
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 1990 de135d1f05b1
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Basefunvotes Plugin
ds@1952
     5
 * Provides votegravity functionality
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id: admin-flatfile.sp 1438 2007-09-16 03:45:06Z dvander $
ds@1952
    32
 */
ds@1952
    33
ds@1952
    34
ds@1952
    35
DisplayVoteGravityMenu(client,count,String:items[5][])
ds@1952
    36
{
ds@1952
    37
	LogAction(client, -1, "\"%L\" initiated a gravity vote.", client);
ds@1952
    38
	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Gravity");
ds@1952
    39
	
ds@1952
    40
	g_voteType = voteType:gravity;
ds@1952
    41
	
ds@1952
    42
	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
ds@1952
    43
	
ds@1952
    44
	if (count == 1)
ds@1952
    45
	{
ds@1952
    46
		strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), items[0]);
ds@1952
    47
			
ds@1952
    48
		SetMenuTitle(g_hVoteMenu, "Change Gravity To");
ds@1952
    49
		AddMenuItem(g_hVoteMenu, items[0], "Yes");
ds@1952
    50
		AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
ds@1952
    51
	}
ds@1952
    52
	else
ds@1952
    53
	{
ds@1952
    54
		g_voteInfo[VOTE_NAME][0] = '\0';
ds@1952
    55
		
ds@1952
    56
		SetMenuTitle(g_hVoteMenu, "Gravity Vote");
ds@1952
    57
		for (new i = 0; i < count; i++)
ds@1952
    58
		{
ds@1952
    59
			AddMenuItem(g_hVoteMenu, items[i], items[i]);
ds@1952
    60
		}	
ds@1952
    61
	}
ds@1952
    62
	
ds@1952
    63
	SetMenuExitButton(g_hVoteMenu, false);
ds@1952
    64
	VoteMenuToAll(g_hVoteMenu, 20);
ds@1952
    65
}
ds@1952
    66
ds@1952
    67
public AdminMenu_VoteGravity(Handle:topmenu, 
ds@1952
    68
							  TopMenuAction:action,
ds@1952
    69
							  TopMenuObject:object_id,
ds@1952
    70
							  param,
ds@1952
    71
							  String:buffer[],
ds@1952
    72
							  maxlength)
ds@1952
    73
{
ds@1952
    74
	if (action == TopMenuAction_DisplayOption)
ds@1952
    75
	{
ds@1952
    76
		Format(buffer, maxlength, "%T", "Gravity vote", param);
ds@1952
    77
	}
ds@1952
    78
	else if (action == TopMenuAction_SelectOption)
ds@1952
    79
	{
ds@1952
    80
		/* Might need a better way of selecting the list of pre-defined gravity choices */
ds@1952
    81
		new String:items[5][5] ={"200","400","800","1600","3200"};
ds@1952
    82
		DisplayVoteGravityMenu(param,5, items);
ds@1952
    83
	}
ds@1952
    84
	else if (action == TopMenuAction_DrawOption)
ds@1952
    85
	{	
ds@1952
    86
		/* disable this option if a vote is already running */
ds@1952
    87
		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
ds@1952
    88
	}
ds@1952
    89
}
ds@1952
    90
ds@1952
    91
public Action:Command_VoteGravity(client, args)
ds@1952
    92
{
ds@1952
    93
	if (args < 1)
ds@1952
    94
	{
ds@1952
    95
		ReplyToCommand(client, "[SM] Usage: sm_votegravity <amount> [amount2] ... [amount5]");
ds@1952
    96
		return Plugin_Handled;	
ds@1952
    97
	}
ds@1952
    98
	
ds@1952
    99
	if (IsVoteInProgress())
ds@1952
   100
	{
ds@1952
   101
		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
ds@1952
   102
		return Plugin_Handled;
ds@1952
   103
	}
ds@1952
   104
	
ds@1952
   105
	if (!TestVoteDelay(client))
ds@1952
   106
	{
ds@1952
   107
		return Plugin_Handled;
ds@1952
   108
	}
ds@1952
   109
	
ds@1952
   110
	decl String:text[256];
ds@1952
   111
	GetCmdArgString(text, sizeof(text));
ds@1952
   112
ds@1952
   113
	decl String:items[5][64];
ds@1952
   114
	new count;	
ds@1952
   115
	new len, pos;
ds@1952
   116
	
ds@1952
   117
	while (pos != -1 && count < 5)
ds@1952
   118
	{	
ds@1952
   119
		pos = BreakString(text[len], items[count], sizeof(items[]));
ds@1952
   120
		
ds@1952
   121
		decl Float:temp;
ds@1952
   122
		if (StringToFloatEx(items[count], temp) == 0)
ds@1952
   123
		{
ds@1952
   124
			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
ds@1952
   125
			return Plugin_Handled;
ds@1952
   126
		}		
ds@1952
   127
ds@1952
   128
		count++;
ds@1952
   129
		
ds@1952
   130
		if (pos != -1)
ds@1952
   131
		{
ds@1952
   132
			len += pos;
ds@1952
   133
		}	
ds@1952
   134
	}
ds@1952
   135
	
ds@1952
   136
	DisplayVoteGravityMenu(client, count, items);
ds@1952
   137
	
ds@1952
   138
	return Plugin_Handled;	
ds@1952
   139
}