AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   problem with halting the plugin (https://forums.alliedmods.net/showthread.php?t=9298)

Revelation 01-13-2005 14:30

problem with halting the plugin
 
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

PM 01-13-2005 14:57

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() }

Revelation 01-13-2005 15:07

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

Da Bishop 01-13-2005 15:15

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)) {

Revelation 01-13-2005 15:17

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. :roll:

XxAvalanchexX 01-13-2005 18:49

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.

Da Bishop 01-13-2005 20:11

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 }


All times are GMT -4. The time now is 19:22.

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