I haven't had much success with TopMenu handle so far. Why won't this code produce a menu ? It is literally taken from the Sourcemod wiki.
Would anyone be kind enough to point out my mistake before I hit my head against a wall?
PHP Code:
#include <sourcemod>
/* Make the admin menu plugin optional */
#undef REQUIRE_PLUGIN
#include <adminmenu>
/* Keep track of the top menu */
TopMenu hAdminMenu = null;
/* Keep track of the menu object */
TopMenuObject obj_dmcommands;
public void OnPluginStart()
{
/* See if the menu plugin is already ready */
TopMenu topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != null))
{
/* If so, manually fire the callback */
OnAdminMenuReady(topmenu);
}
}
public void OnLibraryRemoved(const char[] name)
{
if (StrEqual(name, "adminmenu", false))
{
hAdminMenu = null;
}
}
public void OnAdminMenuReady(Handle topmenu)
{
/* Try to add the category first, if we want to add one.
Leave this out, if you don't add a new category. */
if (obj_dmcommands == INVALID_TOPMENUOBJECT)
{
OnAdminMenuCreated(topmenu);
}
/* Block us from being called twice */
if (topmenu == hAdminMenu)
{
return;
}
hAdminMenu = view_as<TopMenu>(topmenu);
/* :TODO: Add everything to the menu! */
}
public void OnAdminMenuCreated(Handle topmenu)
{
/* Block us from being called twice */
if (topmenu == hAdminMenu && obj_dmcommands != INVALID_TOPMENUOBJECT)
{
return;
}
obj_dmcommands = hAdminMenu.AddCategory("Sample Category", CategoryHandler);
hAdminMenu.AddItem("sm_testingtop", AdminMenu_Testingtop, obj_dmcommands, "sm_topmenu", ADMFLAG_SLAY);
}
public void CategoryHandler(TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if (action == TopMenuAction_DisplayTitle)
{
Format(buffer, maxlength, "Sample Title:");
}
else if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "Sample Commands");
}
}
public void AdminMenu_Testingtop(TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
Format(buffer, maxlength, "Sample Item");
}
else if (action == TopMenuAction_SelectOption)
{
PrintToChat(param, "Testing the command");
}
}
__________________