Help With Derma

Hello.

Im trying to create a derma menu where the Mayor can set the legality of certain weapons, and it would notify the players and they would open another menu where they can see the gun laws, I’m having problems with the DMultiChoice and the DComboBox, basically when the mayor clicks on the gun in the DComboBox, they go and selec either “Legal” or “Illegal” in the DMultiCHoice, I’m wondering how that would work, also how would I add a chat command?

Code:

[lua] local GunFrame = vgui.Create(‘DFrame’)
GunFrame:SetSize(474, 390)
GunFrame:Center()
GunFrame:SetTitle(‘GunLaws’)
GunFrame:SetSizable(true)
GunFrame:SetDeleteOnClose(false)
GunFrame:MakePopup()

Local GunComboBox = vgui.Create(‘DComboBox’ Dframe)
GunComboBox:SetSize(120, 338)
GunComboBox:SetPos(121, 96)
GunComboBox:EnableHorizontal(false)
GunComboBox:EnableVerticalScrollbar(true)
GunComboBox.OnMousePressed = function() end

GunComboBox:AddItem(‘AK47’)
GunComboBox:SetMultiple(false)

GunMultiChoice = vgui.Create(‘DMultiChoice’ Dframe)
GunMultiChoice:SetPos(410, 121)
GunMultiChoice.OnMousePressed = function() end
function GunMultiChoice:OnSelect(Index, Value, Data) end
print("Option " … value … " has been picked at the index " … index )

end

GunMultiChoice:AddChoice(‘Legal’)
GunMultiChoice:AddChoice(‘Illegal’)

end

hook.Add(“Initialize”,“your_hook_name_here”,function()
– Here you must put all your derma controls.
end) – Adds hook, so when we starting a new game or connecting to a server our menu creates.
concommand.Add(“rb655_frame_open”,function() GunFrame:SetVisible(true) end) – Create console command to open your panel.
concommand.Add(“rb655_frame_close”,function() GunFrame:SetVisible(false) end) – Create console command to close your panel. [/lua]

This code is really messy and your parents don’t even make sense. You have Local when it should be local. You don’t need 2 console commands for 1 menu.

But I’ll gladly try to figure this out for you.

[editline]16th January 2012[/editline]

Here is a snippet I found from DarkRP hope its helpful. But this is a lot easier with checkboxes then what you’re trying to do…

[lua]
local DefaultWeapons = {
{name = “GravGun”,class = “weapon_physcannon”},
{name = “Physgun”,class = “weapon_physgun”},
{name = “Crowbar”,class = “weapon_crowbar”},
{name = “Stunstick”,class = “weapon_stunstick”},
{name = “Pistol”,class = “weapon_pistol”},
{name = “357”, class = “weapon_357”},
{name = “SMG”, class = “weapon_smg1”},
{name = “Shotgun”, class = “weapon_shotgun”},
{name = “Crossbow”, class = “weapon_crossbow”},
{name = “AR2”, class = “weapon_ar2”},
{name = “BugBait”, class = “weapon_bugbait”},
{name = “RPG”, class = “weapon_rpg”}
}
for k,v in pairs(DefaultWeapons) do
if type(v) == “table” and v.name then
local checkbox = vgui.Create(“DCheckBoxLabel”)
checkbox:SetText(v.name)
checkbox:SetValue(GetConVarNumber(“licenseweapon_”…v.class))
function checkbox.Button:Toggle()
if ( self:GetChecked() == nil || !self:GetChecked() ) then
self:SetValue( true )
else
self:SetValue( false )
end
local tonum = {}
tonum[false] = “0”
tonum[true] = “1”
RunConsoleCommand(“rp_licenseweapon_”… v.class, tonum[self:GetChecked()])
end
ComboBox:AddItem(checkbox)
end
end
[/lua]

Thanks, does this allow the illegal weapons to be picked up?

They can still be picked up inside DarkRP unless you make it so people need a gun license to actually equip it.

[lua] local DFrame1

DFrame1 = vgui.Create(‘DFrame’)
DFrame1:SetSize(345, 359)
DFrame1:Center()
DFrame1:SetTitle(‘Untitled DFrame’)
DFrame1:SetSizable(true)
DFrame1:SetDeleteOnClose(false)
DFrame1:MakePopup()

local DefaultWeapons = {
{name = “GravGun”,class = “weapon_physcannon”},
{name = “Physgun”,class = “weapon_physgun”},
{name = “Crowbar”,class = “weapon_crowbar”},
{name = “Stunstick”,class = “weapon_stunstick”},
{name = “Pistol”,class = “weapon_pistol”},
{name = “357”, class = “weapon_357”},
{name = “SMG”, class = “weapon_smg1”},
{name = “Shotgun”, class = “weapon_shotgun”},
{name = “Crossbow”, class = “weapon_crossbow”},
{name = “AR2”, class = “weapon_ar2”},
{name = “BugBait”, class = “weapon_bugbait”},
{name = “RPG”, class = “weapon_rpg”}

for k,v in pairs(DefaultWeapons) do
if type(v) == “table” and v.name then
local checkbox = vgui.Create(“DCheckBoxLabel”)
checkbox:SetText(v.name)
checkbox:SetValue(GetConVarNumber(“licenseweapon_”…v.class))
function checkbox.Button:Toggle()
if ( self:GetChecked() == nil || !self:GetChecked() ) then
self:SetValue( true )
else
self:SetValue( false )
end
local tonum = {}
tonum[false] = “0”
tonum[true] = “1”
RunConsoleCommand(“rp_licenseweapon_”… v.class, tonum[self:GetChecked()]) then
NotifyAll(1,4, “The Mayor has changed the gun laws”)
end
ComboBox:AddItem(checkbox)
end
end

[/lua]

Would this work?

You can test this yourself with lua_openscript_cl <filename>.lua inside of singleplayer. Put the lua file inside gmod/lua and test it.