Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. local cvars = cvars
  2. local draw = draw
  3. local hook = hook
  4. local math = math
  5. local table = table
  6. local timer = timer
  7. local Color = Color
  8. local ColorAlpha = ColorAlpha
  9. local CreateClientConVar = CreateClientConVar
  10. local GetConVar = GetConVar
  11. local GetConVarNumber = GetConVarNumber
  12. local ipairs = ipairs
  13. local pairs = pairs
  14. local unpack = unpack
  15.  
  16. local ConVars = {}
  17. local HUDWidth
  18.  
  19. local FoodAteAlpha = -1
  20. local FoodAteY = 0
  21.  
  22. surface.CreateFont("HungerPlus", {
  23. size = 70,
  24. weight = 500,
  25. antialias = true,
  26. shadow = false,
  27. font = "ChatFont"})
  28.  
  29. local function ReloadConVars()
  30. ConVars = {
  31. HungerBackground = {0, 0, 0, 255},
  32. HungerForeground = {30, 30, 120, 255},
  33. HungerPercentageText = {255, 255, 255, 255},
  34. StarvingText = {200, 0, 0, 255},
  35. FoodEatenBackground = {0, 0, 0}, -- No alpha
  36. FoodEatenForeground = {20, 100, 20} -- No alpha
  37. }
  38. for name, Colour in pairs(ConVars) do
  39. ConVars[name] = {}
  40. for num, rgb in ipairs(Colour) do
  41. local ConVarName = name..num
  42. local CVar = GetConVar(ConVarName) or CreateClientConVar(ConVarName, rgb, true, false)
  43. table.insert(ConVars[name], CVar:GetInt())
  44.  
  45. if not cvars.GetConVarCallbacks(ConVarName, false) then
  46. cvars.AddChangeCallback(ConVarName, function() timer.Simple(0, ReloadConVars) end)
  47. end
  48. end
  49. ConVars[name] = Color(unpack(ConVars[name]))
  50. end
  51.  
  52. if not HUDWidth then
  53. cvars.AddChangeCallback("HudW", function() timer.Simple(0, ReloadConVars) end)
  54. end
  55.  
  56. HUDWidth = GetConVarNumber("HudW")
  57. end
  58. timer.Simple(0, ReloadConVars)
  59.  
  60. local function HMHUD()
  61. local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_Hungermod")
  62. if shouldDraw == false then return end
  63.  
  64. local energy = math.ceil(LocalPlayer():getDarkRPVar("Energy") or 0)
  65.  
  66. local x = (ScrW() / 2) - (HUDWidth / 2)
  67. local y = ScrH() - 9
  68.  
  69. local cornerRadius = 4
  70. if energy > 0 then
  71. cornerRadius = math.Min(4, (HUDWidth-9)*(energy/100)/3*2 - (HUDWidth-9)*(energy/100)/3*2%2)
  72. end
  73.  
  74. draw.RoundedBox(cornerRadius, x - 1, y - 1, HUDWidth - 8, 9, ConVars.HungerBackground)
  75.  
  76. if energy > 0 then
  77. draw.RoundedBox(cornerRadius, x, y, (HUDWidth - 9) * (energy / 100), 7, ConVars.HungerForeground)
  78. draw.SimpleText(energy .. "%", "DefaultSmall", x + HUDWidth, y - 3, ConVars.HungerPercentageText, 1)
  79. else
  80. draw.SimpleText(DarkRP.getPhrase("starving"), "ChatFont", x + HUDWidth, y - 5, ConVars.StarvingText, 1)
  81. end
  82.  
  83. if FoodAteAlpha > -1 then
  84. local mul = 1
  85. if FoodAteY <= ScrH() - 100 then
  86. mul = -.5
  87. end
  88.  
  89. draw.SimpleText("++", "HungerPlus", 208, FoodAteY + 1, ColorAlpha(ConVars.FoodEatenBackground, FoodAteAlpha), 0)
  90. draw.SimpleText("++", "HungerPlus", 207, FoodAteY, ColorAlpha(ConVars.FoodEatenForeground, FoodAteAlpha), 0)
  91.  
  92. FoodAteAlpha = math.Clamp(FoodAteAlpha + 4 * FrameTime() * mul, -1, 1) --ColorAlpha works with 0-1 alpha
  93. FoodAteY = FoodAteY - 150 * FrameTime()
  94. end
  95. end
  96. hook.Add("HUDDrawTargetID", "HMHUD", HMHUD) --HUDDrawTargetID is called after DarkRP HUD is drawn in HUDPaint
  97.  
  98. local function AteFoodIcon(msg)
  99. FoodAteAlpha = 1
  100. FoodAteY = ScrH() - 8
  101. end
  102. usermessage.Hook("AteFoodIcon", AteFoodIcon)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement