plugins/funvotes/voteburn.sp
changeset 1889 5b4d6acc4d82
child 1947 e73a1e51833b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/funvotes/voteburn.sp	Fri Feb 22 21:01:08 2008 +0000
     1.3 @@ -0,0 +1,178 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basefunvotes Plugin
     1.8 + * Provides voteburn functionality
     1.9 + *
    1.10 + * SourceMod (C)2004-2007 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 +DisplayVoteBurnMenu(client, target, String:name[])
    1.38 +{
    1.39 +	if (!IsPlayerAlive(target))
    1.40 +	{
    1.41 +		ReplyToCommand(client, "[SM] %t", "Cannot be performed on dead", name);
    1.42 +		return;
    1.43 +	}
    1.44 +	
    1.45 +	g_voteClient[VOTE_CLIENTID] = target;
    1.46 +	GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
    1.47 +
    1.48 +	LogAction(client, target, "\"%L\" initiated a burn vote against \"%L\"", client, target);
    1.49 +	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Burn", g_voteInfo[VOTE_NAME]);
    1.50 +	
    1.51 +	g_voteType = voteType:burn;
    1.52 +	
    1.53 +	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
    1.54 +	SetMenuTitle(g_hVoteMenu, "Voteburn player");
    1.55 +	AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
    1.56 +	AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
    1.57 +	SetMenuExitButton(g_hVoteMenu, false);
    1.58 +	VoteMenuToAll(g_hVoteMenu, 20);
    1.59 +}
    1.60 +
    1.61 +DisplayBurnTargetMenu(client)
    1.62 +{
    1.63 +	new Handle:menu = CreateMenu(MenuHandler_Burn);
    1.64 +	
    1.65 +	decl String:title[100];
    1.66 +	Format(title, sizeof(title), "%T:", "Burn vote", client);
    1.67 +	SetMenuTitle(menu, title);
    1.68 +	SetMenuExitBackButton(menu, true);
    1.69 +	
    1.70 +	AddTargetsToMenu(menu, client, true, true);
    1.71 +	
    1.72 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    1.73 +}
    1.74 +
    1.75 +public AdminMenu_VoteBurn(Handle:topmenu, 
    1.76 +							  TopMenuAction:action,
    1.77 +							  TopMenuObject:object_id,
    1.78 +							  param,
    1.79 +							  String:buffer[],
    1.80 +							  maxlength)
    1.81 +{
    1.82 +	if (action == TopMenuAction_DisplayOption)
    1.83 +	{
    1.84 +		Format(buffer, maxlength, "%T", "Burn vote", param);
    1.85 +	}
    1.86 +	else if (action == TopMenuAction_SelectOption)
    1.87 +	{
    1.88 +		DisplayBurnTargetMenu(param);
    1.89 +	}
    1.90 +	else if (action == TopMenuAction_DrawOption)
    1.91 +	{	
    1.92 +		/* disable this option if a vote is already running */
    1.93 +		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
    1.94 +	}
    1.95 +}
    1.96 +
    1.97 +public MenuHandler_Burn(Handle:menu, MenuAction:action, param1, param2)
    1.98 +{
    1.99 +	if (action == MenuAction_End)
   1.100 +	{
   1.101 +		CloseHandle(menu);
   1.102 +	}
   1.103 +	else if (action == MenuAction_Cancel)
   1.104 +	{
   1.105 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.106 +		{
   1.107 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.108 +		}
   1.109 +	}
   1.110 +	else if (action == MenuAction_Select)
   1.111 +	{
   1.112 +		decl String:info[32], String:name[32];
   1.113 +		new userid, target;
   1.114 +		
   1.115 +		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   1.116 +		userid = StringToInt(info);
   1.117 +
   1.118 +		if ((target = GetClientOfUserId(userid)) == 0)
   1.119 +		{
   1.120 +			PrintToChat(param1, "[SM] %t", "Player no longer available");
   1.121 +		}
   1.122 +		else if (!CanUserTarget(param1, target))
   1.123 +		{
   1.124 +			PrintToChat(param1, "[SM] %t", "Unable to target");
   1.125 +		}
   1.126 +		else if (!IsPlayerAlive(target))
   1.127 +		{
   1.128 +			PrintToChat(param1, "[SM] %t", "Player has since died");
   1.129 +		}
   1.130 +		else
   1.131 +		{
   1.132 +			DisplayVoteBurnMenu(param1, target, name);
   1.133 +		}
   1.134 +	}
   1.135 +}
   1.136 +
   1.137 +public Action:Command_VoteBurn(client, args)
   1.138 +{
   1.139 +	if (args < 1)
   1.140 +	{
   1.141 +		ReplyToCommand(client, "[SM] Usage: sm_voteburn <player>");
   1.142 +		return Plugin_Handled;	
   1.143 +	}
   1.144 +	
   1.145 +	if (IsVoteInProgress())
   1.146 +	{
   1.147 +		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   1.148 +		return Plugin_Handled;
   1.149 +	}	
   1.150 +	
   1.151 +	if (!TestVoteDelay(client))
   1.152 +	{
   1.153 +		return Plugin_Handled;
   1.154 +	}
   1.155 +	
   1.156 +	decl String:text[256], String:arg[64];
   1.157 +	GetCmdArgString(text, sizeof(text));
   1.158 +	
   1.159 +	BreakString(text, arg, sizeof(arg));
   1.160 +	
   1.161 +	decl String:target_name[MAX_TARGET_LENGTH];
   1.162 +	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   1.163 +	
   1.164 +	if ((target_count = ProcessTargetString(
   1.165 +			arg,
   1.166 +			client,
   1.167 +			target_list,
   1.168 +			MAXPLAYERS,
   1.169 +			COMMAND_FILTER_NO_MULTI,
   1.170 +			target_name,
   1.171 +			sizeof(target_name),
   1.172 +			tn_is_ml)) <= 0)
   1.173 +	{
   1.174 +		ReplyToTargetError(client, target_count);
   1.175 +		return Plugin_Handled;
   1.176 +	}
   1.177 +
   1.178 +	DisplayVoteBurnMenu(client, target_list[0], arg);
   1.179 +	
   1.180 +	return Plugin_Handled;
   1.181 +}