Raised This Month: $51 Target: $400
 12% 

Error when adding entry to admin menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-09-2017 , 04:54   Error when adding entry to admin menu
Reply With Quote #1

Hello,
I get this error when trying to compile:
error 181: function argument named 'topmenu' differs from prototype

This is the code it's referring to:
PHP Code:
public void OnAdminMenuReady(TopMenu topmenu) {
    
    if(
obj_dmcommands == INVALID_TOPMENUOBJECT) {
        
OnAdminMenuCreated(topmenu);
    }
    
    if(
topmenu == hAdminMenu) {
        return;
    }
    
    
hAdminMenu topmenu;
    
    
// TODO: Add stuff to the menu
    

It also gives me the same error on OnAdminMenuCreated()

What does that error actually mean?
I was following this tutorial.
__________________

Last edited by condolent; 06-09-2017 at 04:55.
condolent is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-09-2017 , 05:23   Re: Error when adding entry to admin menu
Reply With Quote #2

what version is your compiler?
8guawong is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-09-2017 , 06:03   Re: Error when adding entry to admin menu
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
what version is your compiler?
Latest
__________________
condolent is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 06-09-2017 , 06:14   Re: Error when adding entry to admin menu
Reply With Quote #4

See that here : https://sm.alliedmods.net/new-api/to...opMenu/TopMenu

The tutorial is old so the syntax may changed. (Maybe)
Just look at the new api when you have an error like that.
__________________
Walgrim is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-09-2017 , 06:58   Re: Error when adding entry to admin menu
Reply With Quote #5

Not sure what to do with that information, tbh xd
__________________
condolent is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 06-09-2017 , 07:52   Re: Error when adding entry to admin menu
Reply With Quote #6

Quote:
error 181: function argument named 'topmenu' differs from prototype
This error means that you made a mistake with the basic function.
If you used the latest compiler of sourcemod, and you tried the code of this tutorial, it will make an error like that.
Since this tutorial is old, the syntax is old also. To resolve that, use the new syntax which is in the link I gave you.

The last modification on the tutorial was in August 2015...
__________________
Walgrim is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-09-2017 , 11:26   Re: Error when adding entry to admin menu
Reply With Quote #7

Someone attempted to update the sample code on that wiki article, but they did a poor job of it. They introduced the error you're getting and still didn't really use the new methodmaps for topmenus. I'll see if I can make a better sample sometime today.

In the meantime, you can try clicking on "view history" on the top of the wiki article and seeing if an older version before the 2015 edits work, though it'll use the older style.

Quote:
Originally Posted by Walgrim View Post
This error means that you made a mistake with the basic function.
If you used the latest compiler of sourcemod, and you tried the code of this tutorial, it will make an error like that.
Since this tutorial is old, the syntax is old also. To resolve that, use the new syntax which is in the link I gave you.
All old syntax plugins should compile with a newer compiler and already-compiled plugins should run on a newer SM.

Quote:
Originally Posted by Walgrim View Post
The last modification on the tutorial was in August 2015...
And the actual release of SM 1.7 was early 2015.
Fyren is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 06-09-2017 , 12:49   Re: Error when adding entry to admin menu
Reply With Quote #8

Quote:
All old syntax plugins should compile with a newer compiler and already-compiled plugins should run on a newer SM.
Yeah they should but some don't lol
__________________
Walgrim is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-09-2017 , 19:02   Re: Error when adding entry to admin menu
Reply With Quote #9

Here's a sample that makes a category and adds one item. I tried to explain what's going on.

PHP Code:
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <adminmenu>

#define MY_CATEGORY "My Custom Category" 
#define MY_CATEGORY_OVERRIDE "My Custom Category Override"
#define MY_ITEM "My Custom Item" 
#define MY_ITEM_OVERRIDE "My Custom Item Override"

TopMenuObject myCategory;
TopMenuObject myItem;

public 
void OnPluginStart() {
    
/* handle late loading */
    
TopMenu am;
    if (
LibraryExists("adminmenu") && ((am GetAdminTopMenu()) != null)) {
        
OnAdminMenuCreated(am);
        
OnAdminMenuReady(am);
    }
}
 
/*
    When the adminmenu plugin creates the menu, it calls this forward.

    Add categories here.
*/ 
public void OnAdminMenuCreated(Handle am)
{
    
TopMenu adminMenu view_as<TopMenu>(am);
    
myCategory adminMenu.AddCategory(MY_CATEGORYTMHandlerMY_CATEGORY_OVERRIDEADMFLAG_GENERIC);
}

/*
    This forward is called immediately after the above one is called for all plugins.

    If you want to add things to a different plugin's category, you have do it here to be sure the category
    was created.  I could have added items above since I know I just created the category, but I'll do it
    here anyway.
*/
public void OnAdminMenuReady(Handle am)
{
    
TopMenu adminMenu view_as<TopMenu>(am);
    
myItem adminMenu.AddItem(MY_ITEMTMHandlermyCategoryMY_ITEM_OVERRIDEADMFLAG_GENERIC); 
}

/* 
    You can have separate handlers for everything, if you want.  I'm using one for both the category and item
    I created above.

    The object will be the category or item object returned from AddCategory/AddItem.  Since I'm only using
    one handler, I have to check it against myCategory/myItem.  If you have separate handlers for everything
    you added, you wouldn't need to.

    Here's the list of possible actions: https://sm.alliedmods.net/new-api/topmenus/TopMenuAction

    param will be the client ID for most actions.

    I didn't handle translations, but you could make MY_CATEGORY/MY_ITEM translation names and use %T/%t
    in the Format calls below.
*/
public void TMHandler(TopMenu tmTopMenuAction actTopMenuObject objint paramchar[] bufint len)
{
    if (
obj == myCategory
        switch (
act) {
            case 
TopMenuAction_DisplayOption//put the string for the category name in buf
                
Format(buflenMY_CATEGORY);
            case 
TopMenuAction_DisplayTitle//put the string for the category header in buf
                
Format(buflenMY_CATEGORY);
        }
    else if (
obj == myItem)
        switch (
act) {
            case 
TopMenuAction_DisplayOption//put the string for the menu item in buf
                
Format(buflenMY_ITEM);
            case 
TopMenuAction_SelectOption: { //do something since the user picked the item
                
Menu menu = new Menu(MHandler);
                
menu.SetTitle("Custom Submenu:");
                
menu.ExitBackButton true;
                
menu.AddItem("Hello.""Hello.");
                
menu.AddItem("Hi.""Hi.");
                
menu.Display(paramMENU_TIME_FOREVER);
            }
        }
}

public 
int MHandler(Menu menuMenuAction actint param1int param2) {
    switch (
act) {
        case 
MenuAction_End:
            
delete menu;
        case 
MenuAction_Cancel//if they hit back, redisplay the admin menu
            
if (param2 == MenuCancel_ExitBackGetAdminTopMenu().Display(param1TopMenuPosition_LastCategory);
        case 
MenuAction_Select: {
            
char buf[32];
            
menu.GetItem(param2bufsizeof(buf));
            
PrintToChat(param1buf);
        }
    }
    return 
0;

If you use separate handlers, you can get rid of the globals.

Last edited by Fyren; 06-10-2017 at 14:16. Reason: update sample for re-showing admin menu after submenu
Fyren is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-09-2017 , 19:54   Re: Error when adding entry to admin menu
Reply With Quote #10

Quote:
Originally Posted by Fyren View Post
Here's a sample that makes a category and adds one item. I tried to explain what's going on.

PHP Code:
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <adminmenu>

#define MY_CATEGORY "My Custom Category" 
#define MY_CATEGORY_OVERRIDE "My Custom Category Override"
#define MY_ITEM "My Custom Item" 
#define MY_ITEM_OVERRIDE "My Custom Item Override"

TopMenuObject myCategory;
TopMenuObject myItem;

public 
void OnPluginStart() {
    
/* handle late loading */
    
TopMenu am;
    if (
LibraryExists("adminmenu") && ((am GetAdminTopMenu()) != null)) {
        
OnAdminMenuCreated(am);
        
OnAdminMenuReady(am);
    }
}
 
/*
    When the adminmenu plugin creates the menu, it calls this forward.

    Add categories here.
*/ 
public void OnAdminMenuCreated(Handle am)
{
    
TopMenu adminMenu view_as<TopMenu>(am);
    
myCategory adminMenu.AddCategory(MY_CATEGORYTMHandlerMY_CATEGORY_OVERRIDEADMFLAG_GENERIC);
}

/*
    This forward is called immediately after the above one is called for all plugins.

    If you want to add things to a different plugin's category, you have do it here to be sure the category
    was created.  I could have added items above since I know I just created the category, but I'll do it
    here anyway.
*/
public void OnAdminMenuReady(Handle am)
{
    
TopMenu adminMenu view_as<TopMenu>(am);
    
myItem adminMenu.AddItem(MY_ITEMTMHandlermyCategoryMY_ITEM_OVERRIDEADMFLAG_GENERIC); 
}

/* 
    You can have separate handlers for everything, if you want.  I'm using one for both the category and item
    I created above.

    The object will be the category or item object returned from AddCategory/AddItem.  Since I'm only using
    one handler, I have to check it against myCategory/myItem.  If you have separate handlers for everything
    you added, you wouldn't need to.

    Here's the list of possible actions: https://sm.alliedmods.net/new-api/topmenus/TopMenuAction

    param will be the client ID for most actions.

    I didn't handle translations, but you could make MY_CATEGORY/MY_ITEM translation names and use %T/%t
    in the Format calls below.
*/
public void TMHandler(TopMenu tmTopMenuAction actTopMenuObject objint paramchar[] bufint len)
{
    if (
obj == myCategory
        switch (
act) {
            case 
TopMenuAction_DisplayOption//put the string for the category name in buf
                
Format(buflenMY_CATEGORY);
            case 
TopMenuAction_DisplayTitle//put the string for the category header in buf
                
Format(buflenMY_CATEGORY);
        }
    else if (
obj == myItem)
        switch (
act) {
            case 
TopMenuAction_DisplayOption//put the string for the menu item in buf
                
Format(buflenMY_ITEM);
            case 
TopMenuAction_SelectOption//do something since the user picked the item
                
PrintToChat(param"Hello.");
        }

If you use separate handlers, you can get rid of the globals.
Thank you so much for this!!
__________________
condolent 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 12:26.


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