高手麻烦帮忙看看错在哪
本帖最后由 Zero0senven 于 2011-1-6 09:16 编辑我的意思是在菜单把配置文件的参数状态显示在菜单上,然后在菜单更改其状态并保存到配置文件中
例如这个..
============================================================
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <regex>
new menu_position
new config_file_plugin
new const AMXMD_CONFIG_PLUGIN[] = "amxmd.cfg"
new config_dir_main
#define AMXMD_ACCESS ADMIN_LEVEL_A
#define NUM_CVARS 22
new cvar_names[] = {
"amx_match_endtype", // 0
"amx_match_hostname", // 1
"amx_match_hltvdelay", // 30
"amx_match_kniferound", // 0
"amx_match_overtime", // 1
"amx_match_otcfg", // 1
"amx_match_otlength", // 3
"amx_match_otunlimited", // 0
"amx_match_password", // 1
"amx_match_password2", // scrim
"amx_match_playerneed", // 10
"amx_match_pugstyle", // 0
"amx_match_randomizeteams", // 0
"amx_match_readytype", // 1
"amx_match_swaptype", // 1
"amx_match_screenshot", // 1
"amx_match_screenshot2", // 1
"amx_match_shield", // 1
"amx_match_shield2", // 1
"amx_match_showscore", // 1
"amx_match_stats", // 0
"amx_match_warmupcfg" // 0
}
new cvar_language[] = {
"END_TYPE", // amx_match_endtype
"CHANGE_HOSTNAME", // amx_match_hostname
"HLTV_DELAY", // amx_match_hltvdelay
"KNIFE_ROUND", // amx_match_kniferound
"ALLOW_OVERTIME", // amx_match_overtime
"OVERTIME_CONFIGS", // amx_match_otcfg
"OVERTIME_LENGTH", // amx_match_otlength
"OVERTIME_UNLIMITED", // amx_match_otunlimited
"CHANGE_PASSWORD", // amx_match_password
"PASSWORD", // amx_match_password2
"NEEDED_READY_PLAYERS", // amx_match_playerneed
"PUG_STYLE", // amx_match_pugstyle
"RANDOMIZE_TEAMS", // amx_match_randomizeteams
"READY_TYPE", // amx_match_readytype
"AUTO_SWAP", // amx_match_swaptype
"SCREEN_SHOT", // amx_match_screenshot
"ALWAYS_SCREENSHOT", // amx_match_screenshot2
"ALLOW_SHIELDS", // amx_match_shield
"REALLOW_SHIELD", // amx_match_shield2
"SHOW_SCORE", // amx_match_showscore
"STATS", // amx_match_stats
"WARMUP_CONFIGS" // amx_match_warmupcfg
}
new cvar_properties[] = {
"0", // amx_match_endtype
"1", // amx_match_hostname
"30", // amx_match_hltvdelay
"0", // amx_match_kniferound
"1", // amx_match_overtime
"1", // amx_match_otcfg
"3", // amx_match_otlength
"0", // amx_match_otunlimited
"1", // amx_match_password
"scrim", // amx_match_password2
"10", // amx_match_playerneed
"0", // amx_match_pugstyle
"0", // amx_match_randomizeteams
"1", // amx_match_readytype
"1", // amx_match_swaptype
"1", // amx_match_screenshot
"1", // amx_match_screenshot2
"1", // amx_match_shield
"1", // amx_match_shield2
"1", // amx_match_showscore
"0", // amx_match_stats
"0" // amx_match_warmupcfg
}
public plugin_precache()
{
register_concmd("amx_matchmenu", "menu_console", AMXMD_ACCESS, " - AMX Match Menu")
}
public plugin_init()
{
register_menucmd(register_menuid("SConfiguration"),1023,"menuactionsettings")
format(config_file_plugin,63,"%s/%s", config_dir_main, AMXMD_CONFIG_PLUGIN)
if (file_exists(config_file_plugin))
{
server_cmd("exec %s", config_file_plugin)
}
for (new i = 0; i < NUM_CVARS; i++)
{
register_cvar(cvar_names, cvar_properties)
}
return PLUGIN_CONTINUE
}
public menu_console(id,level)
{
if (!access(id,level))
{
return PLUGIN_HANDLED
}
menu_show_settings(id)
return PLUGIN_CONTINUE
}
// Plugin Settings Menu
public menu_show_settings(id)
{
new menu_body
new keys = (1<<7)|(1<<9)
new formatPos = 0
new setting
new cvar_property
new start = menu_position * 7
new end = start + 7
new cvar_name
new cvar_lang
// Format heading
formatPos = format(menu_body, 1023, "\y菜单标题: (%d/%d)^n",menu_position + 1, (NUM_CVARS / 7) + 1 )
// Make sure we don't go off the end of the world
if( end > NUM_CVARS)
{
end = NUM_CVARS
}
new j = 1
for(new i = start; i < end; i++)
{
copy(cvar_name, 31, cvar_names)
copy(cvar_lang, 31, cvar_language)
get_cvar_string(cvar_name, cvar_property, 31)
format(setting, 31, "%L", id, (str_to_num(cvar_property) == 1) ? "ON" : "OFF")
// Format end
if( end == NUM_CVARS)
{
formatPos += format(menu_body, 1023 - formatPos, "^n^n\w8. %L^n^n^n^n0. %L", id, "SAVE_CONFIG", id, "BACK")
}
else
{
formatPos += format(menu_body,1023 - formatPos,"^n^n\w8. %L^n^n9. %L^n^n0. %L",id, "SAVE_CONFIG", id, "MORE", id, "BACK")
keys |= (1<<8)
}
// show_menu(id, keys, menu_body)
show_menu(id, keys, menu_body, -1, "SConfiguration")
return PLUGIN_CONTINUE
}
public menuactionsettings(id,key)
{
new cvar_number
new cvar_name
if( key <= 6)
{
cvar_number = key + (menu_position * 7)
copy(cvar_name, 31, cvar_names)
}
switch(key) // Main switch
{
case 7:// Save settings
{
client_print(id,print_chat,"* %L ...",id, "SETTINGS_SAVED")
save_settings(config_file_plugin)
menu_show_settings(id)
}
case 8:// Get more
{
menu_position++
menu_show_settings(id)
}
case 9: // Go back
{
if( menu_position == 0 )
{
menu_show_settings(id)
}
else
{
menu_position--
menu_show_settings(id)
}
}
default:
{
set_cvar_num(cvar_name,!(get_cvar_num(cvar_name)))
menu_show_settings(id)
}
}
return PLUGIN_HANDLED
} save_settings(filename[])
{
if (file_exists(filename))
{
delete_file(filename)
}
new temp
format(temp, 127, "// %L^n", LANG_SERVER, "AMX_MATCH_CONFIG")
if (!write_file(filename, temp))
{
return 0
}
new pos
new text
// Print Cvars
for(new i = 0; i < NUM_CVARS; i++)
{
get_cvar_string(cvar_names, temp, 31)
format(text,1023,"%s ^"%s^"", cvar_names,temp)
write_file(filename,text)
}
format(temp, 127, "^n^n// %L^n", LANG_SERVER, "MENU")
if (!write_file(filename,temp))
{
return 0
}
// Print Types
format(temp, 127, "// %L^n", LANG_SERVER, "LENGTHS")
if (!write_file(filename,temp))
{
return 0
}
if ( menu_lengthlist_pos > 0)
{
pos = format(text,1023,"amx_match_lmenu ")
for(new i = 0; i < menu_lengthlist_pos; i++)
{
pos += format(text,1023 - pos,"^"%s^" ", menu_lengthlist)
if( ((i + 1) % 8) == 7 && (i + 1) < menu_lengthlist_pos)
{
pos += format(text,1023 - pos,"^namx_match_lmenu ")
}
}
write_file(filename,text)
}
// Print Configs
format(temp, 127, "^n^n// %L^n", LANG_SERVER, "CONFIGS")
if (!write_file(filename,temp))
{
return 0
}
if ( menu_configlist_pos > 0)
{
for(new i = 0; i < menu_configlist_pos; i++)
{
format(text,1023,"amx_match_cmenu ^"%s^" ^"%s^"", menu_configlist_name,menu_configlist_file)
write_file(filename,text)
}
}
return 1
} 举手之老的东西还可以................很麻烦的问题需要点通金币........................
页:
[1]