Raised This Month: $ Target: $400
 0% 

Fixing Plugin Confliction


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MOBOB
Member
Join Date: Dec 2004
Old 01-01-2006 , 19:30   Fixing Plugin Confliction
Reply With Quote #1

I am running the teo following plugins on my server. The first one works and the second one doesnt. I suspect that there is some confliction between them because they are basically the same code. One grants clients a free gun once per map and one grants users hp or ap once per map. Can someone help me find the confliction and fix it?

Code:
#include <amxmodx>   #include <amxmisc>   #include <cstrike>   #include <fun>   #define PLUGIN "Health/Armor"   #define VERSION "1.0"   #define AUTHOR "|sXe| Mr. Foster"   new bool:user_tookhealth[33] public plugin_init() {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_clcmd("give", "cmd_weapon", ADMIN_LEVEL_G, "<give(hp, ap)>")         }   public client_putinserver(id) {     user_tookhealth[id] = false } public cmd_weapon(id, level, cid) {       if(!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED     if(user_tookhealth[id])         return PLUGIN_HANDLED             new requested[32]       read_argv(1, requested, 31)           new name[32]     get_user_name(id, name, 31)         if(equali(requested,"hp", 2))     {       set_user_health(id, 200)         client_print(0,print_chat, "%s used his Health/Armor power to give himself an 200 health", name)     client_print(0,print_chat, "Say /rewards to learn about donating to our server and receiving rewards.", name)           user_tookhealth[id] = true     }     else if(equali(requested,"ap", 2))     {       set_user_armor(id, 100)         client_print(0,print_chat, "%s used his Health/Armor power to give himself an 100 armor.", name)     client_print(0,print_chat, "Say /rewards to learn about donating to our server and receiving rewards.", name)           user_tookhealth[id] = true     }     return PLUGIN_HANDLED }

Code:
#include <amxmodx>   #include <amxmisc>   #include <cstrike>   #include <fun>   #define PLUGIN "Freegun"   #define VERSION "1.0"   #define AUTHOR "|sXe| Mr. Foster"   new bool:user_gothisgun[33] public plugin_init() {       register_plugin(PLUGIN, VERSION, AUTHOR)       register_clcmd("freegun", "cmd_weapon", ADMIN_LEVEL_H, "<weapon(m4, ak)>")   }   public client_putinserver(id) {     user_gothisgun[id] = false } public cmd_weapon(id, level, cid) {       if(!cmd_access(id, level, cid, 2))         return PLUGIN_HANDLED     if(user_gothisgun[id])         return PLUGIN_HANDLED             new whatwassaid[32]       read_argv(1, whatwassaid, 31)           new name[32]     get_user_name(id, name, 31)         if(equali(whatwassaid,"m4", 2))     {           give_item(id, "weapon_m4a1")           cs_set_user_bpammo(id, CSW_M4A1, 90)         client_print(0,print_chat, "%s used his freegun power to give himself an M4A1.", name)     client_print(0,print_chat, "Say /rewards to learn about dontating to our server and recieving rewards.", name)           user_gothisgun[id] = true     }     else if(equali(whatwassaid,"ak", 2))     {           give_item(id, "weapon_ak47")         cs_set_user_bpammo(id, CSW_AK47, 90)         client_print(0,print_chat, "%s used his freegun power to give himself an AK47.", name)     client_print(0,print_chat, "Say /rewards to learn about dontating to our server and recieving rewards.", name)           user_gothisgun[id] = true     }     return PLUGIN_HANDLED }

Thanks,
MOBOB
__________________
MOBOB is offline
Des12
Senior Member
Join Date: Jan 2005
Old 01-01-2006 , 20:04  
Reply With Quote #2

I dont think they conflict, because the clcmds are different
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
Wolle
Member
Join Date: Jun 2005
Location: Berlin / Germany
Old 01-01-2006 , 20:08  
Reply With Quote #3

I'm just curious.
What happens when you use "return PLUGIN_CONTINUE" instead of "return PLUGIN_HANDLED"?
Wolle is offline
Send a message via AIM to Wolle
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-02-2006 , 04:54  
Reply With Quote #4

Ah, no, well.

Both plugins register a client command ("give" and "freegun") and map it to their cmd_weapon public function. Yes, there are two of them, but they don't conflict because each one is in another plugin and they are mapped to two different clcmds. What WOULD conflict is if both plugins used the same command name (ie. the first parameter of register_clcmd was the same).

Well at least they shouldn't conflict, I just woke up and I'm confused.


Anyway, let's go on. What would happen if you returned PLUGIN_CONTINUE ? Let's go from the beginning (talking about client commands). Here is an example:

Plugin A registers client command hello
Plugin B registers client command hello (later than plugin A)

Okay, the simplest case is that plugin A returns PLUGIN_HANDLED from its handler. plugin B's handler won't execute at all.

The next case is that plugin A returns PLUGIN_CONTINUE. In this case, plugin B's handler will be executed. If plugin B's handler now returns PLUGIN_CONTINUE as well, you will get the "command not found" message in your console. If it returns PLUGIN_HANDLED, there will be no such message.

BUT!!!!!!!!!! THERE'S ONE MORE CASE!!!!!!! Plugin A can return PLUGIN_HANDLED_MAIN. Then plugin B's handler gets called. However, no matter what plugin B's handler returns - the result of the "whole operation" will be PLUGIN_HANDLED (because plugin A said it would be) - which means that you won't get that "command not found" message thing.

IIRC it's a bit different with server commands, because with client commands, server plugins act like filters. ie. the engine says: DUDE, LOOK, A CLIENT COMMAND ARRIVED and then each plugin can say "Yup, I handled it, it's ok" or "Oh noes LOL!!!!! NOES!!! I don't want this command". AMXX, being one of the server plugins, has two ways of performing this filtering action: 1) register_clcmd, which we've just talked about and 2) the client_command forward function, which works just like metamod's ClientCommand forward. Okay, so what's the matter with server commands? Well, here, the engine does the filtering. That is, you say, "I register command gaben" and then the engine always knows that command gaben is registered by you, so it only calls your handler. You can't decide "I don't know this server command" once you've registered it (unlike with client commands). However, you can decide whether subsequent handlers of the same command will be executed by returning either PLUGIN_CONTINUE or PLUGIN_HANDLED. Note that I'm not completly sure about the server commands thing.
__________________
hello, i am pm
PM is offline
Dizzy
Veteran Member
Join Date: Jun 2004
Location: Massachusetts
Old 01-02-2006 , 10:56  
Reply With Quote #5

Wouldn't you want to do this

Code:
    if(user_gothisgun[id]) = true         return PLUGIN_HANDLED

instead of this
Code:
    if(user_gothisgun[id])         return PLUGIN_HANDLED

If your using true and false you want to tell it what it's looking for.

Correct me if I'm wrong.
__________________
My Plugins

Purchase Mod - Stable
Type Sounds - Stable
Monster Spawner - Stable
Nade Giver - Maintenance
Dizzy is offline
Send a message via AIM to Dizzy
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-02-2006 , 13:23  
Reply With Quote #6

You probably mean

Code:
if (user_gothisgun[id] == true)

(note that the == true part is inside the parenthesis and that you have to use the == operator for comparision (instead of = which is assignment)).

However, in this case, it has the same effect. false is 0 and true is 1, and
Code:
if (expression) {    thefreakingcode }
Evaluates thefreakingcode if, and only if expression is non-zero.

This means that
Code:
if (user_gothisgun[id])
is equivalent to
Code:
if (user_gothisgun[id] != 0)
which is
Code:
if (user_gothisgun[id] != false)

If you are only using true/false (as in this example), != false is basically the same as checking for == true.
__________________
hello, i am pm
PM is offline
TJA
Junior Member
Join Date: May 2005
Old 04-15-2009 , 20:14   Re: Fixing Plugin Confliction
Reply With Quote #7

Now ... that is all interesting, BUT:

What more can happen if i use PLUGIN_CONTINUE everywhere?!?
Just that stupid error-message?
TJA is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2009 , 20:23   Re: Fixing Plugin Confliction
Reply With Quote #8

If you use PLUGIN_CONTINUE, then for commands that are chat messages such as /me will be shown in chat.
Also, more than one plugin can register the same command as long as PLUGIN_HANDLED is never returned.

By the way, don't revive a 3-year-old topic again.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
TJA
Junior Member
Join Date: May 2005
Old 04-16-2009 , 08:21   Re: Fixing Plugin Confliction
Reply With Quote #9

Quote:
Originally Posted by Exolent[jNr] View Post
By the way, don't revive a 3-year-old topic again.
Why not?
It contains exactly the discussion with information that seem to help
I can start a new one, but what is the difference?

On topic:

Now, PLUGIN_CONTINUE is the default, so only in some cases that should be changed to PLUGIN_HANDLED* - if required.

So far, i just cannot find a situation where changing this to PLUGIN_HANDLED* is required!
For what reason?

If the only effect of using PLUGIN_CONTINUE everywhere, is the message "command not found", it seems, i could just use PLUGIN_CONTINUE everywhere.

No?
Yes?
TJA is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 04-16-2009 , 08:23   Re: Fixing Plugin Confliction
Reply With Quote #10

It depends on the context you use the PLUGIN_HANDLED/CONTINUE

HANDLED means that you break the operation that is hooked, but not all the time!
CONTINUE means that you didn't do any modifications so the action will continue!
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Reply


Thread Tools
Display Modes

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 16:12.


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