Advertisement
szymski

Untitled

Dec 27th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.73 KB | None | 0 0
  1. /*-----------------------------------------------------------
  2. Material HUD
  3.  
  4. Copyright © 2015 Szymon (Szymekk) Jankowski
  5. All Rights Reserved
  6. Steam: https://steamcommunity.com/id/szymski
  7. -------------------------------------------------------------*/
  8.  
  9. if SERVER then
  10. AddCSLuaFile()
  11. AddCSLuaFile("mathud_config.lua")
  12.  
  13. CreateConVar("mhud_ver", 1, FCVAR_NOTIFY)
  14.  
  15. resource.AddFile("materials/mathud/heart.png")
  16. resource.AddFile("materials/mathud/armor.png")
  17. resource.AddFile("materials/mathud/hunger.png")
  18. resource.AddFile("materials/mathud/money.png")
  19. resource.AddFile("materials/mathud/warning.png")
  20.  
  21. resource.AddFile("materials/mathud/menu.png")
  22. resource.AddFile("materials/mathud/info.png")
  23. resource.AddFile("materials/mathud/mic.png")
  24. resource.AddFile("materials/mathud/speak.png")
  25.  
  26. resource.AddFile("materials/shadow/u.png")
  27. resource.AddFile("materials/shadow/l.png")
  28. resource.AddFile("materials/shadow/r.png")
  29. resource.AddFile("materials/shadow/d.png")
  30.  
  31. resource.AddFile("materials/shadow/lu.png")
  32. resource.AddFile("materials/shadow/ru.png")
  33. resource.AddFile("materials/shadow/ld.png")
  34. resource.AddFile("materials/shadow/rd.png")
  35.  
  36. return
  37. end
  38.  
  39. include("mathud_config.lua")
  40. local Config = MHUDConfig
  41.  
  42. /*------------------------------------
  43. Hiding default HUD
  44. --------------------------------------*/
  45.  
  46. local hidden = { "DarkRP_LocalPlayerHUD", "DarkRP_HUD", "DarkRP_Hungermod", "CHudHealth",}
  47.  
  48. hook.Add("HUDShouldDraw", "MHUD_Hide", function(name)
  49. if table.HasValue(hidden, name) || (name == "DarkRP_EntityDisplay" && Config.HeadHUD) then return false end
  50. end)
  51.  
  52. /*--------------------------------
  53. Useful
  54. ----------------------------------*/
  55.  
  56. local function StencilStart()
  57. render.ClearStencil()
  58. render.SetStencilEnable( true )
  59. render.SetStencilWriteMask( 1 )
  60. render.SetStencilTestMask( 1 )
  61. render.SetStencilFailOperation( STENCILOPERATION_KEEP )
  62. render.SetStencilZFailOperation( STENCILOPERATION_KEEP )
  63. render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
  64. render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS )
  65. render.SetStencilReferenceValue( 1 )
  66. render.SetColorModulation( 1, 1, 1 )
  67. end
  68.  
  69. local function StencilReplace()
  70. render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
  71. render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
  72. render.SetStencilReferenceValue(0)
  73. end
  74.  
  75. local function StencilEnd()
  76. render.SetStencilEnable( false )
  77. end
  78.  
  79. local MatGradientUp = Material("vgui/gradient-u")
  80. local MatGradientDown = Material("vgui/gradient-d")
  81. local MatBlur = Material("pp/blurscreen")
  82.  
  83. local MatHealth = Material("mathud/heart.png", "unlitgeneric")
  84. local MatArmor = Material("mathud/armor.png", "unlitgeneric")
  85. local MatHunger = Material("mathud/hunger.png", "unlitgeneric")
  86. local MatMoney = Material("mathud/money.png", "unlitgeneric")
  87. local MatWarning = Material("mathud/warning.png", "unlitgeneric")
  88.  
  89. local MatMenu = Material("mathud/menu.png", "unlitgeneric")
  90. local MatInfo = Material("mathud/info.png", "unlitgeneric")
  91. local MatMic = Material("mathud/mic.png", "unlitgeneric")
  92. local MatSpeak = Material("mathud/speak.png", "unlitgeneric")
  93.  
  94. local SU = Material("shadow/u.png", "unlitgeneric")
  95. local SL = Material("shadow/l.png", "unlitgeneric")
  96. local SR = Material("shadow/r.png", "unlitgeneric")
  97. local SD = Material("shadow/d.png", "unlitgeneric")
  98.  
  99. local SLU = Material("shadow/lu.png", "unlitgeneric")
  100. local SRU = Material("shadow/ru.png", "unlitgeneric")
  101. local SLD = Material("shadow/ld.png", "unlitgeneric")
  102. local SRD = Material("shadow/rd.png", "unlitgeneric")
  103.  
  104.  
  105. surface.CreateFont("mhud_name", {
  106. font = "Roboto",
  107. size = 24,
  108. weight = 5000,
  109. blursize = 0,
  110. scanlines = 0,
  111. antialias = true,
  112. })
  113.  
  114. surface.CreateFont("mhud_ammo", {
  115. font = "Roboto",
  116. size = 22,
  117. weight = 5000,
  118. blursize = 0,
  119. scanlines = 0,
  120. antialias = true,
  121. })
  122.  
  123. surface.CreateFont("mhud_ammo_big", {
  124. font = "Roboto",
  125. size = 30,
  126. weight = 5000,
  127. blursize = 0,
  128. scanlines = 0,
  129. antialias = true,
  130. })
  131.  
  132.  
  133. surface.CreateFont("mhud_names", {
  134. font = "Roboto",
  135. size = 19,
  136. weight = 5000,
  137. blursize = 0,
  138. scanlines = 0,
  139. antialias = true,
  140. })
  141.  
  142. surface.CreateFont("mhud_job", {
  143. font = "Roboto",
  144. size = 18,
  145. weight = 100,
  146. blursize = 0,
  147. scanlines = 0,
  148. antialias = true,
  149. })
  150.  
  151. surface.CreateFont("mhud_mtext", {
  152. font = "Roboto",
  153. size = 19,
  154. weight = 5000,
  155. blursize = 0,
  156. scanlines = 0,
  157. antialias = true,
  158. })
  159.  
  160.  
  161. surface.CreateFont("mhud_ename", {
  162. font = "Roboto",
  163. size = 48,
  164. weight = 5000,
  165. blursize = 0,
  166. scanlines = 0,
  167. antialias = true,
  168. })
  169.  
  170. surface.CreateFont("mhud_enameb", {
  171. font = "Roboto",
  172. size = 48,
  173. weight = 5000,
  174. blursize = 5,
  175. scanlines = 0,
  176. antialias = true,
  177. })
  178.  
  179. surface.CreateFont("mhud_ejob", {
  180. font = "Roboto",
  181. size = 38,
  182. weight = 5000,
  183. blursize = 0,
  184. scanlines = 0,
  185. antialias = true,
  186. })
  187.  
  188. surface.CreateFont("mhud_ejobb", {
  189. font = "Roboto",
  190. size = 38,
  191. weight = 5000,
  192. blursize = 5,
  193. scanlines = 0,
  194. antialias = true,
  195. })
  196.  
  197. local function DrawSimpleCircle(posx, posy, radius, color)
  198. local poly = { }
  199. local v = 40
  200. for i = 0, v do
  201. poly[i+1] = {x = math.sin(-math.rad(i/v*360)) * radius + posx, y = math.cos(-math.rad(i/v*360)) * radius + posy}
  202. end
  203. draw.NoTexture()
  204. surface.SetDrawColor(color)
  205. surface.DrawPoly(poly)
  206. end
  207.  
  208. local function DrawCircle(posx, posy, radius, progress, color)
  209. local poly = { }
  210. local v = 220
  211. poly[1] = {x = posx, y = posy}
  212. for i = 0, v*progress+0.5 do
  213. poly[i+2] = {x = math.sin(-math.rad(i/v*360)) * radius + posx, y = math.cos(-math.rad(i/v*360)) * radius + posy}
  214. end
  215. draw.NoTexture()
  216. surface.SetDrawColor(color)
  217. surface.DrawPoly(poly)
  218. end
  219.  
  220. local function DrawCircleGradient(posx, posy, radius, progress, color)
  221. local poly = { }
  222. local v = 100
  223. poly[1] = {x = posx, y = posy}
  224. for i = 0, v*progress do
  225. poly[i+2] = {x = math.sin(-math.rad(i/v*360)) * radius + posx, y = math.cos(-math.rad(i/v*360)) * radius + posy}
  226. poly[i+2].u = 0
  227. poly[i+2].v = 0.6
  228. end
  229. surface.SetMaterial(MatGradientDown)
  230. surface.SetDrawColor(Color(0,0,0,200))
  231. surface.DrawPoly(poly)
  232. end
  233.  
  234. local function DrawBlur(panel, x2, y2, w2, h2, layers, density, alpha)
  235. local x, y = panel:LocalToScreen(0, 0)
  236.  
  237. surface.SetDrawColor( 255, 255, 255, alpha )
  238. surface.SetMaterial( MatBlur )
  239.  
  240. for i = 1, 3 do
  241. MatBlur:SetFloat( "$blur", ( i / layers ) * density )
  242. MatBlur:Recompute()
  243.  
  244. render.UpdateScreenEffectTexture()
  245. surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() )
  246. end
  247. end
  248.  
  249. local function DrawMatShadowC(x, y, w, h, left, top, right, bottom, cs)
  250. surface.SetDrawColor(255, 255, 255, 255)
  251.  
  252. local s = cs or 16
  253.  
  254. if top then
  255. local m = {
  256. {x = x, y = y-s, u = 0, v = 0},
  257. {x = x+w, y = y-s, u = 1/w/1024, v = 0},
  258. {x = x+w, y = y-s+s, u = 1/w/1024, v = 1},
  259. {x = x, y = y-s+s, u = 0, v = 1},
  260. }
  261. surface.SetMaterial(SU)
  262. surface.DrawPoly(m)
  263. end
  264.  
  265. if right then
  266. local m = {
  267. {x = x+w, y = y, u = 0, v = 0},
  268. {x = x+w+s, y = y, u = 1, v = 0},
  269. {x = x+w+s, y = y+h, u = 1, v = 1/h/1024},
  270. {x = x+w, y = y+h, u = 0, v = 1/h/1024},
  271. }
  272. surface.SetMaterial(SR)
  273. surface.DrawPoly(m)
  274. end
  275.  
  276. if bottom then
  277. local m = {
  278. {x = x, y = y+h, u = 0, v = 0},
  279. {x = x+w, y = y+h, u = 1/w/1024, v = 0},
  280. {x = x+w, y = y+h+s, u = 1/w/1024, v = 1},
  281. {x = x, y = y+h+s, u = 0, v = 1},
  282. }
  283. surface.SetMaterial(SD)
  284. surface.DrawPoly(m)
  285. end
  286.  
  287. if left then
  288. local m = {
  289. {x = x-s, y = y, u = 0, v = 0},
  290. {x = x-s+s, y = y, u = 1, v = 0},
  291. {x = x-s+s, y = y+h, u = 1, v = 1/h/1024},
  292. {x = x-s, y = y+h, u = 0, v = 1/h/1024},
  293. }
  294. surface.SetMaterial(SL)
  295. surface.DrawPoly(m)
  296. end
  297. end
  298.  
  299. local function DrawMatShadow(x, y, w, h)
  300. surface.SetDrawColor(255, 255, 255, 255)
  301.  
  302. local m = {
  303. {x = x, y = y-16, u = 0, v = 0},
  304. {x = x+w, y = y-16, u = 1/w/1024, v = 0},
  305. {x = x+w, y = y-16+16, u = 1/w/1024, v = 1},
  306. {x = x, y = y-16+16, u = 0, v = 1},
  307. }
  308. surface.SetMaterial(SU)
  309. surface.DrawPoly(m)
  310. //surface.DrawTexturedRect(x, y-16, w, 16)
  311.  
  312. local m = {
  313. {x = x+w, y = y, u = 0, v = 0},
  314. {x = x+w+16, y = y, u = 1, v = 0},
  315. {x = x+w+16, y = y+h, u = 1, v = 1/h/1024},
  316. {x = x+w, y = y+h, u = 0, v = 1/h/1024},
  317. }
  318. surface.SetMaterial(SR)
  319. surface.DrawPoly(m)
  320. //surface.DrawTexturedRect(x+w, y, 16, h)
  321.  
  322. local m = {
  323. {x = x, y = y+h, u = 0, v = 0},
  324. {x = x+w, y = y+h, u = 1/w/1024, v = 0},
  325. {x = x+w, y = y+h+16, u = 1/w/1024, v = 1},
  326. {x = x, y = y+h+16, u = 0, v = 1},
  327. }
  328. surface.SetMaterial(SD)
  329. surface.DrawPoly(m)
  330. //surface.DrawTexturedRect(x, y+h, w, 16)
  331.  
  332. local m = {
  333. {x = x-16, y = y, u = 0, v = 0},
  334. {x = x-16+16, y = y, u = 1, v = 0},
  335. {x = x-16+16, y = y+h, u = 1, v = 1/h/1024},
  336. {x = x-16, y = y+h, u = 0, v = 1/h/1024},
  337. }
  338. surface.SetMaterial(SL)
  339. surface.DrawPoly(m)
  340. //surface.DrawTexturedRect(x-16, y, 16, h)
  341.  
  342.  
  343. surface.SetMaterial(SLU)
  344. surface.DrawTexturedRect(x-16, y-16, 16, 16)
  345.  
  346. surface.SetMaterial(SRU)
  347. surface.DrawTexturedRect(x+w, y-16, 16, 16)
  348.  
  349. surface.SetMaterial(SRD)
  350. surface.DrawTexturedRect(x+w, y+h, 16, 16)
  351.  
  352. surface.SetMaterial(SLD)
  353. surface.DrawTexturedRect(x-16, y+h, 16, 16)
  354. end
  355.  
  356. local function DrawMatBox(x, y, w, h, col)
  357. surface.SetDrawColor(col)
  358. surface.DrawRect(x, y, w, h)
  359. end
  360.  
  361. local function DrawMatBoxS(x, y, w, h, col)
  362. surface.SetDrawColor(col)
  363. //surface.DrawRect(x, y, w, h)
  364. draw.RoundedBox(4, x, y, w, h, col)
  365.  
  366. DrawMatShadow(x, y, w, h)
  367. end
  368.  
  369. /*------------------------------------
  370. Panel vars
  371. --------------------------------------*/
  372.  
  373. MHUD = MHUD or nil
  374. MHUDA = MHUDA or nil
  375. MHUDAg = MHUDAg or nil
  376.  
  377. local HP = 0
  378. local Armor = 0
  379. local Hunger = 0
  380. local Ammo = 0
  381. local MaxAmmo = { }
  382.  
  383. /*------------------------------------
  384. Panel creation
  385. --------------------------------------*/
  386.  
  387. local function CreateHUDPanel()
  388. if IsValid(MHUD) then
  389. MHUD:Remove()
  390. end
  391.  
  392. if IsValid(MHUDA) then
  393. MHUDA:Remove()
  394. end
  395.  
  396. if IsValid(MHUDAg) then
  397. MHUDAg:Remove()
  398. end
  399.  
  400. // Main parent
  401. MHUD = vgui.Create("DPanel")
  402. MHUD:SetSize(380, 220)
  403. MHUD:SetPos(5, ScrH() - MHUD:GetTall() - 5)
  404. MHUD:ParentToHUD()
  405. MHUD:SetExpensiveShadow(10, Color(0,0,0,255))
  406. function MHUD:Paint(w, h)
  407. DrawMatBoxS(16, 16, w-32, h-32, Config.BgColor)
  408. end
  409.  
  410. // Bar
  411.  
  412. local bar = MHUD:Add("DPanel")
  413. bar:Dock(TOP)
  414. bar:SetHeight(64)
  415. function bar:Paint(w, h)
  416. DrawMatBox(16, 16, w-32, h-32, Config.BarColor)
  417. DrawMatShadowC(16, 16, w-32, h-32, false, false, false, true, 4)
  418. DrawMatShadowC(16, 16, w-32, h-32, false, false, false, true, 4)
  419.  
  420. surface.SetDrawColor(255, 255, 255)
  421. surface.SetMaterial(MatMenu)
  422. surface.DrawTexturedRect(16, 16, 32, 32)
  423.  
  424. if LocalPlayer():getDarkRPVar("wanted") then
  425. surface.SetDrawColor(244, 67, 54)
  426. surface.SetMaterial(MatWarning)
  427. surface.DrawTexturedRect(w-16-24-8, 16, 32, 32)
  428. end
  429. end
  430.  
  431. // Avatar box
  432.  
  433. local avatarbox = MHUD:Add("DPanel")
  434. avatarbox:SetWide(152)
  435. avatarbox:DockMargin(16,-16,0,16)
  436. avatarbox:Dock(LEFT)
  437. function avatarbox:Paint(w, h)
  438. DrawMatShadowC(0, 0, w-4, h, false, false, true, false, 4)
  439. DrawMatShadowC(0, 0, w-4, h, false, false, true, false, 4)
  440. end
  441.  
  442. // Avatar
  443.  
  444. local avatar = avatarbox:Add("AvatarImage")
  445. avatar:SetSize( 72, 72 )
  446. avatar:SetPlayer(LocalPlayer(), 128)
  447. avatar:SetPos(16+16, avatar:GetParent():GetTall()/2)
  448. avatar:CenterHorizontal()
  449. function avatar:PaintOver(w, h)
  450. StencilStart()
  451. DrawCircle(w/2, h/2, w/2, 1, Color(0,0,0,1))
  452. StencilReplace()
  453. surface.SetDrawColor(Config.BgColor)
  454. surface.DrawRect(0, 0, w, h)
  455. StencilEnd()
  456. end
  457. function avatar:Think()
  458. avatar:SetPos(16+16, avatar:GetParent():GetTall()/2 - 72/2 - 20)
  459. avatar:CenterHorizontal()
  460. end
  461.  
  462. // Name
  463.  
  464. local name = avatarbox:Add("DLabel")
  465. name:SetColor(Config.TextColor)
  466. name:SetFont("mhud_name")
  467. name:SetSize( name:GetParent():GetWide(), 32)
  468. name:SetPos(16+16, name:GetParent():GetTall()/2 + 72/2 + 14)
  469. name:CenterHorizontal()
  470. name:SetContentAlignment(5)
  471. function name:Think()
  472. name:SetPos(16+16, name:GetParent():GetTall()/2 + 72/2 - 22)
  473. name:CenterHorizontal()
  474. name:SetContentAlignment(5)
  475. name:SetText(LocalPlayer():Name())
  476. end
  477.  
  478. // Job
  479.  
  480. local job = avatarbox:Add("DLabel")
  481. job:SetColor(Config.TextColor)
  482. job:SetFont("mhud_job")
  483. job:SetSize( job:GetParent():GetWide(), 32)
  484. job:SetPlayer(LocalPlayer(), 128)
  485. job:SetPos(16+16, job:GetParent():GetTall()/2 + 72/2 + 14)
  486. job:CenterHorizontal()
  487. job:SetContentAlignment(5)
  488. function job:Think()
  489. job:SetPos(16+16, job:GetParent():GetTall()/2 + 72/2 - 2)
  490. job:CenterHorizontal()
  491. job:SetContentAlignment(5)
  492. job:SetText(LocalPlayer():getDarkRPVar("job") or "")
  493. end
  494.  
  495. // Right box
  496.  
  497. local rbox = MHUD:Add("DPanel")
  498. rbox:SetWide(152)
  499. rbox:DockMargin(-4,-16,16,16)
  500. rbox:Dock(FILL)
  501. function rbox:Paint(w, h) end
  502.  
  503.  
  504. local function MakeEntry()
  505. local entry = rbox:Add("DPanel")
  506. entry:DockMargin(8, LocalPlayer():getDarkRPVar("Energy") and 4 or 6, 8, LocalPlayer():getDarkRPVar("Energy") and -12 or 0)
  507. entry:SetTall(32)
  508. entry:Dock(TOP)
  509.  
  510. function entry:Paint(w, h) end
  511.  
  512. local img = entry:Add("DPanel")
  513. img:SetSize(32, 32)
  514. img:Dock(LEFT)
  515. function img:Paint(w, h)
  516. surface.SetDrawColor(entry.color1)
  517. surface.SetMaterial(entry.mat)
  518. surface.DrawTexturedRect(0, 0, w, h)
  519. end
  520.  
  521. local pbar = entry:Add("DPanel")
  522. entry.aprog = 0
  523. pbar:SetSize(128,4)
  524. pbar:DockMargin(8, 14, 8, 14)
  525. pbar:Dock(FILL)
  526. function pbar:Paint(w, h)
  527. surface.SetDrawColor(entry.color2)
  528. surface.DrawRect(0, 0, w, h)
  529. surface.SetDrawColor(entry.color1)
  530. surface.DrawRect(0, 0, w*(math.Clamp(entry.aprog or 0, 0, 1)), h)
  531. end
  532. function pbar:Think()
  533. entry.aprog = Lerp(FrameTime()*10, entry.aprog, entry.prog)
  534. end
  535.  
  536. return entry
  537. end
  538.  
  539. local lastHP = 100
  540. local animHP = 0
  541. local toAdd = 0
  542.  
  543. local maxHP = 100
  544.  
  545. local hpEntry = MakeEntry()
  546. hpEntry.color1 = Config.HPColor1
  547. hpEntry.color2 = Config.HPColor2
  548. hpEntry.mat = MatHealth
  549. function hpEntry:Think()
  550. maxHP = math.max(maxHP, LocalPlayer():Health())
  551.  
  552. toAdd = 20*math.sin(math.Clamp(animHP-RealTime(), 0, 9000)*20)
  553. self.prog = LocalPlayer():Health() / maxHP
  554. self.color1 = Color(Config.HPColor1.r+toAdd,Config.HPColor1.g+toAdd,Config.HPColor1.b+toAdd)
  555. self.color2 = Color(Config.HPColor2.r+toAdd,Config.HPColor2.g+toAdd,Config.HPColor2.b+toAdd)
  556. if LocalPlayer():Health() < lastHP then
  557. animHP = RealTime() + 4
  558. end
  559. lastHP = LocalPlayer():Health()
  560. end
  561.  
  562. local lastArmor = 0
  563. local animArmor = 0
  564. local toAdd = 0
  565.  
  566. local armorEntry = MakeEntry()
  567. armorEntry.color1 = Config.ArmorColor1
  568. armorEntry.color2 = Config.ArmorColor2
  569. armorEntry.mat = MatArmor
  570. function armorEntry:Think()
  571. toAdd = 20*math.sin(math.Clamp(animArmor-RealTime(), 0, 9000)*20)
  572. self.prog = LocalPlayer():Armor() / 100
  573. self.color1 = Color(Config.ArmorColor1.r+toAdd,Config.ArmorColor1.g+toAdd,Config.ArmorColor1.b+toAdd)
  574. self.color2 = Color(Config.ArmorColor2.r+toAdd,Config.ArmorColor2.g+toAdd,Config.ArmorColor2.b+toAdd)
  575. if LocalPlayer():Armor() < lastArmor then
  576. animArmor = RealTime() + 4
  577. end
  578. lastArmor = LocalPlayer():Armor()
  579. end
  580.  
  581. if LocalPlayer():getDarkRPVar("Energy") then
  582. local hungerEntry = MakeEntry()
  583. hungerEntry.color1 = Config.HungerColor1
  584. hungerEntry.color2 = Config.HungerColor2
  585. hungerEntry.mat = MatHunger
  586. function hungerEntry:Think()
  587. self.prog = (LocalPlayer():getDarkRPVar("Energy") or 60)/100
  588. end
  589. end
  590.  
  591. // Money box
  592.  
  593. local mbox = rbox:Add("DPanel")
  594. mbox:SetWide(152)
  595. mbox:DockMargin(-4, 0, 0, 0)
  596. mbox:SetTall(72)
  597. mbox:Dock(BOTTOM)
  598. function mbox:Paint(w, h)
  599. DrawMatShadowC(0, 4, w, h, false, true, false, false, 2)
  600. DrawMatShadowC(0, 4, w, h, false, true, false, false, 2)
  601. end
  602.  
  603. // Microphone
  604.  
  605. local mic = mbox:Add("DPanel")
  606. mic:SetSize(64,64)
  607. function mic:Think()
  608. mic:SetPos(mbox:GetWide()-64-2, mbox:GetTall()-64-2)
  609. end
  610.  
  611. local micAnim = 0
  612.  
  613. function mic:Paint(w, h)
  614. surface.SetDrawColor(Color(Config.TextColor.r,Config.TextColor.g,Config.TextColor.b,255*math.Clamp(micAnim,0,1)))
  615. surface.SetMaterial(MatMic)
  616. surface.DrawTexturedRect(0, 0, w, h)
  617. if LocalPlayer():IsSpeaking() then
  618. micAnim = Lerp(FrameTime()*2, micAnim, 5)
  619. else
  620. micAnim = Lerp(FrameTime()*5, micAnim, 0)
  621. end
  622. end
  623.  
  624. // Bars
  625.  
  626. local function MakeEntry()
  627. local entry = mbox:Add("DPanel")
  628. entry:DockMargin(12,6,8,-6)
  629. entry:SetTall(32)
  630. entry:Dock(TOP)
  631.  
  632. function entry:Paint(w, h) end
  633.  
  634. local img = entry:Add("DPanel")
  635. img:SetSize(32, 32)
  636. img:Dock(LEFT)
  637. function img:Paint(w, h)
  638. surface.SetDrawColor(entry.color1)
  639. surface.SetMaterial(entry.mat)
  640. surface.DrawTexturedRect(0, 0, w, h)
  641. end
  642.  
  643. local text = entry:Add("DLabel")
  644. entry.text = text
  645. text:SetFont("mhud_mtext")
  646. text:SetSize(128,2)
  647. text:DockMargin(8, 2, 16, 2)
  648. text:Dock(FILL)
  649. text:SetColor(entry.color1)
  650. text:SetContentAlignment(4)
  651.  
  652. return entry
  653. end
  654.  
  655. local moneyEntry = MakeEntry()
  656. moneyEntry.color1 = Config.MoneyColor
  657. moneyEntry.mat = MatMoney
  658. moneyEntry.text:SetColor(Config.MoneyColor)
  659. function moneyEntry:Think()
  660. self.text:SetText(DarkRP.formatMoney(LocalPlayer():getDarkRPVar("money")))
  661. end
  662.  
  663. local salaryEntry = MakeEntry()
  664. salaryEntry.color1 = Config.SalaryColor
  665. salaryEntry.mat = MatMoney
  666. salaryEntry.text:SetColor(Config.SalaryColor)
  667. function salaryEntry:Think()
  668. self.text:SetText(DarkRP.formatMoney(LocalPlayer():getDarkRPVar("salary")))
  669. end
  670.  
  671.  
  672. end
  673.  
  674. /*------------------------------------
  675. Entity Display
  676. --------------------------------------*/
  677.  
  678. local function DrawEntityDisplay()
  679. local shootPos = LocalPlayer():GetShootPos()
  680. local aimVec = LocalPlayer():GetAimVector()
  681.  
  682. for k, ply in pairs(players or player.GetAll()) do
  683. if ply == LocalPlayer() or not ply:Alive() or ply:GetNoDraw() then continue end
  684. local hisPos = ply:GetShootPos()
  685. if ply:getDarkRPVar("wanted") && ply.drawWantedInfo then ply:drawWantedInfo() end
  686.  
  687. if hisPos:DistToSqr(shootPos) < 100000 then
  688. local pos = hisPos - shootPos
  689. local unitPos = pos:GetNormalized()
  690. if unitPos:Dot(aimVec) > 0.95 then
  691. local trace = util.QuickTrace(shootPos, pos, LocalPlayer())
  692. if trace.Hit and trace.Entity ~= ply then return end
  693.  
  694. local pos = (ply:EyePos()+Vector(0,0,15)):ToScreen()
  695. pos.y = pos.y - 90
  696.  
  697. if ply:IsSpeaking() then
  698. surface.SetMaterial(MatSpeak)
  699. surface.SetDrawColor(Config.SpeakColor)
  700. surface.DrawTexturedRect(pos.x - 64, pos.y - 64 - 50, 128, 128)
  701. end
  702.  
  703. draw.DrawText(ply:Name(), "mhud_enameb", pos.x, pos.y, Color(0,0,0), 1)
  704.  
  705. local a, b, c = ColorToHSV(team.GetColor(ply:Team()))
  706. draw.DrawText(ply:Name(), "mhud_ename", pos.x, pos.y, HSVToColor(a,b*0.8,0.9), 1)
  707.  
  708. draw.DrawText(ply:getDarkRPVar("job") or "", "mhud_ejobb", pos.x, pos.y + 40, Color(0,0,0), 1)
  709. draw.DrawText(ply:getDarkRPVar("job") or "", "mhud_ejob", pos.x, pos.y + 40, Color(255,255,255), 1)
  710.  
  711. local w, h = 100, 4
  712. surface.SetDrawColor(Config.EntHPColor2)
  713. surface.DrawRect(pos.x - w/2, pos.y + 90, w, h)
  714. surface.SetDrawColor(Config.EntHPColor1)
  715. surface.DrawRect(pos.x - w/2, pos.y + 90, w*math.Clamp(ply:Health()/100,0,1), h)
  716. end
  717. end
  718. end
  719.  
  720. local tr = LocalPlayer():GetEyeTrace()
  721.  
  722. if IsValid(tr.Entity) and tr.Entity:isKeysOwnable() and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 200 then
  723. tr.Entity:drawOwnableInfo()
  724. end
  725. end
  726.  
  727. local AdminTell = function() end
  728.  
  729. usermessage.Hook("AdminTell", function(msg)
  730. timer.Destroy("DarkRP_AdminTell")
  731. local Message = msg:ReadString()
  732.  
  733. AdminTell = function()
  734. draw.RoundedBox(4, 10, 10, Scrw - 20, 110, colors.darkblack)
  735. draw.DrawNonParsedText(DarkRP.getPhrase("listen_up"), "GModToolName", Scrw / 2 + 10, 10, colors.white, 1)
  736. draw.DrawNonParsedText(Message, "ChatFont", Scrw / 2 + 10, 90, colors.brightred, 1)
  737. end
  738.  
  739. timer.Create("DarkRP_AdminTell", 10, 1, function()
  740. AdminTell = function() end
  741. end)
  742. end)
  743.  
  744.  
  745. hook.Add("HUDPaint", "MHUDEntityDisplay", function()
  746. if Config.HeadHUD then
  747. DrawEntityDisplay()
  748. end
  749. //AdminTell()
  750. end)
  751.  
  752. /*------------------------------------
  753. HUD Loading
  754. --------------------------------------*/
  755.  
  756. local function HideMic()
  757. local mat, mat2, mat3, mat4, bt
  758.  
  759. mat = Material( "invisible" )
  760. bt = mat:GetMaterialTexture( "$basetexture" )
  761.  
  762. mat2 = Material( "voice/icntlk_local" )
  763. mat3 = Material( "voice/icntlk_sv" )
  764. mat4 = Material( "voice/icntlk_pl" )
  765.  
  766. mat2:SetMaterialTexture( "$basetexture", bt )
  767. mat3:SetMaterialTexture( "$basetexture", bt )
  768. mat4:SetMaterialTexture( "$basetexture", bt )
  769. end
  770.  
  771. //hook.Add("Initialize", "MHUDHideMic", HideMic)
  772.  
  773. if MHUD then
  774. CreateHUDPanel()
  775. end
  776.  
  777. hook.Add("InitPostEntity", "MHUDInit", function()
  778. CreateHUDPanel()
  779. end)
  780.  
  781. hook.Add("Tick", "MHUDTick", function()
  782. if Config != MHUDConfig then
  783. Config = MHUDConfig
  784. CreateHUDPanel()
  785. end
  786. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement