Untested.
Instead of cvars I made a config file where the syntax is the same as you wrote in your cvars (mapname, sound, duration).
The cvar amx_ambience_method is for if you want to play waves or mp3 files. Value 0 = Mp3, Value 1 = .wav. Default: 0.
Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Ambience Sounds"
#define VERSION "1.0"
#define AUTHOR "Jon"
new gCvarMethod;
new gSound[64];
new gDuration[32];
new gMap[32];
new bool:gFoundMap;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
gCvarMethod = register_cvar("amx_ambience_method", "0")
set_task(20.0, "PlaySound")
get_mapname(gMap, 31)
}
public plugin_cfg()
{
new configfile[96];
get_configsdir(configfile, 96);
add(configfile, 96, "/ambience_sounds.ini");
new f = fopen(configfile, "rt");
while (!feof(f))
{
new Data[160]
new Map[32]
new Sound[64];
new Duration[32];
fgets(f, Data, 160);
parse(Data, Map, 20, Sound, 64, Duration, 32);
if(equali(gMap, Map) && strlen(Sound) > 0 && strlen(Duration) > 0)
{
gSound = Sound
gDuration = Duration
gFoundMap = true;
return;
}
}
fclose(f);
}
public PlaySound()
{
if(!gFoundMap)
return;
if(get_pcvar_num(gCvarMethod) == 1)
client_cmd(0, "spk %s", gSound)
else
client_cmd(0, "mp3 play %s", gSound)
set_task(float(str_to_num(gDuration)) + 5.0, "PlaySound")
}