plugins/basevotes/voteban.sp
author David Anderson <dvander@alliedmods.net>
Sun Nov 25 18:50:13 2007 +0000 (2007-11-25)
changeset 1725 ea875bcbc286
parent 1626 8775cc33c01e
child 1789 55172f6df9a4
permissions -rw-r--r--
small clarification to param2 in MenuAction_End
     1 
     2 DisplayVoteBanMenu(client, target)
     3 {
     4 	g_voteClient[VOTE_CLIENTID] = target;
     5 	g_voteClient[VOTE_USERID] = GetClientUserId(target);
     6 
     7 	GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
     8 	GetClientAuthString(target, g_voteInfo[VOTE_AUTHID], sizeof(g_voteInfo[]));
     9 	GetClientIP(target, g_voteInfo[VOTE_IP], sizeof(g_voteInfo[]));
    10 
    11 	LogAction(client, target, "\"%L\" initiated a ban vote against \"%L\"", client, target);
    12 	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Ban", g_voteInfo[VOTE_NAME]);
    13 
    14 	g_voteType = voteType:ban;
    15 	
    16 	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
    17 	SetMenuTitle(g_hVoteMenu, "Voteban Player");
    18 	AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
    19 	AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
    20 	SetMenuExitButton(g_hVoteMenu, false);
    21 	VoteMenuToAll(g_hVoteMenu, 20);
    22 }
    23 
    24 DisplayBanTargetMenu(client)
    25 {
    26 	new Handle:menu = CreateMenu(MenuHandler_Ban);
    27 	
    28 	decl String:title[100];
    29 	Format(title, sizeof(title), "%T:", "Ban vote", client);
    30 	SetMenuTitle(menu, title);
    31 	SetMenuExitBackButton(menu, true);
    32 	
    33 	AddTargetsToMenu(menu, client, false, false);
    34 	
    35 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    36 }
    37 
    38 public AdminMenu_VoteBan(Handle:topmenu, 
    39 							  TopMenuAction:action,
    40 							  TopMenuObject:object_id,
    41 							  param,
    42 							  String:buffer[],
    43 							  maxlength)
    44 {
    45 	if (action == TopMenuAction_DisplayOption)
    46 	{
    47 		Format(buffer, maxlength, "%T", "Ban vote", param);
    48 	}
    49 	else if (action == TopMenuAction_SelectOption)
    50 	{
    51 		DisplayBanTargetMenu(param);
    52 	}
    53 	else if (action == TopMenuAction_DrawOption)
    54 	{	
    55 		/* disable this option if a vote is already running */
    56 		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
    57 	}
    58 }
    59 
    60 public MenuHandler_Ban(Handle:menu, MenuAction:action, param1, param2)
    61 {
    62 	if (action == MenuAction_End)
    63 	{
    64 		CloseHandle(menu);
    65 	}
    66 	else if (action == MenuAction_Cancel)
    67 	{
    68 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    69 		{
    70 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    71 		}
    72 	}
    73 	else if (action == MenuAction_Select)
    74 	{
    75 		decl String:info[32], String:name[32];
    76 		new userid, target;
    77 		
    78 		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
    79 		userid = StringToInt(info);
    80 
    81 		if ((target = GetClientOfUserId(userid)) == 0)
    82 		{
    83 			PrintToChat(param1, "[SM] %t", "Player no longer available");
    84 		}
    85 		else if (!CanUserTarget(param1, target))
    86 		{
    87 			PrintToChat(param1, "[SM] %t", "Unable to target");
    88 		}
    89 		else
    90 		{
    91 			g_voteArg[0] = '\0';
    92 			DisplayVoteBanMenu(param1, target);
    93 		}
    94 	}
    95 }
    96 
    97 public Action:Command_Voteban(client, args)
    98 {
    99 	if (args < 1)
   100 	{
   101 		ReplyToCommand(client, "[SM] Usage: sm_voteban <player> [reason]");
   102 		return Plugin_Handled;	
   103 	}
   104 	
   105 	if (IsVoteInProgress())
   106 	{
   107 		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   108 		return Plugin_Handled;
   109 	}	
   110 	
   111 	if (!TestVoteDelay(client))
   112 	{
   113 		return Plugin_Handled;
   114 	}
   115 	
   116 	decl String:text[256], String:arg[64];
   117 	GetCmdArgString(text, sizeof(text));
   118 	
   119 	new len = BreakString(text, arg, sizeof(arg));
   120 	
   121 	if (len != -1)
   122 	{
   123 		strcopy(g_voteArg, sizeof(g_voteArg), text[len]);
   124 	}
   125 	else
   126 	{
   127 		g_voteArg[0] = '\0';
   128 	}
   129 	
   130 	decl String:target_name[MAX_TARGET_LENGTH];
   131 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   132 	
   133 	if ((target_count = ProcessTargetString(
   134 			arg,
   135 			client,
   136 			target_list,
   137 			MAXPLAYERS,
   138 			COMMAND_FILTER_NO_MULTI,
   139 			target_name,
   140 			sizeof(target_name),
   141 			tn_is_ml)) <= 0)
   142 	{
   143 		ReplyToTargetError(client, target_count);
   144 		return Plugin_Handled;
   145 	}
   146 
   147 	DisplayVoteBanMenu(client, target_list[0]);
   148 	
   149 	return Plugin_Handled;
   150 }