DCheckBox

Hey, I was wondering how I could make a DCheckBox run a ConVar 2.

like “convar_here 2”.

then when it’s unchecked make it run “convar_here 1”.

How can I do that?

thanks

Not possible.

Just make use of the OnChange function.

so like this

[lua]function CheckBoxNameHere.OnChange()
RunConsoleCommand(“convar_here”, “2”)
end[/lua]

if that is correct, then how do I Set it back to 1?

Oh I got you wrong give me a minute or two…

To avoid using OnChange for a thing that basicly already exists…

This was copied from the sourcecode I just edited a line…
[lua]
function CheckBoxNameHere.Button:SetValue( val )
val = tobool( val )
self:SetChecked( val )
if ( !val ) then self:SetType( “none” ) else self:SetType( “tick” ) end
self.m_bValue = val
self:OnChange( val )
if ( val ) then val = “2” else val = “1” end
self:ConVarChanged( val
end
[/lua]

Just use SetConVar on the Checkbox now…

There is a bool argument to the onchange hook. Do: (bool and 2 or 1) bool being the argument.

do I need to change any lines in that code?(besides CheckBoxNameHere in line1)?

Also thanks for the code

That’s not working right, the checkbox won’t uncheck lol, it is always stuck on cvar 2, the checkbox won’t uncheck to revert it to 1

Show us your god damn code c-unit.

You can’t expect us to know what’s wrong without some code! (All of it!)

Alright:

[lua]models = vgui.Create(‘DCheckBoxLabel’)
models:SetParent(Panel)
models:SetPos(10, 10)
models:SetConVar( “r_drawothermodels” )
models:SetText(‘draw other models’)
models1:SizeToContents()
function models.Button:SetValue( val )
val = tobool( val )
self:SetChecked( val )
if ( !val ) then self:SetType( “none” ) else self:SetType( “tick” ) end
self.m_bValue = val
self:OnChange( val )
if ( val ) then val = “2” else val = “1” end
self:ConVarChanged( val )
end
[/lua]

there you go =\

[lua]
function models.Button:SetValue( val )
val = tobool( val )
self:SetChecked( val )

if ( !val ) then self:SetType( "none" ) else self:SetType( "tick" ) end

self.m_bValue = val

self:OnChange( val )

local finalval = "1"

if (val) then val = "2" end

RunConsoleCommand("r_drawothermodels", val)

end
[/lua]

Try that. And remove: (models:SetConvar…)

alright, thank you! I will test it now.

[editline]12:41PM[/editline]

It works originally when you click the checkbox(it runs r_drawothermodels 2), then when you uncheck it, it does not run r_drawothermodels 1

new code
[lua]models = vgui.Create(‘DCheckBoxLabel’)
models:SetParent(Panel)
models:SetPos(10, 10)
models:SetText(‘draw other models’)
models:SizeToContents()
function models.Button:SetValue( val )
val = tobool( val )
self:SetChecked( val )

if ( !val ) then self:SetType( "none" ) else self:SetType( "tick" ) end

self.m_bValue = val

self:OnChange( val )

local finalval = "1"

if (val) then val = "2" end

RunConsoleCommand("r_drawothermodels", val)

end[/lua]

anyway to fix?

Is there anyway to fix that?

Isn’t r_drawothermodels a cheat command?

Duh?
Whats wrong with making a hack?

Just saying how is he gonna force it with out no module.

baconbop bypasses sv_cheats strictly with lua correct?

Not correct.

[lua]
local CvarMeta = _R.ConVar

local oldConVarGetBool = _R.ConVar.GetBool

_R.ConVar.GetBool = function(cvar)

	if cvar:GetName() == "sv_cheats" then

		return false

	end

	

	return oldConVarGetBool(cvar)

end[/lua]

I’m guessing that’s how they go about it.

[editline]09:10AM[/editline]

oh really? I was told baconbot bypasses it without using a module

No, they use a module to bypass it, that is what require(“baconbot”) is for lol!

You could of told us you were trying to make a hack, you need a module to force this convar or you can use cvar2 to change it to a non-cheat cvar.