Raised This Month: $ Target: $400
 0% 

Custom message in console when access is denied


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Janet Jackson
Veteran Member
Join Date: Mar 2005
Location: far, far away from here
Old 11-06-2005 , 19:52   Custom message in console when access is denied
Reply With Quote #1

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 ?
__________________
Janet Jackson is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 11-06-2005 , 19:57  
Reply With Quote #2

Take out the first return.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 11-06-2005 , 20:01  
Reply With Quote #3

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;     }     // ..
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 11-06-2005 , 20:02  
Reply With Quote #4

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 }
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 11-06-2005 , 20:04  
Reply With Quote #5

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Janet Jackson
Veteran Member
Join Date: Mar 2005
Location: far, far away from here
Old 11-06-2005 , 20:46  
Reply With Quote #6

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.
__________________
Janet Jackson is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 11-06-2005 , 21:08  
Reply With Quote #7

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

psst... use whichever you prefer.
Brad is offline
Janet Jackson
Veteran Member
Join Date: Mar 2005
Location: far, far away from here
Old 11-06-2005 , 21:44  
Reply With Quote #8



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 ?
__________________
Janet Jackson is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 11-06-2005 , 22:00  
Reply With Quote #9

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
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Janet Jackson
Veteran Member
Join Date: Mar 2005
Location: far, far away from here
Old 11-06-2005 , 22:19  
Reply With Quote #10

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.
__________________
Janet Jackson is offline
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 23:40.


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