Button + DComboBox

I have a DComboBox on the left side with several options, then on the right i have a button that says Join. I want it to that when you click one of the options then click join it does somthing. But idk how to link the button to the options. Is there anyway to name an option as somthing so like

If button + Option1 are pressed, then it says Red Team
If button + Option2 are pressed, then it says Blue Team


[lua]local options = {
[“Cyan Team”] = TEAM_CYAN
[“Orange Team”] = TEAM_ORANGE

jointeambutton.DoClick = function()
local value = teambox:GetSelected:GetValue()
local t = options[value]
– “t” is your team value, now you do concommands or something to make the player join the team

Like that, essentially. The idea is the strings in the combo box correspond with a team value, and then you set the player’s team based on the strings in the combo box.

after that do i then add

If t=TEAM_RED then
… do all the stuff
Ifelse t=TEAM_BLUE then
… do more stuff

so on and so on?


local TeamSel = vgui.Create( "DComboBox", self.TeamBackground )
		TeamSel:SetPos(((self.TeamBackground:GetWide()*.15)), 50)	
		TeamSel:SetSize( 250, 175 )
		TeamSel:SetMultiple( false )	
		TeamSel:AddItem( "Red Team" )
		TeamSel:AddItem( "Green Team" )
		TeamSel:AddItem( "Blue Team" )
		TeamSel:AddItem( "Yellow Team" )
		TeamSel:AddItem( "Cyan Team" )
		TeamSel:AddItem( "Orange Team" )
		TeamSel:AddItem( "White Team" )
		TeamSel:AddItem( "Black Team" )
		local options = {  
		["Red Team"] = TEAM_RED
		["Green Team"] = TEAM_GREEN
		["Blue Team"] = TEAM_BLUE
		["Yellow Team"] = TEAM_YELLOW
		["Cyan Team"] = TEAM_CYAN
		["Orange Team"] = TEAM_ORANGE
		["White Team"] = TEAM_WHITE
		["Black Team"] = TEAM_BLACK
		local JoinButton = vgui.Create( "DButton" )
		JoinButton:SetParent( self.TeamBackground )
		JoinButton:SetText( "Join Team" )
		JoinButton:SetPos(((self.TeamBackground:GetWide()*.6)), 65 )
		JoinButton:SetSize( 150, 50 )
		JoinButton.DoClick = function()  
		local value = TeamSel:GetSelected:GetValue()  
		local t = options[value]  
			if t = TEAM_RED then
				LocalPlayer():ChatPrint("You joined the Red Team")

didn’t seem to work, it made the game mode back to sandbox when i tried

if t == TEAM_RED


if t = TEAM_RED

Two things:

  1. You can’t set a player’s team serverside. You’d have to do a concommand, like

RunConsoleCommand( "join_team", t )

  1. In order to keep consistency, it’s best to add the strings to the combo box as they appear in the table.

for k,v in pairs(options) do TeamSel:AddItem( k ) end