AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get actual cvar name (https://forums.alliedmods.net/showthread.php?t=271978)

OciXCrom 09-21-2015 09:30

How to get actual cvar name
 
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"?

siriusmd99 09-21-2015 10:08

Re: How to get actual cvar name
 
Are you banned on google ?
https://www.amxmodx.org/api/cvars/get_pcvar_string

HamletEagle 09-21-2015 10:57

Re: How to get actual cvar name
 
Quote:

Originally Posted by siriusmd99 (Post 2345554)

He wants the cvar name, he is not asking how to get a string value from a cvar. OP, why do you need this ?

siriusmd99 09-21-2015 13:31

Re: How to get actual cvar name
 
i think you need this :
Quote:

native CvarGetName( handleCvar, const cvar[], len );
Click Here

Arkshine 09-21-2015 13:40

Re: How to get actual cvar name
 
You should explain what are you really trying to achieve, because getting name is usually not useful.

OciXCrom 09-22-2015 08:34

Re: How to get actual cvar name
 
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?

Arkshine 09-22-2015 08:48

Re: How to get actual cvar name
 
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.

OciXCrom 09-22-2015 09:43

Re: How to get actual cvar name
 
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 


fysiks 09-22-2015 20:16

Re: How to get actual cvar name
 
A period (.) is not a valid word character, is it a valid character for cvars?

OciXCrom 09-23-2015 06:57

Re: How to get actual cvar name
 
Cvars are strings, therefore I see no reason for it to be invalid, nor I'm having any problems with it.


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

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