Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FemboyKZ/mm-cs2menus

Repository files navigation

CS2 Menu API

Downloads Last commit Open issues Closed issues Size GitHub Workflow Status

A Metamod:Source plugin that provides a shared menu API for CS2.

It owns player input and rendering so other Metamod plugins can create interactive menus without each one reimplementing chat parsing, HTML rendering, and pagination.

Menu types

Type Render Navigation
Chat Numbered list printed to chat Type an item number, 0 exits, page keys follow items
HTML Center-screen panel Movement keys - W/S move, D select, A exit by default (configurable)

Pass MenuType::Default to use the server's configured default style.

Plugins using this library

For server owners

Dependencies

Installation

  1. Download the latest release.
  2. Extract the downloaded .zip file into your server's root folder (~/game/csgo/).
  3. (Optional) If you use CounterStrikeSharp and/or SwiftlyS2, you might want to install the bridge plugins.

Note

On its own, this plugin does nothing visible, it's a library other plugins use.

Configuration

cfg/cs2menus/core.cfg, reloaded automatically on every map change.

TBA...

For plugin developers

Acquire the interface via Metamod's factory (interface name ICS2Menus003):

#include "ics2menus.h"

ICS2Menus *g_pMenus = nullptr;

void AcquireMenus() {
    g_pMenus = (ICS2Menus *)g_SMAPI->MetaFactory(CS2MENUS_INTERFACE, nullptr, nullptr);
}

Re-resolve it from IMetamodListener::OnPluginLoad / OnPluginUnload so you never hold a dangling pointer.

Example

MenuHandle m = g_pMenus->CreateMenu(MenuType::Default, "\x04Pick a map",
    [](MenuHandle menu, int slot, int item) {
        const char *info = g_pMenus->GetItemInfo(menu, item); // e.g. "de_dust2"
        // ... act on the selection
    });

g_pMenus->AddItem(m, "Dust II", "de_dust2", false);
g_pMenus->AddItem(m, "Mirage",  "de_mirage", false);
g_pMenus->AddItem(m, "Coming soon", "", /*disabled*/ true);

// One-shot: free the menu when the player's display ends.
g_pMenus->SetMenuEndCallback(m, [](MenuHandle menu, int slot, MenuEndReason reason) {
    g_pMenus->DestroyMenu(menu);
});

// HTML-only: override nav keys for this menu (no-op for chat menus).
g_pMenus->SetMenuKey(m, MenuNavAction::Select, MenuButton::Use);   // E selects
g_pMenus->SetMenuKey(m, MenuNavAction::Back,   MenuButton::Speed); // Shift backs out

g_pMenus->DisplayMenu(m, slot, 20.0f); // show to one player, 20s timeout (0 = none)

The full surface is documented in ics2menus.h.

SwiftlyS2 and CounterStrikeSharp

CS2Menus supports both platforms via bridges.

Build

Prerequisites

  • This repository is cloned recursively (ie. has submodules)
  • python3
  • ambuild, make sure ambuild command is available via the PATH environment variable;
  • MSVC (VS build tools)/Clang installed for Windows/Linux.

AMBuild

mkdir -p build && cd build
python3 ../configure.py --enable-optimize
ambuild

Credits

About

A Metamod:Source plugin that provides a shared menu API for CS2.

Resources

License

Stars

Watchers

Forks

Contributors