/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <tutor>
#include <ColorChat>
#define PLUGIN "RoundSound"
#define VERSION "1.1"
#define AUTHOR "speedkill"
new Array:g_PathCT,
Array:g_PathTT,
Array:g_SoundNameCT,
Array:g_SoundNameTT;
new bool:g_RoundSound[33],
bool:g_FirstPlay;
new g_LastSoundPath[128],
g_LastSong[96],
g_Prefix[64],
g_ArraySize[4],
g_ShowType,
g_ShowTitle,
g_MaxPlayers,
g_PlaylistType;
new const g_LangCmd[][]={
"say /rs",
"say /roundsound",
"say_team /rs",
"say_team /roundsound"
};
new const g_LastLangCmd[][]={
"say /last",
"say_team /last"
};
enum{
Tutor_Msg = 1,
Chat_Msg
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
for(new i = 0; i < sizeof g_LangCmd; i++){
register_clcmd(g_LangCmd[i], "ShowRsMenu");
}
for(new i = 0; i < sizeof g_LastLangCmd; i++){
register_clcmd(g_LastLangCmd[i], "ShowLastSong");
}
register_event("SendAudio", "PlaySoundTT", "a", "2&%!MRAD_terwin");
register_event("SendAudio", "PlaySoundCT", "a", "2&%!MRAD_ctwin");
tutorInit();
register_cvar("Roundsound_ads_time", "120");
register_cvar("Roundsound_prefix", "RoundSound");
register_cvar("Roundsound_show_title", "1");
/* | 1 - Tutor | 2 - Chat | */
register_cvar("Roundsound_show_type", "1");
}
public plugin_precache(){
g_PathCT = ArrayCreate(128);
g_PathTT = ArrayCreate(128);
g_SoundNameCT = ArrayCreate(96);
g_SoundNameTT = ArrayCreate(96);
LoadSounds();
tutorPrecache();
}
public plugin_cfg(){
get_cvar_string("Roundsound_prefix", g_Prefix, charsmax(g_Prefix));
g_ShowType = get_cvar_num("Roundsound_show_type");
g_ShowTitle = get_cvar_num("Roundsound_show_title");
g_MaxPlayers = get_maxplayers();
new Float:g_AdsTime = get_cvar_float("Roundsound_ads_time");
if(g_AdsTime >= 30){
set_task(g_AdsTime, "ShowAds",.flags = "b");
}
}
public client_authorized(id){
g_RoundSound[id] = true;
}
public LoadSounds(){
new g_Path[128];
formatex(g_Path[ get_configsdir(g_Path, charsmax(g_Path)) ], charsmax(g_Path), "/RoundSound.ini");
if(file_exists(g_Path)){
new g_Line[256],
g_SoundPath[128],
g_Name[96],
g_Team[3],
g_Len;
for(new i = 0; read_file(g_Path, i, g_Line, charsmax(g_Line), g_Len); i++){
if(!g_Len || !g_Line[0] || g_Line[0] == ';'){
continue;
}
parse(g_Line, g_SoundPath, charsmax(g_SoundPath), g_Name, charsmax(g_Name), g_Team, charsmax(g_Team));
new g_Value = strlen(g_SoundPath) - 4;
log_amx("Path: %s | Title: %s | Team: %s | Format: %s", g_SoundPath, g_Name, g_Team, g_SoundPath[ g_Value ]);
if(equal(g_SoundPath[ g_Value ], ".mp3") || equal(g_SoundPath[ g_Value ], ".wav")){
if(equal(g_SoundPath[ g_Value ], ".mp3")){
format(g_SoundPath, charsmax(g_SoundPath), "sound/%s", g_SoundPath);
precache_generic(g_SoundPath);
}
else{
precache_sound(g_SoundPath);
}
/* Check team */
if(equal(g_Team, "CT")){
ArrayPushString(g_PathCT, g_SoundPath);
ArrayPushString(g_SoundNameCT, g_Name);
}
else if(equal(g_Team, "TT")){
ArrayPushString(g_PathTT, g_SoundPath);
ArrayPushString(g_SoundNameTT, g_Name);
}
log_amx("File %s has a good format", g_SoundPath);
}
else{
log_amx("File %s has a bad format", g_SoundPath);
}
}
}
else{
/* Houston, We've Got a Problem. */
set_fail_state("File RoundSound.ini not exist in configs/");
}
GetArraySize();
}
public GetArraySize(){
g_ArraySize[0] = ArraySize(g_PathCT);
g_ArraySize[1] = ArraySize(g_PathTT);
g_ArraySize[2] = ArraySize(g_SoundNameCT);
g_ArraySize[3] = ArraySize(g_SoundNameTT);
}
public ShowRsMenu(id){
new g_FormatText[64];
new g_Menu = menu_create("\wRoundSound ustawienia", "MenuChoose");
formatex(g_FormatText, charsmax(g_FormatText), "\yRoundsound: \d%s", g_RoundSound[id] ? "ON" : "OFF");
menu_additem(g_Menu, g_FormatText);
menu_additem(g_Menu, "\rOdsluchaj utwory CT \d( \yPlaylista \d)");
menu_additem(g_Menu, "\yOdsluchaj utwory TT \d( \rPlaylista \d)");
menu_setprop(g_Menu, MPROP_EXITNAME, "Wyjscie");
menu_display(id, g_Menu);
}
public MenuChoose(id, menu, item){
if(item == MENU_EXIT){
menu_destroy(menu);
return PLUGIN_HANDLED;
}
switch(item){
case 0:{
g_RoundSound[id] = !g_RoundSound[id];
ColorChat(id, TEAM_COLOR, "[%s]^x04 Roundsound^x03 %s", g_Prefix, g_RoundSound[id] ? "wlaczony" : "wylaczony");
ShowRsMenu(id);
}
case 1..2:{
ShowPlaylist(id, item);
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public ShowPlaylist(id, g_Type){
new g_FormatText[64],
g_Name[96];
formatex(g_FormatText, charsmax(g_FormatText), "Playlista \d%s", g_Type == 1 ? "CT" : "TT");
new g_Menu = menu_create(g_FormatText, "PlaylistChoose");
switch(g_Type){
case 1:{
for(new i = 0; i < g_ArraySize[2]; i++){
ArrayGetString(g_SoundNameCT, i, g_Name, charsmax(g_Name));
menu_additem(g_Menu, g_Name);
}
}
case 2:{
for(new i = 0; i < g_ArraySize[3]; i++){
ArrayGetString(g_SoundNameTT, i, g_Name, charsmax(g_Name));
menu_additem(g_Menu, g_Name);
}
}
}
g_PlaylistType = g_Type;
menu_setprop(g_Menu, MPROP_BACKNAME, "Powrot");
menu_setprop(g_Menu, MPROP_NEXTNAME, "Dalej");
menu_setprop(g_Menu, MPROP_EXITNAME, "Wyjscie");
menu_setprop(g_Menu, MPROP_NUMBER_COLOR, "\r");
menu_display(id, g_Menu);
}
public PlaylistChoose(id, menu, item){
if(item == MENU_EXIT){
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new g_SoundPath[128];
ArrayGetString(g_PlaylistType == 1 ? g_PathCT : g_PathTT, item, g_SoundPath, charsmax(g_SoundPath));
new g_Format = strlen(g_SoundPath) - 4;
if(equal(g_SoundPath[ g_Format ], ".mp3")){
client_cmd(id, "mp3 play %s", g_SoundPath);
}
else{
client_cmd(id, "spk %s", g_SoundPath);
}
ShowPlaylist(id, g_PlaylistType);
return PLUGIN_CONTINUE;
}
public ShowLastSong(id){
if(g_FirstPlay){
ColorChat(id, TEAM_COLOR, "[%s]^x04 Ostatni utwor:^x03 %s", g_Prefix, g_LastSong);
}
else{
ColorChat(id, TEAM_COLOR, "[%s]^x04 Nie zostala odegrana zadna^x03 piosenka !", g_Prefix);
}
}
public PlaySoundTT(){
RandMusic(1);
}
public PlaySoundCT(){
RandMusic(2);
}
public RandMusic(g_Type){
if(!g_FirstPlay){
g_FirstPlay = true;
}
new g_SoundPath[128],
g_SoundName[128],
g_Name[96],
g_Value,
g_Format,
g_FileFormat;
switch(g_Type){
case 1:{
g_Value = random(g_ArraySize[1]);
ArrayGetString(g_PathTT, g_Value, g_SoundPath, charsmax(g_SoundPath));
ArrayGetString(g_SoundNameTT, g_Value, g_Name, charsmax(g_Name));
}
case 2:{
g_Value = random(g_ArraySize[0]);
ArrayGetString(g_PathCT, g_Value, g_SoundPath, charsmax(g_SoundPath));
ArrayGetString(g_SoundNameCT, g_Value, g_Name, charsmax(g_Name));
}
}
if(equal(g_LastSoundPath, g_SoundPath)){
RandMusic(g_Type);
}
copy(g_LastSoundPath, charsmax(g_LastSoundPath), g_SoundPath);
copy(g_LastSong, charsmax(g_LastSong), g_Name);
g_Format = strlen(g_SoundPath) - 4;
if(equal(g_SoundPath[ g_Format ], ".mp3")){
g_FileFormat = 1;
}
else{
g_FileFormat = 2;
}
formatex(g_SoundName, charsmax(g_SoundName), "Teraz gramy: %s", g_Name);
for(new i = 1; i <= g_MaxPlayers; i++){
if(is_user_connected(i) && g_RoundSound[i]){
switch(g_FileFormat){
case 1:{
client_cmd(i, "mp3 play %s", g_SoundPath);
}
case 2:{
client_cmd(i, "spk %s", g_SoundPath);
}
}
if(g_ShowTitle){
switch(g_ShowType){
case Tutor_Msg:{
ColorChat(i, TEAM_COLOR, "[%s]^x04 %s", g_Prefix, g_SoundName);
}
case Chat_Msg:{
ColorChat(i, TEAM_COLOR, "[%s]^x04 %s", g_Prefix, g_SoundName);
}
}
}
}
}
}
public ShowAds(){
for(new i = 1; i <= g_MaxPlayers; i++){
if(is_user_connected(i)){
switch(random(3)){
case 0:{
ColorChat(i, TEAM_COLOR, "[%s]^x04 Chcesz %s roundsounda ? Napisz^x03 /roundsound ^x04lub^x03 /rs", g_Prefix, g_RoundSound[i] ? "wylaczyc" : "wlaczyc");
}
case 1:{
ColorChat(i, TEAM_COLOR, "[%s]^x04 Podobala Ci sie ostatnia piosenka, a nie pamietasz jej nazwy ? Napisz^x03 /last", g_Prefix);
}
case 2:{
ColorChat(i, TEAM_COLOR, "[%s]^x04 Chcesz posluchac utworow CT/TT, oraz zobaczyc ich playliste ? Napisz^x03 /roundsound ^x04lub^x03 /rs", g_Prefix);
}
}
}
}
}
public plugin_end(){
ArrayDestroy(g_PathCT);
ArrayDestroy(g_PathTT);
ArrayDestroy(g_SoundNameCT);
ArrayDestroy(g_SoundNameTT);
}