Getting players into a DComboBox?

[DEL]How would I go on creating a DComboBox with the players inside the server listed in it?[/DEL]

[DEL]“Bring/Goto” commands?
Would it be as simple as


function Bring(ply)
local pos = LocalPlayer():GetPos()
	target:SetPos(pos)
end


[/DEL]

Muting?
I was thinking of making a NetworkedBool and then check if the player has it = 1, then return false on PlayerCanVoice hook.
How would I go on, creating a NetworkedBool?

Thanks in advance!

Use the for loop to get all the players, AddItem to add the player’s Nick().

You need to then store a variable with the player selected.

If you can’t figure it out after that I’ll post code :confused:

[lua]
for k,v in pairs(players:GetAll()) do
YourParent:AddItem(v:Nick())
[/lua]

use this for getting the selected player:
[lua]
local playaa = YourParentName:GetSelected()
– slay command, not sure cuase its client side
[/lua]

That will make local player = their name

0_0

Im pretty sure it would

He’s right and you can’t simply use GetSelected() which you’ve just looked up from the wiki.

To retrieve the value of the currently selected box in a DComboBox, you use

[lua]local selected = box:GetSelectedItems()[1]:GetValue()[/lua]

[lua] local DComboBox1 = vgui.Create(‘DComboBox’, AdFrame)
DComboBox1:SetSize(180, 340)
DComboBox1:SetPos(60, 90)
DComboBox1:EnableHorizontal(false)
DComboBox1:EnableVerticalScrollbar(true)
DComboBox1:SetMultiple(false)
DComboBox1.Paint = function()
surface.SetDrawColor(0,0,0,155)
end

	for _,ply in pairs(player.GetAll()) do
		DComboBox1:AddItem(ply:Nick())
		DComboBox1:SelectByName(LocalPlayer():Nick())
	end


function DComboBox1:Think()
	if (DComboBox1:GetSelected() != nil) then
		X = DComboBox1:GetSelected():GetValue()
	end
	
	for o,p in pairs(player.GetAll()) do
		if (p:Nick() == X) then
			TSP = p -- TSP is the selected player.
		end
	end
end 

[/lua]

That is an awful way to do it.

[lua]local DComboBox1 = vgui.Create( “DComboBox”, AdFrame )
DComboBox1:SetSize( 180, 340 )
DComboBox1:SetPos( 60, 90 )
DComboBox1:EnableHorizontal( false )
DComboBox1:EnableVerticalScrollbar( true )
DComboBox1:SetMultiple( false )

for _,ply in ipairs( player.GetAll() ) do
local item = DComboBox1:AddItem( ply:Nick() )
item.Ply = ply

if ( ply == LocalPlayer() ) then
	item:SetSelected( true )
end

end

function DComboBox1:Think()
TSP = DComboBox1:GetSelectedItems()[1].Ply
end[/lua]

So, with Overvs code, would it be like this?


DButton4.DoClick = function()
	TSP:Kill()
end

Yes, TSP returns the player entity

Thanks, I’ma try it out :slight_smile:

No, because Kill() is a serverside function, you’d have to set it up in a console command.

Also, I’d suggest you run checks to see if the player running the command is an admin/superadmin.

I can post you the full code for what you want if you’d like, up to you, if you’d prefer to come up with it yourself or not.

In that case you’d do

[lua]DButton4.DoClick = function()
DComboBox1:GetSelectedItems()[1]:Kill()
end[/lua]

FapHack has a rather good example of this, feel free to read. It’s basically what Overv did, in a bit more depth.

[lua]local friends_false = vgui.Create(“DComboBox”)
friends_false:SetParent(dpanel)
friends_false:SetPos(((FapHack.Menu:GetWide() - 151) / 2 )- 90 , texh + 55 )
friends_false:SetSize(90 , 120 )
friends_false.OldItem = friends_false.SelectItem

friends_false.OldPaint = friends_false.Paint
friends_false.Paint = function(…)
for k , v in pairs(friends_false:GetItems()) do
if ValidEntity(v.Player) then
v:SetText(v.Player:Nick())
else
v:Remove()
end
end
return friends_false.OldPaint(…)
end

local friends_true = vgui.Create(“DComboBox”)
friends_true:SetParent(dpanel)
friends_true:SetPos(((FapHack.Menu:GetWide() - 151) / 2 )- 90 + friends_false:GetWide() + 25 , texh + 55 )
friends_true:SetSize(90 , 120 )
friends_true.OldItem = friends_true.SelectItem

friends_true.OldPaint = friends_true.Paint
friends_true.Paint = function(…)
for k , v in pairs(friends_true:GetItems()) do
if ValidEntity(v.Player) then
v:SetText(v.Player:Nick())
else
v:Remove()
end
end
return friends_true.OldPaint(…)
end

function PopulateCombo()
friends_false:Clear()
friends_true:Clear()

local friends , notfriends = FapHack:GetFriends()

for k , v in pairs(friends) do
	local it = friends_true:AddItem(v:Nick())
	it.Player = v
end

for k , v in pairs(notfriends) do
	local it = friends_false:AddItem(v:Nick())
	it.Player = v
end

end

friends_true.SelectItem = function(self , item , multi)
local pl = item.Player
print("FapHack: Removing player “…pl:Nick()… " from the aim friends list.”)
FapHack:RemoveFriend(pl)

PopulateCombo()

end

friends_false.SelectItem = function(self , item, multi)
local pl = item.Player
print("FapHack: Adding player “…pl:Nick()… " to the aim friends list.”)
FapHack:AddFriend(pl)

PopulateCombo()

end

function AddPlayer(pl)
–print("FapHack: Entity created: " , pl)
if pl:IsPlayer() then
PopulateCombo()
end
end
FapHack:RegisterFunc(AddPlayer , “OnEntityCreated”)

function RemovePlayer(pl)
if pl:IsPlayer() then
timer.Simple(0.1 , PopulateCombo)
end
end

FapHack:RegisterFunc(RemovePlayer , “EntityRemoved”)[/lua]

Yea, but I have this though;


function DComboBox1:Think()
	target = DComboBox1:GetSelectedItems()[1].Ply
end

so it should work like this, yes?


DButton4.DoClick = function()
target:Kill()
end

What’s the point in setting the target every frame when you can set it when you need it?

I dont know; thought it was supposed to be like that, since someone posted it. Apparently not, then.

[editline]06:43PM[/editline]

Like this then?


DButton4.DoClick = function()
     local target = DComboBox1:GetSelectedItems()[1].Ply
target:Kill()
end

This will not work because Kill() is a serverside function and DoClick is a clientside function, right?