AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calling function from another plugin (https://forums.alliedmods.net/showthread.php?t=116564)

KadiR 01-24-2010 06:48

Calling function from another plugin
 
I heard that you can call a function from another plugin into the other with callfunc_begin, If I am right..
So can someone help me with it? I looked into much topics, but coudln't do it exactly.
But I like to call the function like that from a plugin which name is test.amxx:

PHP Code:

    case 1:
    {
            
another_plugin_func(id);
    } 

The function's name in the test.amxx is another_plugin_func. So, what do I exactly need to put in those plugins?:crab:

xPaw 01-24-2010 07:51

Re: Calling function from another plugin
 
Look for callfunc_*

joropito 01-24-2010 08:43

Re: Calling function from another plugin
 
PHP Code:

public somelocal(idname[])
{
    if( 
callfunc_begin("someremote","otherplugin.amxx") == 
    {
        
callfunc_push_int(id)
        
callfunc_push_str(name)
        
callfunc_end()
    }


1- begin [setting up call]
2- push [values as parameters]
3- end [setup and do the call]

someremote must be public function in the other plugin.

SnoW 01-24-2010 09:05

Re: Calling function from another plugin
 
Also note that callfunc_end provides the possible return value of the function.

KadiR 01-24-2010 14:43

Re: Calling function from another plugin
 
Quote:

Originally Posted by joropito (Post 1065640)
PHP Code:

public somelocal(idname[])
{
    if( 
callfunc_begin("someremote","otherplugin.amxx") == 
    {
        
callfunc_push_int(id)
        
callfunc_push_str(name)
        
callfunc_end()
    }


1- begin [setting up call]
2- push [values as parameters]
3- end [setup and do the call]

someremote must be public function in the other plugin.

Thanks very much. It works for me, but not 100%. I have this in the otherplugin.amxx:

PHP Code:

public someremote(id){
    if(
get_pcvar_num(p_game)&&isalive(id)&&notadmin(id)){ 

It works well, till the function isalive comes. This is in isalive:

PHP Code:

public isalive(id){
    if(
is_user_alive(id))return 1
    client_print
(id,"PLUGIN stops here -.- , you aren't alive dude!")
    return 
0


But if I do in the same plugin ( otherplugin.amxx ) a
PHP Code:

register_clcmd 

then it does work and continue also after notadmin...

EDIT: Kid, please get the fuck out if you can't read anything. Think before posting, thanks!

ConnorMcLeod 01-24-2010 15:47

Re: Calling function from another plugin
 
If both plugins are yours, you shoud consider using dynamic natives, it's faster to call 1 native than to call few callfunc_*

http://forums.alliedmods.net/showthread.php?t=41251


In another hand, if you want to release a plugin, and if you want that plugin to be able to interact with an already released plugin, then you can consider callfunc.

KadiR 01-24-2010 15:54

Re: Calling function from another plugin
 
Since I don't have much experience in scripting, I would like to continue with joropito's example with callfunc_begin.

joropito 01-24-2010 17:18

Re: Calling function from another plugin
 
Quote:

Originally Posted by KadiR (Post 1066137)
Since I don't have much experience in scripting, I would like to continue with joropito's example with callfunc_begin.

Post both plugins here to see the full code and found the error.

As Connor says, dynamic natives are very easy and when you own both scripts it's the easy way because you call remote functions like a local one.

fysiks 01-24-2010 17:33

Re: Calling function from another plugin
 
Quote:

Originally Posted by KadiR (Post 1066055)
EDIT: Kid, please get the fuck out if you can't read anything. Think before posting, thanks!

Who the hell are you talking to?

ConnorMcLeod 01-25-2010 01:31

Re: Calling function from another plugin
 
Quote:

Originally Posted by KadiR (Post 1066137)
Since I don't have much experience in scripting, I would like to continue with joropito's example with callfunc_begin.

You can use style 1, this way you retrieve args the same (roughly) way you would do with a stock.


Quote:

Originally Posted by fysiks (Post 1066270)
Who the hell are you talking to?

Potential flaming answers i guess :grrr:


All times are GMT -4. The time now is 07:26.

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