Derma not showing up unless I resave?

Im trying to make an armor hud. It is separate from my HUD with health, job and name. (separate meaning a different addon)

When I start my server, this is what shows up:

When I open and resave the cl_init.lua found in addons/govarmor/lua/autorun/cl_init.lua, this is what shows up:

So as you can see, when I first load the server, it’s like the addon doesnt work. Then after opening the .lua and resaving it, everything is dandy. What am I missing?

Post the code so we can see what you may or may not be doing wrong.

cl_init.lua:


local allowedJobs = {
    TEAM_SWAT,
    TEAM_SS,
    TEAM_PRESIDENT
}

local function armorBackground()

    local ply = LocalPlayer()
    
    isAllowed = table.HasValue( allowedJobs, ply:Team() )
    if not isAllowed then return end
    
    draw.RoundedBox( 0, 3, ScrH()-135, 200, 30, Color( 44, 62, 80, 170 ) )
    surface.SetDrawColor( 255, 255, 255, 255 )
    surface.DrawOutlinedRect( 3, ScrH()-135, 200, 30 )
    
    local armor = ply:Armor()
    local drawArmor = math.Min( armor / 100, 1 )
    
    draw.RoundedBox( 0, 10, ScrH()-130, 186, 20, Color( 0, 0, 0, 150 ) )
        
    if armor >= 65 and armor <= 100 then
        draw.RoundedBox( 0, 12, ScrH()-130, 182 * drawArmor, 20, Color(60, 60, 255, 255) )
        draw.DrawText( armor.."%", "daonlyfont", 106, ScrH()-130, Color( 0, 0, 0, 255 ), TEXT_ALIGN_CENTER )
        draw.DrawText( armor.."%", "daonlyfont", 105, ScrH()-130, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
    elseif
    armor >=44 and armor <=64 then
        draw.RoundedBox( 0, 12, ScrH()-130, 182 * drawArmor, 20, Color(100, 100, 255, 255) )
        draw.DrawText( armor.."%", "daonlyfont", 106, ScrH()-130, Color( 0, 0, 0, 255 ), TEXT_ALIGN_CENTER )
        draw.DrawText( armor.."%", "daonlyfont", 105, ScrH()-130, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
    elseif
    armor >=29 and armor <=43 then
        draw.RoundedBox( 0, 12, ScrH()-130, 182 * drawArmor, 20, Color(140, 140, 255, 255) )
        draw.DrawText( armor.."%", "daonlyfont", 106, ScrH()-130, Color( 0, 0, 0, 255 ), TEXT_ALIGN_CENTER )
        draw.DrawText( armor.."%", "daonlyfont", 105, ScrH()-130, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
    end

end

local function armorDraw()
    armorBackground()
end

function armorPaint()
    armorDraw()
end

hook.Add("HUDPaint", "armorPaint", armorPaint)

init.lua:


local allowedArmor = {
            TEAM_SWAT,
            TEAM_SS,
            TEAM_PRESIDENT
}

function giveArmor( ply )
    hasArmor = table.HasValue( allowedArmor, ply:Team() )
    if not hasArmor then return end
    if hasArmor then
        ply:SetArmor( 100 )
    end
end
hook.Add( "PlayerLoadout", "GiveArmor", giveArmor )

Both are placed in addons/govarmor/lua/autorun.

Thank you for any insight.

EDIT: I may have found the error. It seems that when I changed:


local allowedJobs = {
    TEAM_SWAT,
    TEAM_SS,
    TEAM_PRESIDENT
}

to this:


local allowedJobs = {
    6,
    7,
    8
}

it worked fine on server start. Any idea why this might be?

There’s no point in having




local function armorDraw()
    armorBackground()
end

function armorPaint()
    armorDraw()
end

hook.Add("HUDPaint", "armorPaint", armorPaint)


All you need is



hook.Add("HUDPaint", "makecoolhud", armorBackground)


Also, Clientside files should go in autorun/client, and serverside files should go in autorun/server, to make sure they run properly.
I’m not sure why you have so many elseifs too. You can actually make a scrolling bar on the HUD based on a value. Look at this for an example:



draw.RoundedBoxEx(8, 10, ScrH()-70, math.Clamp(client:Armor()*2,0, 200), 30, Color(0,  90, 255, 140), false, false, true, true)


Awesome, thanks for the good info. Still learning some of this stuff, and I find myself being redundant at times. Any idea on my edit on my post above yours?

Teams haven’t been initialised yet.

Ahh I see, thanks for the info.