| shadow.hk |
10-11-2009 02:52 |
Re: Is this would work ?
Well I wrote up a new version of your plugin with explanations in it. I got the Info(id) wrong so I guess fysiks could correct me if I'm wrong here as well...
PHP Code:
#include <amxmodx>
// This shows how many motd's you have
#define MAX_MOTDS 3
// You don't need the parentheses for this, it's one item
new const g_MotdSound[] = "ServerInfo/Motd.wav";
// This is the MOTD header
new const g_MotdName[MAX_MOTDS][] =
{
"Admin Prices", // 0
"Mod Info", // 1
"Server Info" // 2
};
// This is the MOTD path
new const g_MotdPath[MAX_MOTDS][] =
{
"AdminPrices.txt", // 0
"ModInfo.txt", // 1
"ServerInfo.txt" // 2
};
public plugin_precache()
{
precache_sound(g_MotdSound);
}
public plugin_init()
{
// Usually you don't need to create #define's for this, just enter
// it into the register_plugin
register_plugin("Server Info", "0.1", "DoviuX");
// Personally I would remove the capitals, but it's up to you...
register_clcmd("say /ServerInfo", "InfoMenu");
register_clcmd("say_team /ServerInfo", "InfoMenu");
}
public InfoMenu(id)
{
// Be a bit more descriptive in your menus & menu_handlers
// I know that this would be fairly obvious since there's only
// one menu, but it's good practice
new menu = menu_create("\yServer Info Menu:", "InfoMenu_handler");
menu_additem(menu, "Admin Prices", "1");
menu_additem(menu, "Mod Info", "2");
menu_additem(menu, "Info About Server", "3");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
// If you use PLUGIN_HANDLED at the end of the function then you won't see the command
// in chat. (i.e. Someone uses the command /ServerInfo then everyone in the server can
// see /ServerInfo in the chat area. If you pass PLUGIN_HANDLED then it'll open
// the menu and block it from appearing in chat.
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public InfoMenu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new Access, callback;
menu_item_getinfo(menu, item, Access, data, 5, iName, 63, callback);
new key = str_to_num(data) - 1;
// Do this to simply compact the code, so we don't have to write out each case
// since you are using the same functions
show_motd(id, g_MotdPath[key], g_MotdName[key]);
// You had client_cmd(0, ...) the 0 would mean that everyone would hear the sound,
// which I'm sure you didn't intend to do, so just replace it with id to play it to
// that one person who chose the motd
client_cmd(id, "spk ^"%s^"", g_MotdSound);
// InfoMenu(id) will call the menu again once you've selected an item
menu_destroy(menu);
InfoMenu(id);
return PLUGIN_HANDLED;
}
|