Need help fixing a HUD lua error from an old addon
7 replies, posted
So i'm fixing an ODST droppod addon from gmod 10 and it appears that the hud for the drop pod is not showing up. Here is the error code:
[Lua]
[ERROR] addons/odst_drop_pod/lua/autorun/odst_pod.lua:76: bad argument #1 to 'SetTexture' (number expected, got nil)
1. SetTexture - [C]:-1
2. v - addons/odst_drop_pod/lua/autorun/odst_pod.lua:76
3. unknown - lua/includes/modules/hook.lua:84
[/lua]
[lua]
AddCSLuaFile("autorun/odst_pod.lua")
odstrtime = 30
odstcrtime = 3
local function odstchangeremovetime (player,command,args)
if player:IsAdmin() then
if args[1] == nil then return end
if odstcrtime <= tonumber( args[1] ) then
odstrtime = tonumber( args[1] )
player:ChatPrint("ODST Pod remove time changed to " ..odstrtime)
else
player:ChatPrint("ODST Pod remove time must be higher than the chute remove time")
end
end
end
----
local function odstchangechuteremovetime (player,command,args)
if player:IsAdmin() then
if args[1] == nil then return end
if odstrtime >= tonumber( args[1] ) then
odstcrtime = tonumber( args[1] )
player:ChatPrint("ODST Pod Chute remove time changed to " ..odstrtime)
else
player:ChatPrint("ODST Pod Chute remove time must be lower than the pod remove time")
end
end
end
concommand.Add("odst_chuteremovetime",odstchangechuteremovetime)
concommand.Add("odst_removetime",odstchangeremovetime)
----hooks
hook.Add( "CanTool", "odstpodgibs_noremove",
function( pl, tr, toolmode )
if (SERVER) then
local hitentity = tr.Entity
if hitentity:IsValid() then
if !pl:IsAdmin() then
local hitentityent = hitentity:GetClass()
if ( hitentityent == "odst_pod_chute" || hitentityent == "odst_pod_door" || hitentityent == "odst_drop_pod" || hitentityent == "odst_drop_l" || hitentityent == "odst_drop_r" ) then
return false
end
end
end
end
end)
hook.Add( "PhysgunPickup", "odstpodgibs_nopickup",
function( ply, ent )
if (SERVER) then
if ent:IsValid() then
if !ply:IsAdmin() then
local hitentityent = ent:GetClass()
if ( hitentityent == "odst_pod_chute" || hitentityent == "odst_pod_door" || hitentityent == "odst_drop_pod" || hitentityent == "odst_drop_l" || hitentityent == "odst_drop_r" ) then
return false
end
end
end
end
end)
hook.Add( "HUDPaint", "odstpodhud",
function()
local client = LocalPlayer()
if client:GetNetworkedBool( "odstisinpod" ) == true then
if GetViewEntity() ~= client then
return
end
local pod = client:GetNetworkedEntity( "odstpodin" )
surface.SetTexture( stattex )
surface.DrawTexturedRectRotated( ScrW() * 0.86, ScrH() * 0.15 , ScrH() * 0.18, ScrH() * 0.18, 45 )
surface.SetDrawColor( 255, 255, 255, 100 )
local fuel1 = client:GetNetworkedInt( "odstpodf1" ) * 0.01
local fuel2 = client:GetNetworkedInt( "odstpodf2" ) * 0.01
local bartex = surface.GetTextureID("odstpods_bar")
surface.SetTexture( bartex )
surface.DrawTexturedRect( ScrW() * 0.29, ScrH() * 0.05 , ScrW() * 0.42, ScrH() * 0.05 )
surface.DrawTexturedRect( ScrW() * (0.5 - (0.19 * fuel1)), ScrH() * 0.06 , ScrW() * 0.38 * fuel1, ScrH() * 0.03 )
surface.DrawTexturedRect( ScrW() * 0.29, ScrH() * 0.11 , ScrW() * 0.42, ScrH() * 0.05 )
surface.DrawTexturedRect( ScrW() * (0.5 - (0.19 * fuel2)), ScrH() * 0.12 , ScrW() * 0.38 * fuel2, ScrH() * 0.03 )
surface.SetFont( "ChatFont" )
surface.SetTextColor( 255, 255, 255, 180 )
surface.SetTextPos( ScrW() * 0.32, ScrH() * 0.06 )
surface.DrawText( "Thruster Fuel" )
surface.SetTextPos( ScrW() * 0.32, ScrH() * 0.125 )
surface.DrawText( "Manuver Fuel" )
local podvel = tostring( math.Round( pod:GetVelocity().z ) * -1 )
local poddist = nil
local selfpos = pod:GetPos()
local pos5 = selfpos + Vector(0, 0, -10)
local pos25 = selfpos + Vector(0, 0, -7000)
local tracedata = {}
tracedata.start = pos5
tracedata.endpos = pos25
tracedata.filter = pod
local trace = util.TraceLine(tracedata)
if trace.Hit == true then
poddist = tostring( math.Round( 7000 * trace.Fraction ) )
else
poddist = ">7000"
end
surface.SetDrawColor( 255, 255, 255, 225 )
---
local paneltex = surface.GetTextureID("odstpods_panel")
surface.SetTexture( paneltex )
surface.DrawTexturedRect( ScrW() * 0.01, ScrH() * 0.01 , ScrH() * 0.35, ScrH() * 0.15 )
-------indicator 1
local intex1 = surface.GetTextureID("odstpods_light_green")
if pod:GetNetworkedInt( "odstpodstat" ) == 1 then
intex1 = surface.GetTextureID("odstpods_light_unlit")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 2 then
intex1 = surface.GetTextureID("odstpods_light_red")
end
surface.SetTexture( intex1 )
surface.DrawTexturedRect( ScrW() * 0.033, ScrH() * 0.085 , ScrH() * 0.1, ScrH() * 0.1 )
-------indicator 2
local intex2 = surface.GetTextureID("odstpods_light_green")
if pod:GetNetworkedInt( "odstpodstat" ) == 1 then
intex2 = surface.GetTextureID("odstpods_light_unlit")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 2 then
intex2 = surface.GetTextureID("odstpods_light_red")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 3 then
intex2 = surface.GetTextureID("odstpods_light_red")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 4 then
if pod:GetNetworkedBool( "odstpodman" ) && !client:KeyDown( IN_SPEED ) then
intex2 = surface.GetTextureID("odstpods_light_yellow")
else
intex2 = surface.GetTextureID("odstpods_light_green")
end
end
surface.SetTexture( intex2 )
surface.DrawTexturedRect( ScrW() * 0.1, ScrH() * 0.085 , ScrH() * 0.1, ScrH() * 0.1 )
-------indicator 3
local intex3 = surface.GetTextureID("odstpods_light_green")
if pod:GetNetworkedInt( "odstpodstat" ) == 1 then
intex3 = surface.GetTextureID("odstpods_light_unlit")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 2 then
intex3 = surface.GetTextureID("odstpods_light_red")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 3 then
intex3 = surface.GetTextureID("odstpods_light_red")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 4 then
intex3 = surface.GetTextureID("odstpods_light_red")
elseif pod:GetNetworkedInt( "odstpodstat" ) == 5 then
intex3 = surface.GetTextureID("odstpods_light_green")
end
surface.SetTexture( intex3 )
surface.DrawTexturedRect( ScrW() * 0.167, ScrH() * 0.085 , ScrH() * 0.1, ScrH() * 0.1 )
---
local vitaltex = surface.GetTextureID("odstpods_vitals")
surface.SetTexture( vitaltex )
surface.DrawTexturedRect( ScrW() * 0.75, ScrH() * 0.02 , ScrH() * 0.27, ScrH() * 0.13 )
local hlth = tostring( client:Health() )
draw.DrawText( hlth, "HUDNumber5", ScrW() * 0.775, ScrH() * 0.06, Color(255, 255, 255, 180), 0 )
local autotex = surface.GetTextureID("odstpods_indicator_man")
if pod:GetNetworkedBool( "odstpodman" ) == true then
autotex = surface.GetTextureID("odstpods_indicator_man")
elseif pod:GetNetworkedBool( "odstpodman" ) == false then
autotex = surface.GetTextureID("odstpods_indicator_auto")
end
surface.SetTexture( autotex )
surface.DrawTexturedRect( ScrW() * 0.87, ScrH() * 0.035 , ScrH() * 0.10, ScrH() * 0.10 )
---
draw.DrawText( podvel, "ChatFont", ScrW() * 0.12, ScrH() * 0.04, Color(255, 255, 255, 180), 0 )
draw.DrawText( poddist, "ChatFont", ScrW() * 0.12, ScrH() * 0.07, Color(255, 255, 255, 180), 0 )
end
end)
[/lua]
Any possible fixes?
Someone asked this same (similar) question already. Search before you post.
[url]http://facepunch.com/showthread.php?t=1462963&p=47621917[/url]
e: ninja'd
Put in prints in the HUDPaint hook inside each if statement, this should tell you where the code execution is stopping. The only places this could be is if the NWBool "odstisinpod" is false, or GetViewEntity() doesn't return LocalPlayer().
double ninja.
[QUOTE=James xX;47629301]Put in prints in the HUDPaint hook inside each if statement, this should tell you where the code execution is stopping. The only places this could be is if the NWBool "odstisinpod" is false, or GetViewEntity() doesn't return LocalPlayer().
double ninja.[/QUOTE]
I got this error:
[lua]
[ERROR] addons/odst_drop_pod/lua/autorun/odst_pod.lua:69: '=' expected near 'if'
1. unknown - addons/odst_drop_pod/lua/autorun/odst_pod.lua:0
[/lua]
[QUOTE=hardhat;47629435]I got this error:
[lua]
[ERROR] addons/odst_drop_pod/lua/autorun/odst_pod.lua:69: '=' expected near 'if'
1. unknown - addons/odst_drop_pod/lua/autorun/odst_pod.lua:0
[/lua][/QUOTE]
Post your updated code
Okay, I managed to fix it somehow. Now i'm getting this:
[lua][ERROR] lua/includes/modules/draw.lua:146: 'HUDNumber5' isn't a valid font
1. SetFont - [C]:-1
2. DrawText - lua/includes/modules/draw.lua:146
3. v - addons/odst_drop_pod/lua/autorun/odst_pod.lua:173
4. unknown - lua/includes/modules/hook.lua:84
[/lua]
[QUOTE=hardhat;47629514]Okay, I managed to fix it somehow. Now i'm getting this:
[lua][ERROR] lua/includes/modules/draw.lua:146: 'HUDNumber5' isn't a valid font
1. SetFont - [C]:-1
2. DrawText - lua/includes/modules/draw.lua:146
3. v - addons/odst_drop_pod/lua/autorun/odst_pod.lua:173
4. unknown - lua/includes/modules/hook.lua:84
[/lua][/QUOTE]
Come on man, it literally tells you what the problem is.
A bunch of fonts were removed from Garry's Mod 13 that Garry's Mod 12 had, HUDNumber5 being one of them. You can either change everywhere that uses HUDNumber 5 to a font that actually exists by looking at this page: [url]http://wiki.garrysmod.com/page/Default_Fonts[/url] or you can create a new font and call it HUDNumber 5 using: [url]http://wiki.garrysmod.com/page/surface/CreateFont[/url]
Sorry, you need to Log In to post a reply to this thread.