Code: Select all
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#define PREFIX "Radio Menu"
new bool:RadioOn[33]
new PlayerRadio[33], PlayerVolume[33], file[64];
new data[1024], buffer, gRadioName[64], gRadioUrl[128];
new radio_on, adv_msg, volume_menu;
public plugin_init()
{
register_plugin("Radio Menu", "1.6.2", "Wicked-")
register_clcmd("say", "hook_say");
register_clcmd("say_team", "hook_say");
register_concmd("AjustVolume", "AjustVolume");
radio_on = register_cvar("rm_on", "1");
volume_menu = register_cvar("rm_volumemenu","1");
formatex(file, 63, "addons/amxmodx/configs/radio.ini");
}
public hook_say(id)
{
new args[43], arg_cmd[11], arg2[32]
read_args(args,42)
remove_quotes(args)
parse(args, arg_cmd,10, arg2,31)
if(get_pcvar_num(radio_on))
{
if(equali(arg_cmd,"/radio"))
{
if(equal(arg2,""))
{
MainMenu(id);
return
}
if(file_exists(file))
{
for(new i=1;i < file_size(file,1);i++)
{
read_file(file,i,data,1023,buffer);
parse(data, gRadioName,63, gRadioUrl,127);
replace_all(gRadioName,63, "\w","")
replace_all(gRadioName,63, "\y","")
replace_all(gRadioName,63, "\r","")
replace_all(gRadioName,63, "\d","")
if(containi(gRadioName, arg2) != -1)
{
PlayerRadio[id] = i
ColorChat(id, GREEN, "[%s]^x03 Radio changed to^x04 %s.", PREFIX, gRadioName);
if(RadioOn[id])
Radio(id);
return
}
}
}
return
}
if(equali(arg_cmd,"/volume") || equali(arg_cmd,"/vol"))
{
if(equal(arg2,""))
{
if(!get_pcvar_num(volume_menu))
{
client_cmd(id, "messagemode AjustVolume");
}
else
{
VolumeMenu(id);
}
return
}
new iVolume = str_to_num(arg2)
if(0 < iVolume <= 100)
{
PlayerVolume[id] = iVolume
ColorChat(id, GREEN, "[%s]^x03 Volume changed to^x04 %d.", PREFIX, iVolume);
if(RadioOn[id])
Radio(id);
}
else
{
ColorChat(id, GREEN, "[%s]^x03 Volume must be between^x04 1^x03 and^x04 100^x03!", PREFIX);
}
return
}
if(equali(arg_cmd,"/stop") || equali(arg_cmd,"/radiooff"))
{
StopRadio(id);
return
}
}
}
public MainMenu(id)
{
if(!get_pcvar_num(radio_on))
{
ColorChat(id, GREEN, "[%s]^x03 Radio is disabled!", PREFIX)
return PLUGIN_HANDLED;
}
new szText[128], gRadioName[64], gRadioUrl[128];
if(PlayerRadio[id])
{
read_file(file,PlayerRadio[id],data,1023,buffer);
parse(data, gRadioName,63, gRadioUrl,127);
}
else
{
formatex(gRadioName, 63, "N/A");
}
formatex(szText, charsmax(szText), "\wYour radio is now: \r%s^n\wListening to: \r%s^n\wVolume: \r%d", (RadioOn[id]) ? "ON" : "OFF", gRadioName, PlayerVolume[id]);
new menu = menu_create(szText, "main_menu_handler")
formatex(szText, charsmax(szText), "Turn Radio \r%s", (RadioOn[id]) ? "OFF" : "ON");
menu_additem(menu, szText, "1", 0);
formatex(szText, charsmax(szText), "Choose Radio");
menu_additem(menu, szText, "2", 0);
formatex(szText, charsmax(szText), "Ajust Volume");
menu_additem(menu, szText, "3", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public main_menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], info[64], access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), info,charsmax(info), callback);
new key = str_to_num(data)
switch(key)
{
case 1:
{
if(RadioOn[id])
{
RadioOn[id] = false
StopRadio(id);
}
else
{
if(!PlayerRadio[id])
{
ColorChat(id, GREEN, "[%s]^x03 Choose a radio first!", PREFIX)
RadioMenu(id);
}
else if(!PlayerVolume[id])
{
ColorChat(id, GREEN, "[%s]^x03 Ajust the volume first!", PREFIX)
if(!get_pcvar_num(volume_menu))
{
client_cmd(id, "messagemode AjustVolume");
}
else
{
VolumeMenu(id);
}
}
else
{
RadioOn[id] = true
Radio(id);
}
}
}
case 2:
{
RadioMenu(id);
}
case 3:
{
if(!get_pcvar_num(volume_menu))
{
client_cmd(id, "messagemode AjustVolume");
}
else
{
VolumeMenu(id)
}
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public RadioMenu(id)
{
new menu
menu = menu_create("\rChoose Radio:","radio_menu_handler")
if(file_exists(file))
{
for(new i=1;i < file_size(file,1);i++)
{
read_file(file,i,data,1023,buffer);
parse(data, gRadioName,63, gRadioUrl,127);
new i_str[3];
num_to_str(i, i_str, 2);
if(!equal(data,"//",2) && !equal(data,"")) menu_additem(menu, gRadioName, i_str);
}
} else {
log_amx("[Radio Menu] ERROR: Faila configs/radios.ini ne sushtestvuva!");
}
menu_display(id, menu, 0)
return PLUGIN_HANDLED;
}
public radio_menu_handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new data[64],name[64], access,callback
menu_item_getinfo(menu, item, access, data,63, name, 63, callback)
PlayerRadio[id] = str_to_num(data)
if(RadioOn[id])
Radio(id);
menu_destroy(menu)
MainMenu(id)
return PLUGIN_HANDLED;
}
public AjustVolume(id)
{
new gVolume[6];
read_argv(1, gVolume, 5);
new iVolume = str_to_num(gVolume)
if(0 < iVolume <= 100)
{
PlayerVolume[id] = iVolume
ColorChat(id, GREEN, "[%s]^x03 Volume changed to^x03 %d.", PREFIX, iVolume);
if(RadioOn[id])
Radio(id);
}
else
{
ColorChat(id, GREEN, "[%s]^x03 Volume must be between^x04 1^x03 and^x04 100^x03!", PREFIX);
}
MainMenu(id)
}
public VolumeMenu(id)
{
new menu = menu_create("\rVolume Menu:", "volumemenu_handler")
menu_additem(menu, "\w25%", "25", 0);
menu_additem(menu, "\w50%", "50", 0);
menu_additem(menu, "\w75%", "75", 0);
menu_additem(menu, "\w100%", "100", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
public volumemenu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], info[64], access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), info,charsmax(info), callback);
PlayerVolume[id] = str_to_num(data)
if(RadioOn[id])
Radio(id)
menu_destroy(menu);
MainMenu(id)
return PLUGIN_HANDLED;
}
stock Radio(id) {
new szMotd[1024], n;
if(file_exists(file))
{
read_file(file,PlayerRadio[id],data,1023,buffer);
parse(data, gRadioName,63, gRadioUrl,127);
}
replace_all(gRadioName,63, "\w","")
replace_all(gRadioName,63, "\y","")
replace_all(gRadioName,63, "\r","")
replace_all(gRadioName,63, "\d","")
n = formatex(szMotd[n], charsmax(szMotd)-n, "<html><head><meta http-equiv=^"content-type^" content=^"text/html; charset=UTF-8^"></head><body bgcolor=^"#000000^"><center><span style=^"color: #FFB000; font-size: 17pt^">Your now listening to: <b>%s</b><br><br><hr><br>", gRadioName)
n += formatex(szMotd[n], charsmax(szMotd)-n, "<object classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 codebase=http://www.microsoft.com/ntserver/netshow/download/en/nsmp2inf.cab#Version=5,1,51,415 type=application/x-oleobject name=msplayer width=256 height=65 align=^"middle^" id=msplayer>")
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"enableContextMenu^" value=^"0^"><param name=^"stretchToFit^" value=^"1^">")
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"AutoRewind^" value=^"1^">")
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"Volume^" value=^"%d^">", PlayerVolume[id])
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"AutoStart^" value=^"1^"><param name=^"URL^" value=^"%s^">", gRadioUrl)
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"uiMode^" value=^"full^"><param name=^"width^" value=^"256^"><param name=^"height^" value=^"65^">")
n += formatex(szMotd[n], charsmax(szMotd)-n, "<param name=^"TransparentAtStart^" value=^"1^"></object>")
n += formatex(szMotd[n], charsmax(szMotd)-n, "</center></body></html>")
show_motd(id, szMotd, "Radio")
}
public StopRadio(id)
{
new szMotd[256];
formatex(szMotd, charsmax(szMotd), "<html><head><meta http-equiv=^"content-type^" content=^"text/html; charset=UTF-8^"></head><body bgcolor=^"#000000^" align=^"center^"><center><span style=^"color: #FFB000; font-size: 19pt^">Радиото е спряно.</span></center></body></html>", id)
show_motd(id, szMotd, "Stop Radio")
RadioOn[id] = false
return PLUGIN_HANDLED
}