Not tested.
PHP Code:
// SYNTAX: "map" "sound path" "duration"
// Don't include "sound/" in the sound path
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"
new const gClass[ ] = "SoundThinker"
new gSoundFormat, Float:gDuration, gSound[ 32 ]
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, AUTHOR )
new Data[ 96 ]
get_configsdir( Data, 95 )
add( Data, 95, "/ambience_sounds.ini" )
new CurMap[ 32 ], Map[ 32 ], Duration[ 5 ], f = fopen( Data, "rt" )
get_mapname( CurMap, 31 )
while( !feof( f ) )
{
fgets( f, Data, 95 )
trim( Data )
if( !Data[ 0 ] || Data[ 0 ] == ';' || Data[ 0 ] == '/' && Data[ 1 ] == '/' )
continue
parse( Data, Map, 31, gSound, 31, Duration, 4 )
if( equal( CurMap, Map ) )
{
if( containi( gSound, ".mp3" ) != -1 )
{
gSoundFormat = true
engfunc( EngFunc_PrecacheGeneric, gSound )
}
else
engfunc( EngFunc_PrecacheSound, gSound )
gDuration = str_to_float( Duration ) + 1
register_think( gClass, "SoundThink" )
new Ent = create_entity( "info_target" )
entity_set_string( Ent, EV_SZ_classname, gClass )
entity_set_float( Ent, EV_FL_nextthink, get_gametime( ) + 15.0 )
break
}
}
fclose( f )
}
public SoundThink( Ent )
{
if( !is_valid_ent( Ent ) )
return PLUGIN_CONTINUE
if( gSoundFormat )
{
client_cmd( 0, "mp3 stop" )
client_cmd( 0, "mp3 play sound/%s", gSound )
}
else
client_cmd( 0, "spk sound/%s", gSound )
entity_set_float( Ent, EV_FL_nextthink, get_gametime( ) + gDuration )
return PLUGIN_CONTINUE
}