/*
* Game Menu
* 10/12/2012
*
* It is unlikely that you are able to add more than 3 servers.
* Total allowed max game menu file size is 1010 bytes.
*
* Credits:
* - to DJ_WEST for original 'GameMenu' plugin
* - to PomanoB & UFPS.Team for 'Fix AutoBuy Bug' plugin. I used much code of it.
*/
#include <amxmodx>
#define PLUGIN "Game Menu"
#define VERSION "1.3"
#define AUTHOR "DJ_WEST / Safety1st"
#define GAMEMENU_FILE "resource/GameMenu.res"
#define MAX_SIZE 1011 // because we waste 1 additional byte for ";" later
#define MAX_CMD_SIZE 1024 // total null-terminated string size allowed for commands; it is needed to check file size
#define NEW 0
#define DEFAULT 1
new gszGMText[2][MAX_SIZE]
new gMenuId
public plugin_init() {
register_plugin( PLUGIN, VERSION, AUTHOR )
register_dictionary( "gamemenu.txt" )
register_clcmd( "say /setmenu", "PrintMenu" )
register_clcmd( "say_team /setmenu", "PrintMenu" )
}
public plugin_cfg() {
// get file names
new szCfgDir[128], szGMFile[2][128]
get_localinfo( "amxx_configsdir", szCfgDir, 127 )
formatex( szGMFile[NEW], 127, "%s/gamemenu.txt", szCfgDir )
formatex( szGMFile[DEFAULT], 127, "%s/gamemenu_def.txt", szCfgDir )
// load file data
new i, fp, szData[MAX_CMD_SIZE]
for ( i = 0; i < 2; i++ ) {
fp = fopen( szGMFile[i], "rt" ) //read text
if ( !fp ) {
format( szGMFile[i], 127, "%s file not found", szGMFile[i] )
set_fail_state( szGMFile[i] )
}
fgets( fp, szData, MAX_CMD_SIZE - 1 )
if ( strlen(szData) > MAX_SIZE - 1 ) { // string lenghts are compared without null termination!
format( szGMFile[i], 127, "%s file too big", szGMFile[i] )
set_fail_state( szGMFile[i] )
}
copy( gszGMText[i], MAX_SIZE - 1, szData )
fclose( fp )
}
// create menu
gMenuId = menu_create( "MENUSET", "HandleMenu", .ml = 1 )
menu_additem( gMenuId, "", "1" )
menu_additem( gMenuId, "", "2" )
menu_setprop( gMenuId, MPROP_NUMBER_COLOR, "\\y" )
menu_setprop( gMenuId, MPROP_EXIT, MEXIT_ALL )
}
public client_putinserver(id) {
set_task( 4.0, "PrintMenu", id )
}
public PrintMenu(id) {
if ( !is_user_connected(id) )
return
new szMenuTitle[256], szMenuSetNew[128], szMenuSetDefault[128], szMenuExit[64]
formatex( szMenuTitle, charsmax(szMenuTitle) - 1, "%L", id, "GM_TITLE" )
formatex( szMenuSetNew, charsmax(szMenuSetNew) - 1, "%L", id, "GM_NEW" )
formatex( szMenuSetDefault, charsmax(szMenuSetDefault) - 1, "%L", id, "GM_DEFAULT" )
formatex( szMenuExit, charsmax(szMenuExit) - 1, "%L", id, "GM_EXIT" )
menu_item_setname( gMenuId, 0, szMenuSetNew )
menu_item_setname( gMenuId, 1, szMenuSetDefault )
menu_setprop( gMenuId, MPROP_TITLE, szMenuTitle )
menu_setprop( gMenuId, MPROP_EXITNAME, szMenuExit )
menu_display( id, gMenuId )
}
public HandleMenu( id, menu, item ) {
if ( item == MENU_EXIT )
return PLUGIN_HANDLED
new access, info[3], callback
menu_item_getinfo( menu, item, access, info, charsmax( info ), _, _, callback )
new key = str_to_num( info )
client_cmd( id, ";Motdfile %s", GAMEMENU_FILE )
switch( key ) {
case 1: {
client_cmd( id, ";Motd_write %s", gszGMText[NEW] )
client_print( id, print_chat, "%L", id, "GM_OKNEW" )
}
case 2: {
client_cmd( id, ";Motd_write %s", gszGMText[DEFAULT] )
client_print( id, print_chat, "%L", id, "GM_OKSTD" )
}
}
// restore default CVar value; dunno whether it is needed
client_cmd( id, ";Motdfile motd.txt" )
return PLUGIN_HANDLED
}