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

help editing adminmenu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Wild1234
Junior Member
Join Date: Oct 2007
Old 10-20-2007 , 04:45   help editing adminmenu
Reply With Quote #1

Hello,
I'll start off by saying I'm rather clueless here so I'm hoping that I am just missing something very simple I am trying to edit the adminmenu plugin to add a new top menu catagory, "Fun Commands". I have managed to add the new catagory to the menu and can add commands to it from other plugins fine, but the name for it is incorrect. It just displays the same name as the command above it, "Voting Commands" and when the menu is opened the section title displays a bunch of symbols that seems to change every time I reconnect to the server.

Here is the code, most of it is still the same as in the original plugin I have just tried adding the new menu option to it.

Code:
/**
 * vim: set ts=4 :
 * =============================================================================
 * SourceMod Admin Menu Plugin
 * Creates the base admin menu, for plugins to add items to.
 *
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
 * =============================================================================
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, version 3.0, as published by the
 * Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * As a special exception, AlliedModders LLC gives you permission to link the
 * code of this program (as well as its derivative works) to "Half-Life 2," the
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
 * by the Valve Corporation.  You must obey the GNU General Public License in
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
 * this exception to all derivative works.  AlliedModders LLC defines further
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
 * or <http://www.sourcemod.net/license.php>.
 *
 * Version: $Id: adminmenu.sp 1609 2007-10-17 17:12:26Z dvander $
 */

#pragma semicolon 1

#include <sourcemod>
#include <topmenus>

public Plugin:myinfo = 
{
    name = "Admin Menu",
    author = "AlliedModders LLC",
    description = "Administration Menu",
    version = SOURCEMOD_VERSION,
    url = "http://www.sourcemod.net/"
};

/* Forwards */
new Handle:hOnAdminMenuReady = INVALID_HANDLE;
new Handle:hOnAdminMenuCreated = INVALID_HANDLE;

/* Menus */
new Handle:hAdminMenu = INVALID_HANDLE;

/* Top menu objects */
new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT;
new TopMenuObject:obj_servercmds = INVALID_TOPMENUOBJECT;
new TopMenuObject:obj_votingcmds = INVALID_TOPMENUOBJECT;
new TopMenuObject:obj_funcmds = INVALID_TOPMENUOBJECT;

public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
{
    CreateNative("GetAdminTopMenu", __GetAdminTopMenu);
    CreateNative("AddTargetsToMenu", __AddTargetsToMenu);
    RegPluginLibrary("adminmenu");
    return true;
}

public OnPluginStart()
{
    LoadTranslations("common.phrases");
    
    hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
    hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);

    RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "sm_admin");
}

public OnConfigsExecuted()
{
    decl String:path[PLATFORM_MAX_PATH];
    decl String:error[256];
    
    BuildPath(Path_SM, path, sizeof(path), "configs/adminmenu_sorting.txt");
    
    if (!LoadTopMenuConfig(hAdminMenu, path, error, sizeof(error)))
    {
        LogError("Could not load admin menu config (file \"%s\": %s)", path, error);
        return;
    }
}

public OnAllPluginsLoaded()
{
    hAdminMenu = CreateTopMenu(CategoryHandler);
    
    obj_playercmds = AddToTopMenu(hAdminMenu, 
        "PlayerCommands",
        TopMenuObject_Category,
        CategoryHandler,
        INVALID_TOPMENUOBJECT);

    obj_servercmds = AddToTopMenu(hAdminMenu,
        "ServerCommands",
        TopMenuObject_Category,
        CategoryHandler,
        INVALID_TOPMENUOBJECT);

    obj_votingcmds = AddToTopMenu(hAdminMenu,
        "VotingCommands",
        TopMenuObject_Category,
        CategoryHandler,
        INVALID_TOPMENUOBJECT);

    obj_funcmds = AddToTopMenu(hAdminMenu,
        "FunCommands",
        TopMenuObject_Category,
        CategoryHandler,
        INVALID_TOPMENUOBJECT);
    
    Call_StartForward(hOnAdminMenuCreated);
    Call_PushCell(hAdminMenu);
    Call_Finish();
    
    Call_StartForward(hOnAdminMenuReady);
    Call_PushCell(hAdminMenu);
    Call_Finish();
}

public CategoryHandler(Handle:topmenu, 
                        TopMenuAction:action,
                        TopMenuObject:object_id,
                        param,
                        String:buffer[],
                        maxlength)
{
    if (action == TopMenuAction_DisplayTitle)
    {
        if (object_id == INVALID_TOPMENUOBJECT)
        {
            Format(buffer, maxlength, "%T:", "Admin Menu", param);
        }
        else if (object_id == obj_playercmds)
        {
            Format(buffer, maxlength, "%T:", "Player Commands", param);
        }
        else if (object_id == obj_servercmds)
        {
            Format(buffer, maxlength, "%T:", "Server Commands", param);
        }
        else if (object_id == obj_votingcmds)
        {
            Format(buffer, maxlength, "%T:", "Voting Commands", param);
        }
        else if (object_id == obj_funcmds)
        {
            Format(buffer, maxlength, "%T:", "Fun Commands", param);
        }
    }
    else if (action == TopMenuAction_DisplayOption)
    {
        if (object_id == obj_playercmds)
        {
            Format(buffer, maxlength, "%T", "Player Commands", param);
        }
        else if (object_id == obj_servercmds)
        {
            Format(buffer, maxlength, "%T", "Server Commands", param);
        }
        else if (object_id == obj_votingcmds)
        {
            Format(buffer, maxlength, "%T", "Voting Commands", param);
        }
        else if (object_id == obj_funcmds)
        {
            Format(buffer, maxlength, "%T", "Fun Commands", param);
        }
    }
}

public __GetAdminTopMenu(Handle:plugin, numParams)
{
    return _:hAdminMenu;
}

public __AddTargetsToMenu(Handle:plugin, numParams)
{
    return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
}

public Action:Command_DisplayMenu(client, args)
{
    if (client == 0)
    {
        ReplyToCommand(client, "[SM] %t", "Command is in-game only");
        return Plugin_Handled;
    }
    
    DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
    
    return Plugin_Handled;
}

stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only)
{
    new max_clients = GetMaxClients();
    decl String:user_id[12];
    decl String:name[MAX_NAME_LENGTH];
    decl String:display[MAX_NAME_LENGTH+12];
    
    new num_clients;
    
    for (new i = 1; i <= max_clients; i++)
    {
        if (!IsClientConnected(i) || IsClientInKickQueue(i))
        {
            continue;
        }
        
        if (in_game_only && !IsClientInGame(i))
        {
            continue;
        }
        
        if (source_client && !CanUserTarget(source_client, i))
        {
            continue;
        }
        
        IntToString(GetClientUserId(i), user_id, sizeof(user_id));
        GetClientName(i, name, sizeof(name));
        Format(display, sizeof(display), "%s (%s)", name, user_id);
        AddMenuItem(menu, user_id, display);
        num_clients++;
    }
    
    return num_clients;
}
Thank you in advance for any help you can provide this clueless newb
/me runs off to hide in shame from the very simple mistake he is sure he made
Wild1234 is offline
dubbeh
Senior Member
Join Date: Jul 2007
Old 10-20-2007 , 08:22   Re: help editing adminmenu
Reply With Quote #2

Looks like the translation might be missing from common.phrases.txt
__________________
SM Plugins - dubbeh.net - Plugin requests are welcome
dubbeh is offline
csallis
Senior Member
Join Date: Sep 2007
Old 10-20-2007 , 10:29   Re: help editing adminmenu
Reply With Quote #3

Your further on then I am. I am also new to this and trying to put commands on the menu if you could help me out that would be appreciated on how you are getting commands from other plugins on the menu.
csallis is offline
BAILOPAN
Join Date: Jan 2004
Old 10-20-2007 , 11:21   Re: help editing adminmenu
Reply With Quote #4

If you file a bug report we can add this category.
__________________
egg
BAILOPAN is offline
Wild1234
Junior Member
Join Date: Oct 2007
Old 10-20-2007 , 14:08   Re: help editing adminmenu
Reply With Quote #5

Quote:
Originally Posted by dubbeh View Post
Looks like the translation might be missing from common.phrases.txt
Well, as I said... it was a very simple mistake Thank you for the quick response, it works great now.

Quote:
Originally Posted by BAILOPAN View Post
If you file a bug report we can add this category.
Thanks for the offer, but I'm doing this as much for a way to learn as I am for a desire to have the aditional default menu option.
Wild1234 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 15:00.


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