Hey I have a few questions on, well, the title.

[lua]CreateClientConVar(“prp_bankamount”, “0”, false, false)[/lua]

What are the 2 falses at the end for? Also can I set the convar up to have a function like in it like this:

[lua]CreateClientConVar(“matching_command”, “0”, false, false)
function() blah
–do shit
concommand.Add(“matching_command”, “is it possible?”, blah)[/lua]

Like would something like that work, so then I know if I turn matching_command to 1 then it would do whatever’s in the function? - for reference.

The first boolean determines whether the convar and its value should be saved to a text file and loaded up next time you start the game. So you can keep the value between playing sessions if this is a desirable outcome.

The second determines whether the value is sent to the server. I’ve not tried this myself but presumably if you want to make a convar for the appearance of some HUD you’ve made, the server doesn’t need to know about this, so the boolean would be false.

For the function thing try

I have been reading the wiki, but I don’t quite understand how to set up functiojn using the ConVar as the “concommand” persay.

In your case it would be something like

cvars.AddChangeCallback(“prp_bankamount”, function (cvar, oldvalue, newvalue)
print(cvar…" changed from “…oldvalue…” to "…newvalue)

cvars.AddChangeCallback(“matching_command”, function()
–do shit
concommand.Add(“matching_command”, “this work?”, something here)

so like that?

No, the idea with AddChangeCallback is you use that for convars instead of concommand.Add. And you’ve not added the closing bracket to the end of AddChangeCallback. The example I have is all you really need, just replace the print line with whatever you want the function to do.

Alright thank you :smiley:

I’m not sure if CreateClientConVar works with callbacks, they didnt for me the other day anyway

oh ok, also another question. If I want a “convar_somthing” and then a “+convar_something”, do I have to set up 2 different CreateClientConVar’s?

Like if I want both of the conVars to do the same thing, except I just one to be where you gotta hold down the key?

like would i have to do this
[lua]CreateClientConVar("+convar", 1, true, false)
CreateClientConVar(“convar”, 0, true, false)[/lua]

if you get what i mean?

It seems to me you are trying to use the wrong tool for the job. What are you trying to accomplish? Why do you need convars and not concommands?

So I can use DCheckBoxs


from what I understand you cannot use concommands with DCheckBoxs

You can. It’s pretty easy.
Its like how baconbot functions(You use it I know you do)

for example on baconbot:

Bunny Hopping would run the console command ‘Bacon_Bhop 1’
Bunny Hopping would run the console command ‘Bacon_Bhop 0’

Bacon_Bhop is a ConVar…Hence the 1 or 0 after words…


[lua]local bhop = CreateClientConVar( “bacon_bhop”, 0, true, false )[/lua]

proof :smiley:

Try a DoClick function

local checkbox = vgui.Create(“DCheckBox”)
function checkbox:DoClick()
self:GetChecked() – If you need the ‘checked’ value, here it is.
RunConsoleCommand(“command here”)

I had no clue you could do that! Thank you!


Also, how can I make it run a certain console command when it gets unchecked?