I have a VGUI made but I cannot seem to figure out how to use the GUI to actually edit the settings file. I use vON to serialize and de-serialize the settings file. I'm pretty sure I'm doing something wrong with the net functions as I'm fairly new to them as well as VGUI. Any help is appreciated and thank you for your help in advance. Below is the net.Send function for the GUI text command:
[CODE]
function RAS.OpenMenu(ply, text, pub)
local text = string.lower(text)
if(string.sub(text, 0, 4)== "/ras" or string.sub(text, 0, 4)== "!ras") then
net.Start("RAS.Menu")
net.WriteTable(RAS.Settings)
net.Send( ply )
return ''
end
end
hook.Add("PlayerSay", "RASOpenAdminGUICMD", RAS.OpenMenu)
[/CODE]
Below this is the GUI code:
[CODE]
local function CreateCategory( DCategoryList, Name )
local Category = DCategoryList:Add(Name)
Category.AddItem = function(self, ctrl)
ctrl:SetParent(self)
ctrl:Dock(TOP)
end
return Category
end
local function CreateMenu()
local Settings = net.ReadTable()
--[[Create DFrame & Category List]]--
local MainMenu = vgui.Create( "DFrame" )
MainMenu:SetSize( 354, 600 )
MainMenu:SetSizable( true )
MainMenu:SetTitle( "[RAS] Configs Menu" )
MainMenu:Center()
MainMenu:MakePopup()
local Categories = vgui.Create( "DCategoryList", MainMenu )
Categories:SetPos( 20,0 )
Categories:Dock( FILL )
Categories.AddCategory = function(self, name)
self[name] = CreateCategory( self, name )
end
--[[General Category]]--
Categories:AddCategory("General")
//Create CheckBox
local General_EnableDisable = vgui.Create( "DCheckBoxLabel" )
General_EnableDisable:SetText( "Enable/Disable RAS" )
General_EnableDisable:SetTextColor( Color(0,0,0) )
General_EnableDisable:SetValue( Settings.AntiSpamming )
General_EnableDisable:SizeToContents()
function General_EnableDisable:OnChange( checked )
Settings.AntiSpamming = checked
end
Categories.General:AddItem( General_EnableDisable ) -- Add the above item to our list
--[[Chat Category]]--
Categories:AddCategory("Chat")
//Create CheckBox
local Chat_EnableDisable = vgui.Create( "DCheckBoxLabel" )
Chat_EnableDisable:SetText( "Enable/Disable Chat Spam Protection" )
Chat_EnableDisable:SetTextColor( Color(0, 0, 0) )
Chat_EnableDisable:SetValue( 0 )
Chat_EnableDisable:SizeToContents()
function Chat_EnableDisable:OnChange( checked )
Settings.Chat.Enabled = checked
end
//Create Label
local LC = vgui.Create( "DLabel" )
LC:SetText("Seconds which the player can send a message right after sending one")
LC:SetTextColor(Color(0,0,0))
//Create Slider
local Chat_Slider = vgui.Create( "Slider" )
Chat_Slider:SetMin(1)
Chat_Slider:SetMax(250)
Chat_Slider:SetDecimals(0)
Chat_Slider:SetValue(Settings.Chat.Timeout)
Chat_Slider:SizeToContents()
local ovc = Chat_Slider.ValueChanged
function Chat_Slider:ValueChanged(val)
ovc(self, val)
Settings.Chat.Timeout = val
end
//Adds all of the above to the category
Categories.Chat:AddItem(Chat_EnableDisable)
Categories.Chat:AddItem(LC)
Categories.Chat:AddItem(Chat_Slider)
--[[Prop Category]]--
Categories:AddCategory("Props")
//Create CheckBox
local Prop_EnableDisable = vgui.Create( "DCheckBoxLabel" )
Prop_EnableDisable:SetText( "Enable/Disable Prop Spam Protection" )
Prop_EnableDisable:SetTextColor( Color(0, 0, 0) )
Prop_EnableDisable:SetValue( 0 )
Prop_EnableDisable:SizeToContents()
function Chat_EnableDisable:OnChange( checked )
Settings.Chat.Enabled = checked
end
//Create Label
local LP = vgui.Create( "DLabel" )
LP:SetText("Seconds which the player can spawn a prop right after spawning one")
LP:SetTextColor(Color(0,0,0))
//Create Slider
local Prop_Slider = vgui.Create( "Slider" )
Prop_Slider:SetMin(1)
Prop_Slider:SetMax(250)
Prop_Slider:SetDecimals(0)
Prop_Slider:SetValue(Settings.Prop.Timeout)
Prop_Slider:SizeToContents()
local ovp = Prop_Slider.ValueChanged
function Prop_Slider:ValueChanged(val)
ovp(self, val)
Settings.Prop.Timeout = val
end
//Adds all of the above to the category
Categories.Props:AddItem(Prop_EnableDisable)
Categories.Props:AddItem(LP)
Categories.Props:AddItem(Prop_Slider)
--[[Scripted Entities Category]]--
Categories:AddCategory("SENTs")
//Create CheckBox
local Sent_EnableDisable = vgui.Create( "DCheckBoxLabel" )
Sent_EnableDisable:SetText( "Enable/Disable SENT(s) Spam Protection" )
Sent_EnableDisable:SetTextColor( Color(0, 0, 0) )
Sent_EnableDisable:SetValue( 0 )
Sent_EnableDisable:SizeToContents()
function Sent_EnableDisable:OnChange( checked )
Settings.Sent.Enabled = checked
end
//Create Label
local LS = vgui.Create( "DLabel" )
LS:SetText("Seconds which the player can spawn a SENT right after spawning one")
LS:SetTextColor(Color(0,0,0))
//Create Slider
local Sent_Slider = vgui.Create( "Slider" )
Sent_Slider:SetMin(1)
Sent_Slider:SetMax(250)
Sent_Slider:SetDecimals(0)
Sent_Slider:SetValue(Settings.Sent.Timeout)
Sent_Slider:SizeToContents()
local ovs = Sent_Slider.ValueChanged
function Prop_Slider:ValueChanged(val)
ovs(self, val)
Settings.Sent.Timeout = val
end
//Adds all of the above to the category
Categories.SENTs:AddItem(Sent_EnableDisable)
Categories.SENTs:AddItem(LS)
Categories.SENTs:AddItem(Sent_Slider)
MainMenu:SizeToContents()
end
net.Receive( "RAS.Menu", CreateMenu)
[/CODE]
Sorry, you need to Log In to post a reply to this thread.