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

callfunc( function[], pluginname[] )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-29-2012 , 17:43   callfunc( function[], pluginname[] )
Reply With Quote #1

Hello;

My question is that how can i call functions in plugin like this:
PHP Code:
new decl String:myfunctions[8][64]

myfunctions[0][] = "test_function1"
myfunctions[1][] = "test_function2"
...

public 
something(ie)
{
    
callfuncmyfunctions[ie], "" // last param "" means that call function what is only inside of my plugin.
}

public 
test_function1() 
Edit:

I found those things here:
PHP Code:
new r
Call_StartFunction
(Handle:plugin, Function:func// i dont know how to use this, help :)
Call_PushCell(8// this is int value right?
Call_PushFloat(5.0)
Call_PushString("my string")
Call_Finish(r)

if(!
r// failed 

-DareDevil

Last edited by .Dare Devil.; 09-29-2012 at 17:50.
.Dare Devil. is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-29-2012 , 18:55   Re: callfunc( function[], pluginname[] )
Reply With Quote #2

Not sure why you'd be wanting to do this, but since your functions don't use any parameters, try something like the following, but obviously fill in the blanks yourself.

PHP Code:
new String:g_sMyFunctions[2][32] = { "test_function1""test_function2" };
new 
Handle:g_hPlugin INVALID_HANDLE;

public 
OnPluginStart()
{
    
g_hPlugin GetMyHandle();
    
CallSomething(0);
}


CallSomething(num)
{
    if ((
num 0) || (num >= sizeof(g_sMyFunctions)))
    {
        return;
    }
    
    new Function:
func GetFunctionByName(g_hPluging_sMyFunctions[num]);
    if (
func != INVALID_FUNCTION)
    {
        
Call_StartFunction(g_hPluginfunc);
        
Call_Finish();
    }
}

test_function1() {}
test_function2() {} 
__________________

Last edited by 11530; 09-29-2012 at 19:28.
11530 is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 09-29-2012 , 19:35   Re: callfunc( function[], pluginname[] )
Reply With Quote #3

11530: There's almost never any reason to use GetMyHandle. When using functions that require a plugin Handle, you can usually use INVALID_HANDLE to specify the calling plugin.
__________________
Dr. McKay is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-29-2012 , 20:10   Re: callfunc( function[], pluginname[] )
Reply With Quote #4

Quote:
Originally Posted by 11530 View Post
Not sure why you'd be wanting to do this, but since your functions don't use any parameters, try something like the following, but obviously fill in the blanks yourself.

PHP Code:
new String:g_sMyFunctions[2][32] = { "test_function1""test_function2" };
new 
Handle:g_hPlugin INVALID_HANDLE;

public 
OnPluginStart()
{
    
g_hPlugin GetMyHandle();
    
CallSomething(0);
}


CallSomething(num)
{
    if ((
num 0) || (num >= sizeof(g_sMyFunctions)))
    {
        return;
    }
    
    new Function:
func GetFunctionByName(g_hPluging_sMyFunctions[num]);
    if (
func != INVALID_FUNCTION)
    {
        
Call_StartFunction(g_hPluginfunc);
        
Call_Finish();
    }
}

test_function1() {}
test_function2() {} 
Basically i can use this GetFunctionByName(g_hPlugin, g_sMyFunctions[num]) in any time and in any place right?
.Dare Devil. is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-29-2012 , 20:15   Re: callfunc( function[], pluginname[] )
Reply With Quote #5

Quote:
Originally Posted by Dr. McKay View Post
11530: There's almost never any reason to use GetMyHandle. When using functions that require a plugin Handle, you can usually use INVALID_HANDLE to specify the calling plugin.
Ah, didn't know that. Cheers!

@.Dare Devil. Yep, just ensure you use similar checks too.
__________________
11530 is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-29-2012 , 20:33   Re: callfunc( function[], pluginname[] )
Reply With Quote #6

Quote:
Originally Posted by 11530 View Post
Ah, didn't know that. Cheers!

@.Dare Devil. Yep, just ensure you use similar checks too.
Sweet!
Also is that integer value Call_PushCell( 24 ) ?

Last edited by .Dare Devil.; 09-29-2012 at 20:33.
.Dare Devil. is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-29-2012 , 20:56   Re: callfunc( function[], pluginname[] )
Reply With Quote #7

Yep.
__________________
11530 is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 09-29-2012 , 21:21   Re: callfunc( function[], pluginname[] )
Reply With Quote #8

Quote:
Originally Posted by .Dare Devil. View Post
Basically i can use this GetFunctionByName(g_hPlugin, g_sMyFunctions[num]) in any time and in any place right?
It's easier to use

PHP Code:
GetFunctionByName(INVALID_HANDLEg_sMyFunctions[num]) 
INVALID_HANDLE specifies the calling plugin.

Then you can get rid of

PHP Code:
new Handle:g_hPlugin INVALID_HANDLE
and

PHP Code:
g_hPlugin GetMyHandle(); 
__________________

Last edited by Dr. McKay; 09-29-2012 at 21:22.
Dr. McKay is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-29-2012 , 21:58   Re: callfunc( function[], pluginname[] )
Reply With Quote #9

thanks guys!
.Dare Devil. is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 09-29-2012 , 22:07   Re: callfunc( function[], pluginname[] )
Reply With Quote #10

Why do you need to call functions like that?
__________________
FaTony 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:45.


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