Getting user input

I’m currently working on a Neon Signs addon for my server. What I want to do is make it so that when the user presses ‘E’ on my entity it opens up a derma menu, and you can enter text into a box. Then, once you’ve finished typing your text it will display the text you put next to the entity.

But how would I display what the user puts into the text box?

Here’s my code:

cl_init.lua


include("shared.lua")

function ENT:Initialize()

end

local function DrawTheMenu()
	local frame = vgui.Create( "DFrame" )
	frame:SetTitle("Neon Signs")
	frame:SetSize( 400, 110 )
	frame:Center()
	frame:MakePopup()

	local TextEntry = vgui.Create( "DTextEntry", frame )
	TextEntry:SetPos( 25, 50 )
	TextEntry:SetSize( 350, 20 )
	TextEntry:SetText( "" )
	TextEntry.OnEnter = function( self )
		chat.AddText( self:GetValue() )
	end
end
usermessage.Hook( "DrawTheMenu", DrawTheMenu )

function ENT:Draw()
	self:DrawModel()

	local Pos = self:GetPos()
	local Ang = self:GetAngles()

	Ang:RotateAroundAxis(Ang:Forward(), 90)
	Ang:RotateAroundAxis(Ang:Right(), 90)

	cam.Start3D2D(Pos + Ang:Forward() * 0, Ang, 0.11)
		draw.WordBox(2, 30, -70, "Testing positioning", "DermaLarge", Color(0, 0, 0, 0), Color(255,255,255,255))
	cam.End3D2D()
end

function ENT:Think()

end


init.lua


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include ( "shared.lua" )

function ENT:Initialize()
	self:SetModel( "models/Items/battery.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	self:SetUseType( SIMPLE_USE )
	self:DrawShadow( false )
end


function ENT:Use( ply, caller )
    umsg.Start( "DrawTheMenu", ply )
        umsg.Short( "1" )
    umsg.End()
end

Bump.

When you send the DrawTheMenu usermessage, pass the entity that is being used so you have something like:

[lua]
function ENT:Use( ply, caller )
umsg.Start( “DrawTheMenu”, ply )
umsg.Entity( self )
umsg.End()
end
[/lua]

That way, you can make it so that the client can let the server know which sign they’re trying to edit:

[lua]
local function DrawTheMenu(um)
local sign = um:ReadEntity() – We now have the sign we want to edit

local frame = vgui.Create( "DFrame" )
frame:SetTitle("Neon Signs")
frame:SetSize( 400, 110 )
frame:Center()
frame:MakePopup()

local TextEntry = vgui.Create( "DTextEntry", frame )
TextEntry:SetPos( 25, 50 )
TextEntry:SetSize( 350, 20 )
TextEntry:SetText( "" )
TextEntry.OnEnter = function( self )
	net.Start("EditSignText")
		net.WriteEntity(sign) -- Let the server know which sign we're editing
		net.WriteString(self:GetText()) -- We want the sign to have this text set
	net.SendToServer()
end

end
usermessage.Hook( “DrawTheMenu”, DrawTheMenu )
[/lua]

Then, on the server, you would have something like this:

[lua]
util.AddNetworkString(“EditSignText”) – Necessary for net messages, which you should use instead of user messages.

net.Receive(“EditSignText”, function(len, ply)
local sign = net.ReadEntity()
local text = net.ReadText()

-- Do your checks here; validity, distance, text length, ownership, etc.

sign:SetText(text) -- Assuming you've made a SetText fonction.. See ENT:SetupDataTables for more info

end)
[/lua]