How do I target a player with DTextEntry?

I’m making a little RP themed code that when a players name is entered, it says in chat that players RP information. (Basically just their money…)

First I struggled with figuring out how to send a message using lua and since I couldn’t remember the function, I just reverted to using RunConsoleCommand and running “say” with the additional args.
This is what I have so far.


// RP Dox V2
/*
START MENU
*/
function rpdoxmenu()
	local manyoo = vgui.Create("DFrame")
	manyoo:SetSize(200,100)
	manyoo:MakePopup()
	manyoo:SetTitle("Entity Finder")
	manyoo:Center()
--	manyoo:SetKeyBoardInputEnabled() (I guess you can't have the ability to walk while in menu if there is a text entry. Boo.)

	for k, v in pairs(player.GetAll()) do
		local playermoney = (v.DarkRPVars and v.DarkRPVars.money) or 0
		local mark = ("(rpdox)")
	
	local Entroo = vgui.Create( "DTextEntry", manyoo )
	Entroo:SetPos(manyoo:GetWide()/2-40,manyoo:GetTall()/2)
	Entroo:SetSize( 77, 20)
	Entroo.OnEnter = function()
		RunConsoleCommand("say", mark .. " PLAYERNAME: " .. v:Nick() .. ". STEAMID: " .. v:SteamID() .. ". PLAYERCASH: $" .. playermoney .. " (PLAYER IS STAFF) " .. mark)
		end
	end	
end
concommand.Add("_rpdoxmenu", rpdoxmenu)
/*
END MENU
*/

I want to be able to TARGET players by typing in their name… I don’t exactly know how to do that.
Right know no matter what you type in, it chooses a random player and displays their info.
Please help!



Entroo.OnEnter = function( self )
    local playername = self:GetText()
    for _,v in ipairs(player.GetHumans()) do
        if v:Nick() == playername then
            local mark = ("(rpdox)") -- what
            local playermoney = (v.DarkRPVars and v.DarkRPVars.money) or 0
            RunConsoleCommand("say", mark .. " PLAYERNAME: " .. v:Nick() .. ". STEAMID: " .. v:SteamID() .. ". PLAYERCASH: $" .. playermoney .. " (PLAYER IS STAFF) " .. mark)
        end
    end
end


Also, since you’re creating that text entry in a loop, one text entry is being created for each of all the players on the server. There will be a ton stacked on top of eachother

[editline]31st January 2017[/editline]

Also, searching for players by names is not the best idea because if there are two players with the same name it’ll print both

[editline]31st January 2017[/editline]

Also, try using

chat.AddText rather than that console command

Well I want to use say because I want to send (type) that message out to the server. Isn’t there a shortened one like Player:Say() or something? I couldn’t get that one to work if that’s the one I was looking for…

Anyway, I figured it would be more user friendly (Even though I’d be pretty much the only person to use this script) to use a player list rather than an entry box…

So far I have this.


// RP Dox V3

/*
START MENU
*/
function RPDoxMenuV3()

	local Menyoo = vgui.Create("DFrame")
	Menyoo:SetSize(500,350)
	Menyoo:MakePopup()
	Menyoo:SetTitle("RP DoxMenu Version 3")
	Menyoo:Center()
	Menyoo:SetKeyBoardInputEnabled()
	
	local plyrz = vgui.Create("DListView", Menyoo)
	plyrz:SetSize(200, Menyoo:GetTall()-40)
	plyrz:SetPos(10,30)
	plyrz:AddColumn("Players")
	
	local doxem = vgui.Create("DButton", Menyoo)
	doxem:SetSize(50,25)
	doxem:SetPos(Menyoo:GetWide()/2-25,Menyoo:GetTall()/2-20)
	doxem:SetText("RP Dox")
	doxem.DoClick = function() 
		if plyrz:GetSelectedLine() != nil then 
		local plyr = plyrz:GetLine(plyrz:GetSelectedLine()):GetValue(1)
			RunConsoleCommand("say", "// " .. mark .. " PLAYERNAME: " .. plyrz:Nick() .. ". STEAMID: " .. plyr:SteamID() .. ". PLAYERCASH: $" .. playermoney .. mark)
		end
	end
		
	for k, v in pairs(player.GetAll()) do
		plyrz:AddLine(v:Nick())
	end
end
concommand.Add("RPDoxMenuV3", RPDoxMenuV3)
/*
END MENU
*/

I’m getting an error



[ERROR] external:27: attempt to call method 'Nick' (a nil value)
  1. DoClick - external:27
   2. unknown - lua/vgui/dlabel.lua:232


This menu and list is a chopped version of an entity finder I found, so I’m not 100% on what the line above RunConsoleCommand does. I also can’t figure out why Nick is nil.

Thanks for the help on the previous one though, but I think I’m more keen on the list