• DarkRP Custom HUD Error: bad argument #1 to 'GetTextSize' (string expected, got nil)
    0 replies, posted
Hey there facepunch! I'm getting this error on this HUD that I made following a tutorial via the wiki (the tutorial is outdated by 2 years). Since the code is old, and lacks revision, I'm getting flooded with errors when I join my server for about the first 5 seconds, then they never occur again, and they don't break any aspects of the gamemode (Hud still functions perfectly). The error I'm getting spammed with is: [CODE][ERROR] lua/includes/modules/draw.lua:86: bad argument #1 to 'GetTextSize' (string expected, got nil) 1. GetTextSize - [C]:-1 2. SimpleText - lua/includes/modules/draw.lua:86 3. DoActualHUD - gamemodes/darkrp/gamemode/client/hud.lua:243 4. unknown - gamemodes/darkrp/gamemode/client/hud.lua:365 [/CODE] I haven't touched draw.lua, so I'm ignoring that altogether. The error occurred when inserting the following code into hud.lua: [CODE]local function DoActualHUD() --If the variables table has not be initialized, initialize it LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} --If the money is not set, don't do anything local v1 = LocalPlayer().DarkRPVars.money if not v1 then v1 = "" end --If the salary is not set, don't do anything local v2 = LocalPlayer().DarkRPVars.salary if not v2 then v2 = "" end draw.RoundedBox(1, 25, ScrH() - 60, 350, 50, Color(50,50,50,175)) surface.SetDrawColor(255,255,255) draw.RoundedBox(1, 25, ScrW() - 60, 400, 50, Color(25,25,25,200)) surface.SetDrawColor(255,255,255) surface.SetTexture(surface.GetTextureID("gui/silkicons/user")) surface.DrawTexturedRect(25 + 5,ScrH() - 57,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money")) surface.DrawTexturedRect(25 + 225,ScrH() - 30,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/money_add")) surface.DrawTexturedRect(25 + 225,ScrH() - 57,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/group")) surface.DrawTexturedRect(25 + 5,ScrH() - 30,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/heart")) surface.DrawTexturedRect(25 + 155,ScrH() - 57,16,16) surface.SetTexture(surface.GetTextureID("gui/silkicons/shield")) surface.DrawTexturedRect(25 + 155,ScrH() - 30,16,16) draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 25,ScrH() - 40, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v1,"TargetID", 25 + 245,ScrH() - 15, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText("$" .. v2,"TargetID", 25 + 245,ScrH() - 40, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 25,ScrH() - 15, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Health() ,"TargetID", 25 + 175,ScrH() - 40, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) draw.SimpleText(LocalPlayer():Armor() ,"TargetID", 25 + 175,ScrH() - 15, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP) end local function DrawHUD() Scrw, Scrh = ScrW(), ScrH() RelativeX, RelativeY = 0, Scrh --Background DoActualHUD() GunLicense() Agenda() DrawVoiceChat() LockDown() Arrested() AdminTell() end[/CODE] The whole hud.lua: [CODE]/*--------------------------------------------------------------------------- HUD ConVars ---------------------------------------------------------------------------*/ local ConVars = {} local HUDWidth local HUDHeight CreateClientConVar("weaponhud", 0, true, false) local function ReloadConVars() ConVars = { background = {0,0,0,100}, Healthbackground = {0,0,0,200}, Healthforeground = {140,0,0,180}, HealthText = {255,255,255,200}, Job1 = {0,0,150,200}, Job2 = {0,0,0,255}, salary1 = {0,150,0,200}, salary2 = {0,0,0,255} } for name, Colour in pairs(ConVars) do ConVars[name] = {} for num, rgb in SortedPairs(Colour) do local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false) table.insert(ConVars[name], CVar:GetInt()) if not cvars.GetConVarCallbacks(name..num, false) then cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end) end end ConVars[name] = Color(unpack(ConVars[name])) end HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt() HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt() if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end) cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end) end end ReloadConVars() local function formatNumber(n) n = tonumber(n) if (!n) then return 0 end if n >= 1e14 then return tostring(n) end n = tostring(n) sep = sep or "," local dp = string.find(n, "%.") or #n+1 for i=dp-4, 1, -3 do n = n:sub(1, i) .. sep .. n:sub(i+1) end return n end local Scrw, Scrh, RelativeX, RelativeY /*--------------------------------------------------------------------------- HUD Seperate Elements ---------------------------------------------------------------------------*/ local Health = 0 local function DrawHealth() Health = math.min(100, (Health == LocalPlayer():Health() and Health) or Lerp(0.1, Health, LocalPlayer():Health())) local DrawHealth = math.Min(Health / GAMEMODE.Config.startinghealth, 1) local Border = math.Min(6, math.pow(2, math.Round(3*DrawHealth))) draw.RoundedBox(Border, RelativeX + 4, RelativeY - 30, HUDWidth - 8, 20, ConVars.Healthbackground) draw.RoundedBox(Border, RelativeX + 5, RelativeY - 29, (HUDWidth - 9) * DrawHealth, 18, ConVars.Healthforeground) draw.DrawText(math.Max(0, math.Round(LocalPlayer():Health())), "DarkRPHUD2", RelativeX + 4 + (HUDWidth - 8)/2, RelativeY - 32, ConVars.HealthText, 1) -- Armor local armor = LocalPlayer():Armor() if armor ~= 0 then draw.RoundedBox(2, RelativeX + 4, RelativeY - 15, (HUDWidth - 8) * armor / 100, 5, Color(0, 0, 255, 255)) end end local function DrawInfo() LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} local Salary = LANGUAGE.salary .. CUR .. (LocalPlayer().DarkRPVars.salary or 0) local JobWallet = LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or "") .. "\n".. LANGUAGE.wallet .. CUR .. (formatNumber(LocalPlayer().DarkRPVars.money) or 0) local wep = LocalPlayer( ):GetActiveWeapon( ); if IsValid(wep) and GAMEMODE.Config.weaponhud then local name = wep:GetPrintName(); draw.DrawText("Weapon: "..name, "UiBold", RelativeX + 5, RelativeY - HUDHeight - 18, Color(255, 255, 255, 255), 0) end draw.DrawText(Salary, "DarkRPHUD2", RelativeX + 5, RelativeY - HUDHeight + 6, ConVars.salary1, 0) draw.DrawText(Salary, "DarkRPHUD2", RelativeX + 4, RelativeY - HUDHeight + 5, ConVars.salary2, 0) surface.SetFont("DarkRPHUD2") local w, h = surface.GetTextSize(tostring(Salary)) draw.DrawText(JobWallet, "DarkRPHUD2", RelativeX + 5, RelativeY - HUDHeight + h + 6, ConVars.Job1, 0) draw.DrawText(JobWallet, "DarkRPHUD2", RelativeX + 4, RelativeY - HUDHeight + h + 5, ConVars.Job2, 0) end local Page = Material("icon16/page_white_text.png") local function GunLicense() if LocalPlayer().DarkRPVars.HasGunlicense then surface.SetMaterial(Page) surface.SetDrawColor(255, 255, 255, 255) surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32) end end local function Agenda() local DrawAgenda, AgendaManager = DarkRPAgendas[LocalPlayer():Team()], LocalPlayer():Team() if not DrawAgenda then for k,v in pairs(DarkRPAgendas) do if table.HasValue(v.Listeners or {}, LocalPlayer():Team()) then DrawAgenda, AgendaManager = DarkRPAgendas[k], k break end end end if DrawAgenda then draw.RoundedBox(10, 10, 10, 460, 110, Color(0, 0, 0, 155)) draw.RoundedBox(10, 12, 12, 456, 106, Color(51, 58, 51,100)) draw.RoundedBox(10, 12, 12, 456, 20, Color(0, 0, 70, 100)) draw.DrawText(DrawAgenda.Title, "DarkRPHUD1", 30, 12, Color(255,0,0,255),0)
Sorry, you need to Log In to post a reply to this thread.