Yo
I just reinstalled a gamemode I made a while back, and it's working except one thing. Everyone is being spammed with this error:
[CODE]
[ERROR] gamemodes/btk/gamemode/cl_init.lua:84: Tried to use a NULL entity!
1. GetNWString - [C]:-1
2. fn - gamemodes/btk/gamemode/cl_init.lua:84
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
[/CODE]
The code:
[CODE]hook.Add( "HUDPaint", "HUDPaint_ProtectBox", function()
draw.RoundedBox( 16, (ScrW() / 2 - 128), 0, 256, 32, Color( 0, 0, 0, 220 ) )
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos (ScrW() / 2 - 85, 4)
surface.SetFont( "Trebuchet20" )
surface.DrawText( "Build Protection: " )
if ply:GetNWString( "buildProtText" ) == "OFF" then
surface.SetTextColor( 255, 0, 0, 255 )
else
surface.SetTextColor( 0, 255, 0, 255 )
end
//surface.SetTextColor( protTxtColor )
surface.SetTextPos (ScrW() / 2 + 40, -16)
surface.SetFont( "buildprotFontOne" )
surface.DrawText( LocalPlayer():GetNWString( "buildProtText" ) )
end )
[/CODE]
Basically, it's supposed to say ON or OFF, and it's not showing up (along with the spam of lua errors). Also, the custom HUD we have installed doesn't show up until we edit the cl_init.lua file.
However, whenever I edit the cl_init.lua file, it's fixed. que
Change ply in that file to LocalPlayer()
I have local ply = LocalPlayer() defined somewhere else in the file.
[QUOTE=Pazda;48082392]I have local ply = LocalPlayer() defined somewhere else in the file.[/QUOTE]
Don't do this outside of functions/hooks. Gmod loads the gamemode files before any entities have been created, so LocalPlayer() and any ent functions will return invalid entities. It's 'working' because you have autorefresh on and it's hot-reloading the file after entities have been created.
[QUOTE=Pazda;48082392]I have local ply = LocalPlayer() defined somewhere else in the file.[/QUOTE]
Well, because ply = LocalPlayer() isn't in a function that is called before InitPostEntity(LocalPlayer() returns the client, but it doesn't return it until the InitPostEntity hook has been called), LocalPlayer() returns null(nil, or nothing), so because you're calling functions meant for a player on an entity that counts as [i]nothing[/i], it doesn't work. Just use LocalPlayer() inside of HUDPaint instead of ply.
Alright, got it. Thanks guys!
Sorry, you need to Log In to post a reply to this thread.