AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Registering Same Commands (https://forums.alliedmods.net/showthread.php?t=241455)

akcaliberg 06-03-2014 20:02

Registering Same Commands
 
Is there any problem with registering the same client commands in different plugins ?

For example, when a user typed the X command, two or more plugins must be called.

Let's say, I have a plugin like this

PHP Code:

new bool:is_logged[32];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("login","cmdLogin")
    
register_clcmd("func_x","cmdX")
}
public 
cmdLogin(id) {
    new 
arg[32];
    
read_argv(1,arg,31)
    
    if(
equal(arg,"123")) {
        
console_print(id,"Logged in.")
        
is_logged[id] = true;
        return 
PLUGIN_HANDLED
    
}
    
console_print(id,"Wrong password")
    return 
PLUGIN_HANDLED
}
public 
cmdX(id) {
    if(!
is_logged[id]) {
        
console_print(id,"You are not authorized to use this function.")
        return 
PLUGIN_HANDLED
    
}
    
    
//...



and this

PHP Code:


new bool:is_logged[32];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("login","cmdLogin")
    
register_clcmd("func_y","cmdY")
}
public 
cmdLogin(id) {
    new 
arg[32];
    
read_argv(1,arg,31)
    
    if(
equal(arg,"123")) {
        
console_print(id,"Logged in.")
        
is_logged[id] = true;
        return 
PLUGIN_HANDLED
    
}
    
console_print(id,"Wrong password")
    return 
PLUGIN_HANDLED
}
public 
cmdY(id) {
    if(!
is_logged[id]) {
        
console_print(id,"You are not authorized to use this function.")
        return 
PLUGIN_HANDLED
    
}
    
    
//...



YamiKaitou 06-03-2014 20:16

Re: Registering Same Commands
 
There is nothing wrong with it. Just note that if any of the plugins return PLUGIN_HANDLED, none of the other plugins will be called. You can use PLUGIN_HANDLED_MAIN to have the same effects as PLUGIN_HANDLED but still allow the other plugins to be called

aron9forever 06-04-2014 02:43

Re: Registering Same Commands
 
Quote:

Originally Posted by YamiKaitou (Post 2146438)
There is nothing wrong with it. Just note that if any of the plugins return PLUGIN_HANDLED, none of the other plugins will be called. You can use PLUGIN_HANDLED_MAIN to have the same effects as PLUGIN_HANDLED but still allow the other plugins to be called

gonna expand a little on this since I've had trouble understanding at first, hope nobody minds

plugin1
plugin2
plugin3
all use the same command
if plugin 2 has return PLUGIN_HANDLED at the end of the function the command calls, the command will no longer work for plugin 3
it goes on like this depending on their order in plugins.ini

Flick3rR 06-04-2014 03:57

Re: Registering Same Commands
 
Yes. And to avoid this, use handled main, which will stop the function only for the current plugin.

akcaliberg 06-05-2014 13:41

Re: Registering Same Commands
 
Then, what is the difference between PLUGIN_HANDLED_MAIN and PLUGIN_CONTINUE

I suppose PLUGIN_CONTINUE stops the call for the current plugin, but lets the call continue to following plugins.

So what does PLUGIN_HANDLED_MAIN differently from PLUGIN_CONTINUE

aron9forever 06-05-2014 14:17

Re: Registering Same Commands
 
Quote:

Originally Posted by akcaliberg (Post 2147231)
Then, what is the difference between PLUGIN_HANDLED_MAIN and PLUGIN_CONTINUE

I suppose PLUGIN_CONTINUE stops the call for the current plugin, but lets the call continue to following plugins.

So what does PLUGIN_HANDLED_MAIN differently from PLUGIN_CONTINUE

you got it wrong
PLUGIN_HANDLED immediately stops execution of other handlers in plugins and mod dll / engine
PLUGIN_HANDLED_MAIN halts the function from being called in the mod DLL or the engine(not from other plugins)
PLUGIN_CONTINUE - default value - does nothing basically, you don't need it for simple stuff


All times are GMT -4. The time now is 09:48.

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