[Half-Life AMXX] / mp3_plus.sma Repository:
ViewVC logotype

View of /mp3_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (download) (annotate)
Mon Mar 3 06:00:27 2008 UTC (12 years, 8 months ago) by ian
File size: 4346 byte(s)
renamed mp3 plugin to mp3_plus & updated project file;
added setinfo for clients to individually disable mp3 playback;
added chat commands to stop and disable mp3s;
/*
MP3+ v0.5
Copyright (C) 2005-2007 Ian (Juan) Cammarata

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------
http://ian.cammarata.us
*/

#include <amxmodx>
#include <amxmisc>

#define PRECACHE_COUNT 2

new const VERSION[ ] = "0.5";
new const TRKCVAR[ ] = "mp3_plus_version";
new const INFO_VAR[ ] = "mp3+";

new inifile[100];

public plugin_init( )
{
	register_plugin( "mp3+", VERSION, "Ian Cammarata" );
	register_cvar( TRKCVAR, VERSION, FCVAR_SERVER );
	set_cvar_string( TRKCVAR, VERSION );
	
	register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, "<play|loop|stop|list> [mp3] - Play mp3 on all clients." );
	register_clcmd( "say mp3_stop", "mp3_stop" );
	register_clcmd( "say mp3_disable", "mp3_disable" );
	return PLUGIN_CONTINUE
}

public plugin_precache( )
{
	new varfile[100];
	new len, text[100], pcfile[100];
	
	//Make var folder if not exists
	get_localinfo( "amxx_datadir", varfile, 99 );
	format( varfile, 99, "%s/var", varfile );
	if( !dir_exists( varfile ) ) mkdir( varfile );
	
	get_localinfo( "amxx_configsdir", inifile, 99 );
	format( inifile, 99, "%s/mp3precache.ini", inifile );
	format( varfile, 99, "%s/mp3precache.var", varfile );
	
	//Get name of last precached file
	if( file_exists( varfile ) )
		read_file( varfile, 0, pcfile, 99, len );
	
	if( file_exists( inifile ) )
	{
		new inisize = file_size( inifile, 1 );
		if( inisize )
		{
			new line = 0;
			if( strlen( pcfile ) )
				while( !equal( pcfile, text ) && read_file( inifile, line, text, 99, len ) )
					line++;
			
			
			new oldline = line;
			
			for( new i = 0; i <= PRECACHE_COUNT; i++)
			{
				if ( line == inisize ) line = 0;
				
				read_file( inifile, line, pcfile, 99, len );
				write_file( varfile, pcfile, 0 );
				format( pcfile, 99, "media/%s", pcfile );
				precache_generic( pcfile );
				line++;
				if( line == oldline ) break;
			}
		}
	}
	return PLUGIN_CONTINUE;
}

public mp3( id, level, cid )
{
	if( !cmd_access( id, level, cid, 2 ) )
		return PLUGIN_HANDLED;

	new cmd[4];
	read_argv( 1, cmd, 4 );
	if( equali( cmd, "stop") )
	{
		client_cmd( 0, "mp3 stop" );
		client_print( 0, print_chat, "[AMX] MP3 : Stopped" );
	}
	if( equali( cmd, "list") )
	{
		show_motd( id, inifile, "MP3s" );
	}
	else
	{
		if( read_argc( ) != 3 )
			client_print( id, print_console, "Usage: amx_mp3 <play|loop|stop> [mp3]");
		else
		{
			new title[32];
			read_argv( 2, title, 31 );
			
			new players[32], pcount, info_val[4], exec_cmd[64], id2;
			get_players( players, pcount, "ch" );
			
			formatex( exec_cmd, 63, "mp3 %s media/%s", cmd, title );
			strtoupper( cmd );
			
			for( new i = 0; i < pcount; i++ )
			{
				id2 = players[i];
				get_user_info( id2, INFO_VAR, info_val, 3 );
				if( strcmp( info_val, "off" ) )
				{
					client_cmd( id2, exec_cmd );
					client_print( id2, print_chat, "[AMX] : %s MP3 %s - To stop type, ^"mp3_stop^".", cmd, title );
				}
			}
		}
	}
	return PLUGIN_HANDLED;
}

public mp3_stop( id )
{
	client_cmd( id, "mp3 stop" );
	client_print( id, print_chat, "MP3 Stopped. To disable MP3's permanently, type ^"mp3_disable^" or exec ^"setinfo mp3+ off^"" );
	return PLUGIN_HANDLED;
}

public mp3_disable( id )
{
	new info_val[4];
	get_user_info( id, INFO_VAR, info_val, 3 );
	if( strcmp( info_val, "off" ) )
	{
		client_print( id, print_chat, "MP3's Disabled. To enable again, type ^"mp3_disable^" or exec ^"setinfo mp3+ on^"" );
		set_user_info( id, INFO_VAR, "off" );
	}
	else
	{
		client_print( id, print_chat, "MP3's Enabled." );
		set_user_info( id, INFO_VAR, "on" );
	}
	return PLUGIN_HANDLED;
}

Contact
ViewVC Help
Powered by ViewVC 1.0.4