plugins/funvotes/voteburn.sp
author David Anderson <dvander@alliedmods.net>
Wed Feb 25 20:07:12 2009 -0500 (2009-02-25)
changeset 2607 f3b8bbe17f85
parent 2289 44045ead61cd
permissions -rw-r--r--
Backed out changeset fa286305bd3f
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefunvotes Plugin
     5  * Provides voteburn 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 DisplayVoteBurnMenu(client, target, String:name[])
    35 {
    36 	if (!IsPlayerAlive(target))
    37 	{
    38 		ReplyToCommand(client, "[SM] %t", "Cannot be performed on dead", name);
    39 		return;
    40 	}
    41 	
    42 	g_voteClient[VOTE_CLIENTID] = target;
    43 	GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
    44 
    45 	LogAction(client, target, "\"%L\" initiated a burn vote against \"%L\"", client, target);
    46 	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Burn", g_voteInfo[VOTE_NAME]);
    47 	
    48 	g_voteType = voteType:burn;
    49 	
    50 	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
    51 	SetMenuTitle(g_hVoteMenu, "Voteburn player");
    52 	AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
    53 	AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
    54 	SetMenuExitButton(g_hVoteMenu, false);
    55 	VoteMenuToAll(g_hVoteMenu, 20);
    56 }
    57 
    58 DisplayBurnTargetMenu(client)
    59 {
    60 	new Handle:menu = CreateMenu(MenuHandler_Burn);
    61 	
    62 	decl String:title[100];
    63 	Format(title, sizeof(title), "%T:", "Burn vote", client);
    64 	SetMenuTitle(menu, title);
    65 	SetMenuExitBackButton(menu, true);
    66 	
    67 	AddTargetsToMenu(menu, client, true, true);
    68 	
    69 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    70 }
    71 
    72 public AdminMenu_VoteBurn(Handle:topmenu, 
    73 							  TopMenuAction:action,
    74 							  TopMenuObject:object_id,
    75 							  param,
    76 							  String:buffer[],
    77 							  maxlength)
    78 {
    79 	if (action == TopMenuAction_DisplayOption)
    80 	{
    81 		Format(buffer, maxlength, "%T", "Burn vote", param);
    82 	}
    83 	else if (action == TopMenuAction_SelectOption)
    84 	{
    85 		DisplayBurnTargetMenu(param);
    86 	}
    87 	else if (action == TopMenuAction_DrawOption)
    88 	{	
    89 		/* disable this option if a vote is already running */
    90 		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
    91 	}
    92 }
    93 
    94 public MenuHandler_Burn(Handle:menu, MenuAction:action, param1, param2)
    95 {
    96 	if (action == MenuAction_End)
    97 	{
    98 		CloseHandle(menu);
    99 	}
   100 	else if (action == MenuAction_Cancel)
   101 	{
   102 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   103 		{
   104 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   105 		}
   106 	}
   107 	else if (action == MenuAction_Select)
   108 	{
   109 		decl String:info[32], String:name[32];
   110 		new userid, target;
   111 		
   112 		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   113 		userid = StringToInt(info);
   114 
   115 		if ((target = GetClientOfUserId(userid)) == 0)
   116 		{
   117 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   118 		}
   119 		else if (!CanUserTarget(param1, target))
   120 		{
   121 			PrintToChat(param1, "[SM] %t", "Unable to target");
   122 		}
   123 		else if (!IsPlayerAlive(target))
   124 		{
   125 			PrintToChat(param1, "[SM] %t", "Player has since died");
   126 		}
   127 		else
   128 		{
   129 			DisplayVoteBurnMenu(param1, target, name);
   130 		}
   131 	}
   132 }
   133 
   134 public Action:Command_VoteBurn(client, args)
   135 {
   136 	if (args < 1)
   137 	{
   138 		ReplyToCommand(client, "[SM] Usage: sm_voteburn <player>");
   139 		return Plugin_Handled;	
   140 	}
   141 	
   142 	if (IsVoteInProgress())
   143 	{
   144 		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   145 		return Plugin_Handled;
   146 	}	
   147 	
   148 	if (!TestVoteDelay(client))
   149 	{
   150 		return Plugin_Handled;
   151 	}
   152 	
   153 	decl String:text[256], String:arg[64];
   154 	GetCmdArgString(text, sizeof(text));
   155 	
   156 	BreakString(text, arg, sizeof(arg));
   157 	
   158 	decl String:target_name[MAX_TARGET_LENGTH];
   159 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   160 	
   161 	if ((target_count = ProcessTargetString(
   162 			arg,
   163 			client,
   164 			target_list,
   165 			MAXPLAYERS,
   166 			COMMAND_FILTER_NO_MULTI,
   167 			target_name,
   168 			sizeof(target_name),
   169 			tn_is_ml)) <= 0)
   170 	{
   171 		ReplyToTargetError(client, target_count);
   172 		return Plugin_Handled;
   173 	}
   174 
   175 	DisplayVoteBurnMenu(client, target_list[0], arg);
   176 	
   177 	return Plugin_Handled;
   178 }