Raised This Month: $51 Target: $400
 12% 

How to get actual cvar name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-21-2015 , 09:30   How to get actual cvar name
Reply With Quote #1

cvar = register_cvar("very_cool_cvar", "1")

I know that I can get the "1" with get_pcvar_num, but is it possible to get the string "very_cool_cvar"?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 09-21-2015 , 10:08   Re: How to get actual cvar name
Reply With Quote #2

Are you banned on google ?
https://www.amxmodx.org/api/cvars/get_pcvar_string
siriusmd99 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-21-2015 , 10:57   Re: How to get actual cvar name
Reply With Quote #3

Quote:
Originally Posted by siriusmd99 View Post
He wants the cvar name, he is not asking how to get a string value from a cvar. OP, why do you need this ?
__________________
HamletEagle is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 09-21-2015 , 13:31   Re: How to get actual cvar name
Reply With Quote #4

i think you need this :
Quote:
native CvarGetName( handleCvar, const cvar[], len );
Click Here
siriusmd99 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-21-2015 , 13:40   Re: How to get actual cvar name
Reply With Quote #5

You should explain what are you really trying to achieve, because getting name is usually not useful.
__________________
Arkshine is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-22-2015 , 08:34   Re: How to get actual cvar name
Reply With Quote #6

I came up with the idea of making a CS Essentials plugin, inspired by the one used in Minecraft. If you're not familiar with it, the plugin has a bunch of commands that use special permissions, for example "essentials.tphere" (this permission allows you to use the "/tphere" command). In order to achieve something similar, I register every permission as a cvar and add an admin flag to it - register_cvar("essentials.tphere", "d"). So, when the user doesn't have the required flag, I want to make a chat message that will say "Insufficent permissions ( essentials.tphere ). Isn't there a simple way of doing this?
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-22-2015 , 08:48   Re: How to get actual cvar name
Reply With Quote #7

You will have to use get_plugins_cvar/nums() so to loop over all cvars, checking by handle, then saving the cvar name.

In 1.8.3, I did added first a get_pcvar_name, but removed later because could not find any usefulness in it. Could add a stock using above natives, or reintroducing get_pcvar_name, don't know.
__________________
Arkshine is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-22-2015 , 09:43   Re: How to get actual cvar name
Reply With Quote #8

I'd rather make it like this for now:

PHP Code:
new essentials_tpessentials_tphere
new const g_Permissions[][] = { "essentials.tp""essentials.tphere" }

essentials_tp register_cvar(g_Permissions[0], "d")
essentials_tphere register_cvar(g_Permissions[1], "d"
Adding a simple function for this would be quite useful.

PS: Is something like this possible?

PHP Code:
new essentials_tpessentials_tphere

new const g_Permissions[][] = {
    
essentials_tp"essentials.tp""d"
    
essentials_tphere"essentials.tphere""d"
}

for new(
0sizeof(g_Permissions) - 2+= 3)
    
g_Permissions[i] = register_cvar(i+1i+2
//Edit: nevermind, I found a somewhat simple way:

PHP Code:
if(!user_permission(idessentials_tphere"essentials.tphere"1))
    return 
PLUGIN_HANDLED 

Last edited by OciXCrom; 09-22-2015 at 13:43.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-22-2015 , 20:16   Re: How to get actual cvar name
Reply With Quote #9

A period (.) is not a valid word character, is it a valid character for cvars?
__________________
fysiks is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 09-23-2015 , 06:57   Re: How to get actual cvar name
Reply With Quote #10

Cvars are strings, therefore I see no reason for it to be invalid, nor I'm having any problems with it.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 08:00.


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