• Derma not showing up unless I resave?
    6 replies, posted
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: [IMG]http://i.gyazo.com/c747834d7ed62bd84a0c4bd87f873aa0.png[/IMG] When I open and resave the cl_init.lua found in addons/govarmor/lua/autorun/cl_init.lua, this is what shows up: [IMG]http://i.gyazo.com/3b15dd963451185fe65b10ca73782504.png[/IMG] 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: [CODE]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)[/CODE] init.lua: [CODE]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 )[/CODE] Both are placed in addons/govarmor/lua/autorun. Thank you for any insight. [B]EDIT: I may have found the error. It seems that when I changed:[/B] [CODE]local allowedJobs = { TEAM_SWAT, TEAM_SS, TEAM_PRESIDENT }[/CODE] to this: [CODE]local allowedJobs = { 6, 7, 8 }[/CODE] it worked fine on server start. Any idea why this might be?
There's no point in having [code] local function armorDraw() armorBackground() end function armorPaint() armorDraw() end hook.Add("HUDPaint", "armorPaint", armorPaint) [/code] All you need is [code] hook.Add("HUDPaint", "makecoolhud", armorBackground) [/code] 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: [code] draw.RoundedBoxEx(8, 10, ScrH()-70, math.Clamp(client:Armor()*2,0, 200), 30, Color(0, 90, 255, 140), false, false, true, true) [/code]
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?
[QUOTE=imMrAnarchy;45821797]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?[/QUOTE] Teams haven't been initialised yet.
Ahh I see, thanks for the info.
Sorry, you need to Log In to post a reply to this thread.