Garry's Mod Wiki

Panel:Command

Panel:Command( string command )

Description

Sends an action command signal to the panel. The response is handled by PANEL:ActionSignal.

Arguments

1 string command
The command to send to the panel.

Example

Defines a function which displays a dialog box that asks the player if they want to leave the server. Clicking the buttons fire panel commands that call the PANEL:ActionSignal which handles what action should be taken.

function DisconnectDialog() -- Remove existing dialog box if(DialogBox) then DialogBox:Remove() end -- Font and message local font = "ChatFont" local msg = "Would you like to disconnect?" -- Get the size of the text surface.SetFont(font) local msg_w, msg_h = surface.GetTextSize(msg) -- Padding and button size local padding = 15 local btn_w, btn_h = 35, 25 -- Calculate dialog box size local dialog_w = msg_w+(padding*2) local dialog_h = msg_h+(padding*3)+btn_h -- Create the dialog box DialogBox = vgui.Create("DPanel") DialogBox:SetSize(dialog_w, dialog_h) DialogBox:Center() DialogBox:SetBackgroundColor(Color(64, 64, 92, 255)) -- Message local lbl = vgui.Create("DLabel", DialogBox) lbl:SetPos(padding, padding) lbl:SetSize(msg_w, msg_h) lbl:SetText(msg) lbl:SetFont(font) -- Yes button local yes = vgui.Create("DButton", DialogBox) yes:SetPos((dialog_w/2)-btn_w-20, msg_h+padding*2) yes:SetSize(btn_w, btn_h) yes:SetText("Yes") yes:SetFont(font) yes.DoClick = function() DialogBox:Command("yes") end -- No button local no = vgui.Create("DButton", DialogBox) no:SetPos((dialog_w/2)+20, msg_h+padding*2) no:SetSize(btn_w, btn_h) no:SetText("No") no:SetFont(font) no.DoClick = function() DialogBox:Command("no") end -- Force mouse input DialogBox:MakePopup() -- Hook fired when DialogBox:Command is used function DialogBox:ActionSignal(signalName, signalValue) -- Thank the player and disconnect after 2 seconds if(signalName == "yes") then chat.AddText(Color(192, 192, 224), "Thanks for playing "..LocalPlayer():Nick()..", come back soon!") timer.Simple(2.0, function() RunConsoleCommand("disconnect") end) self:Remove() -- Remove the dialog box elseif(signalName == "no") then self:Remove() end end end
Output:

Page Links


Special Pages


Wikis

?

Render Time: 42ms

DB GetPage 4
Generate Html 14
SaveChanges (1) 15
Render Body 0
Render Sidebar 7