Hi!
I found a custom chatbox , for roleplay, but i cant fix it.
The ooc,yell,whisper etc. doesn't work.
And it doesn't show the prints.
Can anybody help me to fix it, because i like that chatbox ?
[lua]// Custom Chatbox
surface.CreateFont( "Tahoma", 16, 1000, true, false, "DarklandChatBox" )
function FluctuateColor(a)
a = a or 1
return math.abs(math.sin(CurTime()*a))
end
teamchat = false
chaton = false
local realtext = ""
local chattext = ""
local maxlines = 10
local history = {}
local cursorpos = 0
local COLOR_CHAT = Color( 255, 255, 255, 255 )
local COLOR_CONSOLE = Color( 217, 0, 25, 255 )
local COLOR_WHISPER = Color( 101, 202, 36, 255 )
local COLOR_NOTIFY = Color( 101, 202, 36, 255 )
local COLOR_HINT = Color( 77, 131, 240, 255 )
local COLOR_PRINT = Color( 127, 127, 127, 255)
function AddHistory( pl, msg, type )
type = tonumber(type) or 0
local col = COLOR_CONSOLE
if type == 1 then
col = COLOR_CHAT
elseif type == 2 then
col = COLOR_WHISPER
elseif type == 3 then
col = COLOR_NOTIFY
elseif type == 4 then
col = COLOR_HINT
elseif type == 5 then
col = COLOR_PRINT
end
if pl == 0 then pl = nil end
if tonumber(pl) == pl then
for k, v in pairs( player.GetAll() ) do
if v:UserID() == pl then
pl = v
break
end
end
end
if pl and pl:IsPlayer() and pl.UserID then
local r,g,b,a = pl:GetColor()
local color = Color( r, g, b, 255 )
if ( r == 255 and
g == 255 and
b == 255 and
a == 255 ) then
color = team.GetColor( pl:Team() )
end
local chatInfo = {
pl = pl,
admin = pl:IsAdmin(),
name = pl:GetName(),
color = color,
textcolor = col,
msg = msg,
type = type or 1,
time = RealTime()+10
};
if type == 6 then
print("PM from " .. pl:GetName().." - "..msg)
elseif type == 7 then
chatInfo = {
pl = pl,
admin = false,
name = "(Advert)",
color = Color(46,116,24,255),
textcolor = Color(255,255,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
elseif type == 8 then
chatInfo = {
pl = pl,
admin = false,
name = "(Request)",
color = Color(66,218,241,255),
textcolor = Color(255,255,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
elseif type == 9 then
chatInfo = {
pl = pl,
admin = false,
name = "(Radio)",
color = Color(43,117,208,255),
textcolor = Color(255,255,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
elseif type == 10 then
chatInfo = {
pl = pl,
admin = false,
name = "(Broadcast)",
color = Color(225,96,51,255),
textcolor = Color(255,255,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
elseif type == 11 then
chatInfo = {
admin = false,
color = Color(225,128,0,255),
textcolor = Color(255,128,0,255),
msg = pl:GetName().." "..msg,
type = type or 1,
time = RealTime()+10
};
print(pl:GetName().." "..msg)
elseif type == 12 then
chatInfo = {
pl = pl,
admin = false,
name = "(Gang)",
color = Color(80,80,80,255),
textcolor = Color(255,255,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
elseif type == 13 then
chatInfo = {
pl = pl,
admin = true,
name = pl:Name(),
color = Color(43,117,208,255),
textcolor = Color(120,120,255,255),
msg = msg,
type = type or 1,
time = RealTime()+10
};
end
table.insert(history,1,chatInfo)
else
local chatInfo = {
textcolor = col,
msg = msg,
type = type or 1,
time = RealTime()+10
};
table.insert(history,1,chatInfo)
end
history[maxlines+1] = nil
end
usermessage.Hook("__chatprint",function(um) local msg = um:ReadString() AddHistory(NULL,msg,0) print(msg) end)
function OnPlayerChat( player, msg )
if !IsValid(player) then
AddHistory( nil, msg, 0 )
print(msg)
else
local name = player:Name()
AddHistory( player, msg, 1 )
MsgN(name..": "..msg)
end
return true
end
hook.Add("OnPlayerChat","SeriousChat",OnPlayerChat)
function TW(s,f)
local w = surface.GetTextSize(s,f)
return w
end
function ChatPaint()
local x, y = 80, ScrH()-140
if ChatOffset then
x = ChatOffset.x or x
y = ChatOffset.y or y
end
local num = 0
local total = 0
for i,v in pairs(history) do
if v.time > RealTime() or chaton then
if v.pl then
local x2 = x
/*if v.admin and v.pl:GetNWBool("disguised") == false then
draw.SimpleText("(Admin)","DarklandChatBox",x-4,(y-i*15)+1,Color(0,0,0,255),2)
draw.SimpleText("(Admin)","DarklandChatBox",x-5,(y-i*15),Color(FluctuateColor(2)*255,0,0,255),2)
end */
draw.SimpleText(v.name,"DarklandChatBox",x+1,(y-i*15)+1,Color(0,0,0,255))
draw.SimpleText(v.name,"DarklandChatBox",x,y-i*15,v.color)
x2 = x2+TW(v.name,"DarklandChatBox")+1
draw.SimpleText(": "..v.msg,"DarklandChatBox",x2+1,(y-i*15)+1,Color(0,0,0,255))
draw.SimpleText(": "..v.msg,"DarklandChatBox",x2,y-i*15,v.textcolor)
else
draw.SimpleText(v.msg,"DarklandChatBox",x+1,(y-i*15)+1,Color(0,0,0,255))
draw.SimpleText(v.msg,"DarklandChatBox",x,y-i*15,v.textcolor)
end
end
end
-- Draw text input
if chaton then
local prefix = "Say"
if string.find(GAMEMODE.Name,"RP") then
if string.find( realtext, "//" ) == 1 then
prefix = "OOC"
elseif string.find( realtext, "/y" ) == 1 then
prefix = "Yell
Errm you are aware thats the Darklands chatbox. So it will only work with there gamemode.
make your own instead of ripping darkland's from your cache and then we will help
[QUOTE=CombineGuru;23688139]make your own instead of ripping darkland's from your cache and then we will help[/QUOTE]
i found it on facepunch.
I tried to make my own, but i couldnt :(
i just need a simple template
This should be in request section because you dont want to do any work
[QUOTE=King Flawless;23688716]This should be in request section because you dont want to do any work[/QUOTE]
I just want to learn. I f****d my whole day with this.
I dont want that other people do the whole chatbox for me.
[QUOTE=ToNi;23689007]I dont want that other people do the whole chatbox for me.[/QUOTE]
Yet your using someone elses chatbox?
[QUOTE=King Flawless;23689100]Yet your using someone elses chatbox?[/QUOTE]
Now i use the normal chatbox, because that one doesn't work.
I dont know how to start a new chatbox, that's why i tried to find a working custom chatbox.
[QUOTE=King Flawless;23688716]This should be in request section because you dont want to do any work[/QUOTE]
[QUOTE=King Flawless;23689100]Yet your using someone elses chatbox?[/QUOTE]
very constructive comments.. you have 2posts and both just flaming? why dont u leave?
Full quide to making a custom chat box in GMod:
A) Learn Lua.
B) Learn Lua.
C) Learn Lua.
D) Make chatbox derma/HUD.
C) Overwrite the chatbox binds.
D) Overwrite chat.AddText.
E) Learn Lua.
Understand?
Also notice how nearly every post here but his has 2XDumb.
[QUOTE=goluch;23690629]Full quide to making a custom chat box in GMod:
A) Learn Lua.
B) Learn Lua.
C) Learn Lua.
D) Make chatbox derma/HUD.
C) Overwrite the chatbox binds.
D) Overwrite chat.AddText.
E) Learn Lua.
Understand?
Also notice how nearly every post here but his has 2XDumb.[/QUOTE]
I've already read:
[url]http://www.lua.org/pil/[/url]
And Garry's Mod Wiki.
But i didnt know how to start it.
But thank you for that.Finally someone, who gave me a start.
[QUOTE]D) Make chatbox derma/HUD.
C) Overwrite the chatbox binds.
D) Overwrite chat.AddText.
[/QUOTE]
[QUOTE=Zedger;23689282]very constructive comments.. you have 2posts and both just flaming? why dont u leave?[/QUOTE]
I have over 2k posts here and 90% of them is flaming people who dont want to learn and want everything done for them, So if you dont like it Why dont you just leave?
[QUOTE=King Flawless;23702413]I have over 2k posts here and 90% of them is flaming people who dont want to learn and want everything done for them, So if you dont like it Why dont you just leave?[/QUOTE]
July 2010
4 Posts
Orly?
[QUOTE=nandris94;23703794]July 2010
4 Posts
Orly?[/QUOTE]
My other accounts were misplaced
[QUOTE=King Flawless;23702413]I have over 2k posts here and 90% of them is flaming people who dont want to learn and want everything done for them, So if you dont like it Why dont you just leave?[/QUOTE]
Why do you visit the newbie questions section? You don't even know how to answer any of the questions posted here.
blackops posted a stripped down version of his chatbox earlier. You could find that and use it as a base.
[QUOTE=|FlapJack|;23704634]blackops posted a stripped down version of his chatbox earlier. You could find that and use it as a base.[/QUOTE]
Hm thank you very much :)
I try to find it.
I found it. Thanks for the tip!
Ok now i start to work on the chatbox.
It goes well, but when i press Y, the cursor is not in the DTextEntry, so i have to click in. How can i fix it?
[lua]--These two hooks should stop the default chatbox from ever showing up
hook.Add( "StartChat", "ChatStartChat", function(t) return true end )
hook.Add( "HUDShouldDraw", "ChatNoOldChatPlox", function ( x ) if ( x == "CHudChat" ) then return false end end ) --Disable that fucking shitty chat
function ChatBox()
--Create your chatbox vgui here
local x, y = 80, ScrH()-300
surface.CreateFont ("coolvetica",17, 700, true, false, "ChatSay")
local DermaFrame = vgui.Create( "DFrame" )
DermaFrame:SetPos( x-25, y-50 )
DermaFrame:SetSize( 475, 220 )
DermaFrame:SetTitle( "" )
DermaFrame:SetVisible( true )
DermaFrame:SetDraggable( false )
DermaFrame:ShowCloseButton( true )
DermaFrame:MakePopup()
DermaFrame.Paint = function()
draw.RoundedBox(2, 4, 4, DermaFrame:GetWide()-8, DermaFrame:GetTall() - 8, Color(0, 0, 0, 100))
end
local TestingPanel = vgui.Create( "DPanel",DermaFrame )
TestingPanel:SetPos( x-25, y-50 )
TestingPanel:SetSize( 475, 200 )
TestingPanel.Paint = function()
surface.SetDrawColor( 1, 1, 1, 100 )
surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() )
end
local DermaText = vgui.Create( "DTextEntry",DermaFrame )
DermaText:SetPos( 42,196 )
DermaText:SetTall( 20 )
DermaText:SetWide( 425 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
DermaFrame:Remove()
end
local Say= vgui.Create("DLabel",DermaFrame)
Say:SetText("Say :")
Say:SetPos( 10,200 )
Say:SetFont("ChatSay")
end
hook.Add( "Initialize", "ChatInitialize")
concommand.Add( "ChatBox",ChatBox )
hook.Add("PlayerBindPress", "ChatOverrideChat", function( ply, bind, pressed )
if ply == LocalPlayer() then
if string.find( bind, "messagemode" ) and pressed then
local teamchat = string.find( bind, "messagemode2" ) != nil
--Do some stuff, this hooks into when a player presses their chat key
ply:ConCommand("ChatBox")
return true --Don't run the command
end
end
end )
hook.Add( "ChatText", "ChatChatText", function( entindex, name, text, msgtype )
--Useful information that you can use for your chatbox
return true --Don't display in default chatbox
end )
hook.Add( "OnPlayerChat", "ChatOnPlayerChat", function( ply, text, teamchat, dead )
--When a player talks you can do stuff
end )
oldChatAddText = chat.AddText -- Save a reference to the original function, you could use it later to print to console in color! It's actually printing to both the original chat and console, but you already disabled the original chat
function chat.AddText( ... ) --fix
for k, v in pairs( {...} ) do
--Even override the addtext function to use with your custom chatbox
end
end[/lua]
Another problem for me: how can i write on the messages?
( I know thats a newbie question , but thats why im here in the newbie topic)
That isn't going to work.
You have no text display, Your going to need to code one. Either use a HUD or a custom DTextEntry or custom DLabel. Either way this is most deffinatly going to be to much work for you. Chatbox prints in multicolor and that means writing a custom draw function. This will then need to be linked into your chat.AddText() function.
Second of all you need to request focus on your Textbox to make the cursor be focused on it when chat box opens.
[QUOTE=ToNi;23706512]Ok now i start to work on the chatbox.
the cursor is not in the DTextEntry, so i have to click in. How can i fix it?
[/QUOTE]
do something like
[lua]
function updatetext( text )
updatetext = text
end
hook.Add( "ChatTextChanged", "updatetext", updatetext );
// then in the derma code do
myText:SetText(updatetext)
[/lua]
Im not 100% sure if the derma will update but that should give you the idea of how to get the text
[QUOTE=King Flawless;23710212]do something like
[lua]
function updatetext( text )
updatetext = text
end
hook.Add( "ChatTextChanged", "updatetext", updatetext );
// then in the derma code do
myText:SetText(updatetext)
[/lua]
Im not 100% sure if the derma will update but that should give you the idea of how to get the text[/QUOTE]
Thanks I give it a try
Just request focus on the DTextEntry.. There is no need for any of the original chat hooks. They won't even work anyway because you disabled the old chatbox.
[QUOTE=blackops7799;23711305]Just request focus on the DTextEntry.. There is no need for any of the original chat hooks. They won't even work anyway because you disabled the old chatbox.[/QUOTE]
Thanks it works;)
Now i have to write out that i write in the DTextEntry.
How should i start it ?
Sorry, you need to Log In to post a reply to this thread.