AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Fixing Plugin Confliction (https://forums.alliedmods.net/showthread.php?t=22688)

MOBOB 01-01-2006 19:30

Fixing Plugin Confliction
 
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

Des12 01-01-2006 20:04

I dont think they conflict, because the clcmds are different

Wolle 01-01-2006 20:08

I'm just curious.
What happens when you use "return PLUGIN_CONTINUE" instead of "return PLUGIN_HANDLED"?

PM 01-02-2006 04:54

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.

Dizzy 01-02-2006 10:56

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.

PM 01-02-2006 13:23

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.

TJA 04-15-2009 20:14

Re: Fixing Plugin Confliction
 
Now ... that is all interesting, BUT:

What more can happen if i use PLUGIN_CONTINUE everywhere?!?
Just that stupid error-message?

Exolent[jNr] 04-15-2009 20:23

Re: Fixing Plugin Confliction
 
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.

TJA 04-16-2009 08:21

Re: Fixing Plugin Confliction
 
Quote:

Originally Posted by Exolent[jNr] (Post 806471)
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?

ot_207 04-16-2009 08:23

Re: Fixing Plugin Confliction
 
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!


All times are GMT -4. The time now is 16:12.

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