Advertisement
Guest User

demovoicefix.lua

a guest
Jan 23rd, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. if not engine.IsPlayingDemo() then return end
  2.  
  3. talkingPlayers = {}
  4.  
  5. function OnVoiceStarted( ply )
  6.     if not table.HasValue( talkingPlayers, ply:Name()) then
  7.         table.insert( talkingPlayers, ply:Name() )
  8.     end
  9.     --PrintTable( talkingPlayers )
  10. end
  11.  
  12. function OnVoiceEnd( ply )
  13.     if vgui.GetWorldPanel():Find( ply:Name() ) != nil then
  14.         vgui.GetWorldPanel():Find( ply:Name() ):Remove()
  15.     end
  16.     table.RemoveByValue( talkingPlayers, ply:Name())
  17. end
  18.  
  19. function getProfilePicture( ply )
  20.     if vgui.GetWorldPanel():Find( ply:Name() ) != nil then
  21.         return vgui.GetWorldPanel():Find( ply:Name() )
  22.     end
  23.     return nil
  24. end
  25.  
  26. function removeProfilePicture( ply )
  27.     if vgui.GetWorldPanel():Find( ply:Name() ) != nil then
  28.         vgui.GetWorldPanel():Find( ply:Name() ):Remove()
  29.     end
  30. end
  31.  
  32.  
  33. function getPlayerByName( name )
  34.     for k,v in pairs( player.GetAll() ) do
  35.         if name == v:Name() then
  36.             return v
  37.         end
  38.     end
  39.     return nil
  40. end
  41.  
  42.  
  43. hook.Add( "PlayerStartVoice", "OnVoiceStarted", function(ply)
  44.     OnVoiceStarted( ply )
  45. end)
  46.  
  47. hook.Add( "PlayerEndVoice", "OnVoiceEnd", function(ply)
  48.     OnVoiceEnd( ply )
  49. end)
  50.  
  51. hook.Add( "HUDPaint", "DrawVoiceBoxes", function()
  52.     if #talkingPlayers != 0 then
  53.         local baseW = ScrW()-310
  54.         --local baseH = (ScrH()/2)+385
  55.         --above does not work on lower resolutions.
  56.         local baseH = (ScrH()/2)+250 -- confirmed working on everything above 800x600.
  57.         local hIncrement = 0
  58.         for i,name in ipairs( talkingPlayers ) do
  59.             local ply = getPlayerByName( name )
  60.             local profilepicture = getProfilePicture( ply )
  61.             if profilepicture == nil then
  62.                 profilepicture = vgui.Create( "AvatarImage", self, ply:Name())
  63.                 profilepicture:SetSize( 32, 32 )
  64.                 profilepicture:SetPos( baseW+4, (baseH+4)-hIncrement )
  65.                 profilepicture:SetPlayer( ply, 32 )
  66.             else
  67.                 profilepicture:SetPos( baseW+4, (baseH+4)-hIncrement )
  68.             end
  69.             draw.RoundedBox( 4, baseW, baseH-hIncrement, 246, 40, Color( 0, ply:VoiceVolume() * 255, 0, 240 ) )
  70.             draw.DrawText( talkingPlayers[i], "GModNotify", baseW+45, (baseH+10)-hIncrement, Color( 255, 255, 255, 255 ), 0 )
  71.             hIncrement = hIncrement + 45
  72.         end
  73.     end
  74. end)
  75.  
  76. print( "==============================================================" )
  77. print( "GMod Demo Voice Fix Script Loaded                             " )
  78. print( "Version: 1.1                                                  " )
  79. print( "Created by youtube.com/videooven                              " )
  80. print( "Edited by Sticky Bandit                                       " )
  81. print( "==============================================================" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement