• Show when a user is typing?
    28 replies, posted
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! :D
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.
[QUOTE=yakahughes;20974289]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.[/QUOTE] 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\n", "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. :)
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. [code] 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\n", "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 [/code] 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!\n") 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.
[QUOTE=JamesFoil;20978744][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!\n") 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.[/QUOTE] What if the player is moving as they type? :smile:
[QUOTE=Crazy Quebec;20979528]What if the player is moving as they type? :smile:[/QUOTE] How is that possible? Other than Noclipping then un-noclipping in midair to start typing.
[QUOTE=Kidd;20980448]How is that possible? Other than Noclipping then un-noclipping in midair to start typing.[/QUOTE] +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
[QUOTE=Crazy Quebec;20979528]What if the player is moving as they type? :smile:[/QUOTE] [lua]ply.chatprop:SetParent(ply)[/lua] It's parented to the player, it's going to move with them.
[QUOTE=Kogitsune;20980760][lua]ply.chatprop:SetParent(ply)[/lua] It's parented to the player, it's going to move with them.[/QUOTE] Ah right, didn't notice.
Awesome, thanks for the help guys. :) 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. :|
cam.3d2d is used to render text as if it was in 3d space. Though, for this type of thing, I think it's important that the user always sees the text instead of having to position his angles to see the rendered 3d text. In that case, you would use Vector.ToScreen with Player.GetPos to use draw.DrawText with the ToScreen coordinates :)
Yeah, I definitely meant DrawText, not some 3d text or anything. I just want a DrawText above the user's head. I want to incorporate it into my gamemode, which has DarkRP as its base. When you walk up to a player it shows their name and job and the like.. I just want it to show if they are typing as well. Thanks again guys. :)
He doesn't mean 3D text. I believe he means 2D Text in 3D Space (Within the world and not on a flat surface)
Yup, DarkRP does that with how it shows users' names and such. Its cl_init.lua file already has hooks for ChatStart and FinishChat, so reconfiguring the script to fit shouldn't be too hard? I am no good with hooks and protocol, I just like making cool things with the knowledge I have. D:
[QUOTE=superkyol;21044752]Yup, DarkRP does that with how it shows users' names and such. Its cl_init.lua file already has hooks for ChatStart and FinishChat, so reconfiguring the script to fit shouldn't be too hard? I am no good with hooks and protocol, I just like making cool things with the knowledge I have. D:[/QUOTE] That's called hudpaint and ply:Name() lol.
[QUOTE=Cubar;21054899]That's called hudpaint and ply:Name() lol.[/QUOTE] Believe me, I've tried.. I can't seem to figure it out at all. I tried setting a custom variable for the player when they open the chatbox, and showing that to other players if they're close enough to see their name.. nada. Bloody complicated, this stuff is.
For everyone to see that a person is typing, you would have to send the fact that the player opened their chatbox to the server, then to all of the other clients. Let me paint a picture with text: Client Opens Chatbox - > Sends the fact that they opened the chatbox to the server using a console command - > Server says "LET'S DO THIS!" Like Captain Price and anally rapes all of the other clients with the fact that that specific player has opened their chatbox by sending it to them in usermessages.
Right so I was wanting to use something like this on my JailBreak server... A[I]nd I realize this is a sort of old thread but uhh, its the only one I could find that actually had some comments.[/I] Anyways, I do like the release that Kidd has made, especially with the speech bubble and everything. But I would really love to know how to resize the thing, I mean the model is gigantic. Is there a way to script it so it appears smaller (and closer to the user's head)? -It gets rather annoying to see a giant speech bubble just to indicate that someone is typing >.< [B]Thanks in advance![/B]
[url=http://wiki.garrysmod.com/?title=Entity.SetModelScale]Entity.SetModelScale[/url]
Sorry, you need to Log In to post a reply to this thread.