All current players on Derma menu?

Hello, need someone to help me.
How can i add all current players online onto my Derma Menu?

[editline]23rd November 2016[/editline]

I would also need to be able to click on them and then allow someone to do something.

[lua]
local menu = DermaMenu()
for k,v in pairs(player.GetAll()) do
menu:AddOption( v:Nick(), function() MsgN("You clicked on "…v:Nick()) end )
end
menu:Open()
[/lua]

This is how I would do it, it also adds the ability to have a scroll bar and you can add buttons to players to do something. Its bigger and uglier than gonzalogs but it does the job well.


local DermaFrame = vgui.Create("DFrame") -- Make your frame to put your list in
	DermaFrame:SetPos(50,50)
	DermaFrame:SetSize(350,510)
	DermaFrame:SetTitle("")
	DermaFrame:SetVisible(true)
	DermaFrame:SetDraggable(true)
	DermaFrame:ShowCloseButton(true)
	DermaFrame.Paint = function (s,w,h)
		draw.SimpleText("My New Derma!","FONT",175,15, Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
	end

	local UserListScrollBar = vgui.Create("DScrollPanel", DermaFrame) -- This means you can scroll up and down, unless your only expecting a few players and its not needed
		UserListScrollBar:SetSize(350,300)
		UserListScrollBar:SetPos(0,10)
		local UserList = vgui.Create("DListLayout", UserListScrollBar)
			UserList:SetPos(0,0)
			UserList:SetSize(350,3840) -- You want this 128x your UsersList:SetSize(x,y) y value as max of 128 players on a server
			for k, v in pairs(player.GetAll()) do
				local Users = vgui.Create("DPanel", UserList)
					Users:SetSize(350,30)
						Users.Paint = function(s,w,h)
							if v:IsValid() then -- This is important as if a player DC's your list will throw errors if this is not in
								draw.SimpleText(v:Nick(),"FONT",5,15,Color(255,0,0,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER) -- Your player name
							else
								draw.SimpleText("Disconnected","FONT",5,15,Color(255,0,0,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER) -- This is important as if a player DC's your list will throw errors if this is not in
							end
						end
			end

You can also customise your scroll bar with GetVBar. You also probably don’t have to use draw.SimpleText, but I haven’t experimented with anything else, id assume SetText() would throw errors on player disconnected though. To add buttons you have to make a DButton and parent it off the UserList DPanel.

Gonza gave u an idea. If you are looking for that menu. Other ideas good but gonza gave u the simple easy version.

Sir TEST coming in here with the greatest answer of all, a disagree rating. If he did something wrong, why not correct him?

He does rate spam

He does, it’s absolutely ridiculous.

Hello, so i have chosen to use bings design, was wondering if someone could tell me if i was to click on a name how could i make it so if i press a button it will do something to the player that was selected?

So what i mean is:

  1. Press on the name ( It Highlights It )
  2. There is a button on the side which allows me to press and it would do a function e.g. kill.

Many Thanks :smiley:

Why not just create a dcombo box on a frame and have a dbutton with the words kill that kills the selected player? If not you could probably create the button when you do OnSelect.

Alright, thanks a lot guys :smiley: