-
Notifications
You must be signed in to change notification settings - Fork 4
Example
Linus edited this page May 8, 2018
·
15 revisions
@name VGUI_Simple_example
@persist F:dframe B:dbutton
if(first()) {
#triggers the e2 in events like a button press or slider moved etc.
runOnVgui(1)
#redefines the default players who will see the panel, otherwise its just the e2 owner and people added with :addPlayer(E)
vguiDefaultPlayers(players())
#creates the dframe
F = dframe(1)
F:center()
F:makePopup()
#tells the clients to create the panel, otherwise the panel will not get created
F:create()
#creates the dbutton
B = dbutton(2,F)
B:setPos(50,50)
B:setText("Click me!")
B:create()
timer("1sec",1000)
}elseif(clk("1sec")) {
local C = hsv2rgb(vec((realtime()*10)%360,1,1))
#sets the color
F:setColor(C)
#tells the clients to apply those changes
F:modify()
timer("1sec",1000)
}elseif(vguiClk()) {
local Ply = vguiClkPlayer() #the player that triggered the e2
local PanelID = vguiClkPanelID() #the id of the panel that he interacted with
#some data that the panel returns.
#E.g. color of a DColorMixer, but in this case just the name of the button
local Data = vguiClkValues() #or vguiClkValuesTable()
print(format("Player: %s ID: %d Data: %s",Ply:name(),PanelID,Data:concat(",")))
if(PanelID == B) {
local C = hsv2rgb(vec((realtime()*10)%360,1,1))
#sets the new color
B:setColor(C)
#applies the new color
B:modify()
}
}