DarkRP simple custom hud, not working on mp

Hello guys,

I made a very simple hud for my friends new gmod server, but he keeps getting

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:256
  4. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:271
  5. unknown - gamemodes/darkrp/gamemode/client/hud.lua:38

I cant find the problem, it works offline! :open_mouth:

This is the script i wrote:


 local function DoActualHUD() 

LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
 
local v1 = LocalPlayer().DarkRPVars.money
if not v1 then v1 = "" end
 
local v2 = LocalPlayer().DarkRPVars.salary
if not v2 then v2 = "" end


draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200))
surface.SetDrawColor(255,255,255)


surface.SetTexture(surface.GetTextureID("gui/silkicons/hgicon"))
surface.DrawTexturedRect(25 + 10,ScrH() -180,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/user"))
surface.DrawTexturedRect(25 + 10,ScrH() -160,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/money"))
surface.DrawTexturedRect(25 + 10,ScrH() -140,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/money_add"))
surface.DrawTexturedRect(25 + 10,ScrH() -120,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/group"))
surface.DrawTexturedRect(25 + 10,ScrH() -100,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/heart"))
surface.DrawTexturedRect(25 + 10,ScrH() -80,16,16)


surface.SetTexture(surface.GetTextureID("gui/silkicons/shield"))
surface.DrawTexturedRect(25 + 10,ScrH() -60,16,16)


draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() -145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText("$" ..v1,"TargetID", 25 + 30,ScrH() -125, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText("$" ..v2,"TargetID", 25 + 30,ScrH() -105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() -100, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
draw.SimpleText(LocalPlayer():Health() ,"TargetID", 25 + 30,ScrH() -65, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText(LocalPlayer():Armor() ,"TargetID", 25 + 30,ScrH() -45, 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()
    JobHelp()
    DrawVoiceChat()
    LockDown()


    Arrested()
    AdminTell()
end 

LocalPlayer():Armor(), LocalPlayer():Health(), LocalPlayer().DarkRPVars.job or LocalPlayer():Nick() is invalid. Check them.
Oh and never ever run GetTextureID every frame, do like this instead:
[lua]
local hearticon = surface.GetTextureID(“gui/silkicons/heart”)
local function DoActualHUD()
<somecode>
surface.SetTexture(hearticon)
surface.DrawTexturedRect(…
end[/lua]

Thanks man

[editline]2nd January 2013[/editline]

But what do i do then with (LocalPlayer():Nick(), etc?

Add under [lua]local function DoActualHUD()[/lua] [lua]if not LocalPlayer():IsValid() then return end[/lua]

The problem should be that, when they’re joining the server, LocalPlayer does not exist, thus this is causing the errors to occur. Checking if LocalPlayer():IsValid() or if LocalPlayer() ~= NULL should work.

Thanks Ruzza, we will test soon

It works now Thanks all

Did you write that all by yourself?

I wrote that hud, it’s very unoptimized and people should stop using it and/or claiming they made it. Well, actually, it makes them look like the shitty coder.

I also hope that your friend didn’t pay any money for that.