Activate Function with Checkbox How ?

I want to find a way to when I activate the checkbox my function hook.Add stay activated.

Some one can help me with this ?

Thanks

Do you want the function to be executed when you tick the checkbox or the function to obtain data from a checkbox when a button is beeng pressed?

the first one, when I tick the checkbox to activate in example inf ammo from a function.

Try hooking DCheckbox.DoClick or somthing

ah Yeah thanks that was my missing puzzle :slight_smile:


oops error

What I do improperly ?

[lua]if CLIENT then

function MousePressed(mc)

	if input.IsMouseDown(MOUSE_LEFT) then 

		LocalPlayer():ConCommand( "Clip1" )
	end

	
	if input.IsMouseDown(MOUSE_RIGHT) then
	
		LocalPlayer():ConCommand( "Clip2" )
end

end
concommand.Add(“InfAmmo”, MousePressed)

function DermaMenu()

local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50, 50 )
DermaPanel:SetSize( 300, 325 )
DermaPanel:SetTitle( “Testing Derma Stuff” )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()

local TestingPanel = vgui.Create( “DPanel”, DermaPanel )
TestingPanel:SetPos( 25, 50 )
TestingPanel:SetSize( 250, 250 )
TestingPanel.Paint = function() – Paint function
surface.SetDrawColor( 50, 50, 50, 255 ) – Set our rect color below us; we do this so you can see items added to this panel
surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) – Draw the rect
end

local CheckBoxAmmo = vgui.Create( “DCheckBoxLabel”, TestingPanel )
local cValueCbox = CheckBoxAmmo:GetValue( )

CheckBoxAmmo:SetPos( 12, 30 )
CheckBoxAmmo:SetText( "Freeze Ammo" )
CheckBoxAmmo:SizeToContents()
CheckBoxAmmo:SetValue( cValueCbox )

if 	CheckBoxAmmo.DoClick = function()
		if input.IsMouseDown(MOUSE_LEFT) then 
	LocalPlayer():ConCommand( "Clip1" )
	end
end

end

end
concommand.Add(“Ammo_Pannel”, DermaMenu)
end

if SERVER then

function AClip(ply, cmd, args)

	ply:GetActiveWeapon():SetClip1( 255 )

end

concommand.Add(“Clip1”, AClip)

function AClip2(ply, cmd, args)

local AmmoType2     =		ply:GetActiveWeapon():GetSecondaryAmmoType() 

	ply:SetAmmo( 9, AmmoType2 )

end

concommand.Add(“Clip2”, AClip2)

end[/lua]



autorun/ammo2.lua:47: 'then' expected near '='

Line 47 shoud be
[lua]
DermaButton1.DoClick = function ()
[/lua]
i think

Edit:

Btw, remember then on if`s!

[lua]CheckBoxAmmo.DoClick = function()[/lua]

That is valid syntax, the if just needs to be removed on that line.

Damit, ninja`d!

It’s work but the ammo won’t stay at 255 when the function MousePressed is called by my DoClick, any one have an idea ?

CheckBoxes do not have a “DoClick” event. You probably want the “OnChange” event.

They do have “DoClick”

[lua]concommand.Add(“menu”,function()
local f = vgui.Create(“DFrame”)
f:SetSize(100,100)
f:Center()
f:MakePopup()

local c = vgui.Create("DCheckBoxLabel",f)
c:SetPos( 30, 30 )
c:SetSize( 25, 25 )
print(c.DoClick and "hansihe was right" or "entoros was right")

end)
[/lua]



] menu
entoros was right


DoClick is only for DButtons and things made from DButtons… and DCheckBoxes sans the label.

I’m pretty sure that DCheckBox has a DoClick function but DCheckBoxLabel does not.

[lua]concommand.Add(“menu”,function()
local f = vgui.Create(“DFrame”)
f:SetSize(100,100)
f:Center()
f:MakePopup()

local c = vgui.Create("DCheckBox",f)
c:SetPos( 30, 30 )
c:SetSize( 25, 25 )
print(c.DoClick and "maker is right as usual" or "entoros is kind of right")

end)

[/lua]



] menu 
maker is right as usual


http://www.facepunch.com/ads/rating/tick.png

[editline]08:49PM[/editline]

Oh fuck, I hope I don’t get banned for image macro again :\

Yesh! I knew i where right!