kizaru335

nxserv hud

Aug 10th, 2017
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.60 KB | None | 0 0
  1. local hideHUDElements = {
  2. -- if you DarkRP_HUD this to true, ALL of DarkRP's HUD will be disabled. That is the health bar and stuff,
  3. -- but also the agenda, the voice chat icons, lockdown text, player arrested text and the names above players' heads
  4. ["DarkRP_HUD"] = true,
  5.  
  6. -- DarkRP_EntityDisplay is the text that is drawn above a player when you look at them.
  7. -- This also draws the information on doors and vehicles
  8. ["DarkRP_EntityDisplay"] = true,
  9.  
  10. -- DarkRP_ZombieInfo draws information about zombies for admins who use /showzombie.
  11. ["DarkRP_ZombieInfo"] = false,
  12.  
  13. -- This is the one you're most likely to replace first
  14. -- DarkRP_LocalPlayerHUD is the default HUD you see on the bottom left of the screen
  15. -- It shows your health, job, salary and wallet
  16. ["DarkRP_LocalPlayerHUD"] = true,
  17. ["DarkRP_Hungermod"] = true,
  18.  
  19. -- Drawing the DarkRP agenda
  20. ["DarkRP_Agenda"] = false,
  21. ["CHudAmmo"] = true,
  22. }
  23.  
  24. -- hide shitty overhead sprite
  25. timer.Simple(2, function()
  26. Material("voice/icntlk_pl"):SetFloat("$alpha", 0)
  27. end)
  28. hook.Add("ShutDown", "voice/icntlk_pl", function()
  29. Material("voice/icntlk_pl"):SetFloat("$alpha", 1)
  30. end)
  31.  
  32. local scale = 1
  33.  
  34. local shadow_x = 1*scale -- I left 1 to make it noticeble
  35. local shadow_y = 1*scale
  36.  
  37. local col_face = Color(255,255,255,255)
  38. local col_shadow = Color(0,0,0,255)
  39. local col_half_shadow = Color(0,0,0,200)
  40. local col_money = Color(64,192,32)
  41.  
  42. -- this is the code that actually disables the drawing.
  43. hook.Add("HUDShouldDraw", "HideDefaultDarkRPHud", function(name)
  44. if hideHUDElements[name] then return false end
  45. end)
  46.  
  47. surface.CreateFont("nx_hud_time", {
  48. size = 35 * scale,
  49. weight = 350 * scale,
  50. antialias = true,
  51. extended = true,
  52. font = "Roboto"})
  53.  
  54. surface.CreateFont("nx_hud_time_shadow", {
  55. size = 35 * scale,
  56. weight = 350 * scale,
  57. antialias = true,
  58. blursize = 3 * scale,
  59. extended = true,
  60. font = "Roboto"})
  61.  
  62. surface.CreateFont("nx_hud_ammo", {
  63. size = 42 * scale,
  64. weight = 350 * scale,
  65. antialias = true,
  66. extended = true,
  67. font = "Roboto"})
  68.  
  69. surface.CreateFont("nx_hud_ammo_shadow", {
  70. size = 42 * scale,
  71. weight = 350 * scale,
  72. antialias = true,
  73. blursize = 3 * scale,
  74. extended = true,
  75. font = "Roboto"})
  76.  
  77. surface.CreateFont("nx_hud", {
  78. size = 22 * scale,
  79. weight = 350 * scale,
  80. antialias = true,
  81. extended = true,
  82. font = "Roboto"})
  83.  
  84. surface.CreateFont("nx_hud_shadow", {
  85. size = 22 * scale,
  86. weight = 350 * scale,
  87. antialias = true,
  88. blursize = 3 * scale,
  89. extended = true,
  90. font = "Roboto"})
  91.  
  92. surface.CreateFont("nx_hud_icon", {
  93. size = 48 * scale,
  94. weight = 350 * scale,
  95. antialias = true,
  96. extended = true,
  97. font = NX_ICONFONT})
  98.  
  99. surface.CreateFont("nx_hud_icon_shadow", {
  100. size = 48 * scale,
  101. weight = 350 * scale,
  102. antialias = true,
  103. blursize = 3 * scale,
  104. extended = true,
  105. font = NX_ICONFONT})
  106.  
  107. -- why dont we just multiply size by align coeff. and add it to position ?
  108. -- its simple.. see BeautyText
  109. local ALIGN_LEFT = 0
  110. local ALIGN_CENTER = 0.5
  111. local ALIGN_RIGHT = 1
  112. local ALIGN_TOP = 1
  113. local ALIGN_BOTTOM = 0
  114.  
  115. local function SimpleText(str, font, ...)
  116. error "plsno"
  117.  
  118. draw.SimpleText(str, font, ...)
  119. return surface.GetTextSize(str)
  120. end
  121.  
  122. local function BeautyText( str, font, font_shadow, x, y, color, xalign, yalign )
  123. font = font or "nx_hud"
  124. surface.SetFont( font )
  125. local tw, th = surface.GetTextSize( str )
  126. x = (x or 0) - tw * (xalign or 0)
  127. y = (y or 0) - th * (yalign or 0)
  128. surface.SetTextPos( x, y )
  129. -- sorf shadow:
  130. if font_shadow then
  131. surface.SetTextPos( x, y+3 )
  132. surface.SetTextColor( col_shadow )
  133. surface.SetFont( font_shadow )
  134. surface.DrawText( str )
  135. surface.SetTextPos( x, y )
  136. end
  137. -- sharp shadow:
  138. surface.SetTextPos( x + shadow_x , y + shadow_y )
  139. surface.SetTextColor( col_half_shadow )
  140. surface.SetFont( font )
  141. surface.DrawText( str )
  142. -- text itself:
  143. surface.SetTextColor( color or col_face )
  144. surface.SetTextPos( x, y )
  145. surface.DrawText( str )
  146.  
  147. return tw,th
  148. end
  149.  
  150. local function WideBar(num, max, w, color, x, y)
  151. local h = 22 * scale
  152.  
  153. local o = BeautyText(num .. "%", "nx_hud", "nx_hud_shadow", x, y, color, ALIGN_LEFT, ALIGN_TOP) + 4 * scale
  154. x = x + o
  155.  
  156. surface.SetDrawColor(ColorAlpha(color, 64))
  157. surface.DrawRect(x, y - h + h/4, w * scale, h/2)
  158.  
  159. surface.SetDrawColor(color)
  160. surface.DrawRect(x, y - h + h/4, w * math.max(0, math.min(1, num/max)) * scale, h/2)
  161.  
  162. return o + w * scale, h
  163. end
  164.  
  165. local x, y, i_am_the_greatest, seen_anything = 0, 0, 0
  166.  
  167. local function yield(w, h)
  168. x = x + w
  169. i_am_the_greatest = math.max(i_am_the_greatest, h)
  170. seen_anything = true
  171. end
  172.  
  173. local function space()
  174. x = x + 8 * scale
  175. end
  176.  
  177. local hud = {}
  178. local function Row(...)
  179. table.insert(hud, {...})
  180. end
  181.  
  182.  
  183.  
  184. local hunger_alpha = 0
  185. local extraArmor = 0
  186.  
  187. Row ( -- Character info
  188. function() -- Health
  189. yield(BeautyText(DarkRP.getPhrase("health", ""), "nx_hud", "nx_hud_shadow", x, y, color_white, ALIGN_LEFT, ALIGN_TOP))
  190. yield(WideBar(LocalPlayer():Health(), LocalPlayer():GetMaxHealth(), 100, HSVToColor(math.Clamp(LocalPlayer():Health(), 0, LocalPlayer():GetMaxHealth()) / LocalPlayer():GetMaxHealth() * 120, 1, 1), x, y))
  191. end,
  192. function() -- Armour
  193. local amount = LocalPlayer():Armor() * 2
  194.  
  195. if amount > 100 then
  196. extraArmor = math.min(1, extraArmor + RealFrameTime())
  197. else
  198. extraArmor = math.max(0, extraArmor - RealFrameTime())
  199. end
  200.  
  201. if amount > 0 then
  202. yield(BeautyText(DarkRP.getPhrase("armor"), "nx_hud", "nx_hud_shadow", x, y, color_white, ALIGN_LEFT, ALIGN_TOP))
  203. yield(WideBar(amount, 100 * (1+extraArmor), 100 * (1+extraArmor), HSVToColor(math.Clamp(amount, 0, 100) * 1.2, 1, 1), x, y))
  204. end
  205. end,
  206. --not GAMEMODE.Config.DisabledModules.hungermod
  207. --and
  208. function() -- Hunger
  209. --local energy = math.floor(LocalPlayer():GetStat"energy":Get() or 0)
  210. local energy = LocalPlayer():getDarkRPVar("Energy")
  211.  
  212. yield(BeautyText("Голод: ", "nx_hud", "nx_hud_shadow", x, y, Color(255, 255, 255, 255), ALIGN_LEFT, ALIGN_TOP))
  213. yield(WideBar((100 - energy), 100, 100, HSVToColor(energy * 1.2, 1, 1), x, y))
  214. end
  215. --or nil
  216. )
  217.  
  218. local money_last = 0
  219. local money_alpha = 0
  220. local money_alpha_positive = true
  221.  
  222. local color_blend = Color(64, 128, 64)
  223.  
  224. local function getmoney()
  225. if LocalPlayer():GetNWBool("fun_money111") then
  226. return 0
  227. else
  228. return LocalPlayer():getDarkRPVar("money", 0) or 0
  229. end
  230. end
  231. Row ( -- Wallet
  232. function()
  233. yield(BeautyText(LocalPlayer():getDarkRPVar("job") or "", "nx_hud", "nx_hud_shadow", x, y, team.GetColor(LocalPlayer():Team()), ALIGN_LEFT, ALIGN_TOP))
  234.  
  235. space()
  236.  
  237. if money_last ~= getmoney() then
  238. if getmoney() >= (money_last or 0) then
  239. color_blend.r = 0
  240. color_blend.g = 255
  241. color_blend.b = 0
  242. else
  243. color_blend.r = 255
  244. color_blend.g = 0
  245. color_blend.b = 0
  246. end
  247. money_last = getmoney()
  248. end
  249.  
  250. local dt = RealFrameTime() * 0.5
  251. color_blend.r = Lerp(dt, color_blend.r, 0)
  252. color_blend.g = Lerp(dt, color_blend.g, 128)
  253. color_blend.b = Lerp(dt, color_blend.b, 255)
  254.  
  255. yield(BeautyText(DarkRP.formatMoney(getmoney()), "nx_hud", "nx_hud_shadow", x, y, color_blend, ALIGN_LEFT, ALIGN_TOP))
  256. end
  257. )
  258.  
  259. --[[
  260. xpcall(function()
  261. local name, fun = debug.getupvalue(select(2, debug.getupvalue(GAMEMODE.HUDPaint, 1)), 19)
  262. assert(name == "LockDown")
  263. debug.setupvalue(select(2, debug.getupvalue(GAMEMODE.HUDPaint, 1)), 19, function() end)
  264. end, Error)
  265. ]]
  266.  
  267. Row ( -- Lockdown
  268. function()
  269. if GetGlobalBool("DarkRP_LockDown") then
  270. local cin = (math.sin(CurTime()) + 1) / 2
  271. yield(BeautyText(DarkRP.getPhrase("lockdown_started"), "nx_hud", "nx_hud_shadow", x, y, Color(cin * 255, 0, 255 - (cin * 255)), 0, ALIGN_TOP))
  272. end
  273. end
  274. )
  275.  
  276. -- Row ( -- Taxi
  277. -- function()
  278. -- local car = LocalPlayer():GetVehicle()
  279. -- if not car:IsValid() then
  280. -- return
  281. -- end
  282. -- car = car:GetParent():IsValid() and car:GetParent() or car
  283.  
  284. -- if car:IsValid() and car:GetNWBool("TaxiCar") then
  285. -- yield(BeautyText(DarkRP.getPhrase("path"), "nx_hud", "nx_hud_shadow", x, y, color_white, 0, ALIGN_TOP))
  286. -- local km, pathStr = math.sqrt(LocalPlayer():GetNetworkedFloat("TaxiPath", 0)) / 524.9344
  287. -- local price = math.ceil(km * car:GetNWFloat("TaxiPrice"))
  288.  
  289. -- if km < 1 then
  290. -- pathStr = DarkRP.getPhrase("m", math.floor(km * 1000))
  291. -- else
  292. -- pathStr = DarkRP.getPhrase("km", math.floor(km * 100) * 0.01)
  293. -- end
  294.  
  295. -- yield(BeautyText(pathStr .. ", " .. DarkRP.formatMoney(price), "nx_hud", "nx_hud_shadow", x, y, Color(150, 255, 150), 0, ALIGN_TOP))
  296. -- end
  297. -- end
  298. -- )
  299.  
  300.  
  301. Row ( -- Voice
  302. function()
  303. if LocalPlayer():IsSpeaking() then
  304. local sine = HSVToColor(200, math.abs(math.sin(RealTime()*2)), 1)
  305. yield(BeautyText("g", "nx_hud_icon", "nx_hud_icon_shadow", x, y, sine, 0.2, ALIGN_TOP))
  306. end
  307. end
  308. )
  309.  
  310.  
  311. Row ( -- Stats
  312. function ()
  313. if playerstats then
  314. yield( playerstats.DrawHUD(x,y) )
  315. end
  316. end
  317. )
  318.  
  319. hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", function()
  320. if LocalPlayer():Health() <= 0 then return end
  321.  
  322. if hook.Run("HUDShouldDraw", "Noiwex HUD") == false then
  323. return
  324. end
  325.  
  326. local offy, offx, space_width = ScrH() - 8, 8, 8
  327.  
  328. x, y = offx, offy
  329.  
  330. for _, row in pairs(hud) do
  331. for _, fn in pairs(row) do
  332. seen_anything = false
  333. xpcall(fn, Error)
  334. if seen_anything then
  335. space()
  336. end
  337. end
  338. offy = offy - i_am_the_greatest
  339. i_am_the_greatest = 0
  340. y = offy
  341. x = offx
  342. end
  343. end)
  344.  
  345. local insuff_ammo1, insuff_ammo2 = 1, 1
  346. hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint_Ammo", function()
  347. if hook.Run("HUDShouldDraw", "Noiwex HUD Ammo") == false then
  348. return
  349. end
  350.  
  351. local wep = LocalPlayer():GetActiveWeapon()
  352.  
  353. if not IsValid(wep) or wep:GetPrimaryAmmoType() < 0 then
  354. return
  355. end
  356.  
  357. local ammo1 = wep:Clip1()
  358. local ammo2 = LocalPlayer():GetAmmoCount(wep:GetPrimaryAmmoType())
  359.  
  360. if ammo1 < 0 then
  361. ammo1 = nil
  362. end
  363.  
  364. local offy, offx, space_width = ScrH() - 8, (minimap and minimap.x or ScrW()) - 24, 8
  365.  
  366. if ammo1 == 0 then
  367. insuff_ammo1 = math.max(insuff_ammo1 - RealFrameTime(), 0)
  368. else
  369. insuff_ammo1 = math.min(insuff_ammo1 + RealFrameTime(), 1)
  370. end
  371.  
  372. if ammo2 == 0 then
  373. insuff_ammo2 = math.max(insuff_ammo2 - RealFrameTime(), 0)
  374. else
  375. insuff_ammo2 = math.min(insuff_ammo2 + RealFrameTime(), 1)
  376. end
  377.  
  378. offx = offx - BeautyText((ammo1 and " / " or "") .. ammo2, "nx_hud_ammo", "nx_hud_ammo_shadow", offx, offy, Color(255, insuff_ammo2 * 255, insuff_ammo2 * 255), ALIGN_RIGHT, ALIGN_TOP)
  379. offx = offx - BeautyText(ammo1 or "", "nx_hud_time", "nx_hud_time_shadow", offx, offy - 3, Color(255, insuff_ammo1 * 255, insuff_ammo1 * 255), ALIGN_RIGHT, ALIGN_TOP)
  380. end)
  381.  
  382. usermessage.Hook("AteFoodIcon", function()
  383. hunger_alpha = RealTime()
  384. end)
Advertisement
Add Comment
Please, Sign In to add comment