AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [callfunc_begin_i] Public function -1 is invalid (https://forums.alliedmods.net/showthread.php?t=300014)

edon1337 08-02-2017 07:50

[callfunc_begin_i] Public function -1 is invalid
 
Hi,

I searched in many threads and still couldn't fix the error.

Error :
Quote:

[AMXX] Run time error 10: native error (native "callfunc_begin_i")
[AMXX] [0] VipManager.sma::OnVipMenuHandler (line 89)
Public function -1 is invalid
Error Plugin :
PHP Code:

#include < amxmodx >
#include < cstrike >
#include < basebuilder >

enum _:ItemData
{
    
szItemName32 ],
    
iItemCost,
    
iItemPlugin,
    
iItemFuncID
}

new 
g_iTotalItems ;

new Array:
g_aItems ;

public 
plugin_init( ) {

    
register_plugin"[BB] VIP Manager""1.0""DoNii" ) ;

    
register_clcmd"say /shop""ShowShopMenu" ) ;

    
g_aItems ArrayCreateItemData ) ;
}

public 
plugin_natives( ) {

    
register_library"bb_vip" ) ;

    
register_native"bb_vip_register_extra_item""native_register_extra_item") ;
}

public 
ShowShopMenuid  ) {
    
    if( 
bb_is_user_zombieid ) )
    return 
PLUGIN_HANDLED ;
    
    new 
eItemDataItemData ], szItem64 ], szNum], iPage ;
    
    
iPage clampiPage0, ( g_iTotalItems ) / ) ;

    new 
iMenu menu_create"\r[VIP] \yExtra Item Menu""OnVipMenuHandler" ) ;
    
    for( new 
iItems iItems g_iTotalItems iItems++ ) {

        
ArrayGetArrayg_aItemsiItemseItemData ) ;
        
        
num_to_striItemsszNumcharsmax szNum ) ) ;
        
        new 
iMoney cs_get_user_moneyid ) ;
        new 
iCost eItemDataiItemCost ] ;

        if( 
iMoney iCost )
        
formatexszItemcharsmaxszItem ), "\d%s | $%d"eItemDataszItemName ], iCost ) ;
        
        else
        
formatexszItemcharsmaxszItem ), "%s | $%d"eItemDataszItemName ], iCost ) ;
        
        
menu_additemiMenuszItemszNum ) ;
    }

    
menu_displayidiMenuiPage ) ;
    return 
PLUGIN_CONTINUE ;
}

public 
OnVipMenuHandleridiMenuiItem ) {
    
    new 
iAccessszNum], iCallback ;
    
menu_item_getinfoiMenuiItemiAccessszNumcharsmaxszNum ), __iCallback ) ;
    
menu_destroyiMenu ) ;
    
    new 
iItemIndex str_to_numszNum ) ;
    new 
eItemDataItemData ] ;
    
    
ArrayGetArrayg_aItemsiItemIndexeItemData ) ;
    
    new 
iMoney cs_get_user_moneyid ) ;

    if( 
iMoney eItemDataiItemCost ] ) {

        
client_printidprint_chat"[BB] Not Enough Money" ) ;
        return 
PLUGIN_HANDLED ;
    }

    
cs_set_user_moneyidiMoney eItemDataiItemCost ] ) ;

    
callfunc_begin_ieItemDataiItemFuncID ], eItemDataiItemPlugin ] )
    
callfunc_push_intid )
    
callfunc_end( )
    
    return 
PLUGIN_CONTINUE ;
}

public 
native_register_extra_itemiPluginiParams )
{
    new 
eItemDataItemData ], szHandler32 ] ;
    
    
get_string1eItemDataszItemName ], charsmaxeItemDataszItemName ] ) ) ;
    
    
eItemDataiItemCost ] = get_param) ;
    
    
eItemDataiItemPlugin ] = iPlugin ;
    
    
get_string4szHandlercharsmaxszHandler ) ) ;
    
    
eItemDataiItemFuncID ] = get_func_idszHandleriPlugin ) ;
    
    
ArrayPushArrayg_aItemseItemData );
    
    
g_iTotalItems++ ;
    
    return ( 
g_iTotalItems ) ;


Error Line :
Code:
    callfunc_begin_i( eItemData[ iItemFuncID ], eItemData[ iItemPlugin ] )     callfunc_push_int( id )     callfunc_end( )

Sub-Plugin that uses the native.
PHP Code:

#include < amxmodx >
#include < bb_vip >

public plugin_init( ) {

    
register_plugin"Test Plug""1.0""DoNii" ) ;

    
bb_vip_register_extra_item"Test"500"OnTest" ) ;
}

public 
OnTestid ) {

    
client_printidprint_chat"It Prints !" ) ;


Info :

The menu works just fine, the item appears, when you click it you lose your money ($500) but the 'It Prints !' never prints, and I get that error. Means that the problem is in the callfunc part (as the error says)

Thanks. :3

klippy 08-02-2017 07:57

Re: [callfunc_begin_i] Public function -1 is invalid
 
Why not use single plugin forwards instead?

Anyway it seems like your issue is here:
PHP Code:

get_string4szHandlercharsmaxszHandler ) ) ; 

looking at the code, the function name is the third parameter, not fourth.

edon1337 08-02-2017 08:17

Re: [callfunc_begin_i] Public function -1 is invalid
 
Quote:

Originally Posted by KliPPy (Post 2539246)
Why not use single plugin forwards instead?

Anyway it seems like your issue is here:
PHP Code:

get_string4szHandlercharsmaxszHandler ) ) ; 

looking at the code, the function name is the third parameter, not fourth.

Thanks KliPPy that did it. :)

And, I tried using MeRcyLeZZ's method of ZP but it didn't work, though I have no idea how to work with CreateOneForward, do you mind showing me an example?

Thanks again.

klippy 08-02-2017 08:33

Re: [callfunc_begin_i] Public function -1 is invalid
 
It's exactly the same as CreateMultiForward (I guess you've used it at some point? If not, there's many examples around), the only difference being is that you have to provide the plugin you want to call the function in (hence "single plugin forward").
They both get executed with ExecuteForward.

Here's a tutorial: https://forums.alliedmods.net/showthread.php?t=41241

edon1337 08-02-2017 10:50

Re: [callfunc_begin_i] Public function -1 is invalid
 
Hawk's tutorial doesn't really have any example for CreateOneForward, can you give me an example because I'm not very familiar with this..

klippy 08-03-2017 07:14

Re: [callfunc_begin_i] Public function -1 is invalid
 
PHP Code:

public plugin_natives()
{
    
register_native("some_native""some_native_handler");
}

// In 1.8.3 it has been increased to 64
#if AMXX_VERSION_NUM < 183
const MAX_FUNCTIONNAME_LENGTH 32;
#else
const MAX_FUNCTIONNAME_LENGTH 64;
#endif

//native some_native(const callbackFunctionName[]);
public some_native_handler(pluginIdparamCount)
{
    new 
callbackFunctionName[MAX_FUNCTIONNAME_LENGTH];
    
get_string(1callbackFunctionNamecharsmax(callbackFunctionName));
    
    
// Create a forward with 1 cell parameter
    
new const forwardHandle CreateOneForward(pluginIdcallbackFunctionNameFP_CELL);
    
    new 
returnValue// Whatever the called function returns will be stored here
    // Execute the function with first parameter's value being 5
    
ExecuteForward(forwardHandlereturnValue5);
    
    
// Make sure to destroy it when you don't need it anymore
    
DestroyForward(forwardHandle);
}

// In that other plugin
native some_native(const callbackFunctionName[]);

someFunction()
{
    
some_native("MyFunction");
}

public 
MyFunction(param)
{
    
// param's value is 5
    
return 10// `returnValue` will be 10 in the main plugin



edon1337 08-04-2017 12:52

Re: [callfunc_begin_i] Public function -1 is invalid
 
Quote:

Originally Posted by KliPPy (Post 2539409)
PHP Code:

public plugin_natives()
{
    
register_native("some_native""some_native_handler");
}

// In 1.8.3 it has been increased to 64
#if AMXX_VERSION_NUM < 183
const MAX_FUNCTIONNAME_LENGTH 32;
#else
const MAX_FUNCTIONNAME_LENGTH 64;
#endif

//native some_native(const callbackFunctionName[]);
public some_native_handler(pluginIdparamCount)
{
    new 
callbackFunctionName[MAX_FUNCTIONNAME_LENGTH];
    
get_string(1callbackFunctionNamecharsmax(callbackFunctionName));
    
    
// Create a forward with 1 cell parameter
    
new const forwardHandle CreateOneForward(pluginIdcallbackFunctionNameFP_CELL);
    
    new 
returnValue// Whatever the called function returns will be stored here
    // Execute the function with first parameter's value being 5
    
ExecuteForward(forwardHandlereturnValue5);
    
    
// Make sure to destroy it when you don't need it anymore
    
DestroyForward(forwardHandle);
}

// In that other plugin
native some_native(const callbackFunctionName[]);

someFunction()
{
    
some_native("MyFunction");
}

public 
MyFunction(param)
{
    
// param's value is 5
    
return 10// `returnValue` will be 10 in the main plugin



The usage in external plugins would be same as the current method, right? Thanks.


All times are GMT -4. The time now is 22:46.

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