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

View of /mp3_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Tue Oct 30 09:08:11 2007 UTC (16 years, 5 months ago) by ian
Original Path: mp3.sma
File size: 2266 byte(s)
#include <amxmodx>
#include <amxmisc>

#define PRECACHE_COUNT 2

#define VERSION "0.4"

new inifile[100]

public plugin_init( )
{
	register_plugin( "mp3+", VERSION, "Ian Cammarata" )
	register_cvar( "mp3+_version", VERSION, FCVAR_SERVER )
	register_concmd( "amx_mp3", "mp3", ADMIN_SLAY, "<play|loop|stop|list> [mp3] - Play mp3 on all clients." )
	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,32)
			client_cmd(0,"mp3 %s media/%s",cmd,title)
			strtoupper(cmd)
			client_print(0,print_chat,"[AMX] : %s MP3 %s - To stop type, ^"mp3 stop^" in console.",cmd,title)
		}
	}
	return PLUGIN_HANDLED
}

Contact
ViewVC Help
Powered by ViewVC 1.0.4