Guest User

Untitled

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