Skip to content

Example

Linus edited this page Dec 27, 2018 · 15 revisions

A simple panel you can open and close with a chat command.

@persist Frame:dframe

if(first()) {
    runOnChat(1)
    #add all players to the default list
    vguiDefaultPlayers(players())
    Frame = dframe(1)
    Frame:setSize(150,150)
    Frame:center() #puts the frame in the center of the screen
    Frame:setVisible(0) #makes the panel invisible
    Frame:setDeleteOnClose(0) # only hides the panel when the close button is pressed, not delete it
    Frame:makePopup() #makes the panel move in the foreground
    Frame:create() #creates the panel on the clients
}
if(chatClk()) {
    if(lastSaid()=="menu") {
        local Visible = Frame:isVisible(lastSpoke()) #get the current visible status of the panel of a specific player
        Frame:setVisible(!Visible) #inverse the status (makes it visible if it's invisible and visible if it's invisible)
        Frame:modify(array(lastSpoke())) #apply changes only to the player who executed the command
    }
}

A simple menu that shows how to interact with buttons.
@persist Main:dframe [Button Button2]:dbutton


if(first()) {
    runOnChat(1) 
    runOnVgui(1) #use runOnVgui to execute the E2 when an interaction with the a vgui element happens
    vguiDefaultPlayers(players()) #add all players to the default list

    Main = dframe(1)
    Main:setTitle("Menu")
    Main:setPos(60,300)
    Main:setColor(255,120,120)
    Main:setDeleteOnClose(0) #only hides the panel when closing it instead of deleting it
    Main:setVisible(0)
    Main:makePopup()
    Main:enableKeyboardInput(0) #disables the keyboard input, you can still move but your mouse is locked on the panel
                                #needs to be called after :makePopup()
    Main:create()
    
    
    Button = dbutton(2,1)
    Button:setPos(15,25)
    Button:setText("Change Color")
    Button:setIcon("icon16/arrow_refresh.png")
    Button:setSize(110,40)
    Button:create()

    Button2 = dbutton(3,1)
    Button2:setPos(15,70)
    Button2:setText("Spawn Prop")
    Button2:setIcon("icon16/package_add.png")
    Button2:setSize(110,40)
    Button2:create()

}
if(chatClk()) {
    if(lastSaid() == "open") {
        Main:setVisible(!Main:isVisible(lastSpoke()))
        Main:modify(array(lastSpoke()))
    }
}

#this get's triggered when any player interacts with an vgui element (presses a button/clicking on a list/etc.)
if(vguiClk()) { 
    local ID = vguiClkPanelID() #this gets the ID of the interacted element
    switch(ID) { #switch-case statement to differenciate from different elements
        case 2,
            Main:setColor(randvec(0,255))
            Main:modify(array(vguiClkPlayer()))
        break
        case 3,
            local AimPos = vguiClkPlayer():aimPos()
            propSpawn("models/props_junk/cardboard_box001a.mdl",AimPos + vec(0,0,50),0)
        break
    }
}

Clone this wiki locally