Raised This Month: $ Target: $400
 0% 

Registering Same Commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 06-03-2014 , 20:02   Registering Same Commands
Reply With Quote #1

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
    
}
    
    
//...

akcaliberg is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-03-2014 , 20:16   Re: Registering Same Commands
Reply With Quote #2

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-04-2014 , 02:43   Re: Registering Same Commands
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
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
aron9forever is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-04-2014 , 03:57   Re: Registering Same Commands
Reply With Quote #4

Yes. And to avoid this, use handled main, which will stop the function only for the current plugin.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 06-05-2014 , 13:41   Re: Registering Same Commands
Reply With Quote #5

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

Last edited by akcaliberg; 06-05-2014 at 13:41.
akcaliberg is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 06-05-2014 , 14:17   Re: Registering Same Commands
Reply With Quote #6

Quote:
Originally Posted by akcaliberg View Post
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
aron9forever 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 09:48.


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