• SetTexture lua error
    7 replies, posted
I'm trying to fix an old ODST drop pod addon from GMod 10 and I'm getting an error that causes the HUD in the drop pod not to show up. Here's the error: [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] And here is the code from the addon: [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] I know that there should be an ID number, but where do I get it? How would I add it?
All your textures are undefined. You defined them using Material( "Material/Path/Here" )
[QUOTE=James xX;47613201]All your textures are undefined. You defined them using Material( "Material/Path/Here" )[/QUOTE] How would I fix that?
[QUOTE=glarkon;47613272]How would I fix that?[/QUOTE] By reading my post.
[QUOTE=James xX;47613279]By reading my post.[/QUOTE] Just realized that. Thank you :)
With [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/Material]Global.Material[/url], the second argument is for the parameters of the texture. For HUDs, I think "unlitgeneric" is the one to go with.
Okay, i'm still having trouble with this part: [Lua] 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] Is the HUD from gmod 12 incompatible with gmod 13? I tried using global.material but I don't know where to add it.
No, you use surface.GetTextureID("texture name")
Sorry, you need to Log In to post a reply to this thread.