Raised This Month: $ Target: $400
 0% 

problem with halting the plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Revelation
Junior Member
Join Date: Jan 2005
Old 01-13-2005 , 14:30   problem with halting the plugin
Reply With Quote #1

my plugin is slightly large, show I will only show the bits that are relevant:
Code:
/* VARIABLES */ new PLUGIN[]="Peep Show Server Settings" new AUTHOR[]="Revelation" new VERSION[]="1" new sCmd[64] /* server_cmd("?") */ new sLive[64]="exec cfgs/live.cfg" new sKnives[64]="exec cfgs/knives.cfg" new sPublic[64]="exec cfgs/public.cfg" new sWar[64]="exec cfgs/war.cfg" new sRR[64]="sv_restartround 1" /* REGISTER PLUGIN AND COMMANDS */ public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say /live","cmd_live",ADMIN_KICK,"execute the servers live.cfg")     register_concmd("say /knives","cmd_knives",ADMIN_KICK,"execute the servers knives.cfg")     register_concmd("say /public","cmd_public",ADMIN_KICK,"execute the servers public.cfg")     register_concmd("say /war","cmd_war",ADMIN_KICK,"execute the servers war.cfg")     register_concmd("say /rr","cmd_rr",ADMIN_KICK,"server command: sv_restartround 1") } /* AMX NO ACCESS */ public cmd_noaccess(id) {     client_print(id, print_chat, "You do not have acces to this command.")     return PLUGIN_HANDLED } /* RUN COMMAND ON SERVER */ public cmd_run() {     server_cmd(sCmd)     server_exec()     return PLUGIN_HANDLED } /* EXEC LIVE.CFG */ public cmd_live(id, level, cid) {     if (!cmd_access(id, level, cid, 0)) {         cmd_noaccess(id)     }     copy(sCmd,64,sLive)     cmd_run() }
Everything works fine, when an admin runs the command "say /live" the server does 3rr etc etc but the problem is when a non admin runs my command. When someone who isnt a non admin trys "say /live" it first displays "you do not have access to this command" but then it goes ahead and executes the comand anyone even though i have "return PLUGIN_HANDLED" in the function cmd_access. Could someone please help me out, im abit lost. thanks Adam
Revelation is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 01-13-2005 , 14:57  
Reply With Quote #2

Yeah.

Code:
public cmd_noaccess(id) {     client_print(id, print_chat, "You do not have acces to this command.")     return PLUGIN_HANDLED }

So, the function cmd_noaccess return PLUGIN_HANDLED. But, you don't do anything with the return value. If you do something like this:

Code:
func2() {    return 5; } func1() {    func2(); }
The return value of func1 won't be 5 (or, at least shouldn't be ).

Change your code to this:
Code:
/* VARIABLES */ new PLUGIN[]="Peep Show Server Settings" new AUTHOR[]="Revelation" new VERSION[]="1" new sCmd[64] /* server_cmd("?") */ new sLive[64]="exec cfgs/live.cfg" new sKnives[64]="exec cfgs/knives.cfg" new sPublic[64]="exec cfgs/public.cfg" new sWar[64]="exec cfgs/war.cfg" new sRR[64]="sv_restartround 1" /* REGISTER PLUGIN AND COMMANDS */ public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say /live","cmd_live",ADMIN_KICK,"execute the servers live.cfg")     register_concmd("say /knives","cmd_knives",ADMIN_KICK,"execute the servers knives.cfg")     register_concmd("say /public","cmd_public",ADMIN_KICK,"execute the servers public.cfg")     register_concmd("say /war","cmd_war",ADMIN_KICK,"execute the servers war.cfg")     register_concmd("say /rr","cmd_rr",ADMIN_KICK,"server command: sv_restartround 1") } /* RUN COMMAND ON SERVER */ public cmd_run() {     server_cmd(sCmd)     server_exec()     return PLUGIN_HANDLED } /* EXEC LIVE.CFG */ public cmd_live(id, level, cid) {     if (!cmd_access(id, level, cid, 0)) {         client_print(id, print_chat, "You do not have acces to this command.")         return PLUGIN_HANDLED;     }     copy(sCmd,64,sLive)     cmd_run() }
__________________
hello, i am pm
PM is offline
Revelation
Junior Member
Join Date: Jan 2005
Old 01-13-2005 , 15:07  
Reply With Quote #3

thanks for your reply although i still dont understand this return PLUGIN_HANDLED - does the command just stop all execution of code, within that function? what would happen if i didnt return anything, i read in the amxmodx docs that it would display "unknown command" in the client console
Revelation is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 01-13-2005 , 15:15  
Reply With Quote #4

erm...pm...correct me if im wrong but...um

Code:
if (!cmd_access(id, level, cid, 0)) {
to

Code:
if (!cmd_access(id, level, cid, 1)) {
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
Revelation
Junior Member
Join Date: Jan 2005
Old 01-13-2005 , 15:17  
Reply With Quote #5

Quote:
Originally Posted by Da Bishop
erm...pm...correct me if im wrong but...um

Code:
if (!cmd_access(id, level, cid, 0)) {
to

Code:
if (!cmd_access(id, level, cid, 1)) {
hmm, my way seems to work fine with the "0" instead of "1" just it continues running the next function. if your an admin i never see "you dont have access to this command. but im just a noob.
Revelation is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-13-2005 , 18:49  
Reply With Quote #6

What PM was saying is that in cmd_live you call cmd_noaccess. Inside of cmd_noaccess you return PLUGIN_HANDLED, and this stops cmd_noaccess, it does NOT stop cmd_live, since you never put a return statement inside of cmd_live itself. Additionally, the cmd_access function will print "You have no access to this command" by itself, so your entire cmd_noaccess function is useless, and it will be printed twice to the client.

When you call cmd_access, the last parameter is how many parameters the comand has, including the command itself. So if you have a command "amx_command <player> <0|1>" you would have a 3 for the last parameter in cmd_access. 1 is amx_comand, 2 is <player>, and 3 is <0|1>. When you do that, if a player only puts in "amx_command <player>", cmd_access will return an error and show the proper usage. This is also another reason why not to print "You do not have access to this command" yourself, as cmd_access may be false for different reasons. So, technically the last parameter in your case should be 1, although it does work with 0.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Da Bishop
Senior Member
Join Date: Aug 2004
Location: Chester County PA
Old 01-13-2005 , 20:11  
Reply With Quote #7

Try the plugin like this.


Code:
new PLUGIN[]="Peep Show Server Settings" new AUTHOR[]="Revelation" new VERSION[]="1" /* server_cmd("?") */ new sLive[64]="exec cfgs/live.cfg" new sKnives[64]="exec cfgs/knives.cfg" new sPublic[64]="exec cfgs/public.cfg" new sWar[64]="exec cfgs/war.cfg" new sRR[64]="sv_restartround 1" /* REGISTER PLUGIN AND COMMANDS */ public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say /live","cmd_live",ADMIN_KICK,"execute the servers live.cfg")     register_concmd("say /knives","cmd_knives",ADMIN_KICK,"execute the servers knives.cfg")     register_concmd("say /public","cmd_public",ADMIN_KICK,"execute the servers public.cfg")     register_concmd("say /war","cmd_war",ADMIN_KICK,"execute the servers war.cfg")     register_concmd("say /rr","cmd_rr",ADMIN_KICK,"server command: sv_restartround 1") } /* EXEC LIVE.CFG */ public cmd_live(id, level, cid) {     if (!cmd_access(id, level, cid, 1))       return PLUGIN_HANDLED         server_cmd(sLive)     server_exec()     return PLUGIN_HANDLED }
__________________
Anything that is done can only be done better by urself - since life is a opinion make it the way urs feel its best

~live by it
Da Bishop is offline
Send a message via MSN to Da Bishop
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 19:22.


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