AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Custom message in console when access is denied (https://forums.alliedmods.net/showthread.php?t=20345)

Janet Jackson 11-06-2005 19:52

Custom message in console when access is denied
 
Hi, I'm trying to keep a plugin available to people with ADMIN_RESERVATION only. So far so good, but I also want people that don't have this flag to get a custom message instead of the default "You don't have access to this command."

I tried this :
Code:
public cmd_HLMPmenu(id, level, cid) {     if (!cmd_access(id,level,cid,1))     client_print(id, print_console, "Custom message")     return PLUGIN_HANDLED     showMenu(id, g_showPos[id])     return PLUGIN_HANDLED }
but I get this error when compiling :
Code:

hlmp.sma(179) : warning 225: unreachable code
Can anyone point me in the right direction ?

v3x 11-06-2005 19:57

Take out the first return.

Hawk552 11-06-2005 20:01

Code:
#define ACCESS ADMIN_RESERVATION // ... register_clcmd("whatever","func",ACCESS,"stuff"); // ... public func(id) {     if(!(get_user_flags(id) & ACCESS))     {         client_print(id,print_chat,"ah ah ah, you didn't say the magic word");         return 0;     }     // ..

jtp10181 11-06-2005 20:02

Quote:

Originally Posted by v3x
Take out the first return.

actually... no, you need it, but you need {}
Also I would recomend console_print, just cause I like it better :)


Code:
 public cmd_HLMPmenu(id, level, cid) {     if (!cmd_access(id,level,cid,1))  {          console_print(id, "Custom message")            return PLUGIN_HANDLED      }     showMenu(id, g_showPos[id])     return PLUGIN_HANDLED }

Hawk552 11-06-2005 20:04

The problem with that is that cmd_access will print "You have no access to that command" anyways, so your message will come after it, and then it will stop.

Janet Jackson 11-06-2005 20:46

You guys are fast...

Thanks for all the help, I picked jtp10181's one and it works like a charm. It works like Hawk552 predicted, but in this case it is perfect.

Brad 11-06-2005 21:08

I recommend you stick with client_print and ignore jtp's recommendation to use console_print, just because that's my preference. :lol:

psst... use whichever you prefer.

Janet Jackson 11-06-2005 21:44

:lol:

Anyway, I have another question related to user flags. This time I'd like to prevent something to be forced on admins that have ADMIN_IMMUNITY. It's about this piece of code:
Code:
if (get_cvar_num(CVAR_FORCEFORUMNAME))                 force_forumname(id, oldname, authid)
It forces a name on the player, regardless immunity. I looked at the code of some other plugins and and Hawk552's code as posted above, and I thought this would do the trick :
Code:
if(!(get_user_flags(id) & ADMIN_IMMUNITY))             {                 return PLUGIN_CONTINUE                 }             if (get_cvar_num(CVAR_FORCEFORUMNAME))                 force_forumname(id, oldname, authid)
It compiles just fine, but it still doesn't respect the immunity. Has anyone got a suggestion ?

jtp10181 11-06-2005 22:00

Code:
if (!access(id,ADMIN_IMMUNITY) && get_cvar_num(CVAR_FORCEFORUMNAME))                 force_forumname(id, oldname, authid)

fyi you need the amxmisc.inc to use the "access" function

Janet Jackson 11-06-2005 22:19

Your suggestion works, but not consistently. As soon as I change my name forceforumname is performed on me, regardless my immunity.

amxmisc.inc is already included. What would the code look like if I use that method ? Something like this ?
Code:
#define IMMUNITY ADMIN_IMMUNITY // // if (!access(id,IMMUNITY) && get_cvar_num(CVAR_FORCEFORUMNAME))                 force_forumname(id, oldname, authid)
And would the result be any different ?

edit : no, that doesn't work at all. Although it compiles fine.


All times are GMT -4. The time now is 23:40.

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