Raised This Month: $ Target: $400
 0% 

Calling Functions from other plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Damocles
Member
Join Date: Jan 2005
Old 02-03-2005 , 06:00   Calling Functions from other plugins
Reply With Quote #1

Right this is a simple enough question, but its the first time ive done it and i cant get it to work :/

OK, what i want to do is call a function in one plugin from another plugin. In this instance i want to modify my ATAC plugin to send a message to my IRC plugin.

So in my IRC plugin ive added this code:

Code:
register_srvcmd("amx_ircmsg_kick", "inform_kick") public inform_kick() {         if (INFORMKICK)     {           new channel[64]         get_cvar_string("amx_irc_chan", channel, 63)         new victim[32]         read_argv(1, victim, 31)         new output[1024]         format(output, 1023, "PRIVMSG %s :4[cz]1 %s : Kicking %s For TK Violations^n", channel, victim)         socket_send(connection, output, 1023)     }   }

And in my ATAC plugin ive added this:

Code:
server_cmd("amx_ircmsg_kick %s", kName)

Now, when this function should be called by the ATAC plugin it doesnt work. When i try to force it to work by typing the 'amx_ircmsg_kick' command by hand i get these errors:

Quote:
rcon amx_ircmsg_kick Test
L 02/03/2005 - 10:48:48: [AMXX] Run time error 25 (parameter error) (plugin "ircbot.amxx") - debug not enabled.
L 02/03/2005 - 10:48:48: String formatted incorrectly - parameter 6 (total 5)
L 02/03/2005 - 10:48:48: [AMXX] To enable debug mode, add " debug" after the plugin name in plugins.ini (without quot
So how can i get this to work?? Thanks for any help

Damo.
Damocles is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 02-03-2005 , 06:48  
Reply With Quote #2

Use the callfunc mechanism to call functions from one plugin in an another one. Check out the funcwiki or do a forum search
__________________
hello, i am pm
PM is offline
Damocles
Member
Join Date: Jan 2005
Old 02-03-2005 , 08:12  
Reply With Quote #3

Sorry PM, had a look now

The reason i asked was because i know that Yomama did something like this with his amx_bans plugin and the ATAC plugin:

Quote:

Change this...

Code:
if( atac_banvia == 2 ) // If LAN or IP ban via IP     server_cmd("addip %i %s;writeip;kick #%d", atac_bantime, kIP, userid) else     server_cmd("banid %i #%d kick;writeid", atac_bantime, userid)

to this...

Code:
if( atac_banvia == 2 ) // If LAN or IP ban via IP     server_cmd("addip %i %s;writeip;kick #%d", atac_bantime, kIP, userid) else     server_cmd("amx_ban %i %s Team kill violation", atac_bantime, kAuthid)
There's that server_cmd("amx_ban ......) line in there which looks like it directly calls the amx_ban function in the amx_bans plugin, thats why i thought i could do it like i had up the top. Is this not a good way to do it ??
Damocles is offline
EKS
Veteran Member
Join Date: Mar 2004
Location: Norway
Old 02-03-2005 , 10:56  
Reply With Quote #4

No its a bad way.

Use either callfunc_being() or callfunc_begin_i()

Code:
stock GetUserRune(id) {     callfunc_begin("Funtion2Call","NameOfPlugin.amxx")     callfunc_push_int(id)     callfunc_end() }

The function you calling in NameOfPlugin.amxx needs to be public btw
__________________
Github archive for plugins, the repos for the other c++ projects are there to.
EKS is offline
Damocles
Member
Join Date: Jan 2005
Old 02-03-2005 , 15:38  
Reply With Quote #5

kk ty ;)

only problem with learning from other peoples code is you pick up bad habits and learn incorrect work arounds
Damocles is offline
Damocles
Member
Join Date: Jan 2005
Old 02-04-2005 , 07:03  
Reply With Quote #6

OK, Ive tried using callfunc and i cant seem to get it to work, heres what ive got..

Code:
client_print(0, print_chat, "CLIENT ABOUT TO BE KICKED!")         callfunc_begin("inform_kick", "ircbot.amxx"); callfunc_push_str(kName); new returnvalue = callfunc_end(); switch (returnvalue) {     case 1 : client_print(0, print_chat, "Success")     case 2 : client_print(0, print_chat, "Runtime Error")     case 3 : client_print(0, print_chat, "Plugin not found")     case 4 : client_print(0, print_chat, "Function not found") }

That (should) execute the 'inform_kick' function in ircbot.amxx. Note that ive put in the case for my own bug checking at the moment to see if it prints any output....i get nothing at the moment, although i know the code must be getting called because 'CLIENT ABOUT TO BE KICKED!' is displayed.

It must be something to do with the above because its not priting any of the return values after it should have executed the function

Heres the code for the 'inform_kick' function

Code:
public inform_kick(victim[]) {     new channel[64]     get_cvar_string("amx_irc_chan", channel, 63)     new output[1024]         format(output, 1023, "PRIVMSG %s :4[cz]1 %s : Kicking %s For TK Violations^n", channel, victim)         socket_send(connection, output, 1023) }

Anyone got any suggestions, something else i should be doing ??

Thanks

Damo.
Damocles is offline
EKS
Veteran Member
Join Date: Mar 2004
Location: Norway
Old 02-04-2005 , 14:55  
Reply With Quote #7

Post the beginning line of the function your trying to look at
__________________
Github archive for plugins, the repos for the other c++ projects are there to.
EKS is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-04-2005 , 16:03  
Reply With Quote #8

You check inform_kick for a return value, but it doesn't have one...

callfunc_begin returns the following:
1 - Success
0 - Runtime error (=never)
-1 - Plugin not found
-2 - Function not found

callfunc_end returns the return value passed from the function called.

Therefore you are checking if inform_kick returned 1, or 2, or 3, etcetera, because you catch the value from callfunc_end, but it doesn't return anything.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 02-04-2005 , 16:22  
Reply With Quote #9

victim[] should be victim
Freecode is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-04-2005 , 17:27  
Reply With Quote #10

Why? He's sending a string.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX 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 19:26.


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