Hey guys,
I just created a chatbox with a bit of help by this Thread:
But now I have a few problems I don't know how to go on with:
The Chatbox is visible all the time. It just activates when I open the chat so that is correct. But if I just set the chatbox to non visible I also don't see the written chat. And if I take the written chat as an own object which isn't a child of the panel the text is always behind it.
The "TEAM" which is defined in the bottom never shows. The "* DEAD *" shows up but the Team doesn't and I don't know how to make it work correctly.
You always see the complete written text displayed. I think it would be nice if just the newest messages are visible and every message fades out for it own after a specified amount of time. And the complete chat only shows up if you really open the chatbox. But I also don't know how to start here or how to get it working.
I hope some of you can give me some points to get it working.
Your Alphaverse
Code of the Chatbox:
ChatBox = vgui.Create("DFrame")
ChatBox:SetPos(10, ScrH() - 205)
ChatBox:SetSize(300, 200)
ChatBox:SetTitle(GetHostName())
ChatBox:SetDraggable(true)
ChatBox:ShowCloseButton(false)
ChatTextEntry = vgui.Create("DTextEntry", ChatBox)
ChatTextEntry:SetPos(5, 170)
ChatTextEntry:SetSize(250, 20)
ChatTextEntry.OnKeyCodeTyped = function(self, code)
if code == KEY_ESCAPE then
closeChatbox()
gui.HideGameUI()
elseif code == KEY_ENTER then
if string.Trim(self:GetText()) != "" then
LocalPlayer():ConCommand("say "..self:GetText())
end
closeChatbox()
end
end
ChatRichText = vgui.Create("RichText", ChatBox)
ChatRichText:Dock(FILL)
hook.Add( "PlayerBindPress", "overrideChatbind", function(ply, bind, pressed)
bTeamOnly = false
if bind == "messagemode" then
print("global chat")
elseif bind == "messagemode2" then
print("team chat")
bTeamOnly = true
else
return
end
openChatbox(bTeamOnly)
return true
end )
hook.Add("ChatText", "serverNotifications", function(index, name, text, type)
if type == "joinleave" or type == "none" then
ChatRichText:AppendText( text.."\n")
end
end)
hook.Add("HUDShouldDraw", "noMoreDefault", function(name)
if name == "CHudChat" then
return false
end
end)
local oldAddText = chat.AddText
function chat.AddText(...)
local args = {...}
for _, obj in pairs(args) do
if type(obj) == "table" then
ChatRichText:InsertColorChange( obj.r, obj.g, obj.b, 255 )
elseif type(obj) == "string" then
ChatRichText:AppendText(obj)
elseif obj:IsPlayer() then
local col = GAMEMODE:GetTeamColor(obj)
ChatRichText:InsertColorChange(col.r, col.g, col.b, 255)
ChatRichText:AppendText(obj:Nick())
end
end
ChatRichText:AppendText("\n")
oldAddText (...)
end
function openChatbox()
ChatBox:MakePopup()
ChatTextEntry:RequestFocus()
gamemode.Call("StartChat")
end
function closeChatbox()
ChatBox:SetMouseInputEnabled(false)
ChatBox:SetKeyboardInputEnabled(false)
gui.EnableScreenClicker(false)
gamemode.Call("FinishChat")
ChatTextEntry:SetText("")
gamemode.Call("ChatTextChanged", "")
end
function GM:OnPlayerChat(player, strText, bTeamOnly, bPlayerIsDead)
local tab = {}
if (bPlayerIsDead) then
table.insert(tab, Color(0, 255, 40))
table.insert(tab, "*DEAD* ")
end
if (bTeamOnly) then
table.insert(tab, Color(30, 160, 40))
table.insert(tab, "( TEAM ) ")
end
if (IsValid( player)) then
table.insert(tab, player)
else
table.insert(tab, "Console")
end
table.insert(tab, Color(255, 255, 255))
table.insert(tab, ": "..strText)
chat.AddText(unpack(tab))
return true
end
Does nobody no how to do something of this? :c
Does anyone have some ideas?
Chatbox creation seems to be really complicatd task. Have you tried to look for working examples?
I would recommend to use :SetVisible(true) at the beginig and :SetVisible(true\false) on open\close since you have no code for opening or removing the frame.
The problem with this is that the ChatRichText is also hidden then, so you don't see incoming chat also. But if I let he ChatRichText not be a child of the panel the chat is always in the background.
Yes I searched for working examples but they have so much code and features I don't understand or I don't know how to remove.
That's another problem. You may try to make 2 richtext panels, the one will be bound to chatbox (and visible only after you open it) and another will be like 'notification panel' or something. The RichText type has InsertFade feature, that might be helpful in this case.
(sry that my English isn't good enough to explain it better)
Sorry, you need to Log In to post a reply to this thread.