Raised This Month: $32 Target: $400
 8% 

TopMenu with Transitional Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 06-23-2018 , 00:52   Re: TopMenu with Transitional Syntax
Reply With Quote #11

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_Testingtopobj_dmcommands"sm_topmenu"ADMFLAG_SLAY);
}
 
public 
void CategoryHandler(TopMenu topmenuTopMenuAction actionTopMenuObject object_idint param,    char[] bufferint maxlength)
{
    if (
action == TopMenuAction_DisplayTitle)
    {
        
Format(buffermaxlength"Sample Title:");
    }
    else if (
action == TopMenuAction_DisplayOption)
    {
        
Format(buffermaxlength"Sample Commands");
    }
}

public 
void AdminMenu_Testingtop(TopMenu topmenuTopMenuAction actionTopMenuObject object_idint paramchar[] bufferint maxlength)
{
    if (
action == TopMenuAction_DisplayOption)
    {
        
Format(buffermaxlength"Sample Item");
    }
    else if (
action == TopMenuAction_SelectOption)
    {
        
PrintToChat(param"Testing the command");
    }

__________________
Spirit_12 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 06-23-2018 , 02:11   Re: TopMenu with Transitional Syntax
Reply With Quote #12

PHP Code:
TopMenu g_tmTopMenu;

public 
void OnPluginStart()
{
    
TopMenu tmAdminMenu;
    if (
LibraryExists("adminmenu") && ((tmAdminMenu GetAdminTopMenu()) != null))
    {
        
OnAdminMenuReady(tmAdminMenu);
    }
}

public 
void OnAdminMenuReady(Handle topmenu)
{
    if (
topmenu == g_tmTopMenu)
    {
        return;
    }
    
g_tmTopMenu view_as<TopMenu>(topmenu);
    
TopMenuObject menu_commands g_tmTopMenu.AddCategory("My Menu"iAdminMenuHandler);
    if (
menu_commands != INVALID_TOPMENUOBJECT)
    {
        
g_tmTopMenu.AddItem("mycommand"vTopMenuHandlermenu_commands"mycommand"ADMFLAG_KICK);
    }
}

public 
int iAdminMenuHandler(TopMenu topmenuTopMenuAction actionTopMenuObject object_idint paramchar[] bufferint maxlength)
{
    switch (
action)
    {
        case 
TopMenuAction_DisplayTitleTopMenuAction_DisplayOptionFormat(buffermaxlength"My Menu");
    }
}

public 
void OnLibraryRemoved(const char[] name)
{
    if (
StrEqual(name"adminmenu"false))
    {
        
g_tmTopMenu null;
    }

This works for me.
__________________

Last edited by Psyk0tik; 06-24-2018 at 01:48.
Psyk0tik is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode