It runs just fine with gcompute, but as soon as i put it on the server, it spews out an error which i put here at the bottom of the code.
It works fine when i reload the lua file.
Here is a pastebin link for line numbers: [url]http://pastebin.com/8Vaz3MiN[/url]
Any help would be appreciated.
[CODE]local function calcW(num)
local widthcalced = ( 1920 - num ) / 1920
return ScrW() * widthcalced
end
local function calcH(num)
local heightcalced = ( 1080 - num ) / 1080
return ScrH() * heightcalced
end
surface.CreateFont( "chatlogfont", {
font = "Helvetica",
size = ScreenScale(5.5),
weight = 5000,
blursize = 0,
scanlines = 0,
antialias = true
} )
myChat = {}
local function buildbox()
myChat.dFrame2 = vgui.Create("DFrame")
myChat.dFrame2:SetPos(calcW(1910), calcH(530))
myChat.dFrame2:SetTitle("")
myChat.dFrame2:SetSize(calcW(1350), calcH(700))
myChat.dFrame2:ShowCloseButton(false)
myChat.dFrame2.Paint = function(self, w, h)
draw.RoundedBox(10, 0, 0, w, h, Color(0, 0, 0, 0))
self:ShowCloseButton(false)
end
myChat.dRichText2 = vgui.Create("RichText", myChat.dFrame2)
myChat.dRichText2:SetVerticalScrollbarEnabled(false)
myChat.dRichText2:SetPos(myChat.dFrame2:GetWide()*0.04, myChat.dFrame2:GetTall()*0.10)
myChat.dRichText2:SetSize(myChat.dFrame2:GetWide()*0.92, myChat.dFrame2:GetTall()*0.79)
myChat.dRichText2:SetAllowNonAsciiCharacters(true)
myChat.dRichText2.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 0))
self:SetFontInternal("chatlogfont")
end
myChat.dFrame = vgui.Create("DFrame")
myChat.dFrame:SetPos(calcW(1910), calcH(530))
myChat.dFrame:SetTitle("Chat")
myChat.dFrame:SetSize(calcW(1350), calcH(700))
myChat.dFrame:ShowCloseButton(false)
myChat.dFrame.Paint = function(self, w, h)
draw.RoundedBox(10, 0, 0, w, h, Color(0, 0, 0, 180))
self:ShowCloseButton(false)
end
myChat.dTextEntry = vgui.Create("DTextEntry", myChat.dFrame)
myChat.dTextEntry:SetPos(myChat.dFrame:GetWide()*0.04, myChat.dFrame:GetTall()*0.92)
myChat.dTextEntry:SetSize(myChat.dFrame:GetWide()*0.92, myChat.dFrame:GetTall()*0.05)
myChat.dTextEntry:SetTextColor(Color(255,255,255,255))
myChat.dTextEntry:SetCursorColor(Color(255,255,255,255))
myChat.dTextEntry:SetAllowNonAsciiCharacters(true)
myChat.dTextEntry.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 215))
self:DrawTextEntryText(Color(255,255,255,255), Color(255,255,255,255), Color(255,255,255,255))
end
myChat.dRichText = vgui.Create("RichText", myChat.dFrame)
myChat.dRichText:SetPos(myChat.dFrame:GetWide()*0.04, myChat.dFrame:GetTall()*0.10)
myChat.dRichText:SetSize(myChat.dFrame:GetWide()*0.92, myChat.dFrame:GetTall()*0.79)
myChat.dRichText:SetAllowNonAsciiCharacters(true)
myChat.dRichText.Paint = function(self, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 215))
self:SetFontInternal("chatlogfont")
end
end
buildbox()
hook.Add( "PlayerBindPress", "overrideChatbind", function( ply, bind, pressed )
local bTeam = false
if bind == "messagemode" then
elseif bind == "messagemode2" then
bTeam = true
else
return
end
myChat.openChatbox()
return true -- Doesn't allow any functions to be called for this bind
end )
hook.Add( "ChatText", "serverNotifications", function( index, name, text, type )
if type == "joinleave" or type == "none" then
myChat.dRichText: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 = { ... } -- Create a table of varargs
for _, obj in pairs( args ) do
if type( obj ) == "table" then -- We were passed a color object
myChat.dRichText:InsertColorChange( obj.r, obj.g, obj.b, 255 )
myChat.dRichText2:InsertColorChange( obj.r, obj.g, obj.b, 255 )
elseif type( obj ) == "string" then -- This is just a string
myChat.dRichText:AppendText( obj )
myChat.dRichText2:AppendText( obj )
elseif obj:IsPlayer() then
local col = GAMEMODE:GetTeamColor( obj ) -- Get the player's team color
myChat.dRichText:InsertColorChange( col.r, col.g, col.b, 255 ) -- Make their name that color
myChat.dRichText2:InsertColorChange( col.r, col.g, col.b, 255 )
myChat.dRichText:AppendText( obj:Nick() )
myChat.dRichText2:AppendText( obj:Nick() )
end
end
-- Gotta end our line for this message
myChat.dRichText:AppendText( "\n" )
myChat.dRichText2:AppendText( "\n" )
-- Call the original function
oldAddText ( ... )
end
myChat.dTextEntry.OnKeyCodeTyped = function( self, code )
if code == KEY_ESCAPE then
-- Work around to hide the chatbox when the client presses escape
myChat.closeChatbox()
--gui.HideGameUI()
elseif code == KEY_ENTER then
-- Replicate the client pressing enter
if string.Trim( self:GetText() ) != "" then
LocalPlayer():ConCommand( "say "..self:GetText() )
end
myChat.closeChatbox()
end
end
function myChat.openChatbox()
-- Stuff
if ( not ( IsValid(myChat.dFrame) ) ) then return end
-- MakePopup calls the input functions so we don't need to call those
myChat.dFrame:SetMouseInputEnabled( true )
myChat.dFrame:SetKeyboardInputEnabled( true )
myChat.dFrame:MakePopup()
myChat.dFrame:SetVisible(true)
myChat.dFrame2:SetVisible(false)
gui.EnableScreenClicker( true )
myChat.dTextEntry:RequestFocus()
gamemode.Call( "StartChat" )
-- More stuff
end
function myChat.closeChatbox()
-- Stuff
-- Give the player control again
myChat.dFrame:SetMouseInputEnabled( false )
myChat.dFrame:SetKeyboardInputEnabled( false )
myChat.dFrame:SetVisible(false)
myChat.dFrame2:SetMouseInputEnabled( false )
myChat.dFrame2:SetKeyboardInputEnabled( false )
myChat.dFrame2:SetVisible(true)
gui.EnableScreenClicker( false )
-- We are done chatting
gamemode.Call( "FinishChat" )
-- Clear the text entry
myChat.dTextEntry:SetText( "" )
gamemode.Call( "ChatTextChanged", "" )
-- More stuff
end
myChat.closeChatbox()
_______________________________________________________________________________________________________________________
[ERROR] addons/nullclientplugin/lua/autorun/client/cl_nullbox.lua:23: attempt to index field 'dFrame2' (a nil value)
1. unknown - addons/nullclientplugin/lua/autorun/client/cl_nullbox.lua:23[/CODE]
You're trying to create vgui before it's initalized, thus, dframe2 is set to nil because vgui.Create returns nil.
When you work with vgui, you need to delay the execution of your code until at least the client has began drawing the first frame.
This can most easily be done using the gamemode "Initialize" event hook, as this is called when the gamemode has finished loading and starts.
Thank you, i will try that!
EDIT: Thanks, it worked. You saved my day!
Sorry, you need to Log In to post a reply to this thread.