• Creating DComboBox With Players
    3 replies, posted
I'm trying to create a simple drop down box with options. I would like the options to be online players' name, however, I can't find out how to go about doing this. I have the following, however, I'm not sure where to go from here: [code] local plyTbl = player.GetAll() local plyList = vgui.Create("DComboBox") plyList:SetPos(5, 5) plyList:SetSize(100, 20) plyList:SetValue("Players") plyList:AddChoice("Option") [/code] I'm not asking for handouts, as a matter of fact, I'd rather someone [u]not[/u] do this for me. As I will learn from experience. However, I'd like someone to point me in the right direction. PS - I also know I'd have to use a for loop, however, I'm still not sure how to place each option (table values) in "plyList:AddChoice". I also do not know how I'd scale the options to be the current number of players online (I'm guessing I'd do something like "#plyList"). Thanks for any help you can give!
I'm on my phone but something like this should work. [CODE] for k,v in pairs(player.GetAll()) do plyList:AddChoice(v:Name()) end [/CODE] What's happening here is I'm looping thru each player in the server and making a new option choice with the current players name
DComboBox:AddChoice() also accepts a 'data' argument, assuming you're doing something with the player afterward. [lua]plyList:AddChoice(v:Name(), v:UserID()) local name, uid = plyList:GetChoice()[/lua]
[QUOTE=mrotsG;52063889]I'm on my phone but something like this should work. [CODE] for k,v in pairs(player.GetAll()) do plyList:AddChoice(v:Name()) end [/CODE] What's happening here is I'm looping thru each player in the server and making a new option choice with the current players name[/QUOTE] I think I'll try this out. It seems like it should work. EDIT: It works, thanks a bunch, my man!
Sorry, you need to Log In to post a reply to this thread.