So im coding a menu which allows people to use ULX Commands fast. Here is my current code. How do I have it list online players in DComboBox and have a button in which once a player is selected. They will be gagged?
[CODE]
function DermaTest()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( ScrW()/2 - 225, ScrH()/2 -100 )
DermaPanel:SetSize( 350, 400 )
DermaPanel:SetTitle( "Testing Derma Stuff" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
local PropertySheet = vgui.Create( "DPropertySheet", DermaPanel )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 340, 315 )
local DComboBox = vgui.Create( "DComboBox" )
player.GetAll( )
DComboBox:SetSize( 100, 20 )
DComboBox:SetValue( "Players" )
player.GetAll( )
DComboBox.OnSelect = function( panel, index, value )
PrintTable( player.GetAll() )
end
local SheetItemTwo = vgui.Create( "DCheckBoxLabel" , CategoryContentTwo )
SheetItemTwo:SetText( "Use SENTs?" )
SheetItemTwo:SetConVar( "some_convar" )
SheetItemTwo:SetValue( 1 )
SheetItemTwo:SizeToContents()
PropertySheet:AddSheet( "ULX Menu", DComboBox, "icon16/user.png",
false, false, "WOW It's a text box!!!" )
PropertySheet:AddSheet( "Super Menu", SheetItemTwo, "icon16/group.png",
false, false, "Can I haz meh cheezburger now?" )
end
concommand.Add( "dermatest", DermaTest )
net.Receive('Derma_Test', function()
RunConsoleCommand('dermatest')
print('derma_test')
end )
[/CODE]
You can check the Wiki and find that the DComboBox has a function to add values to its menu, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/DComboBox/AddChoice]DComboBox/AddChoice[/url]. With that knowledge you can just loop through all the players ([img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/pairs]Global.pairs[/url]) and add their nicks to the ComboBox.
How do I put the code. I'm not the best at coding right now. Can someone do the code for me real quick?
[QUOTE=BuilderGaming;46973508]How do I put the code. I'm not the best at coding right now. Can someone do the code for me real quick?[/QUOTE]
Best to repair your own code man. Helps you learn quicker. Trust me.
[QUOTE=xthenarwhalx;46974359]Best to repair your own code man. Helps you learn quicker. Trust me.[/QUOTE]
Ok Ill try experimenting a little more
[editline]20th January 2015[/editline]
Is this correct?
[CODE]
DComboBox:AddChoice = function()
for k, v in pairs( player.GetAll() ) do
v:Nick()
end )
[/CODE]
[QUOTE=BuilderGaming;46974791]Ok Ill try experimenting a little more
[editline]20th January 2015[/editline]
Is this correct?
[CODE]
DComboBox:AddChoice = function()
for k, v in pairs( player.GetAll() ) do
v:Nick()
end )
[/CODE][/QUOTE]
-snip-
Try
[lua]
DComboBox:AddChoice("Print Names")
DComboBox.OnSelect = function(self, value)
if value == "Print Names" then
for k, v in pairs( player.GetAll() ) do
print(v:Nick())
end
end
end
[/lua]
[editline] swag [/editline]
To list all players, do something like this:
[lua]
for k, v in pairs( player.GetAll() )do
DComboBox:AddChoice( v:Nick() ) --Add all players.
end
DComboBox.OnSelect = function( self, value )
for k, v in pairs( player.GetAll() ) do
if value == v:Nick() then --If our selected text is the same as a player's name, then...
v:SetMuted( not v:IsMuted() ) --Set their mute status to the opposite of their current mute status. Toggle it.
return --Don't mute two people if there are duplicate names. Stop running this code if we have found someone.
end
end
end
[/lua]
[QUOTE=bobbleheadbob;46975340]-snip-
Try
[lua]
DComboBox:AddChoice("Print Names")
DComboBox.OnSelect = function(self, value)
if value == "Print Names" then
for k, v in pairs( player.GetAll() ) do
print(v:Nick())
end
end
end
[/lua]
Wow I'm stupid. I put it on the combo box. I have done experimenting and I got it to got the way I want. Thank you :)
[editline] swag [/editline]
To list all players, do something like this:
[lua]
for k, v in pairs( player.GetAll() )do
DComboBox:AddChoice( v:Nick() ) --Add all players.
end
DComboBox.OnSelect = function( self, value )
for k, v in pairs( player.GetAll() ) do
if value == v:Nick() then --If our selected text is the same as a player's name, then...
v:SetMuted( not v:IsMuted() ) --Set their mute status to the opposite of their current mute status. Toggle it.
return --Don't mute two people if there are duplicate names. Stop running this code if we have found someone.
end
end
end
[/lua][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.