[QUOTE=TheFallen(TF2);26345836]I am learning the visual basic language in school.[/QUOTE]
/thread
Okay I tried using Banana Lord's but it still won't work. I am still completely stumped as to why it doesn't work. If it is an addon can anyone give me a few ideas which ones may be interfering with my HUD?
Any errors?
List all of your addons please. Any addons that change the HUD will conflict. List htem all anyway please. GMod.org links would be awesome too, but if not, I can find them and tr to help.
[QUOTE=Banana Lord.;26398144]Any errors?
List all of your addons please. Any addons that change the HUD will conflict. List htem all anyway please. GMod.org links would be awesome too, but if not, I can find them and tr to help.[/QUOTE]
I don't have any errors in-game, but it doesn't draw the new hud, it just shows the HL2 HUD.
But here are the Major Addons I have:
Adv Duplicator
Dismemberment Mod 1.9: [url]http://www.garrysmod.org/downloads/?a=view&id=52104[/url]
Durgzmod: [url]http://www.garrysmod.org/downloads/?a=view&id=89712[/url]
HL2BetaPlayerModels: [url]http://hl2betaplayermodels.googlecode.com/svn/trunk/[/url]
Katana: [url]http://www.garrysmod.org/downloads/?a=view&id=110226[/url]
Lightsaber: [url]http://phantom1315.googlecode.com/svn/trunk/[/url]
Mass Effect 2 Models: [url]http://www.garrysmod.org/downloads/?a=view&id=101843[/url]
PAC2: [url]http://playerappearancecustomizer.googlecode.com/svn/trunk/[/url]
PHX3
PlayX: [url]http://www.garrysmod.org/downloads/?a=view&id=104242[/url]
Pyroteknix: [url]http://pyroteknix.googlecode.com/svn/trunk/[/url]
Replicator AI: [url]http://replicatorai.googlecode.com/svn/trunk/Replicator%20AI/[/url]
Sickness Models: [url]http://subversion.assembla.com/svn/SicknessModel/[/url]
PewPew: [url]http://divranspack.googlecode.com/svn/trunk/%20divranspack/PewPew/[/url]
Spider SNPC: [url]http://www.garrysmod.org/downloads/?a=view&id=113525[/url]
Total Train Pack: [url]http://gmodtrainpack.googlecode.com/svn/trunk/[/url]
T-Rex: [url]http://www.garrysmod.org/downloads/?a=view&id=99863[/url]
Wire
Wire Extras
Wire Model Pack
If you need more information just let me know.
I'm having trouble with mine too. I'm just starting out but I don't know what's up with the code.
[lua]
local ply = LocalPlayer()
local health = ply:Health()
function hud()
draw.RoundedBox(0, 5, ScrH() - 15 - 20, health, 15, Color(255,0,0,255 ))
draw.SimpleText(health, "default", 10, ScrH() - 15 - -40, Color(255,255,255,255))
end
hook.Add("HUDPaint", "MyHudName", hud)
function hidehud(name)
for k, v in pairs{"CHudHealth", "CHudBattery"}do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)
[/lua]
When I run the file I get the error "[lua\hudtest.lua:1] attempt to call global 'LocalPlayer' (a nil value)". Does the code think the player doesn't exist or something?
Change play to ply.
Place the file in lua/autorun/client.
Oh that first bit is a silly mistake, but it still gives me the same error.
You need to run it client-side.
I decided to test it out and then check the console and I found this error: "Hook 'hidehud' Failed: [@lua\autorun\client\cl_hud_remove.lua:2] bad argument #1 to 'pairs' (table expected, got string)"
In this case you need brackets instead of parantesis, so
[lua]
pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} --this or
pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) --this (they does exactly the same thing)
[/lua]
[QUOTE=ralle105;26412184]You need to run it client-side.[/QUOTE]
herp a derp, thank you
Okay no errors in the console, and the original HUD has disappeared but the new one isn't being drawn, and I'm not getting any errors in the console. Anyone have a solution for this?
Heres the code for the HUD so far:
[lua]AddCSLuaFile("autorun/client/cl_hud_remove.lua")
function GM:HUDPaint()
self.BaseClass:HUDPaint()
local person = LocalPlyer()
local Health = LocalPlyer(): Health()
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end
[/lua]
Spell Player right? LocalPlyer() doesn't exist.
[QUOTE=Lord Ned;26417470]Spell Player right? LocalPlyer() doesn't exist.[/QUOTE]
Oh because Cubar said to change play to ply sorry. -_-'
EDIT: It's still not working and I don't know why.
You're running this on the client right?
Try this:
[lua]
AddCSLuaFile("autorun/client/cl_hud_remove.lua")
print("cl_hud_remove.lua loaded!")
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
function GM:HUDPaint()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end[/lua]
Then tell us what it prints in the console?
[QUOTE=Lord Ned;26418080]You're running this on the client right?
Try this:
[lua]
AddCSLuaFile("autorun/client/cl_hud_remove.lua")
print("cl_hud_remove.lua loaded!")
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
function GM:HUDPaint()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end[/lua]
Then tell us what it prints in the console?[/QUOTE]
It printed this in the console: Tools Client Initiated
[lua\autorun\client\huddistrict9.lua:16] unexpected symbol near '+'
I saw this when I was debugging the code in SciTE as well, can anybody give me an idea as to why its doing that?
This is huddistrict9.lua then? (The code posted above)
Remove the ).
Here's what you're saying:
SetTextPos[b]([/b]34, ScrH[b]()[/b] / 2 ) + [highlight][b]([/b]ScrH[b]()[/b] / 4[b])[/highlight] )[/b]
Notice there's one extra )? Make it say this instead:
SetTextPos(34, (ScrH() / 2 ) + (ScrH() / 4 ) )
[QUOTE=Lord Ned;26419073]This is huddistrict9.lua then? (The code posted above)
Remove the ).
Here's what you're saying:
SetTextPos[b]([/b]34, ScrH[b]()[/b] / 2 ) + [highlight][b]([/b]ScrH[b]()[/b] / 4[b])[/highlight] )[/b]
Notice there's one extra )? Make it say this instead:
SetTextPos(34, (ScrH() / 2 ) + (ScrH() / 4 ) )[/QUOTE]
I'll test it real quick and see if it works, if not I'll check in tomorrow after school.
EDIT:
This is the only error I found but I'll fix it tomorrow: cl_hud_remove.lua loaded!
[lua\autorun\client\huddistrict9.lua:5] attempt to index global 'GM' (a nil value)
Yeah I don't know on that one. Has to do with the scope of the function and gamemode I guess? I'm not sure, I'd like an explanation too.
You can try this in the mean time:
[lua]
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end)[/lua]
And remove the entire GM:HUDPaint section.
(Entire thing should look like this)
[lua]
AddCSLuaFile("autorun/client/cl_hud_remove.lua")
print("cl_hud_remove.lua loaded!")
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end)[/lua]
[lua]
AddCSLuaFile("autorun/client/cl_hud_remove.lua")
print("cl_hud_remove.lua loaded!")
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
function GM:HUDPaint()
self.BaseClass:HUDPaint()
local person = LocalPlayer()
local Health = LocalPlayer(): Health()
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34, ScrH()/2 + ScrH()/4 ) -- L2 order of operation. ( You had an open set of brackets here, you dont even need them in the first place lol)
surface.SetFont("Text32")
surface.DrawText( Health )
end
[/lua]
This should fix your error. Tell me if it works.
Giving him the answer doesn't let him learn. ;)
[QUOTE=Lord Ned;26421574]Giving him the answer doesn't let him learn. ;)[/QUOTE]
Saves time and endless threads though, and it's a real pain in the ass being stuck on a single simple thing for a while (like me atm) lol.
[QUOTE=Lord Ned;26419397]Yeah I don't know on that one. Has to do with the scope of the function and gamemode I guess? I'm not sure, I'd like an explanation too.
You can try this in the mean time:
[lua]
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end)[/lua]
And remove the entire GM:HUDPaint section.
(Entire thing should look like this)
[lua]
AddCSLuaFile("autorun/client/cl_hud_remove.lua")
print("cl_hud_remove.lua loaded!")
surface.CreateFont("D9 non-humans",54, 400, false, false, "Text32")
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
print("GM:HUDPaint() blah blah")
self.BaseClass:HUDPaint()
local person = LocalPlayer()
print("Player: "..tostring(person))
local Health = LocalPlayer(): Health()
print("Health: "..tostring(health))
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("Text32")
surface.DrawText( Health )
end)[/lua][/QUOTE]
"lua: HUDDistrict9.lua:7: ')' expected (to close '(' at line 6) near 'print'" Why is coding with Lua so sensitive?!
Iirc, you don't have to call self.BaseClass:*() if you're hooking into that function. Hooks only catch the event then do whats in them, they don't override the function.
[lua]
AddCSLuaFile( "autorun/client/cl_hud_remove.lua" )
print ( "cl_hud_remove.lua loaded!" )
surface.CreateFont ("D9 non-humans",54, 400, false, false, "Text32")
function MyCustomHUDPaint()
print ( "idk..?" ) //pointless
/*self.BaseClass:HUDPaint() what is this even doing here?*/
local person = LocalPlayer()
print ( "idk..?v2" ) //pointless
local health = person:Health()
print ( "idk..?v3" ) //pointless
surface.SetText ( 255, 0, 0, 240 )
surface.SetTextPos ( 34, (ScrH()/2) + (ScrH()/4) )
surface.SetFont ( "Text32" )
surface.DrawText ( health )
end
hook.Add ( "HUDPaint", "MyCustomHUDPaint", MyCustomHUDPaint )
[/lua]
Also another note: You aren't setting the text color:
surface.SetTextColor(255,255,255,255)
And it isnt working because you have the function parens in your hook string:
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
should be
hook.Add( "HUDPaint", "MyCustomHUDPaint", function()
[QUOTE=Feihc;26434829]Also another note: You aren't setting the text color:
surface.SetTextColor(255,255,255,255)
And it isnt working because you have the function parens in your hook string:
hook.Add( "HUDPaint()", "MyCustomHUDPaint", function()
should be
hook.Add( "HUDPaint", "MyCustomHUDPaint", function()[/QUOTE]
Okay I tried what you said but when I was debugging it this is what I got:
>lua -e "io.stdout:setvbuf 'no'" "HUDDistrict9.lua"
lua: HUDDistrict9.lua:20: ')' expected (to close '(' at line 6) near '<eof>'
>Exit code: 1
[QUOTE=TheFallen(TF2);26436398]Okay I tried what you said but when I was debugging it this is what I got:
>lua -e "io.stdout:setvbuf 'no'" "HUDDistrict9.lua"
lua: HUDDistrict9.lua:20: ')' expected (to close '(' at line 6) near '<eof>'
>Exit code: 1[/QUOTE]
did you try what I posted above? just add surface.SetTextColor to it
[QUOTE=Zephilinox;26437349]did you try what I posted above? just add surface.SetTextColor to it[/QUOTE]
Okay now the debugger says: lua: HUDDistrict9.lua:1: attempt to call global 'AddCSLuaFile' (a nil value)
stack traceback:
HUDDistrict9.lua:1: in main chunk
[C]: ?
[QUOTE=TheFallen(TF2);26438286]Okay now the debugger says: lua: HUDDistrict9.lua:1: attempt to call global 'AddCSLuaFile' (a nil value)
stack traceback:
HUDDistrict9.lua:1: in main chunk
[C]: ?[/QUOTE]
Learning how to interpret the Lua errors would help you out a great deal. So check here: [url]http://wiki.garrysmod.com/?title=Gmod_Lua_Error_List[/url]
In the file 'HUDDistrict9.lua' on line 1, you are attempting to call a function that doesn't exist. In fact, the name you gave has no value at all, so it is referred to as 'nil'. On the page I linked you, the first possible cause is that you are running it in the wrong Lua state. In this case, this is indeed the problem. [b][url=http://wiki.garrysmod.com/?title=G.AddCSLuaFile]G.AddCSLuaFile [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is a serverside function, and cannot be called on the client. Some scripts will work around this by changing it to look like this:
[lua]
if SERVER then AddCSLuaFile("filename.lua") end
[/lua]
This makes it so that it will only try to run that function on the server. Of course, this fix is only recommended if you are running that particular file on both the client and the server.
EDIT:
Hang on, is this an external Lua interpreter? AddCSLuaFile doesn't exist anywhere other than gmod, so run it in gmod.
Sorry, you need to Log In to post a reply to this thread.