Show when a user is typing?

Anybody know how to show when a user is typing? Just a simple DrawText() dealio on the player, so people can see when they are typing a message.

Thanks! :smiley:

You’d probably have to hook into when they press ‘y’ or, better, run ‘messagemode’ as a concommand (I think) then record what he’s pressing and show it above his head, then clear when he presses enter. I remember seeing something like this on a server, can’t remember who’s it was though.

You could send a usermessage everytime they open the chatbox, and then draw the variable on the HUD. But you would need to think carefully at the side efects

Your best bet is a Networked Int/Bool.

Don’t do the first suggestion, people can change the button that opens the chat.

Mine is Enter.

Clientside:
[lua]
function Typing()
RunConsoleCommand( “c_typing”, “” )
end
hook.Add( “StartChat”, “StartTyping”, Typing )

function NotTyping()
RunConsoleCommand( “c_nottyping”, “” )
end
hook.Add( “StopChat”, “StopTyping”, NotTyping )
[/lua]

Clientside HUD:
[lua]
function DrawTyping()
if( not LocalPlayer():Alive() ) then return end

local trace = { }
	trace.start = LocalPlayer():EyePos()
	trace.endpos = trace.start + LocalPlayer():GetAimVector() * 150
	trace.filter = LocalPlayer()
	local tr = util.TraceLine( trace )
	
	if( tr.Entity:IsValid() and tr.Entity:IsPlayer() ) then
	
		local pos = tr.HitPos:ToScreen()
	
		if( tr.Entity:GetNWBool( "Typing" ) ) then
		
			draw.DrawText( "Typing

", “ScoreboardText”, pos.x, pos.y, Color( 255, 255, 255, 255 ), 1 )

		end
	
	end

end
hook.Add( “HUDPaint”, “DrawType”, DrawTyping )
[/lua]

Server:
[lua]
function cTyping( ply, cmd, args )
ply:SetNWBool( “Typing”, true )
end
concommand.Add( “c_typing”, cTyping )

function cNotTyping( ply, cmd, args )
ply:SetNWBool( “Typing”, false )
end
concommand.Add( “c_nottyping”, cNotTyping )
[/lua]

Okay, thanks for your suggestions guys. :slight_smile:

Posted you an example, you’re basicly running a command clientside when the player opens/closes the chat that sets the networked bool to true or false.

Okay, thanks H0rsey! How would I integrate it into an existing gamemode’s chatsystem? I’m using DarkRP for the record… I know it’s the bane of every good coder’s existence but it’s all I have so far.

make a lua file in garrysmod\lua\autorun\server name it chat.lua and put the code in it that should work

I took H0rsey’s code and made it into one file for you.



if (CLIENT) then
    hook.Add("StartChat", "StartTyping", function()
        RunConsoleCommand("c_typing")
        end)

    hook.Add("StopChat", "StopTyping", function()
        RunConsoleCommand("c_nottyping")
        end)

    hook.Add("HUDPaint", "DrawType", function()
        if (!LocalPlayer:Alive()) then return end

        local Trace = {}
        Trace.start = LocalPlayer():EyePos()
        Trace.endpos = Trace.start + LocalPlayer():GetAimVector() * 150
        Trace.filter = LocalPlayer()
        local Tr = util.TraceLine(Trace)

        if (tr.Entity:IsValid() and tr.Entity:IsPlayer()) then
            local pos = tr.HitPos:ToScreen()

            if (tr.Entity:GetNWBool("Typing")) then
                draw.DrawText("Typing
", "ScoreboardText", pos.x, pox.y, Color(255, 255, 255), 1)
                end
            end
        end)
elseif (SERVER) then
    concommand.Add("c_typing", function(pl)
        pl:SetNWBool("Typing", true)
        end)

    concommand.Add("c_nottyping", function(pl)
        pl:SetNWBool("Typing", false)
        end)

    AddCSLuaFile("autorun/drawchat.lua")
    end


Save that in /lua/autorun/ as drawchat.lua. Unless I made a spelling mistake somewhere that should work.

[lua]if CLIENT then
ErrorNoHalt(“Adding Chatclicker Hooks…”)
hook.Add(“StartChat”, “chatclicker.start”, function() RunConsoleCommand(“chatclicker.start”) end)
hook.Add(“FinishChat”, “chatclicker.end”, function() RunConsoleCommand(“chatclicker.end”) end)
ErrorNoHalt("Done!
")
end

if not SERVER then return end
AddCSLuaFile(“autorun/chatclicker.lua”)

concommand.Add(“chatclicker.start”, function(ply, cmd, n)
if not ply:IsValid() then return end
if ply.chatprop != nil and ply.chatprop:IsValid() then ply.chatprop:Remove() end
ply.chatprop = ents.Create(“prop_physics”)
ply.chatprop:SetModel(“models/extras/info_speech.mdl”)
ply.chatprop:SetPos(ply:LocalToWorld(Vector(0, 0, 100)))
ply.chatprop:SetAngles(ply:GetAngles())
ply.chatprop:SetParent(ply)
end)
concommand.Add(“chatclicker.end”, function(ply, cmd, n)
if not ply:IsValid() then return end
if ply.chatprop:IsValid() then ply.chatprop:Remove() end
end)[/lua]

Save as chatclicker.lua
Place in lua/autorun.

What if the player is moving as they type? :smile:

How is that possible? Other than Noclipping then un-noclipping in midair to start typing.

+forward, various (possible) moving scripts…

oh yeah…well

I am going to rework this and see if I can make it better. :]

If you’re walking/running and open the chat and still hold the keys you’ll move in that direction

[lua]ply.chatprop:SetParent(ply)[/lua]

It’s parented to the player, it’s going to move with them.

Ah right, didn’t notice.

Awesome, thanks for the help guys. :slight_smile:

I’m not sure if I want a prop, though… maybe text that appears over the user’s head?

I think that requires “cam” stuff.

A friend of mine said he could do it but…he lazy. :expressionless: