Name of Swep in Derma list

Im trying to make it so when i have my derma menu open, one tab shows a list of weapons i am holding.
This is What i have So far
[lua]
-----cl_init----
Weapons = vgui.Create(“DListView”)
Weapons:SetParent(DermaPanel)
Weapons:SetPos(25, 50)
Weapons:SetSize(450, 625)
Weapons:SetMultiSelect(false)
Weapons:AddColumn(“Weapon Name”)

PropertySheet:AddSheet( “Weapons”, Weapons, “gui/silkicons/user”, false, false, “Your Weapon’s” )

------ Weapons cl_init-------
function SWEP:Think()
if Weapons then
self.Owner.Weapons:AddLine(“Weapon_test”)
end
end
[/lua]
When i equip the weapon it appears on the list, but it keep making itself on the list multiple times.
Is there a better way to do this ?

Well, the think hook is called on every tick or so, so it adds the line every tick. If you want it to call once, put it in the Init hook, I think.

Did that before and it worked but in the end I want the menu to count how many shots i have taken with the gun.
How can i update the list without making a new line ?

Hmm, maybe try this?

[lua]function SWEP:Think()
self.Owner.Weapons:RemoveLine(“Number of shots”)
self.Owner.Weapons:AddLine(“Number of shots”,numshots)
end[/lua]

Dunno if that’s the syntax for removeline, and insert your total number of shots for the variable “numshots”.

Getting an error on it.
"Attempt to index field ‘Weapons’ (a nil Value)

Err,

[lua]function SWEP:Think()
if Weapons then
self.Owner.Weapons:RemoveLine(“Number of shots”)
self.Owner.Weapons:AddLine(“Number of shots”,numshots)
end
end[/lua]

Maybe? I’ve never messed with derma in SWEPs, or doing the shit you’re talking about.

Yep thats exactly what i have, seems like it cant find weapons.
Weird because when i add a test Msg into it, i get the message after “if weapons then”
but it cant find weapons after that.
Why is this stuff so confusing :S

Got it to work! Took a bit but this is what you have to do :
[lua]
function SWEP:Think()
if Weapons then
self:CallOnClient(Weapons:Clear(“Weapon_empty”) )
self:CallOnClient(Weapons:AddLine(“Weapon_empty”, Shots))
end
end
[/lua]

Only problem is when the derma is closed you get massed with errors that its trying to use an invalid object.