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

Solved callfunc_* alternative


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-13-2019 , 07:53   callfunc_* alternative
Reply With Quote #1

I'm using callfunc_* natives in my plugin so I can register items in a menu from external plugins, but with callfunc_* you don't have the ability of returning PLUGIN_HANDLED in the external plugin and then blocking the function in the main plugin.

I was thinking of using this but it differs from my usage

The usage shown in the link:
PHP Code:
public plugin_init( )

    
some_native("MyFunction"); 


public 
MyFunction(param

    return 
1;

My usage:
PHP Code:
public plugin_init( )

    
some_native"Item Name"Itemcost"CallBackHandler" );


public 
CallBackHandlerid 

    
client_printidprint_chat"Hello there!" );

Can CreateOneForward be used in the form that I'm using callfunc?
__________________

Last edited by edon1337; 08-13-2019 at 16:58.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-13-2019 , 09:16   Re: callfunc_* alternative
Reply With Quote #2

Quote:
Originally Posted by edon1337 View Post
I'm using callfunc_* natives in my plugin so I can register items in a menu from external plugins, but with callfunc_* you don't have the ability of returning PLUGIN_HANDLED in the external plugin and then blocking the function in the main plugin.
PLUGIN_HANDLED is just a magic number. You can check for it and act accordingly, i.e. don't continue with whatever action is taking place.


Quote:
Originally Posted by edon1337 View Post
I was thinking of using this but it differs from my usage

The usage shown in the link:
PHP Code:
public plugin_init( )

    
some_native("MyFunction"); 


public 
MyFunction(param

    return 
1;

My usage:
PHP Code:
public plugin_init( )

    
some_native"Item Name"Itemcost"CallBackHandler" );


public 
CallBackHandlerid 

    
client_printidprint_chat"Hello there!" );

Can CreateOneForward be used in the form that I'm using callfunc?
How are these different? The number of parameters doesn't matter.
__________________
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-13-2019 , 09:16   Re: callfunc_* alternative
Reply With Quote #3

Quote:
Originally Posted by edon1337 View Post
but with callfunc_* you don't have the ability of returning PLUGIN_HANDLED in the external plugin and then blocking the function in the main plugin.
Who told you that ? You can easily get the return value from callfunc_end and check if it's equal to plugin handled or higher to block.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-13-2019 , 09:50   Re: callfunc_* alternative
Reply With Quote #4

Quote:
Originally Posted by KliPPy View Post
PLUGIN_HANDLED is just a magic number. You can check for it and act accordingly, i.e. don't continue with whatever action is taking place.




How are these different? The number of parameters doesn't matter.
I've never used CreateOneForward, that's why it's confusing for me. The prototype looks different.

Main plugin:
PHP Code:
public plugin_natives( )
{
    
register_native"register_extra_item""native_register_extra_item" );


public 
native_register_extra_itemiPluginIdiParamCount 

    new 
eItemDataItemData ], szHandler32 ];
    
    
get_string1eItemDataszItemName ], charsmaxeItemDataszItemName ] ) );
    
eItemDataiItemCost ] = get_param);
    
eItemDataiItemPlugin ] = iPlugin;
    
get_string3szHandlercharsmaxszHandler ) );
    
eItemDataiItemFuncID ] = get_func_idszHandleriPlugin );

    new const 
iFwHandle CreateOneForwardiPluginIdszHandlerFP_STRINGFP_CELLFP_STRING ); 
    
    new 
iDummyResult;
    
ExecuteForwardiFwHandleiDummyResulteItemDataszItemName ], eItemDataiItemCost ], szHandler ); 
    
    
DestroyForward(forwardHandle);
    
    
ArrayPushArrayg_aItemseItemData ); // for later usage

External plugin:
Code:
public plugin_init( ) {     some_native( "Item name", 100, "callbackFunction" ); }
public callbackFunction( id )  // how can I get 'id' to be here with this method?
{     // code }

Quote:
Originally Posted by Natsheh View Post
Who told you that ? You can easily get the return value from callfunc_end and check if it's equal to plugin handled or higher to block.
How does that work? Like how would you modify callfunc_end's return value?
__________________

Last edited by edon1337; 08-13-2019 at 09:50.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-13-2019 , 11:06   Re: callfunc_* alternative
Reply With Quote #5

callfunc_end will return whatever you returned in the target function. PLUGIN_* are just numbers.
__________________

Last edited by HamletEagle; 08-13-2019 at 11:06.
HamletEagle is online now
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-13-2019 , 12:07   Re: callfunc_* alternative
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
callfunc_end will return whatever you returned in the target function. PLUGIN_* are just numbers.
I know PLUGIN_* are just numbers, I just didn't know about callfunc_end returning.

So basically like this?
PHP Code:
public OnShopMenuHandleridiMenuiItem )
{
    
// code

    
callfunc_begin_ieItemDataiItemFuncID ], eItemDataiItemPlugin ] )
    
callfunc_push_intid )
    
    if( 
callfunc_end( ) == PLUGIN_HANDLED )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
// code
    
return PLUGIN_CONTINUE;

PHP Code:
public plugin_init( )
{
    
register_extra_item"Item Name"ITEM_COST "CallBackHandler" );
}

public 
CallBackHandlerid )
{
    return 
PLUGIN_HANDLED;

__________________

Last edited by edon1337; 08-13-2019 at 12:08.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-13-2019 , 13:08   Re: callfunc_* alternative
Reply With Quote #7

Looks okay.
__________________
HamletEagle is online now
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-13-2019 , 16:57   Re: callfunc_* alternative
Reply With Quote #8

Works just fine. Thanks.
__________________
edon1337 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-13-2019 , 21:03   Re: callfunc_* alternative
Reply With Quote #9

Quote:
I've never used CreateOneForward, that's why it's confusing for me. The prototype looks different.
CreateOneForward will create a "private" forward, that means only the plugin where it's registered can hook it.
__________________








CrazY. is offline
Reply


Thread Tools
Display Modes

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 06:31.


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