Advertisement
Guest User

Untitled

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