plugins/sounds.sp
author David Anderson <dvander@alliedmods.net>
Mon Aug 12 00:22:54 2013 +0100 (2013-08-12)
changeset 3990 c7fb79059d7a
parent 2543 c72b673a3b52
permissions -rw-r--r--
Eliminate InfoVars::cip (bug 5844 part 7, r=ds).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Sound Commands Plugin
     5  * Implements basic sound commands.
     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 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 
    38 public Plugin:myinfo =
    39 {
    40 	name = "Sound Commands",
    41 	author = "AlliedModders LLC",
    42 	description = "Sound Commands",
    43 	version = SOURCEMOD_VERSION,
    44 	url = "http://www.sourcemod.net/"
    45 };
    46 
    47 public OnPluginStart( )
    48 {
    49 	LoadTranslations("common.phrases");
    50 	LoadTranslations("sounds.phrases");
    51 
    52 	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
    53 }
    54 
    55 public Action:Command_Play(client, args)
    56 {
    57 	if (args < 2)
    58 	{
    59 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
    60 		return Plugin_Handled;
    61 	}
    62 
    63 	new String:Arguments[PLATFORM_MAX_PATH + 65];
    64 	GetCmdArgString(Arguments, sizeof(Arguments));
    65 
    66  	decl String:Arg[65];
    67 	new len = BreakString(Arguments, Arg, sizeof(Arg));
    68 
    69 	/* Make sure it does not go out of bound by doing "sm_play user  "*/
    70 	if (len == -1)
    71 	{
    72 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
    73 		return Plugin_Handled;
    74 	}
    75 
    76 	/* Incase they put quotes and white spaces after the quotes */
    77 	if (Arguments[len] == '"')
    78 	{
    79 		len++;
    80 		new FileLen = TrimString(Arguments[len]) + len;
    81 
    82 		if (Arguments[FileLen - 1] == '"')
    83 		{
    84 			Arguments[FileLen - 1] = '\0';
    85 		}
    86 	}
    87 	
    88 	decl String:target_name[MAX_TARGET_LENGTH];
    89 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
    90 	
    91 	if ((target_count = ProcessTargetString(
    92 			Arg,
    93 			client,
    94 			target_list,
    95 			MAXPLAYERS,
    96 			COMMAND_FILTER_NO_BOTS,
    97 			target_name,
    98 			sizeof(target_name),
    99 			tn_is_ml)) <= 0)
   100 	{
   101 		ReplyToTargetError(client, target_count);
   102 		return Plugin_Handled;
   103 	}
   104 	
   105 	for (new i = 0; i < target_count; i++)
   106 	{
   107 		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
   108 		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);
   109 	}
   110 	
   111 	if (tn_is_ml)
   112 	{
   113 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
   114 	}
   115 	else
   116 	{
   117 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
   118 	}
   119 
   120 	return Plugin_Handled;
   121 }