• ChatBox help
    2 replies, posted
I have trouble with my chatbox, if i open a chat i doesnt update new messeges, it start to show messeges after reopen chat How to update it on every player message? [LUA] local ltoa = {} local tm = false openchat = 0 hook.Add( "PlayerBindPress", "chatbox", function(_,str) if not string.find( str, "messagemode" ) then return end tm = string.find( str, "messagemode2" ) if not frame or not frame:IsValid() then frame = vgui.Create( "DFrame" ) frame:SetSkin("DarkRP") frame:SetPos( S_X, S_Y ) frame:SetSize( S_W * 1.3, S_W * 0.65) frame:SetDraggable(false) frame:SetSizable(false) frame:MakePopup() frame.btnClose.DoRightClick = function() frame:Remove() end local function onenter(me) local t = me:GetValue() if string.Left( t, 2 ) == "//" then t = "/ooc" .. string.sub( t, 3 ) end LocalPlayer():ConCommand( "say" .. ( tm and "_team " or " " ) .. t) frame:Close() openchat = 0 end function frame:Close() if frame.textentry and frame.textentry:IsValid() then frame.textentry:Remove() end frame.textentry = vgui.Create( "DTextEntry", frame ) frame.textentry:SetTall( 20 ) frame.textentry:Dock( BOTTOM ) frame.textentry.OnEnter = onenter frame.textentry:SetAllowNonAsciiCharacters(true) frame.line:MoveToFront() self:SetVisible( false ) gamemode.Call("FinishChat") openchat = 0 end frame.textentry = vgui.Create( "DTextEntry", frame ) frame.textentry:SetTall( 20 ) frame.textentry:Dock( BOTTOM ) frame.textentry.OnEnter = onenter frame.textentry:SetAllowNonAsciiCharacters(true) frame.tabs = vgui.Create( "DPropertySheet", frame ) frame.tabs:Dock( FILL ) frame.line = vgui.Create( "RichText" ) frame.line:GotoTextEnd() timer.Simple(0,function() if ValidPanel(frame.line) then frame.line:GotoTextEnd() end end) local i = 67 frame.line.Paint = function( me, w, h ) --function frame.line:Think() draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 0, 0, 170 ) ) i = i + 1 if i > 66 then me:SetFontInternal( "TargetID" ) i = 0 end --end end frame.tabs:AddSheet( "Chat", frame.line, "icon16/comments.png" ) frame.line:SetFontInternal( "TargetID" ) end frame:SetTitle( "Chat" ) frame:SetVisible( true ) if frame:IsValid() then gamemode.Call("StartChat") openchat = 1 end for _, t in pairs( ltoa ) do frame.line:InsertColorChange( 255, 255, 255, 255 ) if frame.line.cont then frame.line:AppendText( "\n" ) else frame.line.cont = true end for _, e in pairs( t ) do if type( e ) == "string" then frame.line:AppendText( e ) else frame.line:InsertColorChange( e.r, e.g, e.b, e.a ) end end end ltoa = {} frame.textentry:SetValue( "" ) frame.textentry:RequestFocus(true) return true end ) [/LUA]
Well. I would define the chatbox (vgui element) outside the function so I can access it with other functions and hide it when it's not used - show when needed, instead of making it inside a function and recreating it each time. Then, I would create a function hooked to OnPlayerChat that updates info drawn on the mentioned elements.
Sorry, you need to Log In to post a reply to this thread.