Code:
#include <amxmodx>
#include <colorchat>
#include <amxmisc>
#define PLUGIN_NAME "Sounds via Chat"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "tedaimlocks"
#define SOUND_FLAG ADMIN_RCON
#define MAX_SOUNDS 10 // Maximum number of sounds in the INI file
new g_Sounds[MAX_SOUNDS][64];
new g_SoundCmds[MAX_SOUNDS][32];
new g_NumSounds;
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_clcmd("say /sound", "cmd_play_sound");
read_sound_ini(); // Read sounds from the INI file on plugin start
}
public plugin_precache() {
for (new i = 0; i < g_NumSounds; i++) {
precache_generic(g_Sounds[i]);
}
return PLUGIN_HANDLED;
}
public cmd_play_sound(id) {
new soundIndex = find_sound_by_cmd(get_user_msg(id), g_SoundCmds);
if (soundIndex != -1) {
if (!(get_user_flags(id) & SOUND_FLAG)) {
return PLUGIN_HANDLED;
}
new playerName[32];
get_user_name(id, playerName, sizeof(playerName));
client_cmd(0, "MP3Volume 1");
client_cmd(0, "mp3 play %s", g_Sounds[soundIndex]);
ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03played the sound^x04 %s", playerName, g_SoundCmds[soundIndex]);
}
return PLUGIN_HANDLED;
}
public find_sound_by_cmd(const cmd[], const soundCmds[][]) {
for (new i = 0; i < g_NumSounds; i++) {
if (equali(cmd, soundCmds[i])) {
return i;
}
}
return -1;
}
public read_sound_ini() {
new file = fopen("sound_cmds.ini", "rt");
if (!file) {
server_print("Unable to open sound_cmds.ini file!");
return PLUGIN_HANDLED;
}
g_NumSounds = 0;
new line[256], sound[64], soundCmd[32];
while (fgets(file, line, sizeof(line)) != null) {
if (sscanf(line, "%s %s", soundCmd, sound) >= 2) {
if (g_NumSounds < MAX_SOUNDS) {
format(g_Sounds[g_NumSounds], sizeof(g_Sounds[g_NumSounds]), "sound/%s", sound);
format(g_SoundCmds[g_NumSounds], sizeof(g_SoundCmds[g_NumSounds]), "say /%s", soundCmd);
g_NumSounds++;
} else {
server_print("Too many sounds in sound_cmds.ini file!");
break;
}
}
}
fclose(file);
return PLUGIN_HANDLED;
Make sure you've created an INI file named sound_cmds.ini in the folder for example:
ted sound/spkzm/tedaimlocks.mp3
andrei sound/spkzm/andrei.mp3