搜索
查看: 2881|回复: 2

高手麻烦帮忙看看错在哪

[复制链接]
发表于 2011-1-6 09:13:35 | 显示全部楼层 |阅读模式 来自 广东深圳
本帖最后由 Zero0senven 于 2011-1-6 09:16 编辑

我的意思是在菜单把配置文件的参数状态显示在菜单上,然后在菜单更改其状态并保存到配置文件中
例如这个..

============================================================
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <regex>


new menu_position[33]
new config_file_plugin[64]
new const AMXMD_CONFIG_PLUGIN[] = "amxmd.cfg"


new config_dir_main[64]

#define AMXMD_ACCESS ADMIN_LEVEL_A


#define NUM_CVARS 22

new cvar_names[NUM_CVARS][] = {
        "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[NUM_CVARS][] = {
        "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[NUM_CVARS][] = {
        "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[1024]
        new keys = (1<<7)|(1<<9)
        new formatPos = 0

        new setting[32]

        new cvar_property[32]

        new start = menu_position[id] * 7
        new end = start + 7

        new cvar_name[32]
        new cvar_lang[32]


        // Format heading
        formatPos = format(menu_body, 1023, "\y菜单标题:                                (%d/%d)^n",menu_position[id] + 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[formatPos], 1023 - formatPos, "^n^n\w8. %L^n^n^n^n0. %L", id, "SAVE_CONFIG", id, "BACK")
        }
        else
        {
                formatPos += format(menu_body[formatPos],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[32]

        if( key <= 6)
        {
                cvar_number = key + (menu_position[id] * 7)

                copy(cvar_name, 31, cvar_names[cvar_number])
        }

        switch(key) // Main switch
        {
                case 7:  // Save settings
                {
                        client_print(id,print_chat,"* [AMX MATCH] %L ...",id, "SETTINGS_SAVED")

                        save_settings(config_file_plugin)
                        menu_show_settings(id)
                }
                case 8:  // Get more
                {
                        menu_position[id]++
                        menu_show_settings(id)
                }
                case 9: // Go back
                {
                        if( menu_position[id] == 0 )
                        {
                                menu_show_settings(id)
                        }
                        else
                        {
                                menu_position[id]--
                                menu_show_settings(id)
                        }
                }
                default:
                {
                        set_cvar_num(cvar_name,!(get_cvar_num(cvar_name)))
                        menu_show_settings(id)
                }
        }

        return PLUGIN_HANDLED
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
 楼主| 发表于 2011-1-6 09:16:16 | 显示全部楼层 来自 广东深圳
save_settings(filename[])
{
        if (file_exists(filename))
        {
                delete_file(filename)
        }

        new temp[128]

        format(temp, 127, "// %L^n", LANG_SERVER, "AMX_MATCH_CONFIG")
        if (!write_file(filename, temp))
        {
                return 0
        }

        new pos
        new text[1024]

        // Print Cvars
        for(new i = 0; i < NUM_CVARS; i++)
        {
                get_cvar_string(cvar_names[i], temp, 31)

                format(text,1023,"%s ^"%s^"", cvar_names[i],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[pos],1023 - pos,"^"%s^" ", menu_lengthlist[i])

                        if( ((i + 1) % 8) == 7 && (i + 1) < menu_lengthlist_pos)
                        {
                                pos += format(text[pos],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[i],menu_configlist_file[i])
                        write_file(filename,text)
                }
        }

        return 1
}
回复

使用道具 举报

发表于 2011-1-6 20:40:32 | 显示全部楼层 来自 广西南宁
举手之老的东西还可以................很麻烦的问题需要点通金币........................
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表