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

AddToTopMenu Category Problem?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-09-2009 , 21:57   AddToTopMenu Category Problem?
Reply With Quote #1

Hello all, long time no see.

I've been passing the unemployment time by working on some sourcemod goodies again. This time, I decided to learn to modify the admin menu, categories, items etc..

I've run across an odd issue I'm hoping someone can help with. Based on the information in the Wiki for creating new categories, I've added my own category, along with numerous options within said category.

The problem is, whenever I pull up the admin menu using sm_admin, it defaults into the Player Options menu, instead of the base admin menu. If you exit out of the menu, issue sm_admin again, you get the base menu per normal behaviour.

The custom category and items themselves work great, I'm just battling this odd initial sm_admin menu behaviour.

I won't post the entire plugin code in the snippet, however I will post all menu related entries, and attach the full code if someone chooses to toy with it for themself.

Testing using SM 1.2.4 Release

Thanks for the assist in advance,

(Yes, I named it bling, I was bored. lol)

X

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#define VERSION "0.5"

new Handle:hAdminMenu INVALID_HANDLE;

public 
OnPluginStart()
{
     
/* Account for late loading */
    
new Handle:topmenu;
    if (
LibraryExists("adminmenu") && ((topmenu GetAdminTopMenu()) != INVALID_HANDLE))
    {
        
OnAdminMenuReady(topmenu);
    }
}
public 
OnLibraryRemoved(const String:name[])
{
    if (
StrEqual(name"adminmenu"))
    {
        
hAdminMenu INVALID_HANDLE;
    }
}
 
public 
OnAdminMenuReady(Handle:topmenu)
{
    if (
topmenu == hAdminMenu)
    {
        return;
    }
    
hAdminMenu topmenu;
    new 
TopMenuObject:obj_blingoptions AddToTopMenu(hAdminMenu,"Bling Options",TopMenuObject_Category,Bling_CategoryHandler,INVALID_TOPMENUOBJECT);
    
AddToTopMenu(hAdminMenu,"sm_bling_noscope",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_headshot",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_headshotsounds",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_knifekillsounds",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);                        
    
AddToTopMenu(hAdminMenu,"sm_bling_bulletpath",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_dissolver",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    if (
g_dissolver)
    {
        
AddToTopMenu(hAdminMenu,"sm_bling_dissolvetype",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    }
    
AddToTopMenu(hAdminMenu,"sm_bling_oneshotkill",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_blood",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);
    
AddToTopMenu(hAdminMenu,"sm_bling_noblock",TopMenuObject_Item,Bling_MenuHandler,obj_blingoptions,"sm_kick",ADMFLAG_GENERIC);            
}
public 
Bling_MenuHandler(Handle:topmenu,TopMenuAction:action,TopMenuObject:object_id,param,String:buffer[],maxlength)
{
    new 
String:obj_str[64];
    
GetTopMenuObjName(topmenuobject_idobj_strsizeof(obj_str));
    if (
action == TopMenuAction_DisplayOption)
    {
        if (
StrEqual(obj_str"sm_bling_noscope"))
        {
            if (
g_noscope)
            {
                
menutext "Scout No Scope: Enabled";
            }
            else
            {
                
menutext "Scout No Scope: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_headshot"))
        {
            if (
g_headshot)
            {
                
menutext "Headshot Only: Enabled";
            }
            else
            {
                
menutext "Headshot Only: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_headshotsounds"))
        {
            if (
g_headshotsounds)
            {
                
menutext "Headshot Sounds: Enabled";
            }
            else
            {
                
menutext "Headshot Sounds: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_knifekillsounds"))
        {
            if (
g_knifekillsounds)
            {
                
menutext "Knifekill Sounds: Enabled";
            }
            else
            {
                
menutext "Knifekill Sounds: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_bulletpath"))
        {
            if (
g_bulletpath)
            {
                
menutext "Laser Bulletpaths: Enabled";
            }
            else
            {
                
menutext "Laser Bulletpaths: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_dissolver"))
        {
            if (
g_dissolver)
            {
                
menutext "Ragdoll Dissolver: Enabled";
            }
            else
            {
                
menutext "Ragdoll Dissolver: Disabled";
            }        
        }
        else if (
StrEqual(obj_str"sm_bling_dissolvetype"))
        {
            if (
g_dissolvetype == 0)
            {
                
menutext "Ragdoll Dissolve Type: Random";
            }
            else if (
g_dissolvetype == 1)
            {
                
menutext "Ragdoll Dissolve Type: Energy";
            }
            else if (
g_dissolvetype == 2)
            {
                
menutext "Ragdoll Dissolve Type: Energy & Electrical";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_oneshotkill"))
        {
            if (
g_oneshotkill)
            {
                
menutext "One Shot Kills: Enabled";
            }
            else
            {
                
menutext "One Shot Kills: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_blood"))
        {
            if (
g_blood)
            {
                
menutext "Blood Effects: Enabled";
            }
            else
            {
                
menutext "Blood Effects: Disabled";
            }
        }
        else if (
StrEqual(obj_str"sm_bling_noblock"))
        {
            if (
g_noblock)
            {
                
menutext "No-Block: Enabled";
            }
            else
            {
                
menutext "No-Block: Disabled";
            }
        }
        
Format(buffermaxlengthmenutext);
    }
    else if (
action == TopMenuAction_SelectOption)
    {
        if (
StrEqual(obj_str"sm_bling_noscope"))
        {
            if (
g_noscope)
            {
                
SetConVarBool(Handle:g_Cvarnoscopefalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarnoscopetrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_headshot"))
        {
            if (
g_headshot)
            {
                
SetConVarBool(Handle:g_Cvarheadshotfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarheadshottrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_headshotsounds"))
        {
            if (
g_headshotsounds)
            {
                
SetConVarBool(Handle:g_Cvarheadshotsoundsfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarheadshotsoundstrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_knifekillsounds"))
        {
            if (
g_knifekillsounds)
            {
                
SetConVarBool(Handle:g_Cvarknifekillsoundsfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarknifekillsoundstrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_bulletpath"))
        {
            if (
g_bulletpath)
            {
                
SetConVarBool(Handle:g_Cvarbulletpathfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarbulletpathtrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_dissolver"))
        {
            if (
g_dissolver)
            {
                
SetConVarBool(Handle:g_Cvardissolverfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvardissolvertrue);
            }        
        }
        else if (
StrEqual(obj_str"sm_bling_dissolvetype"))
        {
            if (
g_dissolvetype == 0)
            {
                
SetConVarInt(Handle:g_Cvardissolvetype1);
            }
            else if (
g_dissolvetype == 1)
            {
                
SetConVarInt(Handle:g_Cvardissolvetype2);
            }
            else if (
g_dissolvetype == 2)
            {
                
SetConVarInt(Handle:g_Cvardissolvetype0);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_oneshotkill"))
        {
            if (
g_oneshotkill)
            {
                
SetConVarBool(Handle:g_Cvaroneshotkillfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvaroneshotkilltrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_blood"))
        {
            if (
g_blood)
            {
                
SetConVarBool(Handle:g_Cvarbloodfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarbloodtrue);
            }
        }
        else if (
StrEqual(obj_str"sm_bling_noblock"))
        {
            if (
g_noblock)
            {
                
SetConVarBool(Handle:g_Cvarnoblockfalse);
            }
            else
            {
                
SetConVarBool(Handle:g_Cvarnoblocktrue);
            }
        }
    }
    
RedisplayAdminMenu(Handle:hAdminMenu,param);
}

public 
Bling_CategoryHandler(Handle:topmenu,TopMenuAction:action,TopMenuObject:object_id,param,String:buffer[],maxlength)
{
    if (
action == TopMenuAction_DisplayTitle)
    {
        
Format(buffermaxlength"Bling Options:");
    }
    else if (
action == TopMenuAction_DisplayOption)
    {
        
Format(buffermaxlength"Bling Options");
    }

__________________

Last edited by XARIUS; 10-09-2009 at 22:14.
XARIUS is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-09-2009 , 22:14   Re: AddToTopMenu Category Problem?
Reply With Quote #2

Welp,

As per tradition, a few minutes after posting (and banging my head against it for about an hour), I found the problem.

At the bottom of my menu handler, I was issuing:

PHP Code:
RedisplayAdminMenu(Handle:hAdminMenu,param); 
It was outside the block it needed to be in to re-display the menu after a selection. Apparently, having this redisplay call immediately inside the handler function (instead of TopMenuAction_SelectOption) causes the admin menu to jump into the first menu option, even though you wouldn't think the handler would have even been called yet, since nothing has even been selected at this point!

X
__________________
XARIUS 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 13:49.


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