Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ChatBox = {}
- ChatBox.ChatText = ""
- ChatBox.LastScroll = 0
- ChatBox.ChatTextShow = ""
- ChatBox.ChatTextShow2 = ""
- ChatBox.Active = false
- ChatBox.Teamsay = false
- ChatBox.TextTable = {}
- ChatBox.InputBoxCol = 'b'
- ChatBox.DrawLine = 0
- ChatBox.LastLine = 0
- ChatBox.AddTextColor = Color(255,255,255,255)
- ChatBox.Width = 0
- ChatBox.CleanTimer = 0
- ChatBox.TrStr1=string.Explode(" ","? e o o e a i a o u c o u o u a a i ? i e a ? y y ? n i e o u a ? E O O E A I A O U C O U O U A A I ? I E A ? Y ? ? N I E O U A ?")
- ChatBox.TrStr2=string.Explode(" ","ё й ц у к е н г ш щ з х ъ ф ы в а п р о л д ж э я ч с м и т ь б ю Й Ц У К Е Н Г Ш Щ З Х Ъ Ф Ы В А П Р О Л Д Ж Э Я Ч С М И Т Ь Б Ю")
- ChatBox.Times = {}
- ChatBox.GroupColors = {OWNER = Color(255,0,0,255), SUPERADMIN = Color(255,130,0,255), ADMIN = Color(255,255,0,255), MODER = Color(0,150,0,255), RESPECTED = Color(0,212,255,255), DONATOR = Color(0,255,127), VIP = Color(255,215,0,255), GIRL = Color(252,15,152)}
- //ChatBox.Width DEPENDING ON SCREEN RESOLUTION
- ChatBox.Width = ScreenScale(300)
- function ChatBox.BroadcastStatus()
- ChatBoxActive = ChatBox.Active
- end
- hook.Add("Think", "BroadcastChatboxStatus", ChatBox.BroadcastStatus)
- function ChatBox.StartChat(teamsay)
- ChatBox.Active = true
- ChatBox.Teamsay = teamsay
- --ChatBox.MenuButton:SetVisible(true)
- --ChatBox.DjButton:SetVisible(true)
- --ChatBox.StopButton:SetVisible(true)
- return true
- end
- function ChatBox.FinishChat()
- ChatBox.Active = false
- --ChatBox.MenuButton:SetVisible(false)
- --ChatBox.DjButton:SetVisible(false)
- --ChatBox.StopButton:SetVisible(false)
- end
- function ChatBox.ChatTextChanged(text)
- ChatBox.ChatText = text
- surface.SetFont("ChatBoxboxFont")
- if surface.GetTextSize(ChatBox.ChatText) > ChatBox.Width then
- ChatBox.ChatTextShow = string.sub(ChatBox.ChatText, string.len(text)-ChatBox.Ltl+1, string.len(text))
- else
- ChatBox.Ltl = string.len(text)
- ChatBox.ChatTextShow = ChatBox.ChatText
- end
- /*for k,v in pairs(ChatBox.TrStr1) do
- ChatBox.ChatTextShow = string.Replace(ChatBox.ChatTextShow, v, ChatBox.TrStr2[k])
- end*/
- end
- function ChatBox.ChatTextParse(plyindex, plyname, text, msgtype)
- local texttable = {}
- if msgtype == "none" then
- table.insert(texttable, Color(255, 120, 0, 255))
- table.insert(texttable, text)
- ChatBox.ParseLine(texttable)
- elseif msgtype == "joinleave" then
- table.insert(texttable, Color(140, 255, 111, 255))
- table.insert(texttable, text)
- ChatBox.ParseLine(texttable)
- end
- end
- hook.Add("ChatText", "ChatBoxText", ChatBox.ChatTextParse)
- function ChatBox.ParseLine(texttable)
- local texttable1 = {}
- local texttable2 = {}
- local parsetable2 = false
- local table2point = 0
- local len = 0
- surface.SetFont("ChatBoxboxFont")
- for k,v in pairs(texttable) do
- if type(v) == "string" then
- if len + surface.GetTextSize(v) > ChatBox.Width then
- local s1, s2
- for i=string.len(v),1,-1 do
- if len + surface.GetTextSize(string.sub(v,1,i)) < ChatBox.Width then
- s1 = string.sub(v,1,i)
- s2 = string.sub(v,i+1,string.len(v))
- break
- end
- end
- table.insert(texttable1, s1)
- Msg(s1)
- table.insert(texttable2, texttable[k-1])
- table.insert(texttable2, s2)
- parsetable2 = true
- table2point = k
- len = 0
- break
- else
- len = len + surface.GetTextSize(v)
- table.insert(texttable1, v)
- Msg(v)
- end
- else
- table.insert(texttable1, v)
- end
- end
- table.insert(ChatBox.TextTable, texttable1)
- table.insert(ChatBox.Times,os.time()+10)
- if parsetable2 == true then
- ChatBox.ParseLine(texttable2)
- end
- ChatBox.LastLine = ChatBox.LastLine+1
- ChatBox.DrawLine = ChatBox.LastLine
- if !parsetable2 then
- Msg("\n")
- end
- end
- function ChatBox.DrawTextTable()
- for i=ChatBox.DrawLine-(ChatBox.Active and 13 or 5), ChatBox.DrawLine do
- local drawcolor = Color(255,255,255,255)
- local len = 0
- local row = ChatBox.TextTable[i]
- if row and (ChatBox.Active or (ChatBox.Times[i] > os.time())) then
- for k,v in pairs(row) do
- if type(v) == "string" then
- --draw.SimpleText(v, "ChatBoxboxFont", 12 + len, ScrH() - ScrH() / 2 + ScreenScale(8) * (i-ChatBox.DrawLine+13), drawcolor, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, Color(0, 0, 0,255))
- local text = {}
- text.pos = {}
- text.text = v
- text.pos[1] = 12 + len
- text.pos[2] = ScrH() - ScrH() / 2 + ScreenScale(8) * (i-ChatBox.DrawLine+13)
- text.xalign = TEXT_ALIGN_LEFT
- text.yalign = TEXT_ALIGN_LEFT
- text.color = drawcolor
- text.font = "ChatBoxboxFont"
- draw.TextShadow(text, 1.2, 255)
- surface.SetFont("ChatBoxboxFont")
- len = len + surface.GetTextSize(v)
- else
- drawcolor = v
- end
- end
- end
- end
- end
- function ChatBox.GetLineText(nmLine)
- local row = ChatBox.TextTable[nmLine]
- local str = ""
- if row then
- for k,v in pairs(row) do
- if type(v) == "string" then
- str=str..v
- end
- end
- end
- return str
- end
- function Chatbox_DrawHud()
- surface.SetFont("ChatBoxboxFont")
- ChatBox.DrawTextTable()
- if not ChatBox.Active then return end
- //print("grabbeen peelz")
- if CurTime() > ChatBox.LastScroll then
- if input.IsKeyDown(KEY_PAGEDOWN) or input.IsKeyDown(KEY_DOWN) then
- ChatBox.DrawLine = ChatBox.DrawLine +1
- ChatBox.LastScroll = CurTime()+0.1
- end
- if input.IsKeyDown(KEY_PAGEUP) or input.IsKeyDown(KEY_UP) then
- ChatBox.DrawLine = ChatBox.DrawLine -1
- ChatBox.LastScroll = CurTime()+0.1
- end
- end
- if input.IsMouseDown(MOUSE_RIGHT) then
- local mx, my = gui.MouseX(), gui.MouseY()
- if mx > 12 and mx < ChatBox.Width and !ChatBox.CMenu then
- local ln = -1
- for i = 0,15 do
- local ly = ScrH() - ScrH() / 2 + ScreenScale(8) * (i)
- if my > ly and my < ly+ScreenScale(8) then
- ln = ChatBox.DrawLine-(14-i)+1
- break
- end
- end
- ChatBox.SelLine = ln
- ChatBox.Menu = DermaMenu()
- local m = ChatBox.Menu
- m:AddOption("Scroll up",function() ChatBox.DrawLine = ChatBox.DrawLine -1 end)
- m:AddOption("Copy message to clipboard", function() SetClipboardText(ChatBox.GetLineText(ChatBox.SelLine)) end )
- m:AddSpacer()
- local cs = m:AddSubMenu("Chatbox settings")
- cs:AddOption("Make input box white",function() ChatBox.InputBoxCol = 'w' end)
- cs:AddOption("Make input box black",function() ChatBox.InputBoxCol = 'b' end)
- m:Open()
- end
- end
- ChatBox.DrawLine = math.Clamp(ChatBox.DrawLine,1,ChatBox.LastLine)
- surface.SetDrawColor(0, 0, 0, 100)
- surface.DrawRect(10, ScrH() - ScrH() / 2, ChatBox.Width, ScreenScale(8) * 14)
- surface.SetDrawColor(0, 0, 0, 255)
- surface.DrawOutlinedRect(10, ScrH() - ScrH() / 2, ChatBox.Width, ScreenScale(8) * 14)
- if ChatBox.InputBoxCol == 'b' then
- surface.SetDrawColor(0, 0, 0, 175)
- else
- surface.SetDrawColor(255,255,255,175)
- end
- surface.DrawRect(10, ScrH() - ScrH() / 2 + ScreenScale(8) * 14 + 2, ChatBox.Width - 1, ScreenScale(8))
- if ChatBox.Teamsay then
- surface.SetDrawColor(team.GetColor(LocalPlayer():Team()))
- else
- if ChatBox.InputBoxCol == 'b' then
- surface.SetDrawColor(255,255,255,255)
- else
- surface.SetDrawColor(0,0,0,255)
- end
- end
- surface.DrawOutlinedRect(10, ScrH() - ScrH() / 2 + ScreenScale(8) * 14 + 2, ChatBox.Width, ScreenScale(8))
- if ChatBox.InputBoxCol == 'b' then
- draw.SimpleText(ChatBox.ChatTextShow, "ChatBoxboxFont", 12, ScrH() - ScrH() / 2 + ScreenScale(8) * 14 + 2, Color(255,255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
- else
- draw.SimpleText(ChatBox.ChatTextShow, "ChatBoxboxFont", 12, ScrH() - ScrH() / 2 + ScreenScale(8) * 14 + 2, Color(0,0,0,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT)
- end
- end
- function ChatBox.HideShitFagLol(name)
- if name == "CHudChat" and ChatBox.Active == false then
- return false
- elseif name == "CHudChat" and ChatBox.Active == true then
- hook.Remove("HUDShouldDraw", "AntiDefaultChat")
- end
- end
- function chat.AddText(...)
- arg = {...}
- local texttable = {}
- for k,v in pairs(arg) do
- if type(v) == "string" then
- table.insert(texttable, ChatBox.AddTextColor)
- table.insert(texttable, v)
- elseif type(v) == "Player" then
- local group = v:GetNWString("GA_Group", "USER")
- if group != "USER" and group != "CONSOLE" and group != "MINGEBAG" then
- print("GROUP:"..group)
- table.insert(texttable,ChatBox.GroupColors[group])
- table.insert(texttable,"["..group.."] ")
- end
- if teamonly == true then
- table.insert(texttable, team.GetColor(v:Team()))
- table.insert(texttable, "(TEAM)")
- end
- if dead == true then
- table.insert(texttable, Color(200, 0, 0, 255))
- table.insert(texttable, "*DEAD*")
- end
- table.insert(texttable, team.GetColor(v:Team()))
- table.insert(texttable, v:Name())
- else
- ChatBox.AddTextColor = v
- end
- end
- ChatBox.ParseLine(texttable)
- end
- --hook.Add("Initialize","ChatBoxInit",function() --we're getting this late enough anyways...
- surface.CreateFont("dejavusans", ScreenScale(8), 600, true, false, "ChatBoxboxFont")
- --ChatBox.InitButtons()
- hook.Add("ChatTextChanged", "ChatBoxTextChanged", ChatBox.ChatTextChanged)
- hook.Add("StartChat", "ChatBoxStartChat", ChatBox.StartChat)
- hook.Add("FinishChat", "ChatBoxFinishChat", ChatBox.FinishChat)
- hook.Add("HUDPaint", "Chatbox_DrawHud", Chatbox_DrawHud)
- hook.Add("GUIMousePressed","ChatboxScroll",ChatBox.MouseWheel)
- hook.Add("HUDShouldDraw", "AntiDefaultChat", ChatBox.HideShitFagLol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement