Modules

Docs / API / Modules / topmenu

TopMenu

Admin & chat

@s2script/sdk/topmenu

the extensible admin/top menu registry.

3 exports

Import

import { TopMenuItem } from "@s2script/sdk/topmenu";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

interface
TopMenuItem

A single registered top-menu entry (an admin command surfaced in the adminmenu).

id: string
Plugin-namespaced unique id, e.g. "playercommands:slap". A duplicate id replaces.
name: string
Shown label.
flags: number
Required ADMFLAG bit mask (adminmenu hides items the caller lacks flags for).
onSelect: (adminSlot: number) => void
Runs in THIS plugin's context when an admin selects the item; receives the admin's 0-based slot.
interface
TopMenuSnapshot

A handler-free copy of the whole registry — what a menu renderer reads to build the display.

categories: string[]
All category names, in registration order.
items: { id: string; category: string; name: string; flags: number }[]
Every registered item's metadata (no onSelect), tagged with its category.
const
TopMenu

The shared admin/top-menu registry — renderers read TopMenu.snapshot and dispatch picks through TopMenu.select; items are contributed by plugins via their own ctx.topmenu.

import { TopMenu } from "@s2script/sdk/topmenu";
const snap = TopMenu.snapshot();
for (const cat of snap.categories) renderCategory(cat);
// when the admin picks an item id, dispatch it back to its owner plugin:
m.onSelect(e => { TopMenu.select(e.info, slot); });
snapshot(): TopMenuSnapshot
All categories + item metadata (no handlers) — the adminmenu renderer reads this.
select(id: string, slot: number): void
Fire an item's onSelect (dispatched post-frame to the owner's context).
Back to modules All packages

s2script — Source 2 plugin framework

GitHub