AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calling Functions from other plugins (https://forums.alliedmods.net/showthread.php?t=9908)

Damocles 02-03-2005 06:00

Calling Functions from other plugins
 
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.

PM 02-03-2005 06:48

Use the callfunc mechanism to call functions from one plugin in an another one. Check out the funcwiki or do a forum search :)

Damocles 02-03-2005 08:12

Sorry PM, had a look now :D

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 ??

EKS 02-03-2005 10:56

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 :)

Damocles 02-03-2005 15:38

kk ty ;)

only problem with learning from other peoples code is you pick up bad habits and learn incorrect work arounds :D

Damocles 02-04-2005 07:03

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.

EKS 02-04-2005 14:55

Post the beginning line of the function your trying to look at

XxAvalanchexX 02-04-2005 16:03

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.

Freecode 02-04-2005 16:22

victim[] should be victim

XxAvalanchexX 02-04-2005 17:27

Why? He's sending a string.


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

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