N
N
Nikita Volkov2020-04-18 18:23:09
Lua
Nikita Volkov, 2020-04-18 18:23:09

GLua: Why is the hood not being drawn when entering the map?

I wrote a simple hood, there seems to be no errors, well, only 1, but it doesn’t seem to affect it :)
Here is the code:

if !ply:IsValid() then return end

  hp = ply:Health()
  if hp < 0 then hp = 0 end

  mx = ply:GetMaxHealth()

  ar = ply:Armor()
  if ar == 0 then ar = ''; ar2 = 0 else ar2 = ar end

  sh = '/'
  am = ply:GetActiveWeapon():Clip1()
  if am < 1 then am = ''; sh = '' end
  sa = ply:GetAmmoCount( ply:GetActiveWeapon():GetPrimaryAmmoType() )
  if sa < 1 then sa = ''; sh = '' end

  wp = ply:GetActiveWeapon():GetPrintName()
  nm = ply:Name()

  draw.RoundedBox(5, x - 10, y - 50, 220, 140, Color(0, 0, 0, 200))
  draw.RoundedBox(5, x - 10, y - 50, 220, 40, Color(0, 0, 0, 200))
  draw.SimpleText(nm, 'NameFont', x + 100, y - 30, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

  draw.RoundedBox(2, x, y, 200, 30, Color(150, 50, 0, 250))
  draw.RoundedBox(2, x , y, math.Clamp(hp, 0, 100) * 2, 30, Color(250, 50, 0, 250))
  draw.SimpleText(hp, 'HudFont', x + 100, y + 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

  draw.RoundedBox(2, x, y + 50, 200, 30, Color(0, 50, 150, 250))
  draw.RoundedBox(2, x, y + 50, math.Clamp(ar2, 0, 100) * 2, 30, Color(0, 50, 250, 250))
  draw.SimpleText(ar, 'HudFont', x + 100, y + 65, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

  draw.RoundedBox(5, x2 - 10, y2 - 10, 220, 100, Color(0, 0, 0, 200))
  draw.RoundedBox(5, x2 - 10, y2 - 10, 220, 50, Color(0, 0, 0, 200))
  draw.SimpleText(wp, 'NameFont', x2 + 100, y2 + 15, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  draw.SimpleText(am..sh..sa, 'HudFont', x2 + 100, y2 + 65, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

The code is executed by the HUDPaint hook . Help me please!
And yes, here is the error:
[ERROR] addons/minimal hud/lua/autorun/cl_init.lua:10: attempt to index global 'surface' (a nil value)
1. unknown - addons/minimal hud/lua/autorun/cl_init.lua:10

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EC871, 2020-04-28
@EC871

1) Where is the draw hook itself?
2) Where is the HL2CustomHud removal hook?
3) To draw the number of cartridges, it is better to use this (according to your scheme, there may be errors)

draw.SimpleText( getClip(), "Clip", ScrW() - 210, ScrH() - 210, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
  draw.SimpleText( getFullAmmo(), "FullAmmo", ScrW() - 115, ScrH() - 115, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question