Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.12 KB | None | 0 0
  1. /*------------
  2. Infected Wars
  3. cl_hud.lua
  4. Clientside
  5. ------------*/
  6.  
  7. local textureBullet = surface.GetTextureID("infectedwars/bullet")
  8. local turretTexture = surface.GetTextureID("killicon/infectedwars/turret")
  9. local timeblock = surface.GetTextureID( "infectedwars/timeblock" )
  10. local timeborder = surface.GetTextureID( "infectedwars/HUD/HUDtimer_rev2" )
  11. local undlogo = surface.GetTextureID( "infectedwars/undeadlegion" )
  12. local humlogo = surface.GetTextureID( "infectedwars/specialforces" )
  13.  
  14. /*---------------------------------------------------------
  15.    Name: gamemode:HUDPaint( )
  16.    Desc: Use this section to paint your HUD
  17. ---------------------------------------------------------*/
  18. local undwin = UNDEADWINLIST[math.random(#UNDEADWINLIST)]
  19. local humwin = HUMANWINLIST[math.random(#HUMANWINLIST)]
  20. DrawCrHair = true
  21.  
  22. function GM:HUDPaint()
  23.    
  24.     if not HUD_ON then return end
  25.    
  26.     local MySelf = LocalPlayer()
  27.    
  28.     /*--------------------------------------------------
  29.                 Draw teammate/identified locations
  30.     ---------------------------------------------------*/
  31.  
  32.     local idList = {}
  33.     for k, v in pairs(player.GetAll()) do
  34.         if (ValidEntity(v) and (v:Team() == TEAM_HUMAN or v.Detectable) and v:IsValid() and v:Alive() and v ~= LocalPlayer()) then
  35.             idList[#idList+1] = { Obj = v, ID = v:Name() }
  36.         end
  37.     end
  38.    
  39.     if (MySelf:Team() == TEAM_HUMAN and MySelf:IsValid() and MySelf:Alive() and not ENDROUND) then
  40.    
  41.         local target
  42.         local pos
  43.         local pl
  44.         local dis
  45.         local disToMiddle
  46.         local alpha
  47.         local mypos = MySelf:GetPos()
  48.         local hp
  49.         local maxhp
  50.         local col = COLOR_GREEN
  51.         local ratio = 1
  52.         local enemy
  53.        
  54.         function ScaleAlpha( color, amount )
  55.             return Color(color.r, color.g, color.b, amount)
  56.         end
  57.        
  58.        
  59.         for k=1, #idList do
  60.             target = idList[k].Obj:GetPos()+Vector(0,0,50)
  61.             pl = idList[k].Obj
  62.             hp = pl:Health()
  63.             maxhp = pl:GetMaximumHealth()
  64.             enemy = (idList[k].Obj:Team() ~= MySelf:Team())
  65.  
  66.             pos = target:ToScreen()
  67.             dis = math.floor(target:Distance(mypos))
  68.             disToMiddle = Vector(pos.x-w/2,pos.y-h/2,0):Length()
  69.             alpha = math.min(255,math.max(0,255*50/disToMiddle))
  70.             if (dis < 1500) then
  71.                 SCALEBLACK = ScaleAlpha(COLOR_BLACK,alpha)
  72.                 surface.SetDrawColor( SCALEBLACK )
  73.                 surface.DrawLine( pos.x - 16, pos.y - 16, pos.x - 16, pos.y + 16 ) -- left
  74.                 surface.DrawLine( pos.x + 16, pos.y - 16, pos.x + 16, pos.y + 16 ) -- right
  75.                 surface.DrawLine( pos.x - 23, pos.y - 16, pos.x + 23, pos.y - 16 ) -- top
  76.                 surface.DrawLine( pos.x - 23, pos.y + 16, pos.x + 23, pos.y + 16 ) -- bottom
  77.                 surface.DrawLine( pos.x - 23, pos.y - 16, pos.x - 23, pos.y + 16 ) -- more left
  78.                 surface.DrawLine( pos.x + 23, pos.y - 16, pos.x + 23, pos.y + 16 ) -- more right
  79.                
  80.                 if enemy then
  81.                     col = COLOR_UNDEAD
  82.                     draw.SimpleTextOutlined("UNDEAD TARGET","InfoMedium",pos.x,pos.y+17,col, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 1, SCALEBLACK)
  83.                     draw.SimpleTextOutlined("X","InfoSmall",pos.x,pos.y,col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, SCALEBLACK)
  84.                     surface.SetDrawColor( Color(200,20,20,100) )
  85.                     surface.DrawRect( pos.x - 20,  pos.y - 14, 3, 28 )
  86.                     surface.DrawRect( pos.x + 18,  pos.y - 14, 3, 28 )
  87.                 else
  88.                     col = ScaleAlpha(COLOR_HURT1,alpha)
  89.                     if (hp <= 0.25*maxhp) then col = ScaleAlpha(COLOR_HURT4,alpha)
  90.                     elseif (hp <= 0.5*maxhp) then col = ScaleAlpha(COLOR_HURT3,alpha)
  91.                     elseif (hp <= 0.75*maxhp) then col = ScaleAlpha(COLOR_HURT2,alpha)
  92.                     end
  93.                     surface.SetDrawColor( col )
  94.                     ratio = math.Clamp(hp/maxhp,0,1)
  95.                     surface.DrawRect( pos.x - 20,  pos.y + 14-math.Round((28*ratio)), 3, math.Round(28*ratio) )
  96.                     surface.DrawRect( pos.x + 18,  pos.y + 14-math.Round((28*ratio)), 3, math.Round(28*ratio) )
  97.                     col = ScaleAlpha(COLOR_HUMAN,alpha)
  98.                     draw.SimpleTextOutlined(idList[k].ID,"InfoMedium",pos.x,pos.y+17,col, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 1, SCALEBLACK)
  99.                     draw.SimpleTextOutlined(tostring(hp),"InfoSmall",pos.x,pos.y,col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, SCALEBLACK)
  100.                 end
  101.                 draw.SimpleTextOutlined("Distance: "..dis,"InfoSmall",pos.x,pos.y+40,col, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 1, SCALEBLACK)
  102.                
  103.             end
  104.         end
  105.  
  106.     end
  107.    
  108.     /*--------------- Draw endround -----------*/
  109.     if ENDROUND then
  110.    
  111.         GAMEMODE:DrawDeathNotice( 0.82, 0.04 )
  112.        
  113.         local toDraw = ""
  114.         local displayCol = team.GetColor( self.TeamThatWon )
  115.        
  116.         local tab = {}
  117.         tab[1] = { StatsUndKiller, "Most undead killed by ", "No undead were harmed this round" }
  118.         tab[2] = { StatsHumKiller, "Most humans killed by ", "No humans died this round (wtf O_o)" }
  119.         tab[3] = { StatsUndDmg, "Most damage done to undead by ", "Pussy humans failed to damage the undead" }
  120.         tab[4] = { StatsHumDmg, "Most damage done to humans by ", "Undead couldn't even scratch the humans" }
  121.         tab[5] = { StatsMostSocial, "Most social player was ", "No social player, you're all egocentric dicks" }
  122.         tab[6] = { StatsMostScary, "Most scary player was ", "There were no scary players, you're all pussies" }
  123.         tab[7] = { StatsMostUnlucky, "Most unlucky player was ", "You were all lucky" }
  124.        
  125.         local adv = stattimer-CurTime()
  126.         if (statsreceived) then
  127.             for k=1, #tab do
  128.                 if adv < (#tab)-k then
  129.                     local str = tab[k][2]..tab[k][1]
  130.                     if tab[k][1] == "-" then
  131.                         str = tab[k][3]
  132.                     end
  133.                     draw.SimpleTextOutlined(str, "EndRoundStats", w/2, h/2-270+k*30, displayCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, COLOR_BLACK)
  134.                 end
  135.             end
  136.         end
  137.        
  138.         local tab = {}
  139.         tab[1] = { StatsRoundKills, "Total kills this round: " }
  140.         tab[2] = { StatsRoundDamage, "Total damage this round: " }
  141.        
  142.         if (statsreceived) then
  143.             for k=1, #tab do
  144.                 if adv < (#tab)-k then
  145.                     draw.SimpleTextOutlined(tab[k][2]..tab[k][1], "DoomMedium", w/2, h/2+12+k*30, displayCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, COLOR_BLACK)
  146.                 end
  147.             end
  148.         end
  149.        
  150.         if (self.TeamThatWon == TEAM_UNDEAD) then
  151.             toDraw = undwin
  152.         else
  153.             toDraw = humwin
  154.         end
  155.        
  156.         draw.SimpleTextOutlined(toDraw, "DoomLarge", w/2, h/2, displayCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, COLOR_BLACK)
  157.        
  158.         // Show voting thingies
  159.         if not self.ShowVoting then return end
  160.        
  161.         local m_x, m_y = gui.MouseX(), gui.MouseY()
  162.         local mousepressed = input.IsMouseDown(MOUSE_LEFT)
  163.         local hasvoted = (MySelf.Voted > 0)
  164.        
  165.         local initBox = false
  166.         if not VoteBox then
  167.             initBox = true
  168.             VoteBox = {}
  169.         end
  170.        
  171.         local drawCol = COLOR_GRAY
  172.        
  173.         local str = "VOTE (click one)"
  174.         if hasvoted then
  175.             str = "NOW WAIT"
  176.         end
  177.         draw.SimpleTextOutlined(str, "DoomSmall", w/2, h/2+90, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  178.        
  179.         local y = 0
  180.         local vx, vy
  181.         if self.CanRestart then
  182.             str = "Restart round"
  183.             if MySelf.Voted == 1 then
  184.                 str = "-> "..str.." <-"
  185.             end
  186.             if initBox then
  187.                 vx, vy = surface.GetTextSize( str )
  188.                 table.insert(VoteBox,{ x = (w/2-vx/2), y = (h/2+115+y*40), w = vx, h = vy })
  189.             end
  190.             if (VoteBox[1].x < m_x and VoteBox[1].x+VoteBox[1].w > m_x and VoteBox[1].y < m_y and VoteBox[1].y+VoteBox[1].h > m_y) then
  191.                 drawCol = COLOR_WHITE
  192.                 if mousepressed and not hasvoted then
  193.                     print("Voting for restart round")
  194.                     MySelf.Voted = 1
  195.                     RunConsoleCommand("vote_map_choice",1)
  196.                 end
  197.             end
  198.             draw.SimpleTextOutlined(str, "InfoSmall", w/2, h/2+115+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  199.             draw.SimpleTextOutlined(string.rep("X",MapVotes.curMap), "InfoSmall", w/2, h/2+134+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  200.             y = y+1
  201.             drawCol = COLOR_GRAY
  202.         else
  203.             // quick hacky solution so it doesn't complain about indices further on
  204.             if initBox then
  205.                 table.insert(VoteBox,{})
  206.             end
  207.         end
  208.        
  209.         str = "Map "..self.NextMap
  210.         if MySelf.Voted == 2 then
  211.             str = "-> "..str.." <-"
  212.         end
  213.         if initBox then
  214.             vx, vy = surface.GetTextSize( str )
  215.             table.insert(VoteBox,{ x = (w/2-vx/2), y = (h/2+115+y*40), w = vx, h = vy })
  216.         end
  217.         if (VoteBox[2].x < m_x and VoteBox[2].x+VoteBox[2].w > m_x and VoteBox[2].y < m_y and VoteBox[2].y+VoteBox[2].h > m_y) then
  218.             drawCol = COLOR_WHITE
  219.             if mousepressed and not hasvoted then
  220.                 //print("Voting for next map")
  221.                 MySelf.Voted = 2
  222.                 RunConsoleCommand("vote_map_choice",2)
  223.             end
  224.         end
  225.         draw.SimpleTextOutlined(str, "InfoSmall", w/2, h/2+115+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  226.         draw.SimpleTextOutlined(string.rep("X",MapVotes.nextMap), "InfoSmall", w/2, h/2+134+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  227.         y = y+1
  228.         drawCol = COLOR_GRAY
  229.        
  230.         str = "Map "..self.SecondNextMap
  231.         if MySelf.Voted == 3 then
  232.             str = "-> "..str.." <-"
  233.         end
  234.         if initBox then
  235.             vx, vy = surface.GetTextSize( str )
  236.             table.insert(VoteBox,{ x = (w/2-vx/2), y = (h/2+115+y*40), w = vx, h = vy })
  237.         end
  238.         if (VoteBox[3].x < m_x and VoteBox[3].x+VoteBox[3].w > m_x and VoteBox[3].y < m_y and VoteBox[3].y+VoteBox[3].h > m_y) then
  239.             drawCol = COLOR_WHITE
  240.             if mousepressed and not hasvoted then
  241.                 //print("Voting for second next map")
  242.                 MySelf.Voted = 3
  243.                 RunConsoleCommand("vote_map_choice",3)
  244.             end
  245.         end
  246.         draw.SimpleTextOutlined(str, "InfoSmall", w/2, h/2+115+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  247.         draw.SimpleTextOutlined(string.rep("X",MapVotes.secondNextMap), "InfoSmall", w/2, h/2+134+y*40, drawCol, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  248.         y = y+1
  249.         drawCol = COLOR_GRAY
  250.        
  251.         // Show what is winning the vote
  252.         local winner = "Restarting round"
  253.         if (MapVotes.nextMap > MapVotes.curMap or not self.CanRestart) and MapVotes.nextMap >= MapVotes.secondNextMap then
  254.             winner = "Changing to "..self.NextMap
  255.         elseif MapVotes.secondNextMap > MapVotes.curMap then
  256.             winner = "Changing to "..self.SecondNextMap
  257.         end
  258.         draw.SimpleTextOutlined(winner.." in "..math.floor(self:RoundTimeLeft()).." seconds", "DoomSmall", w/2, h/2+115+y*40, COLOR_GRAY, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  259.        
  260.         return
  261.     end
  262.    
  263.     /*---------- Draw logos and counter stuff -------*/
  264.    
  265.     surface.SetTexture( undlogo )
  266.     surface.SetDrawColor( 180, 20, 20, 240 )
  267.     surface.DrawTexturedRect( 100, -2, 153, 75 )
  268.  
  269.     surface.SetTexture( humlogo )
  270.     surface.SetDrawColor( 20, 20, 180, 240 )
  271.     surface.DrawTexturedRect( 100, 52, 153, 75 )
  272.    
  273.     local undeads = self.Reinforcements
  274.     draw.SimpleTextOutlined("Undead Legion: "..undeads, "DoomSmall", 120, 40, COLOR_UNDEAD, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  275.    
  276.     local humans = team.NumPlayers(TEAM_HUMAN)
  277.     draw.SimpleTextOutlined("Special Forces: "..humans, "DoomSmall", 120, 77, COLOR_HUMAN, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  278.    
  279.    
  280.     /*--------------- Draw round timer -----------------*/
  281.    
  282.     local vertextable = {{}}
  283.     local tim = GAMEMODE:RoundTimeLeft()
  284.     local steps = 36-math.Round((tim/ROUNDLENGTH)*36)
  285.     local clockx = 51
  286.     local clocky = 66
  287.     local clocklength = 35
  288.    
  289.     local function lengthdirx(length, dir)
  290.         return length*math.cos(math.rad(dir))
  291.     end -- Muahahahaha, I'm a mathematical genius! :D
  292.     local function lengthdiry(length, dir)
  293.         return length*math.sin(math.rad(dir))
  294.     end
  295.    
  296.     -- Draw clock background
  297.     surface.SetTexture( timeblock )
  298.     surface.SetDrawColor( 30, 30, 30, 200 )
  299.     for k=1, 36 do     
  300.         vertextable = {}
  301.         vertextable[1] = {}
  302.         vertextable[2] = {}
  303.         vertextable[3] = {}
  304.         vertextable[1]["x"] = clockx
  305.         vertextable[1]["y"] = clocky
  306.         vertextable[1]["u"] = 0
  307.         vertextable[1]["v"] = 0
  308.         vertextable[2]["x"] = clockx+lengthdirx(clocklength,(k-1)*10-90)
  309.         vertextable[2]["y"] = clocky+lengthdiry(clocklength,(k-1)*10-90)
  310.         vertextable[2]["u"] = 1
  311.         vertextable[2]["v"] = 0
  312.         vertextable[3]["x"] = clockx+lengthdirx(clocklength,k*10-90)
  313.         vertextable[3]["y"] = clocky+lengthdiry(clocklength,k*10-90)
  314.         vertextable[3]["u"] = 0
  315.         vertextable[3]["v"] = 1
  316.         surface.DrawPoly( vertextable )
  317.     end
  318.        
  319.     -- Draw clock itself
  320.     surface.SetTexture( timeblock )
  321.     surface.SetDrawColor( team.GetColor(MySelf:Team()) )
  322.    
  323.     if steps > 0 then
  324.         for k=1, steps do      
  325.             vertextable = {}
  326.             vertextable[1] = {}
  327.             vertextable[2] = {}
  328.             vertextable[3] = {}
  329.             vertextable[1]["x"] = clockx
  330.             vertextable[1]["y"] = clocky
  331.             vertextable[1]["u"] = 0
  332.             vertextable[1]["v"] = 0
  333.             vertextable[2]["x"] = clockx+lengthdirx(clocklength,(k-1)*10-90)
  334.             vertextable[2]["y"] = clocky+lengthdiry(clocklength,(k-1)*10-90)
  335.             vertextable[2]["u"] = 1
  336.             vertextable[2]["v"] = 0
  337.             vertextable[3]["x"] = clockx+lengthdirx(clocklength,k*10-90)
  338.             vertextable[3]["y"] = clocky+lengthdiry(clocklength,k*10-90)
  339.             vertextable[3]["u"] = 0
  340.             vertextable[3]["v"] = 1
  341.             surface.DrawPoly( vertextable )        
  342.         end
  343.     end
  344.     -- Draw pointer line(s)
  345.     surface.SetDrawColor( team.GetColor(MySelf:Team()) )
  346.     surface.SetTexture( timeblock )
  347.     surface.DrawTexturedRectRotated( clockx+lengthdirx(clocklength/2,steps*10-90), clocky+lengthdiry(clocklength/2,steps*10-90), clocklength, 3, (36-steps)*10-90 )
  348.    
  349.     surface.SetTexture( timeborder )
  350.     surface.SetDrawColor( 255, 255, 255, 255 )
  351.     surface.DrawTexturedRect( 0,0, 128, 128 )//clockx-clocklength-1,clocky-clocklength-1,clocklength*2+2,clocklength*2+2 )
  352.    
  353.     draw.SimpleTextOutlined(string.ToMinutesSeconds(tim), "DoomSmall", clockx, clocky+10, COLOR_GRAY, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 2, COLOR_BLACK)
  354.    
  355.     -- Rest isn't drawn if player is not alive
  356.     if (MySelf:IsValid() and MySelf:Alive() and MySelf.Class and MySelf.Class ~= 0) then
  357.        
  358.         /*--------------- HUD info --------------------*/
  359.        
  360.         draw.SimpleTextOutlined("F1: Help  F2: Classes  F3: Options  F4: Score", "InfoSmall", 6, 2, COLOR_GRAY, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, 1, COLOR_BLACK)
  361.        
  362.         /*------- Turret info for experimental -----------*/
  363.        
  364.         if MySelf:GetPlayerClass() == 5 and MySelf:Team() == TEAM_HUMAN then
  365.        
  366.             self.TurTabTargetW = self.TurTabTargetW or 78
  367.             self.TurTabCurrentW = self.TurTabCurrentW or 78
  368.        
  369.             -- nice transition effect
  370.             if (self.TurTabTargetW != self.TurTabCurrentW) then
  371.                 self.TurTabCurrentW = math.Approach(self.TurTabCurrentW,self.TurTabTargetW,math.abs(self.TurTabCurrentW-self.TurTabTargetW)*2*FrameTime())
  372.             end
  373.        
  374.             draw.RoundedBox(16, 4, 146, self.TurTabCurrentW, 60, Color(0,0,0,180))
  375.            
  376.             local turcol = COLOR_HUMAN
  377.            
  378.             if MySelf.TurretStatus == TurretStatus.active then
  379.                 if ValidEntity(MySelf.Turret.Entity) then
  380.                     self.TurTabTargetW = 190
  381.                     local turhp = MySelf.Turret:GetTable():GetHealth()
  382.                     local turmaxhp = MySelf.Turret:GetTable():GetMaxHealth()
  383.                     local mode = MySelf.Turret:GetTable():GetMode()
  384.                     local st = { FOLLOWING = 1, TRACKING = 2, LOST = 3, DEFEND = 4, SHUTDOWN = 5 }
  385.                     local kills = 0
  386.                    
  387.                     kills = MySelf.Turret:GetTable():Kills()
  388.                     draw.SimpleText("Kills: "..kills, "InfoSmall", 82, 150, COLOR_HUMAN_LIGHT, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  389.                    
  390.                     local modestr = "* Following owner"
  391.                     local modestr2 = ""
  392.                     if (mode == st.TRACKING) then
  393.                         modestr = "* Lost owner!"
  394.                         modestr2 = "* Tracking..."
  395.                     elseif (mode == st.LOST) then
  396.                         modestr = "* Lost track"
  397.                         modestr2 = "* Waiting for owner"
  398.                     elseif (mode == st.DEFEND) then
  399.                         modestr = "* Defending point"
  400.                         modestr2 = ""
  401.                     end
  402.                     draw.SimpleText(modestr, "InfoSmall", 82, 170, COLOR_HUMAN_LIGHT, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  403.                     draw.SimpleText(modestr2, "InfoSmall", 82, 186, COLOR_HUMAN_LIGHT, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  404.                    
  405.                     surface.SetDrawColor( COLOR_DARKGRAY )
  406.                     surface.DrawRect(10,186,70,10)
  407.                    
  408.                     local col = COLOR_HURT1
  409.                     if (turhp <= 0.25*turmaxhp) then col = COLOR_HURT4
  410.                     elseif (turhp <= 0.5*turmaxhp) then col = COLOR_HURT3
  411.                     elseif (turhp <= 0.75*turmaxhp) then col = COLOR_HURT2
  412.                     end
  413.                     surface.SetDrawColor( col )
  414.                     surface.DrawRect(10,186,70*turhp/turmaxhp,10)
  415.                    
  416.                     surface.SetDrawColor( 0,0,0,255 )
  417.                     surface.DrawOutlinedRect(10,186,70,10)
  418.                 end
  419.             elseif MySelf.TurretStatus == TurretStatus.inactive then
  420.                 self.TurTabTargetW = 78
  421.                 draw.SimpleText("UNDEPLOYED", "InfoSmaller", 42, 186, COLOR_HUMAN_LIGHT, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
  422.             elseif MySelf.TurretStatus == TurretStatus.destroyed then
  423.                 self.TurTabTargetW = 78
  424.                 turcol = COLOR_GRAY
  425.                 draw.SimpleText("DESTROYED", "InfoSmaller", 42, 186, COLOR_HUMAN_LIGHT, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
  426.             end
  427.            
  428.             surface.SetTexture(turretTexture)
  429.             surface.SetDrawColor(turcol.r, turcol.g, turcol.b, 255)
  430.             surface.DrawTexturedRect( 10,130, 64, 64 )
  431.  
  432.         end
  433.        
  434.         // stuff
  435.        
  436.         local classname = ""
  437.         if (MySelf:Team() == TEAM_HUMAN) then
  438.             classname = HumanClass[MySelf.Class].Name
  439.         elseif (MySelf:Team() == TEAM_UNDEAD) then
  440.             classname = UndeadClass[MySelf.Class].Name
  441.         end
  442.         local powername = HumanPowers[(MySelf:GetPower() or 0)].Name
  443.  
  444.         /* ------------ Weapon info drawing ---------------*/
  445.         local clip_left = 0
  446.         local clip_reserve = 0
  447.         if (MySelf:GetActiveWeapon():IsValid()) then
  448.             -- Amount of ammo in clip
  449.             clip_left = MySelf:GetActiveWeapon():Clip1() or 0
  450.             -- Amount of ammunition left
  451.             clip_reserve = MySelf:GetAmmoCount(MySelf:GetActiveWeapon():GetPrimaryAmmoType()) or 0
  452.         end
  453.        
  454.         if (clip_left ~= -1) then  -- mostly meaning user is holding knife or something
  455.        
  456.             clip_type = "none"
  457.             if MySelf:GetActiveWeapon().Primary then
  458.                 clip_type = MySelf:GetActiveWeapon().Primary.Ammo
  459.             end
  460.             local clipline = "Clip: "..clip_left.."/"..clip_reserve
  461.            
  462.             -- Draw bullets
  463.             local function DrawBullet(x,y)
  464.                 surface.SetDrawColor(255,255,255,255)
  465.                 surface.SetTexture( textureBullet )
  466.                 surface.DrawTexturedRect( x,y, 4,10 )
  467.             end
  468.            
  469.             local drawx = w - 10
  470.             local drawy = h - 4
  471.             local linemax = 50 -- Amount of bullets on one line
  472.             if (clip_left > 0 and clip_type ~= "grenade" and clip_type ~= "none") then
  473.                 drawy = drawy-11
  474.                 for k = 1, clip_left, 1 do
  475.                     DrawBullet(drawx,drawy)
  476.                     if (math.fmod(k,linemax)==0 and k ~= clip_left) then -- split up bullet alignment
  477.                         drawy = drawy-11
  478.                         drawx = w - 10
  479.                     else
  480.                         drawx = drawx-5
  481.                     end
  482.                 end
  483.             end
  484.            
  485.             if (clip_type == "none" or clip_type == "grenade" or clip_type == "slam") then
  486.                 clipline = "Amount: "..math.max(clip_left,clip_reserve)
  487.             end
  488.            
  489.             draw.SimpleTextOutlined(clipline, "DoomSmall", w - 16, drawy-20, COLOR_GRAY, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  490.         end
  491.        
  492.         -- Draw team specific HUD elements 
  493.         if MySelf:Team() == TEAM_UNDEAD then
  494.             self:UndeadHUD()
  495.         elseif MySelf:Team() == TEAM_HUMAN then
  496.             self:HumanHUD()
  497.         end
  498.  
  499.         /*------------ Draw class picture ---------------*/
  500.        
  501.         surface.SetDrawColor(MySelf:GetColor())
  502.         if MySelf:Team() == TEAM_UNDEAD then
  503.             surface.SetTexture( surface.GetTextureID(UndeadClass[MySelf.Class].HUDfile) )  
  504.         elseif MySelf:Team() == TEAM_HUMAN then
  505.             surface.SetTexture( surface.GetTextureID(HumanClass[MySelf.Class].HUDfile) )       
  506.         end
  507.         surface.DrawTexturedRect( 0,h-160, 180,160 )
  508.        
  509.         local col = COLOR_GRAY
  510.         if MySelf:Team() == TEAM_UNDEAD then
  511.             col = COLOR_RED
  512.         end
  513.         draw.SimpleTextOutlined(classname, "DoomSmall", 75, h - 20, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, COLOR_BLACK)
  514.        
  515.        
  516.     end
  517.    
  518.     -- Draw target ID
  519.     GAMEMODE:HUDDrawTargetID()
  520.     -- Draw pickup history
  521.     GAMEMODE:HUDDrawPickupHistory()
  522.     -- Draw death notice
  523.     GAMEMODE:DrawDeathNotice( 0.82, 0.04 )
  524.    
  525.     -- Draw crosshair
  526.     if MySelf and MySelf:IsValid() and MySelf:Alive() and MySelf:Team() ~= TEAM_UNASSIGNED and DrawCrHair then
  527.         GAMEMODE:DrawCrosshair()
  528.     end
  529.    
  530. end
  531.  
  532. local showsuitpower = 0
  533. local showhealth = 0
  534.  
  535. local zhud = surface.GetTextureID( "infectedwars/HUD/ZHUD" )
  536.    
  537. function GM:UndeadHUD()
  538.  
  539.     local MySelf = LocalPlayer()
  540.     local myhealth = 0
  541.     local mymaxhealth = MySelf:GetMaximumHealth() or 100
  542.     if (MySelf:IsValid() and MySelf:Alive()) then
  543.         myhealth = math.max(MySelf:Health(), 0)
  544.     end
  545.    
  546.     /*-------- Warghoul smell ----------*/
  547.     for v, ply in pairs(player.GetAll()) do
  548.         if ply:Team() == TEAM_HUMAN and ply:Alive() and (ply.Detectable or MySelf:GetPlayerClass() == 5)then
  549.             local pos = ply:GetPos() + Vector(0,0,50)
  550.             if pos:Distance(pos) < 2000 then
  551.                 local vel = ply:GetVelocity() * 0.6
  552.                 local emitter = ParticleEmitter(pos)
  553.                 for i=1, math.random(2,3) do
  554.                     local par = emitter:Add("Sprites/light_glow02_add_noz.vmt", pos)
  555.                     par:SetVelocity(vel + Vector(math.random(-25, 25),math.random(-25, 25), math.Rand(-20, 20)))
  556.                     par:SetDieTime(0.5)
  557.                     par:SetStartAlpha(4)
  558.                     par:SetEndAlpha(2)
  559.                     par:SetStartSize(math.random(1, 9))
  560.                     par:SetEndSize(math.random(1,4))
  561.                     if ply.Detectable then
  562.                         par:SetColor(250, math.random(220,240), 0)
  563.                     else
  564.                         par:SetColor(220, math.random(10,50), 10)
  565.                     end
  566.                 end
  567.                 emitter:Finish()
  568.             end
  569.         end
  570.     end
  571.    
  572.     /*--------------- Draw healthbar ----------------*/
  573.    
  574.     local barcolor = Color(255,66,66,255)
  575.    
  576.     -- Make the health flash when low on HP
  577.     if myhealth > 25 then
  578.         surface.SetDrawColor( barcolor )
  579.     else
  580.         surface.SetDrawColor(barcolor.r, barcolor.g, barcolor.b, (math.sin(RealTime() * 6) * 100) + 155)
  581.     end
  582.    
  583.     -- Draw bars for below healthbar
  584.     surface.SetDrawColor( COLOR_BLACK )
  585.     surface.DrawRect(160, h - 48, 202, 26) 
  586.     surface.SetDrawColor( Color(255,90,90) )
  587.    
  588.     local targethealth = math.min(myhealth / mymaxhealth,1) * 202
  589.     showhealth = math.Approach(showhealth, targethealth, FrameTime()*202)
  590.     surface.DrawRect(160, h - 48, showhealth, 26)
  591.  
  592.     surface.SetTexture( zhud )
  593.     surface.SetDrawColor( 255, 255, 255, 255 )
  594.     surface.DrawTexturedRect( 0, h-200, 400, 200 )
  595.        
  596.     draw.SimpleTextOutlined(myhealth.."/"..mymaxhealth, "DoomSmall", 360, h - 48, Color(255,0,0), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, 1, Color(75,0,0))
  597.        
  598. end
  599.  
  600. local hhud = surface.GetTextureID( "infectedwars/HUD/HHUD" )
  601.  
  602. function GM:HumanHUD()
  603.     /*--------------- Draw suit power ----------------*/
  604.     local MySelf = LocalPlayer()
  605.     local barcolor = Color (0, 255, 255, 200)
  606.     local suitpower = MySelf:SuitPower()
  607.     local maxsuitpower = MySelf:GetMaxSuitPower()
  608.     local powername = HumanPowers[MySelf:GetPower()].Name
  609.     local myhealth = 0
  610.     local mymaxhealth = MySelf:GetMaximumHealth() or 100
  611.     if (MySelf:IsValid() and MySelf:Alive()) then
  612.         myhealth = math.max(MySelf:Health(), 0)
  613.     end
  614.    
  615.     -- Draw bars for below healthbar
  616.     surface.SetDrawColor( COLOR_BLACK )
  617.     surface.DrawRect(170, h - 31, 190, 22) 
  618.    
  619.     surface.SetDrawColor( barcolor )
  620.     local targetsuitpower = math.min(suitpower / maxsuitpower,1) * 190
  621.     showsuitpower = math.Approach(showsuitpower, targetsuitpower, FrameTime()*190)
  622.     surface.DrawRect(170, h - 31, showsuitpower, 22)
  623.            
  624.    
  625.     /*--------------- Draw healthbar ----------------*/
  626.    
  627.     local barcolor
  628.    
  629.     -- Determine health color
  630.     barcolor = COLOR_HURT1
  631.     if (myhealth <= 0.25*mymaxhealth) then barcolor = COLOR_HURT4
  632.     elseif (myhealth <= 0.5*mymaxhealth) then barcolor = COLOR_HURT3
  633.     elseif (myhealth <= 0.75*mymaxhealth) then barcolor = COLOR_HURT2
  634.     end
  635.    
  636.     -- Draw bars for below healthbar
  637.     surface.SetDrawColor( COLOR_BLACK )
  638.     surface.DrawRect(170, h - 68, 190, 22) 
  639.    
  640.     -- Make the health flash when low on HP
  641.     if myhealth > 25 then
  642.         surface.SetDrawColor( barcolor )
  643.     else
  644.         surface.SetDrawColor(barcolor.r, barcolor.g, barcolor.b, (math.sin(RealTime() * 6) * 100) + 155)
  645.     end
  646.    
  647.     local targethealth = math.min(myhealth / mymaxhealth,1) * 190
  648.     showhealth = math.Approach(showhealth, targethealth, FrameTime()*190)
  649.     surface.DrawRect(170, h - 68, showhealth, 22)
  650.    
  651.     surface.SetTexture( hhud )
  652.     surface.SetDrawColor( 255, 255, 255, 255 )
  653.     surface.DrawTexturedRect( 0, h-200, 400, 200 )
  654.    
  655.     draw.SimpleTextOutlined(suitpower.."/"..maxsuitpower, "DoomSmall", 355, h - 10, Color(0,140,200), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, 1, Color(0,25,45))
  656.     draw.SimpleTextOutlined(myhealth.."/"..mymaxhealth, "DoomSmall", 355, h - 68, Color(0,140,200), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, 1, Color(0,25,45))
  657.    
  658.     -- draw power logo
  659.     local powlogo = surface.GetTextureID( HumanPowers[MySelf:GetPower()].HUDfile )
  660.    
  661.     surface.SetTexture( powlogo )
  662.     surface.SetDrawColor( COLOR_HUMAN )
  663.     surface.DrawTexturedRect( w-100, 10, 100, 100 )
  664.     draw.SimpleTextOutlined(powername, "DoomSmall", w-50, 60, COLOR_HUMAN, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  665.    
  666. end
  667.  
  668. function GM:DrawCrosshair()
  669.     surface.SetTexture( surface.GetTextureID(CROSSHAIR[CurCrosshair]) )
  670.     local col = CROSSHAIRCOLORS[CurCrosshairColor] or Color(255,255,255,255)
  671.     local alph = GetConVarNumber("_iw_crosshairalpha")
  672.     surface.SetDrawColor( col.r, col.g, col.b, alph )  
  673.     surface.DrawTexturedRect( w/2-32, h/2-32, 64, 64 )
  674. end
  675.  
  676. local lastStandTex = surface.GetTextureID("infectedwars/laststand")
  677. local lastStandAlph = 255
  678. function LastHumanPaint()
  679.  
  680.     local sizex = 512
  681.     local sizey = 256
  682.    
  683.     if GAMEMODE.LastHumanStart+8 > CurTime() then
  684.         lastStandAlph = 255
  685.     else
  686.         lastStandAlph = math.max(0,lastStandAlph-255*FrameTime()/2)
  687.     end
  688.    
  689.     surface.SetTexture( lastStandTex )
  690.     surface.SetDrawColor( 255,255,255,lastStandAlph )  
  691.     surface.DrawTexturedRect( w/2-sizex/2, h/2-sizey/2+h/4, sizex, sizey )
  692.     surface.SetDrawColor( 100,100,100, lastStandAlph/4 )   
  693.     surface.DrawTexturedRect( w/2-sizex*4, h/2-sizey/2+h/4, sizex*8, sizey )
  694.    
  695.     local col = COLOR_RED
  696.     col.a = lastStandAlph
  697.     if LocalPlayer():Team() == TEAM_HUMAN then
  698.         draw.SimpleTextOutlined("Survive!", "DoomSmall", w/2, h*3/4+sizey/4, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  699.     else
  700.         draw.SimpleTextOutlined("Kill the last human!", "DoomSmall", w/2, h*3/4+sizey/4, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, COLOR_BLACK)
  701.     end
  702.    
  703.     if GAMEMODE.LastHumanStart != 0 and GAMEMODE.LastHumanStart+10 < CurTime() then
  704.         hook.Remove("HUDPaint","LastHumanP")
  705.     end
  706. end
  707.  
  708.  
  709. function ToggleHUD( pl,commandName,args )
  710.     local MySelf = LocalPlayer()
  711.     HUD_ON = util.tobool(args[1])
  712.     if HUD_ON then
  713.         MySelf:PrintMessage( HUD_PRINTTALK, "HUD activated")
  714.         RunConsoleCommand("r_viewmodel","1")
  715.     else
  716.         MySelf:PrintMessage( HUD_PRINTTALK, "HUD deactivated")
  717.         RunConsoleCommand("r_viewmodel","0")
  718.     end
  719. end
  720. concommand.Add("iw_enablehud",ToggleHUD)
  721.  
  722. /*---------------------------------------------------------
  723.    Name: gamemode:HUDPaintBackground( )
  724.    Desc: Same as HUDPaint except drawn before
  725. ---------------------------------------------------------*/
  726. local armorHitOverlay = surface.GetTextureID("infectedwars/HUD/armorhit")
  727. local armorHitAlpha = 0
  728. function GM:HUDPaintBackground()
  729.  
  730.     if not HUD_ON then return end
  731.    
  732.     local MySelf = LocalPlayer()
  733.    
  734.     -- Call scope drawing before all the other HUD code
  735.     if MySelf:GetActiveWeapon() and MySelf:GetActiveWeapon().DrawScope then
  736.         MySelf:GetActiveWeapon():DrawScope()
  737.     end
  738.    
  739.     if (armorHitAlpha <= 0) then return end
  740.    
  741.     armorHitAlpha = math.max(0,armorHitAlpha-FrameTime()*400)
  742.     surface.SetTexture( armorHitOverlay )
  743.     surface.SetDrawColor( 255,255,255,armorHitAlpha )  
  744.     surface.DrawTexturedRect( 0, 0, w, h )
  745. end
  746.  
  747. local hitSounds = { Sound("weapons/crossbow/hitbod1.wav"), Sound("weapons/crossbow/hitbod2.wav") }
  748. function ShowArmorHit()
  749.     surface.PlaySound(table.Random(hitSounds))
  750.     armorHitAlpha = 200
  751. end
  752. usermessage.Hook("HUDArmorHit",ShowArmorHit)
  753.  
  754. /*---------------------------------------------------------
  755.    Draw coin receival effect
  756. ---------------------------------------------------------*/
  757. local amountAdded = 0
  758. local yAddAdd = 40
  759. local yAdd = 0
  760. local cdrawx = 0
  761. local cdrawstr = ""
  762. function PaintCoinEffect()
  763.     yAdd = yAdd + FrameTime()*yAddAdd
  764.     yAddAdd = math.max(0,yAddAdd - FrameTime()*35)
  765.  
  766.     draw.DrawText(cdrawstr, "InfoSmall", 10+cdrawx, 124-yAdd, Color(115,160,150,255), TEXT_ALIGN_LEFT)
  767. end
  768.  
  769. function KillCoinPaint()
  770.     amountAdded = 0
  771.     cdrawstr = ""
  772.     hook.Remove("HUDPaint","PaintCoinEffect")
  773. end
  774.  
  775. local function CoinEffect(um)
  776.     yAdd = 0
  777.     yAddAdd = 40
  778.  
  779.     local add = um:ReadShort()
  780.     if add then
  781.         amountAdded = amountAdded + add
  782.         hook.Add("HUDPaint","PaintCoinEffect",PaintCoinEffect)
  783.         timer.Remove("CoinKillTimer")
  784.         timer.Create("CoinKillTimer",2,1,KillCoinPaint)
  785.        
  786.         local MySelf = LocalPlayer()
  787.         local coins = MySelf:Money()
  788.        
  789.         cdrawstr = "+"..amountAdded
  790.         if amountAdded < 0 then
  791.             cdrawstr = ""..amountAdded
  792.         end
  793.        
  794.         surface.SetFont("InfoSmall")
  795.         wi, he = surface.GetTextSize("$$$ "..coins)
  796.         wi2, he2 = surface.GetTextSize(cdrawstr)
  797.        
  798.         cdrawx = wi-wi2
  799.    
  800.     end
  801. end
  802. usermessage.Hook("CoinEffect", CoinEffect)
  803.  
  804. function DrawMoney()
  805.     local MySelf = LocalPlayer()
  806.     if not (MySelf:IsValid() and MySelf.Class and MySelf.Class ~= 0) then return end
  807.     if ENDROUND then return end
  808.     local coins = MySelf:Money()
  809.     draw.RoundedBox(5, 3, 120, 200, 24, Color(0, 0, 0, 180))
  810.     local drawcol = Color(115,160,150,185)
  811.     draw.DrawText("$$$ "..coins, "InfoSmall", 10, 124, drawcol, TEXT_ALIGN_LEFT)
  812.     draw.DrawText("$$$ "..coins, "InfoSmall", 10, 124, drawcol, TEXT_ALIGN_LEFT)
  813. end
  814. hook.Add("HUDPaint","DrawMoney",DrawMoney)
  815.  
  816.  
  817. /*---------------------------------------------------------
  818.    Name: gamemode:HUDShouldDraw( name )
  819.    Desc: return true if we should draw the named element
  820. ---------------------------------------------------------*/
  821. local NotToDraw = { "CHudHealth", "CHudSecondaryAmmo","CHudAmmo","CHudBattery" }
  822. function GM:HUDShouldDraw( name )
  823.  
  824.     if not HUD_ON then
  825.         return false
  826.     end
  827.  
  828.     if(name == "CHudDamageIndicator" and not LocalPlayer():Alive()) then
  829.         return false
  830.     end
  831.     for k,v in pairs(NotToDraw) do
  832.         if (v == name) then
  833.             return false
  834.         end
  835.     end
  836.     return true
  837. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement