Help with CreateClientConVar .

I want to make changing position an draw box and I don’t know how to integrate this to my code.

[lua] function myhud( x, y, wide, tall, alpha )

surface.CreateFont (“coolvetica”, 20, 400, true, false, “NormalText”)
surface.CreateFont (“coolvetica”, 24, 400, true, false, “MediumText”)

local mycconvar = CreateClientConVar( “my_client_var”, “0”, false, false )

local yellow = Color(255, 210, 0, 255)
local red = Color(252, 0, 0, 255)

local client = LocalPlayer()

if !client:Alive() then return end

– Pistol Weapon INFO –

for k,v in pairs (LocalPlayer():GetWeapons()) do – Pistol Weapon ( Bottom Right )
if v:GetClass() == “weapon_pistol” then

local PrimaryAmmoType = client:GetAmmoCount(v:GetPrimaryAmmoType())
local SecondaryAmmoType = client:GetAmmoCount(v:GetSecondaryAmmoType())
local MoveX = ss

--	Info Boxes	--

	draw.RoundedBox( 6, ScrW() / 2 + 360, ScrH() / 2 + mycconvar, 170, 25, Color( 0, 0, 0, 100 ) ) 						-- Primary Ammo Type Box
	draw.RoundedBox( 6, ScrW() / 2 + 543, ScrH() / 2 + 220, 70, 25, Color( 0, 0, 0, 100 ) )  						-- Alt. Ammo Box
		
--	Amount PrimaryAmmo	--

	draw.SimpleText("Pistol ", "NormalText", ScrW() / 2 + 370, ScrH() / 2 + 224, yellow, 0, TEXT_ALIGN_RIGHT)		-- Weapon Name Text
	draw.SimpleText("Clip : ", "NormalText", ScrW() / 2 + 415, ScrH() / 2 + 224, yellow, 0, TEXT_ALIGN_RIGHT)		-- Weapon Name Text 2
	draw.SimpleText("" .. v:Clip1(), "MediumText", ScrW() / 2 + 450, ScrH() / 2 + 222, yellow, 0, 0)				-- Amount of Clip1
	draw.SimpleText("/ " .. PrimaryAmmoType, "NormalText", ScrW() / 2 + 482, ScrH() / 2 + 224, yellow, 0, 0)		-- Amount of PrimaryAmmoType

--	Amount Alt. Ammo	--

	draw.SimpleText("      Alt", "NormalText", ScrW() / 2 + 525, ScrH() / 2 + 224, yellow, 0, 0)					-- Alt. Ammo Text
	draw.SimpleText("" .. SecondaryAmmoType, "MediumText", ScrW() / 2 + 578, ScrH() / 2 + 222, yellow, 0, 0)		-- Amount of Alt. Ammo
	


	

	end
end	



– Weapon INFO –



end

hook.Add(“HUDPaint”, “myhud”, myhud)

function myTestFunction()

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 300, 250 )
DermaPanel:SetTitle( “Hud Ammo Modifier” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local NumSliderThingy = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderThingy:SetPos( 25,50 )
NumSliderThingy:SetWide( 150 )
NumSliderThingy:SetText( “Max Props” )
NumSliderThingy:SetMin( 0 ) – Minimum number of the slider
NumSliderThingy:SetMax( 256 ) – Maximum number of the slider
NumSliderThingy:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderThingy:SetConVar( “mycconvar” ) – Set the convar

end

concommand.Add(“my_test_function”, myTestFunction)[/lua]


Hook 'myhud' Failed: autorun\client\MyHud.lua:30: attempt to perform arithmetic on local 'mycconvar' (a userdata value) 

Wiki knows all.

Basically you can’t put the name of the convar when you want to get the value and use it in an expression. Use myconvar:GetInt()

And on line 89, with NumSliderThingy:SetConVar(“myconvar”), the argument should be what you put in the console. So write my_client_var in there instead.

I changed to
[lua] function myhud( x, y, wide, tall, alpha )

surface.CreateFont (“coolvetica”, 20, 400, true, false, “NormalText”)
surface.CreateFont (“coolvetica”, 24, 400, true, false, “MediumText”)

local mycconvar = CreateClientConVar( “my_client_var”, “256”, false, false )
local myint = mycconvar:GetInt()

local yellow = Color(255, 210, 0, 255)
local red = Color(252, 0, 0, 255)

local client = LocalPlayer()

if !client:Alive() then return end

– Pistol Weapon INFO –

for k,v in pairs (LocalPlayer():GetWeapons()) do – Pistol Weapon ( Bottom Right )
if v:GetClass() == “weapon_pistol” then

local PrimaryAmmoType = client:GetAmmoCount(v:GetPrimaryAmmoType())
local SecondaryAmmoType = client:GetAmmoCount(v:GetSecondaryAmmoType())
local MoveX = ss

--	Info Boxes	--

	draw.RoundedBox( 6, ScrW() / 2 + 360, ScrH() / 2 - mycconvar, 170, 25, Color( 0, 0, 0, 100 ) ) 						-- Primary Ammo Type Box
	draw.RoundedBox( 6, ScrW() / 2 + 543, ScrH() / 2 + 220, 70, 25, Color( 0, 0, 0, 100 ) )  						-- Alt. Ammo Box
		
--	Amount PrimaryAmmo	--

	draw.SimpleText("Pistol ", "NormalText", ScrW() / 2 + 370, ScrH() / 2 + 224, yellow, 0, TEXT_ALIGN_RIGHT)		-- Weapon Name Text
	draw.SimpleText("Clip : ", "NormalText", ScrW() / 2 + 415, ScrH() / 2 + 224, yellow, 0, TEXT_ALIGN_RIGHT)		-- Weapon Name Text 2
	draw.SimpleText("" .. v:Clip1(), "MediumText", ScrW() / 2 + 450, ScrH() / 2 + 222, yellow, 0, 0)				-- Amount of Clip1
	draw.SimpleText("/ " .. PrimaryAmmoType, "NormalText", ScrW() / 2 + 482, ScrH() / 2 + 224, yellow, 0, 0)		-- Amount of PrimaryAmmoType

--	Amount Alt. Ammo	--

	draw.SimpleText("      Alt", "NormalText", ScrW() / 2 + 525, ScrH() / 2 + 224, yellow, 0, 0)					-- Alt. Ammo Text
	draw.SimpleText("" .. SecondaryAmmoType, "MediumText", ScrW() / 2 + 578, ScrH() / 2 + 222, yellow, 0, 0)		-- Amount of Alt. Ammo
	


	

	end
end	



– Weapon INFO –



end

hook.Add(“HUDPaint”, “myhud”, myhud)

function myTestFunction()

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 300, 250 )
DermaPanel:SetTitle( “Hud Ammo Modifier” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local NumSliderThingy = vgui.Create( “DNumSlider”, DermaPanel )
NumSliderThingy:SetPos( 25,50 )
NumSliderThingy:SetWide( 150 )
NumSliderThingy:SetText( “Max Props” )
NumSliderThingy:SetMin( 0 ) – Minimum number of the slider
NumSliderThingy:SetMax( 256 ) – Maximum number of the slider
NumSliderThingy:SetDecimals( 0 ) – Sets a decimal. Zero means it’s a whole number
NumSliderThingy:SetConVar( “my_client_var” ) – Set the convar

end

concommand.Add(“my_test_function”, myTestFunction)[/LUA]



Running script autorun\client\MyHud.lua...
Hook 'myhud' Failed: autorun\client\MyHud.lua:30: attempt to perform arithmetic on local 'mycconvar' (a userdata value)


Because as the guy above said you’re supposed to use convar:GetInt() or GetFloat() or whatever.
[lua]draw.RoundedBox( 6, ScrW() / 2 + 360, ScrH() / 2 - mycconvar:GetInt(), 170, 25, Color( 0, 0, 0, 100 ) ) – Primary Ammo Type Box[/LUA]

Oops thanks all it’s working :slight_smile: