AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   return PLUGIN_* (https://forums.alliedmods.net/showthread.php?t=10493)

TaRgEt-PrAcTiCe21 02-21-2005 04:02

return PLUGIN_*
 
Ok, i'm sort of new to writing small. I understand it for the most part except or the return PLUGIN_ command. I know when to use them and stuff it's just that i'm a little slow in the head and I need someone to explain the difference between PLUGIN_HANDLED and PLUGIN_CONTINUE. If you could elaborate this for me i would love you forever. :D

xeroblood 02-21-2005 10:09

PLUGIN_CONTINUE and PLUGIN_HANDLED are returned from AMXX Forwards and Registered Commands that tell AMXX what to do after your function has been executed.

If your function returns PLUGIN_CONTINUE you are telling AMXX to continue processing the same function in other plugins. An example would be

public plugin_cfg() { return PLUGIN_CONTINUE }

plugin_cfg() is an AMXX Forward function, and by returning PLUGIN_CONTINUE you are telling AMXX to continue processing the plugin_cfg() function of other plugins found in your plugins.ini listed *after* your plugin..

If you returned PLUGIN_HANDLED from plugin_cfg() then any other plugins that are listed below yours in plugins.ini which use the Forward plugin_cfg() will not be allowed to execute their respective plugin_cfg() function..

You should almost always return PLUGIN_CONTINUE from AMXX Forwards, however, there are logical exceptions...

Now, with Registered Commands, you get to "Invent" the name of the command and the name of the function that it calls, an example would be:

register_clcmd( "amx_stuff", "DoStuff" )

'amx_stuff' is the name of the command that we are inventing, and the respective Small C Function which we create we called 'DoStuff'..

Now, since probably no other AMXX plugin will have the same command 'amx_stuff' we don't need to worry about other plugins calling our invented command, so we are free to (and encouraged to) return PLUGIN_HANDLED which tells AMXX that after executing our 'DoStuff' command AMXX is done, and does not need to look for the same function from other plugins.

Basically, PLUGIN_CONTINUE tells AMXX to continue processing equivalent functions in other plugins, whereas PLUGIN_HANDLED tells AMXX the exact opposite, to stop proccessing equivalent functions in other plugins..

I hope that helps a bit..

PM 02-21-2005 11:08

plugin_cfg is a bad example. Here is a list of core forwards and what they do with your return value:

plugin_init - return value ignored
client_command - What xeroblood described
client_connect - return value ignored
client_disconnect - return value ignored
client_infochanged - return value ignored
client_putinserver - return value ignored
plugin_cfg - return value ignored
plugin_precache - return value ignored
plugin_log - What xeroblood described
plugin_end - return value ignored
inconsistent_file - What xeroblood described
client_authorized - return value ignored
server_changelevel - What xeroblood described

xeroblood 02-21-2005 13:47

Ooooh.. thx for clearing that up PM!!
I thought they were all handled the same way internally with regards to the return value..

Thx for that list too, now I know which forwards I can omit the return value of completely!! I'm surprised to see that so many are actually ignored..

:D

PM 02-21-2005 14:28

Quote:

Originally Posted by xeroblood
Ooooh.. thx for clearing that up PM!!
I thought they were all handled the same way internally with regards to the return value..

Thx for that list too, now I know which forwards I can omit the return value of completely!! I'm surprised to see that so many are actually ignored..

:D

It would be pretty bad if a plugin decided to block plugin_init ^^

You can search meta_api for "plugin_init" (in quotes), there you will have ET_IGNORE which means the return value is ignored :)

ET_STOP means the "normal PLUGIN_HANDLED system" (basically, nonzero value -> stop executing plugins and return the value that the plugin returned)

ET_STOP2 is like ET_STOP but support PLUGIN_HANDLED_MAIN (-> stop execution on a PLUGIN_HANDLED, continue otherwise, returns the highest return value)

ET_CONTINUE means ignore return value and return the highest one (useful for one-plugin-only forwards).

More on this in CForward.h

TaRgEt-PrAcTiCe21 02-21-2005 15:20

Wow, thanks you guys, this is going to help my tons. I'll just have to experiment a little to see what i'm able to do with my plugins. :D

Geesu 02-21-2005 16:46

PM so if 2 plugins catch the command hegren and one does return PLUGIN_HANDLED, the other won't be able to see it?

xeroblood 02-21-2005 18:05

I know you're asking PM, but I think you're right anyway..

if pluginA hooks hegren using client_command, and returns PLUGIN_HANDLED, then pluginB wont be able to hook hegren using client_command, but only if pluginA is listed before pluginB in plugins.ini

If pluginA were listed very last in plugins.ini then it wouldn't affect the other plugins...

Is this correct?

Geesu 02-22-2005 08:26

that would suck, b/c war3ft is always like the last plugin loaded LOL, luckily I don't think any default plugins return PLUGIN_HANDLED on hegren


All times are GMT -4. The time now is 14:11.

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