Custom chat glitch



local function injCol(c, alp)
  return Color(c.r, c.g, c.b, alp)
end

local PNL = {}
local pv = {}
VoicePanelColl = nil

function PNL:Init()
  self.Avatar = vgui.Create("AvatarImage", self)
  self.Avatar:SetSize(29, 29)
  self.Avatar:SetPos(5, 5)

  self:SetAlpha(255)

  self:SetSize(250, 40)
  self:DockPadding(4, 4, 4, 4)
  self:Dock(BOTTOM)
end

function PNL:Setup(ply)
  self.player = ply
  self.name = ply:Nick()
  self.Avatar:SetPlayer(ply)
  self:SetAlpha(255)
end

surface.CreateFont( "VoiceName", {
  font = "Trebuchet24", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
  extended = false,
  size = 27,
  weight = 1000,
  blursize = 0,
  scanlines = 0,
  antialias = true,
  underline = false,
  italic = false,
  strikeout = false,
  symbol = false,
  rotary = false,
  shadow = false,
  additive = false,
  outline = false,
} )

function PNL:Paint(w, h)
	if self.player ~= nil and IsValid(self.player) then
  local vol = self.player:VoiceVolume()
  local dc = vighud.cfg.mainColor
  local max = {dc.r, dc.g, dc.b}
  local xd = Color(max[1] * vol, max[2] * vol, max[3] * vol)
  local color = team.GetColor(self.player:Team())
  draw.RoundedBox(10, 0, 0, w, h+30, injCol(vighud.cfg.mainColor, 230))
  draw.RoundedBox(0, 0, h-3, w, 300, color)

  draw.SimpleText(self.name.." ", "Trebuchet24", 40, h/2, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end
end

function PNL:Think()
  if not self.player:Alive() then return end	
  if IsValid(self.player) then
    self.name = self.player:Nick()
  end

  if self.lanim then
    self.lanim:Run()
  end
end

function PNL:AnimationOut(anim, del, dat)
  if anim.Finished then
    if IsValid(pv[self.player]) then
      pv[self.player]:Remove()
      pv[self.player] = nil
      return
    end
    return
  end

  local sub = del * 255
  self:SetAlpha(255 - sub)
end

derma.DefineControl("VoiceNotify", "", PNL, "DPanel")

local function playerEndVoice(ply)
  if pv[ply] then
    --if pv[ply].lanim then return end
    pv[ply].lanim = Derma_Anim("FadeOut", pv[ply], pv[ply].AnimationOut)
    pv[ply].lanim:Start(.5)
  end

  return
end

local function playerStartVoice(ply)
  playerEndVoice(ply)

  if not IsValid(ply) then return end

  if IsValid(pv[ply]) then
    if pv[ply].lanim != nil then
      pv[ply].lanim:Stop()
      pv[ply].lanim = nil
    end

    pv[ply]:SetVisible(true)
    pv[ply]:SetAlpha(255)
  else
    local voice = VoicePanelColl:Add("VoiceNotify")
    voice:Setup(ply)
    voice:SetVisible(true)
    voice:SetAlpha(255)
    pv[ply] = voice
  end

  return
end

local function createPanel()
  VoicePanelColl = vgui.Create("DPanel")
  VoicePanelColl:SetSize(250, ScrH() - 100)
  VoicePanelColl:SetPos(ScrW()-VoicePanelColl:GetWide()-10, 100)
  VoicePanelColl:ParentToHUD()
  VoicePanelColl:SetPaintBackground(false)
  -- VoicePanelColl.Paint = function() end
  if IsValid(g_VoicePanelList) then
    g_VoicePanelList:Remove()
    g_VoicePanelList = nil
  end
end

createPanel()

hook.Add("InitPostEntity", "vig_voice_panel", createPanel)
hook.Add("PlayerStartVoice", "vighud_voice_start", playerStartVoice)
hook.Add("PlayerEndVoice", "vighud_voice_end", playerEndVoice)


http://puu.sh/xh4IO/1e7d9e1a9f.jpg

Chats are supposed to show in the bottom right, often times this glitches out, and draws a persisting icon out of place.

On the player of a glitched icon disconnects it throws the error:



[ERROR] addons/vighud_pack/lua/vig/voice.lua:62: Tried to use a NULL entity!
  1. Alive - [C]:-1
   2. unknown - addons/vighud_pack/lua/vig/voice.lua:62


Any help from you geniuses?

In your panel think function check if player is valid before checking if they’re alive.

Think function changed to:


function PNL:Think()
	if self.player:IsValid() then 
		self.name = self.player:Nick()
		if self.lanim then
	    	self.lanim:Run()
		end
		if not self.player:Alive() then
			return 
		end
	else
		return
	end
end

I will be able to see if this worked soon, thanks for the response!

[editline]24th August 2017[/editline]

Problem persists. It seems to happen when first joining the server, and someone talking.

Is self.player needs to be set to NULL in the Panel’s Init method.

Thanks for the reply!

Init function changed to:


function PNL:Init()
  self.Avatar = vgui.Create("AvatarImage", self)
  self.Avatar:SetSize(29, 29)
  self.Avatar:SetPos(5, 5)

  self:SetAlpha(255)

  self:SetSize(250, 40)
  self:DockPadding(4, 4, 4, 4)
  self:Dock(BOTTOM)
  self.player = nil
end

Problem persists.

Not to nil, to NULL.

Sorry about that


function PNL:Init()
  self.Avatar = vgui.Create("AvatarImage", self)
  self.Avatar:SetSize(29, 29)
  self.Avatar:SetPos(5, 5)

  self:SetAlpha(255)

  self:SetSize(250, 40)
  self:DockPadding(4, 4, 4, 4)
  self:Dock(BOTTOM)
  self.player = NULL
end


Reoccurring.
Update: When player has a glitched voice tag, a disconnect removes the box (minus avatar) without errors.

Can you post the full code again?

(Repeat)
Update: When player has a glitched voice tag, a disconnect removes the box (minus avatar) without errors.



local function injCol(c, alp)
  return Color(c.r, c.g, c.b, alp)
end

local PNL = {}
local pv = {}
VoicePanelColl = nil

function PNL:Init()
  self.Avatar = vgui.Create("AvatarImage", self)
  self.Avatar:SetSize(29, 29)
  self.Avatar:SetPos(5, 5)

  self:SetAlpha(255)

  self:SetSize(250, 40)
  self:DockPadding(4, 4, 4, 4)
  self:Dock(BOTTOM)
  self.player = NULL
end

function PNL:Setup(ply)
  self.player = ply
  self.name = ply:Nick()
  self.Avatar:SetPlayer(ply)
  self:SetAlpha(255)
end

surface.CreateFont( "VoiceName", {
  font = "Trebuchet24", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
  extended = false,
  size = 27,
  weight = 1000,
  blursize = 0,
  scanlines = 0,
  antialias = true,
  underline = false,
  italic = false,
  strikeout = false,
  symbol = false,
  rotary = false,
  shadow = false,
  additive = false,
  outline = false,
} )

function PNL:Paint(w, h)
	if self.player ~= nil and IsValid(self.player) then
  local vol = self.player:VoiceVolume()
  local dc = vighud.cfg.mainColor
  local max = {dc.r, dc.g, dc.b}
  local xd = Color(max[1] * vol, max[2] * vol, max[3] * vol)
  local color = team.GetColor(self.player:Team())
  draw.RoundedBox(10, 0, 0, w, h+30, injCol(vighud.cfg.mainColor, 230))
  draw.RoundedBox(0, 0, h-3, w, 300, color)

  draw.SimpleText(self.name.." ", "Trebuchet24", 40, h/2, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end
end

function PNL:Think()
	if self.player:IsValid() then 
		self.name = self.player:Nick()
		if self.lanim then
	    	self.lanim:Run()
		end
		if not self.player:Alive() then
			return 
		end
	else
		return
	end
end
	


function PNL:AnimationOut(anim, del, dat)
  if anim.Finished then
    if IsValid(pv[self.player]) then
      pv[self.player]:Remove()
      pv[self.player] = nil
      return
    end
    return
  end

  local sub = del * 255
  self:SetAlpha(255 - sub)
end

derma.DefineControl("VoiceNotify", "", PNL, "DPanel")

local function playerEndVoice(ply)
  if pv[ply] then
    --if pv[ply].lanim then return end
    pv[ply].lanim = Derma_Anim("FadeOut", pv[ply], pv[ply].AnimationOut)
    pv[ply].lanim:Start(.5)
  end

  return
end

local function playerStartVoice(ply)
  playerEndVoice(ply)

  if not IsValid(ply) then return end

  if IsValid(pv[ply]) then
    if pv[ply].lanim != nil then
      pv[ply].lanim:Stop()
      pv[ply].lanim = nil
    end

    pv[ply]:SetVisible(true)
    pv[ply]:SetAlpha(255)
  else
    local voice = VoicePanelColl:Add("VoiceNotify")
    voice:Setup(ply)
    voice:SetVisible(true)
    voice:SetAlpha(255)
    pv[ply] = voice
  end

  return
end

local function createPanel()
  VoicePanelColl = vgui.Create("DPanel")
  VoicePanelColl:SetSize(250, ScrH() - 100)
  VoicePanelColl:SetPos(ScrW()-VoicePanelColl:GetWide()-10, 100)
  VoicePanelColl:ParentToHUD()
  VoicePanelColl:SetPaintBackground(false)
  -- VoicePanelColl.Paint = function() end
  if IsValid(g_VoicePanelList) then
    g_VoicePanelList:Remove()
    g_VoicePanelList = nil
  end
end

createPanel() -- testing

hook.Add("InitPostEntity", "vig_voice_panel", createPanel)
hook.Add("PlayerStartVoice", "vighud_voice_start", playerStartVoice)
hook.Add("PlayerEndVoice", "vighud_voice_end", playerEndVoice)


This only happens when you first join, and as soon as you start talking. I just cant figure it out.

[editline]26th August 2017[/editline]

Fixed, threw:


if IsValid(g_VoicePanelList) then
    g_VoicePanelList:Remove()
    g_VoicePanelList = nil
  end

in PNL:Init().