plugins/basefuncommands/burn.sp
author Matt Woodrow <pred@alliedmods.net>
Mon Oct 22 02:05:51 2007 +0000 (2007-10-22)
changeset 1626 8775cc33c01e
parent 1625 8e4a6a8c3256
child 1682 a7478db7aa6b
permissions -rw-r--r--
Added alive checks before adding certain player lists to the admin menu
     1 PerformBurn(client, target, Float:seconds)
     2 {
     3 	LogAction(client, target, "\"%L\" ignited \"%L\" (seconds \"%f\")", client, target, seconds);
     4 	IgniteEntity(target, seconds);
     5 }
     6 
     7 DisplayBurnMenu(client)
     8 {
     9 	new Handle:menu = CreateMenu(MenuHandler_Burn);
    10 	
    11 	decl String:title[100];
    12 	Format(title, sizeof(title), "%T:", "Burn player", client);
    13 	SetMenuTitle(menu, title);
    14 	SetMenuExitBackButton(menu, true);
    15 	
    16 	AddTargetsToMenu(menu, client, false, true);
    17 	
    18 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    19 }
    20 
    21 public AdminMenu_Burn(Handle:topmenu, 
    22 					  TopMenuAction:action,
    23 					  TopMenuObject:object_id,
    24 					  param,
    25 					  String:buffer[],
    26 					  maxlength)
    27 {
    28 	if (action == TopMenuAction_DisplayOption)
    29 	{
    30 		Format(buffer, maxlength, "%T", "Burn player", param);
    31 	}
    32 	else if (action == TopMenuAction_SelectOption)
    33 	{
    34 		DisplayBurnMenu(param);
    35 	}
    36 }
    37 
    38 public MenuHandler_Burn(Handle:menu, MenuAction:action, param1, param2)
    39 {
    40 	if (action == MenuAction_End)
    41 	{
    42 		CloseHandle(menu);
    43 	}
    44 	else if (action == MenuAction_Cancel)
    45 	{
    46 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    47 		{
    48 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    49 		}
    50 	}
    51 	else if (action == MenuAction_Select)
    52 	{
    53 		decl String:info[32];
    54 		new userid, target;
    55 		
    56 		GetMenuItem(menu, param2, info, sizeof(info));
    57 		userid = StringToInt(info);
    58 
    59 		if ((target = GetClientOfUserId(userid)) == 0)
    60 		{
    61 			PrintToChat(param1, "[SM] %t", "Player no longer available");
    62 		}
    63 		else if (!CanUserTarget(param1, target))
    64 		{
    65 			PrintToChat(param1, "[SM] %t", "Unable to target");
    66 		}
    67 		else
    68 		{
    69 			new String:name[32];
    70 			GetClientName(target, name, sizeof(name));
    71 			PerformBurn(param1, target, 20.0);
    72 			ShowActivity2(param1, "[SM] ", "%t", "Set target on fire", "_s", name);
    73 		}
    74 		
    75 		/* Re-draw the menu if they're still valid */
    76 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
    77 		{
    78 			DisplaySlayMenu(param1);
    79 		}
    80 	}
    81 }
    82 
    83 public Action:Command_Burn(client, args)
    84 {
    85 	if (args < 1)
    86 	{
    87 		ReplyToCommand(client, "[SM] Usage: sm_burn <#userid|name> [time]");
    88 		return Plugin_Handled;
    89 	}
    90 
    91 	decl String:arg[65];
    92 	GetCmdArg(1, arg, sizeof(arg));
    93 
    94 	new Float:seconds = 20.0;
    95 	
    96 	if (args > 1)
    97 	{
    98 		decl String:time[20];
    99 		GetCmdArg(2, time, sizeof(time));
   100 		if (StringToFloatEx(time, seconds) == 0)
   101 		{
   102 			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
   103 			return Plugin_Handled;
   104 		}
   105 	}
   106 	
   107 	decl String:target_name[MAX_TARGET_LENGTH];
   108 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   109 	
   110 	if ((target_count = ProcessTargetString(
   111 			arg,
   112 			client,
   113 			target_list,
   114 			MAXPLAYERS,
   115 			COMMAND_FILTER_ALIVE,
   116 			target_name,
   117 			sizeof(target_name),
   118 			tn_is_ml)) <= 0)
   119 	{
   120 		ReplyToTargetError(client, target_count);
   121 		return Plugin_Handled;
   122 	}
   123 	
   124 	for (new i = 0; i < target_count; i++)
   125 	{
   126 		PerformBurn(client, target_list[i], seconds);
   127 	}
   128 	
   129 	if (tn_is_ml)
   130 	{
   131 		ShowActivity2(client, "[SM] ", "%t", "Set target on fire", target_name);
   132 	}
   133 	else
   134 	{
   135 		ShowActivity2(client, "[SM] ", "%t", "Set target on fire", "_s", target_name);
   136 	}
   137 
   138 	return Plugin_Handled;
   139 }