DMenu Scoreboard

Hi all,

I try to auto generate a dmenu on every playerline.

however, it only works on the first player, the rest doesn’t have a menu.

How can I fix this?
Here is the code:



local PLAYER_LINE = 
{
	Init = function( self )

		self.AvatarButton = self:Add( "DButton" )
		self.AvatarButton:Dock( LEFT )
		self.AvatarButton:SetSize( 32, 32 )
		self.AvatarButton.DoClick = function() self.Player:ShowProfile() end
		self.AvatarButton.DoRightClick = function ( btn )
			if self.Player:IsAdmin() then
				self.option = self:Add( "DMenu" )
				self.option:AddOption("Goto", function() RunConsoleCommand('ulx goto ' .. self.Player:Nick()) end ):SetIcon("icon16/arrow_up.png")
				self.option:AddOption("Bring", function() RunConsoleCommand('ulx bring ' .. self.Player:Nick()) end ):SetIcon("icon16/arrow_down.png")
				self.option:AddOption("Spectate", function() RunConsoleCommand('"ulx spectate ' .. self.Player:Nick()) end ):SetIcon("icon16/find.png")
				self.option:AddOption("Kick", function() RunConsoleCommand('ulx kick ' .. self.Player:Nick()) end ):SetIcon("icon16/door_in.png")
				self.option:AddOption("Ban", function() RunConsoleCommand('ulx ban ' .. self.Player:Nick()) end ):SetIcon("icon16/door.png")
				self.option:Open()
			end
		end
		
		self.Avatar		= vgui.Create( "AvatarImage", self.AvatarButton )
		self.Avatar:SetSize( 32, 32 )
		self.Avatar:SetMouseInputEnabled( false )		

		self.Name		= self:Add( "DLabel" )
		self.Name:Dock( FILL )
		self.Name:SetFont( "ScoreboardDefault" )
		self.Name:DockMargin( 8, 0, 0, 0 )
		
		self.Job		= self:Add( "DLabel" )
		self.Job:Dock( FILL )
		self.Job:SetFont( "ScoreboardDefault" )
		self.Job:SetContentAlignment( 5 )

		self.Mute		= self:Add( "DImageButton" )
		self.Mute:SetSize( 32, 32 )
		self.Mute:Dock( RIGHT )

		self.Ping		= self:Add( "DLabel" )
		self.Ping:Dock( RIGHT )
		self.Ping:SetWidth( 50 )
		self.Ping:SetFont( "ScoreboardDefault" )
		self.Ping:SetContentAlignment( 5 )

		self:Dock( TOP )
		self:DockPadding( 3, 3, 3, 3 )
		self:SetHeight( 32 + 3*2 )
		self:DockMargin( 2, 0, 2, 2 )
		self:SetMouseInputEnabled( true )




	end,

	Setup = function( self, pl )

		self.Player = pl

		self.Avatar:SetPlayer( pl )

		self:Think( self )

		--local friend = self.Player:GetFriendStatus()
		--MsgN( pl, " Friend: ", friend )

	end,

	Think = function( self )

		if ( !IsValid( self.Player ) ) then
			self:Remove()
			return
		end

		if ( self.NumPing == nil || self.NumPing != self.Player:Ping() ) then
			self.NumPing	=	self.Player:Ping()
			self.Ping:SetText( self.NumPing )
		end
		
		self.Name:SetText( self.Player:Nick() )
		self.Job:SetText( self.Player.job or "Unemployed" )

		--
		-- Change the icon of the mute button based on state
		--
		if ( self.Muted == nil || self.Muted != self.Player:IsMuted() ) then

			self.Muted = self.Player:IsMuted()
			if ( self.Muted ) then
				self.Mute:SetImage( "icon32/muted.png" )
			else
				self.Mute:SetImage( "icon32/unmuted.png" )
			end

			self.Mute.DoClick = function() self.Player:SetMuted( !self.Muted ) end

		end

		--
		-- Connecting players go at the very bottom
		--
		if ( self.Player:Team() == TEAM_CONNECTING ) then
			self:SetZPos( 2000 )
		end

	end,

	Paint = function( self, w, h )
		local teamcolor = team.GetColor(self.Player:Team())

		if ( !IsValid( self.Player ) ) then
			return
		end

		--
		-- We draw our background a different colour based on the status of the player
		--

		if ( self.Player:Team() == TEAM_CONNECTING ) then
			draw.RoundedBox( 4, 0, 0, w, h, Color( 200, 200, 200, 200 ) )
			return
		end
		
		draw.RoundedBox( 4, 0, 0, w, h, Color( teamcolor.r, teamcolor.g, teamcolor.b, 200) )
	end,
}


Because in your code, self.Player refers to the player the line has been created for, duh. So, replace it with LocalPlayer().

Ah stupid, thanks!

Maybe it doesn’t fit in this threat, but:


RunConsoleCommand('ulx goto ' .. self.Player:Nick())

creates the error:


RunConsoleCommand: Command has invalid characters! (ulx goto Monster (' '))

How can I fix that?

EDIT: Found out myself.


RunConsoleCommand("ulx", "goto", self.Player:Nick())

That works!

Thanks all!