Advertisement
Guest User

MRP Hud

a guest
Dec 12th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.84 KB | None | 0 0
  1. --cl_mrphudtest1
  2.  
  3. local function Base()
  4.  
  5. draw.RoundedBox(6, ScrW() - 400 - 10, ScrH () - 200 - 10, 400, 200, Color(40, 40, 40, 250))
  6.  
  7. end
  8.  
  9.  
  10. /*---------------------------------------------------------------------------
  11. HUD ConVars
  12. ---------------------------------------------------------------------------*/
  13. local ConVars = {}
  14. local HUDWidth
  15. local HUDHeight
  16.  
  17. local Color = Color
  18. local cvars = cvars
  19. local DarkRP = DarkRP
  20. local CurTime = CurTime
  21. local draw = draw
  22. local GetConVar = GetConVar
  23. local IsValid = IsValid
  24. local Lerp = Lerp
  25. local localplayer
  26. local math = math
  27. local pairs = pairs
  28. local ScrW, ScrH = ScrW, ScrH
  29. local SortedPairs = SortedPairs
  30. local string = string
  31. local surface = surface
  32. local table = table
  33. local timer = timer
  34. local tostring = tostring
  35.  
  36. CreateClientConVar("weaponhud", 0, true, false)
  37.  
  38. local colors = {}
  39. colors.black = Color(0, 0, 0, 255)
  40. colors.blue = Color(0, 0, 255, 255)
  41. colors.brightred = Color(200, 30, 30, 255)
  42. colors.darkred = Color(0, 0, 70, 100)
  43. colors.darkblack = Color(0, 0, 0, 200)
  44. colors.gray1 = Color(0, 0, 0, 155)
  45. colors.gray2 = Color(51, 58, 51,100)
  46. colors.red = Color(255, 0, 0, 255)
  47. colors.white = Color(255, 255, 255, 255)
  48. colors.white1 = Color(255, 255, 255, 200)
  49.  
  50. local function ReloadConVars()
  51. ConVars = {
  52. background = {0,0,0,100},
  53. Healthbackground = {0,0,0,200},
  54. Healthforeground = {140,0,0,180},
  55. HealthText = {255,255,255,200},
  56. Job1 = {0,0,150,200},
  57. Job2 = {0,0,0,255},
  58. salary1 = {0,150,0,200},
  59. salary2 = {0,0,0,255}
  60. }
  61.  
  62. for name, Colour in pairs(ConVars) do
  63. ConVars[name] = {}
  64. for num, rgb in SortedPairs(Colour) do
  65. local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
  66. table.insert(ConVars[name], CVar:GetInt())
  67.  
  68. if not cvars.GetConVarCallbacks(name..num, false) then
  69. cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
  70. end
  71. end
  72. ConVars[name] = Color(unpack(ConVars[name]))
  73. end
  74.  
  75.  
  76. HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
  77. HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
  78.  
  79. if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
  80. cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
  81. cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
  82. end
  83. end
  84. ReloadConVars()
  85.  
  86. local Scrw, Scrh, RelativeX, RelativeY
  87. /*---------------------------------------------------------------------------
  88. HUD Seperate Elements
  89. ---------------------------------------------------------------------------*/
  90.  
  91. local Page = Material("icon16/page_white_text.png")
  92. local function GunLicense()
  93. if localplayer:getDarkRPVar("HasGunlicense") then
  94. surface.SetMaterial(Page)
  95. surface.SetDrawColor(255, 255, 255, 255)
  96. surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32)
  97. end
  98. end
  99.  
  100. local function Agenda()
  101. local ply = LocalPlayer()
  102.  
  103. local agenda = ply:getAgendaTable()
  104. if not agenda then return end
  105.  
  106. draw.RoundedBox(10, 10, 10, 460, 110, colors.gray1)
  107. draw.RoundedBox(10, 12, 12, 456, 106, colors.gray2)
  108. draw.RoundedBox(10, 12, 12, 456, 20, colors.darkred)
  109.  
  110. draw.DrawNonParsedText(agenda.Title, "DarkRPHUD1", 30, 12, colors.red, 0)
  111.  
  112. local text = ply:getDarkRPVar("agenda") or ""
  113.  
  114. text = text:gsub("//", "\n"):gsub("\\n", "\n")
  115. text = DarkRP.textWrap(text, "DarkRPHUD1", 440)
  116. draw.DrawNonParsedText(text, "DarkRPHUD1", 30, 35, colors.white, 0)
  117. end
  118.  
  119. local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
  120. local function DrawVoiceChat()
  121. if localplayer.DRPIsTalking then
  122. local chbxX, chboxY = chat.GetChatBoxPos()
  123.  
  124. local Rotating = math.sin(CurTime()*3)
  125. local backwards = 0
  126. if Rotating < 0 then
  127. Rotating = 1-(1+Rotating)
  128. backwards = 180
  129. end
  130. surface.SetTexture(VoiceChatTexture)
  131. surface.SetDrawColor(ConVars.Healthforeground)
  132. surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
  133. end
  134. end
  135.  
  136. CreateConVar("DarkRP_LockDown", 0, {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE})
  137. local function LockDown()
  138. local chbxX, chboxY = chat.GetChatBoxPos()
  139. if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
  140. local cin = (math.sin(CurTime()) + 1) / 2
  141. local chatBoxSize = math.floor(ScrH() / 4)
  142. draw.DrawNonParsedText(DarkRP.getPhrase("lockdown_started"), "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
  143. end
  144. end
  145.  
  146. local Arrested = function() end
  147.  
  148. usermessage.Hook("GotArrested", function(msg)
  149. local StartArrested = CurTime()
  150. local ArrestedUntil = msg:ReadFloat()
  151.  
  152. Arrested = function()
  153. if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then
  154. draw.DrawNonParsedText(DarkRP.getPhrase("youre_arrested", math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, colors.white, 1)
  155. elseif not localplayer:getDarkRPVar("Arrested") then
  156. Arrested = function() end
  157. end
  158. end
  159. end)
  160.  
  161. local AdminTell = function() end
  162.  
  163. usermessage.Hook("AdminTell", function(msg)
  164. timer.Destroy("DarkRP_AdminTell")
  165. local Message = msg:ReadString()
  166.  
  167. AdminTell = function()
  168. draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, colors.darkblack)
  169. draw.DrawNonParsedText(DarkRP.getPhrase("listen_up"), "GModToolName", ScrW() / 2 + 10, 10, colors.white, 1)
  170. draw.DrawNonParsedText(Message, "ChatFont", ScrW() / 2 + 10, 80, colors.brightred, 1)
  171. end
  172.  
  173. timer.Create("DarkRP_AdminTell", 10, 1, function()
  174. AdminTell = function() end
  175. end)
  176. end)
  177.  
  178. /*---------------------------------------------------------------------------
  179. Entity HUDPaint things
  180. ---------------------------------------------------------------------------*/
  181. local function DrawPlayerInfo(ply)
  182. local pos = ply:EyePos()
  183.  
  184. pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
  185. pos = pos:ToScreen()
  186. pos.y = pos.y - 50 -- Move the text up a few pixels to compensate for the height of the text
  187.  
  188. if GAMEMODE.Config.showname and not ply:getDarkRPVar("wanted") then
  189. draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  190. draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  191. end
  192.  
  193. if GAMEMODE.Config.showhealth and not ply:getDarkRPVar("wanted") then
  194. draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x + 1, pos.y + 21, colors.black, 1)
  195. draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x, pos.y + 20, colors.white1, 1)
  196. end
  197.  
  198. if GAMEMODE.Config.showjob then
  199. local teamname = team.GetName(ply:Team())
  200. draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, colors.black, 1)
  201. draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x, pos.y + 40, colors.white1, 1)
  202. end
  203.  
  204. if ply:getDarkRPVar("HasGunlicense") then
  205. surface.SetMaterial(Page)
  206. surface.SetDrawColor(255,255,255,255)
  207. surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
  208. end
  209. end
  210.  
  211. local function DrawWantedInfo(ply)
  212. if not ply:Alive() then return end
  213.  
  214. local pos = ply:EyePos()
  215. if not pos:isInSight({localplayer, ply}) then return end
  216.  
  217. pos.z = pos.z + 14
  218. pos = pos:ToScreen()
  219.  
  220. if GAMEMODE.Config.showname then
  221. draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  222. draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  223. end
  224.  
  225. local wantedText = DarkRP.getPhrase("wanted", tostring(ply:getDarkRPVar("wantedReason")))
  226.  
  227. draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x, pos.y - 40, colors.white1, 1)
  228. draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x + 1, pos.y - 41, colors.red, 1)
  229. end
  230.  
  231. /*---------------------------------------------------------------------------
  232. The Entity display: draw HUD information about entities
  233. ---------------------------------------------------------------------------*/
  234. local function DrawEntityDisplay()
  235.  
  236. local shootPos = localplayer:GetShootPos()
  237. local aimVec = localplayer:GetAimVector()
  238.  
  239. for k, ply in pairs(players or player.GetAll()) do
  240. if not ply:Alive() or ply == localplayer then continue end
  241. local hisPos = ply:GetShootPos()
  242. if ply:getDarkRPVar("wanted") then DrawWantedInfo(ply) end
  243.  
  244. if GAMEMODE.Config.globalshow then
  245. DrawPlayerInfo(ply)
  246. -- Draw when you're (almost) looking at him
  247. elseif not GAMEMODE.Config.globalshow and hisPos:DistToSqr(shootPos) < 160000 then
  248. local pos = hisPos - shootPos
  249. local unitPos = pos:GetNormalized()
  250. if unitPos:Dot(aimVec) > 0.95 then
  251. local trace = util.QuickTrace(shootPos, pos, localplayer)
  252. if trace.Hit and trace.Entity ~= ply then return end
  253. DrawPlayerInfo(ply)
  254. end
  255. end
  256. end
  257.  
  258. local tr = localplayer:GetEyeTrace()
  259.  
  260. if IsValid(tr.Entity) and tr.Entity:isKeysOwnable() and tr.Entity:GetPos():Distance(localplayer:GetPos()) < 200 then
  261. tr.Entity:drawOwnableInfo()
  262. end
  263. end
  264.  
  265. /*---------------------------------------------------------------------------
  266. Drawing death notices
  267. ---------------------------------------------------------------------------*/
  268. function GAMEMODE:DrawDeathNotice(x, y)
  269. if not GAMEMODE.Config.showdeaths then return end
  270. self.BaseClass:DrawDeathNotice(x, y)
  271. end
  272.  
  273. /*---------------------------------------------------------------------------
  274. Display notifications
  275. ---------------------------------------------------------------------------*/
  276. local function DisplayNotify(msg)
  277. local txt = msg:ReadString()
  278. GAMEMODE:AddNotify(txt, msg:ReadShort(), msg:ReadLong())
  279. surface.PlaySound("buttons/lightswitch2.wav")
  280.  
  281. -- Log to client console
  282. print(txt)
  283. end
  284. usermessage.Hook("_Notify", DisplayNotify)
  285.  
  286. /*---------------------------------------------------------------------------
  287. Remove some elements from the HUD in favour of the DarkRP HUD
  288. ---------------------------------------------------------------------------*/
  289. function GAMEMODE:HUDShouldDraw(name)
  290. if name == "CHudHealth" or
  291. name == "CHudBattery" or
  292. name == "CHudSuitPower" or
  293. (HelpToggled and name == "CHudChat") then
  294. return false
  295. else
  296. return true
  297. end
  298. end
  299.  
  300. /*---------------------------------------------------------------------------
  301. Disable players' names popping up when looking at them
  302. ---------------------------------------------------------------------------*/
  303. function GAMEMODE:HUDDrawTargetID()
  304. return true
  305. end
  306.  
  307. /*---------------------------------------------------------------------------
  308. Actual HUDPaint hook
  309. ---------------------------------------------------------------------------*/
  310. function DrawHUD()
  311. localplayer = localplayer and IsValid(localplayer) and localplayer or LocalPlayer()
  312. if not IsValid(localplayer) then return end
  313.  
  314. -- Custom
  315. Base()
  316.  
  317. -- Default
  318. GunLicense()
  319. Agenda()
  320. DrawVoiceChat()
  321. LockDown()
  322. Arrested()
  323. AdminTell()
  324. DrawEntityDisplay()
  325.  
  326. end
  327. hook.Add("HUDPaint", "DrawHUD", DrawHUD)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement