plugins/basefuncommands.sp
author David Anderson <dvander@alliedmods.net>
Wed Dec 12 22:45:23 2007 +0000 (2007-12-12)
changeset 1788 6b5331ae47c4
parent 1785 21fb423ab195
child 1791 38e83ea09a24
permissions -rw-r--r--
fixed for amb1279 from ferret
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basic Fun Commands Plugin
     5  * Implements basic punishment commands.
     6  *
     7  * SourceMod (C)2004-2007 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 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 #include <sdktools>
    38 #undef REQUIRE_PLUGIN
    39 #include <adminmenu>
    40 
    41 public Plugin:myinfo =
    42 {
    43 	name = "Basic Fun Commands",
    44 	author = "AlliedModders LLC",
    45 	description = "Basic Fun Commands",
    46 	version = SOURCEMOD_VERSION,
    47 	url = "http://www.sourcemod.net/"
    48 };
    49 
    50 new Handle:hTopMenu = INVALID_HANDLE;
    51 
    52 new g_SlapDamage[MAXPLAYERS+1];
    53 
    54 #include "basefuncommands/slay.sp"
    55 #include "basefuncommands/burn.sp"
    56 #include "basefuncommands/slap.sp"
    57 #include "basefuncommands/beacon.sp"
    58 
    59 public OnPluginStart()
    60 {
    61 	LoadTranslations("common.phrases");
    62 	LoadTranslations("basefuncommands.phrases");
    63 
    64 	RegAdminCmd("sm_burn", Command_Burn, ADMFLAG_SLAY, "sm_burn <#userid|name> [time]");
    65 	RegAdminCmd("sm_slap", Command_Slap, ADMFLAG_SLAY, "sm_slap <#userid|name> [damage]");
    66 	RegAdminCmd("sm_slay", Command_Slay, ADMFLAG_SLAY, "sm_slay <#userid|name>");
    67 	RegAdminCmd("sm_beacon", Command_Beacon, ADMFLAG_SLAY, "sm_beacon <#userid|name>");
    68 	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
    69 	
    70 	/* Account for late loading */
    71 	new Handle:topmenu;
    72 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    73 	{
    74 		OnAdminMenuReady(topmenu);
    75 	}
    76 }
    77 
    78 public OnMapStart()
    79 {
    80 	SetupBeacon();	
    81 }
    82 
    83 public OnMapEnd()
    84 {
    85 	KillAllBeacons();
    86 }
    87 
    88 public OnAdminMenuReady(Handle:topmenu)
    89 {
    90 	/* Block us from being called twice */
    91 	if (topmenu == hTopMenu)
    92 	{
    93 		return;
    94 	}
    95 	
    96 	/* Save the Handle */
    97 	hTopMenu = topmenu;
    98 	
    99 	/* Find the "Player Commands" category */
   100 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   101 
   102 	if (player_commands != INVALID_TOPMENUOBJECT)
   103 	{
   104 		AddToTopMenu(hTopMenu,
   105 			"sm_slay",
   106 			TopMenuObject_Item,
   107 			AdminMenu_Slay,
   108 			player_commands,
   109 			"sm_slay",
   110 			ADMFLAG_SLAY);
   111 			
   112 		AddToTopMenu(hTopMenu,
   113 			"sm_burn",
   114 			TopMenuObject_Item,
   115 			AdminMenu_Burn,
   116 			player_commands,
   117 			"sm_burn",
   118 			ADMFLAG_SLAY);
   119 			
   120 		AddToTopMenu(hTopMenu,
   121 			"sm_slap",
   122 			TopMenuObject_Item,
   123 			AdminMenu_Slap,
   124 			player_commands,
   125 			"sm_slap",
   126 			ADMFLAG_SLAY);	
   127 			
   128 		AddToTopMenu(hTopMenu,
   129 			"sm_beacon",
   130 			TopMenuObject_Item,
   131 			AdminMenu_Beacon,
   132 			player_commands,
   133 			"sm_beacon",
   134 			ADMFLAG_SLAY);			
   135 	}
   136 }
   137 
   138 public Action:Command_Play(client, args)
   139 {
   140 	if (args < 2)
   141 	{
   142 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   143 	}
   144 
   145 	new String:Arguments[PLATFORM_MAX_PATH + 65];
   146 	GetCmdArgString(Arguments, sizeof(Arguments));
   147 
   148  	decl String:Arg[65];
   149 	new len = BreakString(Arguments, Arg, sizeof(Arg));
   150 
   151 	/* Make sure it does not go out of bound by doing "sm_play user  "*/
   152 	if (len == -1)
   153 	{
   154 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   155 		return Plugin_Handled;
   156 	}
   157 
   158 	/* Incase they put quotes and white spaces after the quotes */
   159 	if (Arguments[len] == '"')
   160 	{
   161 		len++;
   162 		new FileLen = TrimString(Arguments[len]) + len;
   163 
   164 		if (Arguments[FileLen - 1] == '"')
   165 		{
   166 			Arguments[FileLen - 1] = '\0';
   167 		}
   168 	}
   169 	
   170 	decl String:target_name[MAX_TARGET_LENGTH];
   171 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   172 	
   173 	if ((target_count = ProcessTargetString(
   174 			Arg,
   175 			client,
   176 			target_list,
   177 			MAXPLAYERS,
   178 			COMMAND_FILTER_NO_BOTS,
   179 			target_name,
   180 			sizeof(target_name),
   181 			tn_is_ml)) <= 0)
   182 	{
   183 		ReplyToTargetError(client, target_count);
   184 		return Plugin_Handled;
   185 	}
   186 	
   187 	for (new i = 0; i < target_count; i++)
   188 	{
   189 		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
   190 		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);	
   191 	}
   192 	
   193 	if (tn_is_ml)
   194 	{
   195 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
   196 	}
   197 	else
   198 	{
   199 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
   200 	}
   201 
   202 	return Plugin_Handled;
   203 }