So randomly my hud will break. It gives me the error -
[QUOTE]ERROR: Hook 'showHud' Failed: [@lua\includes\modules\draw.lua:75] bad argument #1 to 'GetTextSize' (string expected, got nil)
Removing Hook 'showHud'[/QUOTE]
and
[QUOTE][gamemodes\base\gamemode\cl_hudpickup.lua:17] attempt to call method 'GetPrintName' (a nil value)(Hook: HUDWeaponPickedUp)[/QUOTE]
I dont get it cause its just is random. You can join 20 times and half the time youll get that error and you wont have a hud, half the time it works fine. And of course it tells you where it broke in the draw.lua, not where in my HUD file which doesn't help at all. So is there any debug commands that can help me pin point where its breaking in my cl_hud.lua file?
Paste the code.
[lua]
include('shared.lua')
language.Add("trigger_hurt","Stupidity")
// We need the Timer Data!
usermessage.Hook( "TimerStatus", function(loadData)
TimerStatus = loadData:ReadLong()
end )
usermessage.Hook( "Timer", function(loadData)
Timer = loadData:ReadLong()
end )
usermessage.Hook( "RoundMessage", function(loadData)
RoundMessage = loadData:ReadString()
end )
function showHud()
local Cash = LocalPlayer():GetNWInt("Cash")
surface.CreateFont( "coolvetica", 24, 300, true, false, "MenuFont" )
draw.RoundedBox(0, 20, ScrH()-95, 200, 75, Color(0,0,0,200))
draw.RoundedBox(0, 20, ScrH()-145, 200, 40, Color(0,0,0,200))
if TimerStatus == 3 then
draw.RoundedBox(0, 240, ScrH()-95, 100, 75, Color(0,0,0,200))
ActiveWeapon = LocalPlayer():GetActiveWeapon()
if ActiveWeapon && ActiveWeapon ~= NULL && ActiveWeapon ~= nil && ActiveWeapon ~= "" then
Ammo = 0
Clip = 0
Ammo = LocalPlayer():GetAmmoCount(ActiveWeapon:GetPrimaryAmmoType())
Clip = ActiveWeapon:Clip1()
if Clip < 0 || Clip == nil || Clip == NULL || Clip == "" then
draw.RoundedBox(0, 245, ScrH()-55, 90, 30, Color(0,0,0,125))
draw.SimpleText("Ammo", "MenuFont", 290, ScrH()-85, Color(255,255,255,255),TEXT_ALIGN_CENTER)
draw.SimpleText("Unlimited", "MenuFont", 290, ScrH()-50, Color(255,255,255,255),TEXT_ALIGN_CENTER)
else
if Clip <= 0 then
draw.RoundedBox(0, 245, ScrH()-55, 90, 30, Color(0,0,0,125))
elseif Clip <= 5 && Clip > 0 then
draw.RoundedBox(0, 245, ScrH()-55, 90, 30, Color(255,0,0,200))
else
draw.RoundedBox(0, 245, ScrH()-55, 90, 30, Color(171,0,0,200))
end
draw.SimpleText("Ammo", "MenuFont", 290, ScrH()-85, Color(255,255,255,255),TEXT_ALIGN_CENTER)
draw.SimpleText(Ammo+Clip, "MenuFont", 290, ScrH()-50, Color(255,255,255,255),TEXT_ALIGN_CENTER)
end
end
end
// Echo Health
local Health = LocalPlayer():Health()
if Health < 0 || Health == nil then
Health = 0
end
if Health > 65 then
draw.RoundedBox(0, 25, ScrH()-90, 190, 30, Color(24,171,0,175),TEXT_ALIGN_CENTER)
elseif Health < 66 && Health > 30 then
draw.RoundedBox(0, 25, ScrH()-90, 190, 30, Color(234,234,0,175))
elseif Health < 31 then
draw.RoundedBox(0, 25, ScrH()-90, 190, 30, Color(171,0,0,175))
end
draw.SimpleText("Health: " .. Health, "MenuFont", 120, ScrH()-85, Color(255,255,255,255),TEXT_ALIGN_CENTER)
// Echo Cash
if Cash >= 1000000 then
Cashbar = 190
else
Cashbar = Cash*.00019
end
draw.RoundedBox(0, 25, ScrH()-55, 190, 30, Color(0,0,0,125))
draw.RoundedBox(0, 25, ScrH()-55, Cashbar, 30, Color(0,60,255,90))
draw.SimpleText("Cash: $" .. Cash, "MenuFont", 120, ScrH()-50, Color(255,255,255,255),TEXT_ALIGN_CENTER)
// Echo Timer
if TimerStatus == 0 || TimerStatus == nil || TimerStatus == "" || TimerStatus == NULL then
RoundText = "Loading Mod"
Timer = 0
elseif TimerStatus == 1 then
RoundText = "Make a Boat"
elseif TimerStatus == 2 then
RoundText = "Get On It"
elseif TimerStatus == 3 then
RoundText = "Kill Boats"
elseif TimerStatus == 4 then
RoundText = "Reseting"
end
if TimerStatus ~= 5 then
if Timer <= 15 && (TimerStatus == 1 || TimerStatus == 3) then
draw.RoundedBox(0, 165, ScrH()-140, 50, 30, Color(171,0,0,175))
else
draw.RoundedBox(0, 165, ScrH()-140, 50, 30, Color(0,0,0,125))
end
draw.SimpleText(RoundText, "MenuFont", 95, ScrH()-135, Color(255,255,255,255),TEXT_ALIGN_CENTER)
draw.SimpleText(Timer, "MenuFont", 190, ScrH()-135, Color(255,255,255,255),TEXT_ALIGN_CENTER)
else
draw.RoundedBox(0, 25, ScrH()-140, 190, 30, Color(171,0,0,175))
draw.SimpleText(RoundMessage, "MenuFont", 120, ScrH()-135, Color(255,255,255,255),TEXT_ALIGN_CENTER)
end
--------------------------------------- Print Player/Team owner --------------------------------------------------------
local tr = util.TraceLine(util.GetPlayerTrace(LocalPlayer()))
if (tr.Entity:IsValid() and !tr.Entity:IsPlayer()) then
surface.CreateFont( "coolvetica",18,150, true, false, "PropInfoText" )
if tr.Entity:GetNWInt("PropOwnerID") == 0 or tr.Entity:GetNWInt("PropHealth") == 0 then
draw.SimpleTextOutlined("World", "PropInfoText", ScrW()/2, ScrH()/2 - 25, Color(255,255,255,255),1,1,2,Color(0,0,0,255))
elseif tr.Entity:GetNWInt("PropHealth") ~= NULL or tr.Entity:GetNWInt("PropOwnerID") ~= NULL then
PropOwner = "Loading..."
for k,v in pairs(player.GetAll()) do
if v:SteamID() == tr.Entity:GetNWInt("PropOwnerID") then
PropOwner = v:Nick()
end
end
PI = tr.Entity:GetNWInt("PropHealth") .. " - " .. PropOwner
if tr.Entity:GetNWInt("PropHealth") < 50 then
draw.SimpleTextOutlined(PI, "PropInfoText", ScrW()/2, ScrH()/2 - 25, Color(271,0,0,255),1,1,2,Color(0,0,0,255))
else
draw.SimpleTextOutlined(PI, "PropInfoText", ScrW()/2, ScrH()/2 - 25, Color(255,255,255,255),1,1,2,Color(0,0,0,255))
end
end
end
end
hook.Add("HUDPaint", "showHud", showHud)
--------------------------------------- Hides Hud --------------------------------------------------------
function hidehud(name)
for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud)
[/lua]
Line 44 in that code
[lua]draw.SimpleText(Ammo+Clip, "MenuFont", 290, ScrH()-50, Color(255,255,255,255),TEXT_ALIGN_CENTER)[/lua]
I'm not sure if Ammo+Clip is valid. Try replacing it with a String, or something that you know will run
well i do
Ammo = 0
Clip = 0
so thats adding 0+0, should i then tostring() that and check that its got content? It seems when i delete the whole ammo thing it doesnt error out
K so i changed it to
Clip = 0
Ammo = LocalPlayer():GetAmmoCount(ActiveWeapon:GetPrimaryAmmoType())
Clip = ActiveWeapon:Clip1()
AC = "Invalid"
AC = tostring(Ammo+Clip)
I havent seen it yet, but i normally dont get it. Im hoping since i declare AC as a string before, it either overwrites it or still has something to print.
[editline]19th March 2012[/editline]
i still get this error tho...
[gamemodes\base\gamemode\cl_hudpickup.lua:17] attempt to call method 'GetPrintName' (a nil value)(Hook: HUDWeaponPickedUp)
which i image has something to do with Activeweapon. But this doesnt seem to break the hud, just an annoying error that shows up every now and then,
[editline]19th March 2012[/editline]
Uh, i just got the error. Wtf is causing this...
its
LocalPlayer():GetActiveWeapon():Clip1()
not
ActiveWeapon():Clip1()
i dont put ()
I defined ActiveWeapon as:
ActiveWeapon = LocalPlayer():GetActiveWeapon()
therefore its doing the same thing?
[editline]19th March 2012[/editline]
What ive done now is put
[QUOTE]
// Maybe this will fix it?
TimerStatus = 0
Timer = 0
RoundMessage = "Need More Players"
RoundText = "Loading Mod"
Cash = 0
Cashbar = 0
Health = 0[/QUOTE]
when the file is first loaded which is every text option that can be put into the hud so nothing is blank the second you join. Hopefully that works.
K, i havent had an issue yet so i think one of those variables fixed it.
I used to get one of these error messages on a HUD I was working on, too. Specifically this:
[lua]ERROR: Hook 'showHud' Failed: [@lua\includes\modules\draw.lua:75] bad argument #1 to 'GetTextSize' (string expected, got nil)
Removing Hook 'showHud'[/lua]
It used to happen randomly for me too, I just thought "well, it's not my code that's erroring so I can't fix it." and deleted the script :/ I'd really like to see it solved though.
Well that i fixed i belive. Just gave everything a default thing to ouput if nothing write over it. i still get the whole
[lua][gamemodes\base\gamemode\cl_hudpickup.lua:17] attempt to call method 'GetPrintName' (a nil value)(Hook: HUDWeaponPickedUp)[/lua]
error but, that i think has something to do with the ammo shit. Doesn't break the hud, so im not going to worry about it.
[QUOTE=tissue901;35197947]i dont put ()
I defined ActiveWeapon as:
ActiveWeapon = LocalPlayer():GetActiveWeapon()
therefore its doing the same thing?
[editline]19th March 2012[/editline]
What ive done now is put
when the file is first loaded which is every text option that can be put into the hud so nothing is blank the second you join. Hopefully that works.
K, i havent had an issue yet so i think one of those variables fixed it.[/QUOTE]
The () is for arguments. A Variable that you set normally doesn't need (). If you set ActiveWeapon to BlahBlah(), then you just use ActiveWeapon.
Exactly what i did.
Sorry, you need to Log In to post a reply to this thread.