發新話題
打印

投票轉圖 apple_W pls come 幫我解決第二頁問題唔該

[Close]
複製內容到剪貼板
代碼:
new Handle:g_MapMenu = INVALID_HANDLE

public OnPluginStart()
{
        RegConsoleCmd("menu_changemap", Command_ChangeMap);
}

public OnMapStart()
{
        g_MapMenu = BuildMapMenu();
}

public OnMapEnd()
{
        if (g_MapMenu != INVALID_HANDLE)
        {
                CloseHandle(g_MapMenu);
                g_MapMenu = INVALID_HANDLE;
        }
}

Handle:BuildMapMenu()
{
        /* Open the file */
        new Handle:file = OpenFile("maplist.txt", "rt");
        if (file == INVALID_HANDLE)
        {
                return INVALID_HANDLE;
        }

        /* Create the menu Handle */
        new Handle:menu = CreateMenu(Menu_ChangeMap);
        new String:mapname[255];
        while (!IsEndOfFile(file) && ReadFileLine(file, mapname, sizeof(mapname)))
        {
                if (mapname[0] == ';' || !IsCharAlpha(mapname[0]))
                {
                        continue;
                }
                /* Cut off the name at any whitespace */
                new len = strlen(mapname);
                for (new i=0; i<len; i++)
                {
                        if (IsCharSpace(mapname[i]))
                        {
                                mapname[i] = '\0';
                                break;
                        }
                }
                /* Check if the map is valid */
                if (!IsMapValid(mapname))
                {
                        continue;
                }
                /* Add it to the menu */
                AddMenuItem(menu, mapname, mapname);
        }
        /* Make sure we close the file! */
        CloseHandle(file);

        /* Finally, set the title */
        SetMenuTitle(menu, "Please select a map:");

        return menu;
}

public Menu_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
{
        if (action == MenuAction_Select)
        {
                new String:info[32];

                /* Get item info */
                new bool:found = GetMenuItem(menu, param2, info, sizeof(info));

                /* Tell the client */
                PrintToConsole(param1, "You selected item: %d (found? %d info: %s)", param2, found, info);

                /* Change the map */
                ServerCommand("changelevel %s", info);
        }
}

public Action:Command_ChangeMap(client, args)
{
        if (g_MapMenu == INVALID_HANDLE)
        {
                PrintToConsole(client, "The maplist.txt file was not found!");
                return Plugin_Handled;
        }       

        DisplayMenu(g_MapMenu, client, MENU_TIME_FOREVER);

        return Plugin_Handled;
}

TOP

TOP

RegConsoleCmd("menu_changemap", Command_ChangeMap);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

TOP

發新話題