I am making a derma that players can press a key to make pop-up and it will show all the mayor's current rules. The only problem is i dont know how to call the mayors rules to be the text of the derma as the mayors rules will change all the time when he updates them.
MY CURRENT CODE IN cl_init:
[CODE]function RulesDerma()
local base = vgui.Create( "DFrame")
local button = vgui.Create( "DButton")
base:SetPos(5, 5)
base:SetSize( 450, 300)
base:SetVisible( true )
base:SetTitle("The Mayor's Rules")
base:SetDraggable( false )
base:ShowCloseButton( true )
base:MakePopup()
button:SetParent( base )
button:SetText( "Close" )
button:SetPos( 500, 300 )
button:SetSize( 100, 50 )
button.DoClick = function()
end
end
usermessage.Hook("OpenMayorRules", RulesDerma)
[/CODE]
MY CODE FOR init.lua
[CODE]function GM:ShowTeam( ply )
umsg.Start ("OpenMayorRules", ply )
umsg.End()
end
[/CODE]
Any help is greatly appreciated
[editline]14th June 2015[/editline]
After a bit of research should I use a DLabel instead? if so how do I call the mayor's Rules as the contents of the DLabel?
Usermessages are deprecated, use net messages instead.
Serverside:
[CODE]util.AddNetworkString("DarkRPLaws")
hook.Add("ShowTeam", "ShowDarkRPLaws", function(ply)
net.Start("DarkRPLaws")
net.Send(ply)
end)[/CODE]
Clientside:
[CODE]net.Receive("DarkRPLaws", function()
local lawsTable = DarkRP.getLaws() -- returns table with current laws
--Your VGUI here. Also, use second argument in vgui.Create to set parent. Example: local text = vgui.Create("DLabel", parent_panel) == text:SetParent(parent_panel)
end)[/CODE]
[QUOTE=krekeris;47964995]Serverside:
[CODE]util.AddNetworkString("DarkRPLaws")
hook.Add("ShowTeam", "ShowDarkRPLaws", function(ply)
net.Start("DarkRPLaws")
net.Send(ply)
end)[/CODE]
Clientside:
[CODE]net.Receive("DarkRPLaws", function()
local lawsTable = DarkRP.getLaws() -- returns table with current laws
--Your VGUI here. Also, use second argument in vgui.Create to set parent. Example: local text = vgui.Create("DLabel", parent_panel) == text:SetParent(parent_panel)
end)[/CODE][/QUOTE]
How do I set the text from the Dlabel to be the lawsTable?
I have this for client:
[CODE]local Panel = vgui.Create( "DPanel" )
Panel:SetPos( 10, 10 )
Panel:SetSize( 200, 200 )
local DLabel = vgui.Create( "DLabel", Panel )
DLabel:SetPos( 40, 40 )
DLabel:SetText( "Hello, world!" )
[/CODE]
and this for server:
[CODE]hook.Add("ShowTeam", "ShowDarkRPLaws", function(ply)
net.Start("DarkRPLaws")
net.Send(ply)
end)[/CODE]
It's very easy tho. You should learn atleast something about Lua before doing this.
[CODE]local posY = 40
local dist = 10
for lawid, lawtext in pairs(lawsTable) do
local lbl = vgui.Create(40, posY*lawid + dist * (lawid - 1))
lbl:SetText(lawtext)
lbl:SizeToContents()
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.