AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Error when adding entry to admin menu (https://forums.alliedmods.net/showthread.php?t=298345)

condolent 06-09-2017 04:54

Error when adding entry to admin menu
 
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.

8guawong 06-09-2017 05:23

Re: Error when adding entry to admin menu
 
what version is your compiler?

condolent 06-09-2017 06:03

Re: Error when adding entry to admin menu
 
Quote:

Originally Posted by 8guawong (Post 2527285)
what version is your compiler?

Latest

Walgrim 06-09-2017 06:14

Re: Error when adding entry to admin menu
 
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.

condolent 06-09-2017 06:58

Re: Error when adding entry to admin menu
 
Not sure what to do with that information, tbh xd

Walgrim 06-09-2017 07:52

Re: Error when adding entry to admin menu
 
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...

Fyren 06-09-2017 11:26

Re: Error when adding entry to admin menu
 
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 (Post 2527324)
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 (Post 2527324)
The last modification on the tutorial was in August 2015...

And the actual release of SM 1.7 was early 2015.

Walgrim 06-09-2017 12:49

Re: Error when adding entry to admin menu
 
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

Fyren 06-09-2017 19:02

Re: Error when adding entry to admin menu
 
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.

condolent 06-09-2017 19:54

Re: Error when adding entry to admin menu
 
Quote:

Originally Posted by Fyren (Post 2527486)
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!!


All times are GMT -4. The time now is 16:56.

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