Raised This Month: $ Target: $400
 0% 

Calling function from another plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KadiR
Unnecessary Member
Join Date: Aug 2008
Location: Zürich / Switzerland
Old 01-24-2010 , 06:48   Calling function from another plugin
Reply With Quote #1

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?
KadiR is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-24-2010 , 07:51   Re: Calling function from another plugin
Reply With Quote #2

Look for callfunc_*
__________________
xPaw is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 01-24-2010 , 08:43   Re: Calling function from another plugin
Reply With Quote #3

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.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-24-2010 , 09:05   Re: Calling function from another plugin
Reply With Quote #4

Also note that callfunc_end provides the possible return value of the function.
SnoW is offline
Send a message via MSN to SnoW
KadiR
Unnecessary Member
Join Date: Aug 2008
Location: Zürich / Switzerland
Old 01-24-2010 , 14:43   Re: Calling function from another plugin
Reply With Quote #5

Quote:
Originally Posted by joropito View Post
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!
KadiR is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-24-2010 , 15:47   Re: Calling function from another plugin
Reply With Quote #6

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
KadiR
Unnecessary Member
Join Date: Aug 2008
Location: Zürich / Switzerland
Old 01-24-2010 , 15:54   Re: Calling function from another plugin
Reply With Quote #7

Since I don't have much experience in scripting, I would like to continue with joropito's example with callfunc_begin.
KadiR is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 01-24-2010 , 17:18   Re: Calling function from another plugin
Reply With Quote #8

Quote:
Originally Posted by KadiR View Post
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.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-24-2010 , 17:33   Re: Calling function from another plugin
Reply With Quote #9

Quote:
Originally Posted by KadiR View Post
EDIT: Kid, please get the fuck out if you can't read anything. Think before posting, thanks!
Who the hell are you talking to?
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-25-2010 , 01:31   Re: Calling function from another plugin
Reply With Quote #10

Quote:
Originally Posted by KadiR View Post
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 View Post
Who the hell are you talking to?
Potential flaming answers i guess
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 07:26.


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