Advertisement
Guest User

Untitled

a guest
Feb 16th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.23 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. HUD ConVars
  3. ---------------------------------------------------------------------------*/
  4. local ConVars = {}
  5. local HUDWidth
  6. local HUDHeight
  7.  
  8. CreateClientConVar("weaponhud", 0, true, false)
  9.  
  10. local function ReloadConVars()
  11. ConVars = {
  12. background = {0,0,0,100},
  13. Healthbackground = {0,0,0,200},
  14. Healthforeground = {140,0,0,180},
  15. HealthText = {255,255,255,200},
  16. Job1 = {0,0,150,200},
  17. Job2 = {0,0,0,255},
  18. salary1 = {0,150,0,200},
  19. salary2 = {0,0,0,255}
  20. }
  21.  
  22. for name, Colour in pairs(ConVars) do
  23. ConVars[name] = {}
  24. for num, rgb in SortedPairs(Colour) do
  25. local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
  26. table.insert(ConVars[name], CVar:GetInt())
  27.  
  28. if not cvars.GetConVarCallbacks(name..num, false) then
  29. cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
  30. end
  31. end
  32. ConVars[name] = Color(unpack(ConVars[name]))
  33. end
  34.  
  35.  
  36. HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
  37. HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
  38.  
  39. if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
  40. cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
  41. cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
  42. end
  43. end
  44. ReloadConVars()
  45.  
  46. local function formatNumber(n)
  47. n = tonumber(n)
  48. if (!n) then
  49. return 0
  50. end
  51. if n >= 1e14 then return tostring(n) end
  52. n = tostring(n)
  53. sep = sep or ","
  54. local dp = string.find(n, "%.") or #n+1
  55. for i=dp-4, 1, -3 do
  56. n = n:sub(1, i) .. sep .. n:sub(i+1)
  57. end
  58. return n
  59. end
  60.  
  61.  
  62. local Scrw, Scrh, RelativeX, RelativeY
  63. /*---------------------------------------------------------------------------
  64. HUD Seperate Elements
  65. ---------------------------------------------------------------------------*/
  66. local Health = 0
  67. local function DrawHealth()
  68. Health = math.min(100, (Health == LocalPlayer():Health() and Health) or Lerp(0.1, Health, LocalPlayer():Health()))
  69.  
  70. local DrawHealth = math.Min(Health / GAMEMODE.Config.startinghealth, 1)
  71. local Border = math.Min(6, math.pow(2, math.Round(3*DrawHealth)))
  72. draw.RoundedBox(Border, RelativeX + 4, RelativeY - 30, HUDWidth - 8, 20, ConVars.Healthbackground)
  73. draw.RoundedBox(Border, RelativeX + 5, RelativeY - 29, (HUDWidth - 9) * DrawHealth, 18, ConVars.Healthforeground)
  74.  
  75. draw.DrawText(math.Max(0, math.Round(LocalPlayer():Health())), "DarkRPHUD2", RelativeX + 4 + (HUDWidth - 8)/2, RelativeY - 32, ConVars.HealthText, 1)
  76.  
  77. -- Armor
  78. local armor = LocalPlayer():Armor()
  79. if armor ~= 0 then
  80. draw.RoundedBox(2, RelativeX + 4, RelativeY - 15, (HUDWidth - 8) * armor / 100, 5, Color(0, 0, 255, 255))
  81. end
  82. end
  83.  
  84. local function DrawInfo()
  85. LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
  86. local Salary = LANGUAGE.salary .. CUR .. (LocalPlayer().DarkRPVars.salary or 0)
  87.  
  88. local JobWallet =
  89. LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or "") .. "\n"..
  90. LANGUAGE.wallet .. CUR .. (formatNumber(LocalPlayer().DarkRPVars.money) or 0)
  91.  
  92. local wep = LocalPlayer( ):GetActiveWeapon( );
  93.  
  94. if IsValid(wep) and GAMEMODE.Config.weaponhud then
  95. local name = wep:GetPrintName();
  96. draw.DrawText("Weapon: "..name, "UiBold", RelativeX + 5, RelativeY - HUDHeight - 18, Color(255, 255, 255, 255), 0)
  97. end
  98.  
  99. draw.DrawText(Salary, "DarkRPHUD2", RelativeX + 5, RelativeY - HUDHeight + 6, ConVars.salary1, 0)
  100. draw.DrawText(Salary, "DarkRPHUD2", RelativeX + 4, RelativeY - HUDHeight + 5, ConVars.salary2, 0)
  101.  
  102. surface.SetFont("DarkRPHUD2")
  103. local w, h = surface.GetTextSize(Salary)
  104.  
  105. draw.DrawText(JobWallet, "DarkRPHUD2", RelativeX + 5, RelativeY - HUDHeight + h + 6, ConVars.Job1, 0)
  106. draw.DrawText(JobWallet, "DarkRPHUD2", RelativeX + 4, RelativeY - HUDHeight + h + 5, ConVars.Job2, 0)
  107. end
  108.  
  109. local Page = Material("icon16/page_white_text.png")
  110. local function GunLicense()
  111. if LocalPlayer().DarkRPVars.HasGunlicense then
  112. surface.SetMaterial(Page)
  113. surface.SetDrawColor(255, 255, 255, 255)
  114. surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32)
  115. end
  116. end
  117.  
  118. local function JobHelp()
  119. local Helps = {"Cop", "Mayor", "Admin", "Boss"}
  120.  
  121. for k,v in pairs(Helps) do
  122. if LocalPlayer().DarkRPVars["help"..v] then
  123. draw.RoundedBox(10, 10, 10, 590, 194, Color(0, 0, 0, 255))
  124. draw.RoundedBox(10, 12, 12, 586, 190, Color(51, 58, 51, 200))
  125. draw.RoundedBox(10, 12, 12, 586, 20, Color(0, 0, 70, 200))
  126. draw.DrawText(v.." Help", "DarkRPHUD1", 30, 12, Color(255,0,0,255),0)
  127. draw.DrawText(string.format(LANGUAGE[v:lower().."help"], GAMEMODE.Config.jailtimer), "DarkRPHUD1", 30, 35, Color(255,255,255,255),0)
  128. end
  129. end
  130. end
  131.  
  132. local function Agenda()
  133. local DrawAgenda, AgendaManager = DarkRPAgendas[LocalPlayer():Team()], LocalPlayer():Team()
  134. if not DrawAgenda then
  135. for k,v in pairs(DarkRPAgendas) do
  136. if table.HasValue(v.Listeners or {}, LocalPlayer():Team()) then
  137. DrawAgenda, AgendaManager = DarkRPAgendas[k], k
  138. break
  139. end
  140. end
  141. end
  142. if DrawAgenda then
  143. draw.RoundedBox(10, 10, 10, 460, 110, Color(0, 0, 0, 155))
  144. draw.RoundedBox(10, 12, 12, 456, 106, Color(51, 58, 51,100))
  145. draw.RoundedBox(10, 12, 12, 456, 20, Color(0, 0, 70, 100))
  146.  
  147. draw.DrawText(DrawAgenda.Title, "DarkRPHUD1", 30, 12, Color(255,0,0,255),0)
  148.  
  149. local AgendaText = ""
  150. for k,v in pairs(team.GetPlayers(AgendaManager)) do
  151. if not v.DarkRPVars then continue end
  152. AgendaText = AgendaText .. (v.DarkRPVars.agenda or "")
  153. end
  154. draw.DrawText(string.gsub(string.gsub(AgendaText, "//", "\n"), "\\n", "\n"), "DarkRPHUD1", 30, 35, Color(255,255,255,255),0)
  155. end
  156. end
  157.  
  158. local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
  159. local function DrawVoiceChat()
  160. if LocalPlayer().DRPIsTalking then
  161. local chbxX, chboxY = chat.GetChatBoxPos()
  162.  
  163. local Rotating = math.sin(CurTime()*3)
  164. local backwards = 0
  165. if Rotating < 0 then
  166. Rotating = 1-(1+Rotating)
  167. backwards = 180
  168. end
  169. surface.SetTexture(VoiceChatTexture)
  170. surface.SetDrawColor(ConVars.Healthforeground)
  171. surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
  172. end
  173. end
  174.  
  175. local function LockDown()
  176. local chbxX, chboxY = chat.GetChatBoxPos()
  177. if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
  178. local cin = (math.sin(CurTime()) + 1) / 2
  179. local chatBoxSize = math.floor(ScrH() / 4)
  180. draw.DrawText(LANGUAGE.lockdown_started, "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
  181. end
  182. end
  183.  
  184. local Arrested = function() end
  185.  
  186. usermessage.Hook("GotArrested", function(msg)
  187. local StartArrested = CurTime()
  188. local ArrestedUntil = msg:ReadFloat()
  189.  
  190. Arrested = function()
  191. if CurTime() - StartArrested <= ArrestedUntil and LocalPlayer().DarkRPVars.Arrested then
  192. draw.DrawText(string.format(LANGUAGE.youre_arrested, math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1)
  193. elseif not LocalPlayer().DarkRPVars.Arrested then
  194. Arrested = function() end
  195. end
  196. end
  197. end)
  198.  
  199. local AdminTell = function() end
  200.  
  201. usermessage.Hook("AdminTell", function(msg)
  202. local Message = msg:ReadString()
  203.  
  204. AdminTell = function()
  205. draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, Color(0, 0, 0, 200))
  206. draw.DrawText(LANGUAGE.listen_up, "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1)
  207. draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 80, Color(200, 30, 30, 255), 1)
  208. end
  209.  
  210. timer.Simple(10, function()
  211. AdminTell = function() end
  212. end)
  213. end)
  214.  
  215. /*---------------------------------------------------------------------------
  216. Drawing the HUD elements such as Health etc.
  217. ---------------------------------------------------------------------------*/
  218. local function DoActualHUD()
  219.  
  220. --If the variables table has not be initialized, initialize it
  221. LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
  222.  
  223. --If the money is not set, don't do anything
  224. local v1 = LocalPlayer().DarkRPVars.money
  225. if not v1 then v1 = "" end
  226.  
  227. --If the salary is not set, don't do anything
  228. local v2 = LocalPlayer().DarkRPVars.salary
  229. if not v2 then v2 = "" end
  230.  
  231. draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200))
  232.  
  233. surface.SetDrawColor(255,255,255)
  234.  
  235. surface.SetTexture(surface.GetTextureID("gui/silkicons/user"))
  236. surface.DrawTexturedRect(25 + 10,ScrH() - 160,16,16)
  237.  
  238. surface.SetTexture(surface.GetTextureID("gui/silkicons/money"))
  239. surface.DrawTexturedRect(25 + 10,ScrH() - 140,16,16)
  240.  
  241. surface.SetTexture(surface.GetTextureID("gui/silkicons/money_add"))
  242. surface.DrawTexturedRect(25 + 10,ScrH() - 120,16,16)
  243.  
  244. surface.SetTexture(surface.GetTextureID("gui/silkicons/group"))
  245. surface.DrawTexturedRect(25 + 10,ScrH() - 100,16,16)
  246.  
  247. surface.SetTexture(surface.GetTextureID("gui/silkicons/heart"))
  248. surface.DrawTexturedRect(25 + 10,ScrH() - 80,16,16)
  249.  
  250. surface.SetTexture(surface.GetTextureID("gui/silkicons/shield"))
  251. surface.DrawTexturedRect(25 + 10,ScrH() - 60,16,16)
  252.  
  253.  
  254. draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() - 145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  255. draw.SimpleText("$" .. v1,"TargetID", 25 + 30,ScrH() - 125, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  256. draw.SimpleText("$" .. v2,"TargetID", 25 + 30,ScrH() - 105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  257. draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() - 85, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  258. draw.SimpleText(LocalPlayer():Health() ,"TargetID", 25 + 30,ScrH() - 65, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  259. draw.SimpleText(LocalPlayer():Armor() ,"TargetID", 25 + 30,ScrH() - 45, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  260.  
  261.  
  262. end
  263.  
  264. local function DrawHUD()
  265. Scrw, Scrh = ScrW(), ScrH()
  266. RelativeX, RelativeY = 0, Scrh
  267.  
  268. DoActualHUD()
  269. GunLicense()
  270. Agenda()
  271. JobHelp()
  272. DrawVoiceChat()
  273. LockDown()
  274.  
  275. Arrested()
  276. AdminTell()
  277. end
  278.  
  279. /*---------------------------------------------------------------------------
  280. Entity HUDPaint things
  281. ---------------------------------------------------------------------------*/
  282. local function DrawPlayerInfo(ply)
  283. local pos = ply:EyePos()
  284.  
  285. pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
  286. pos = pos:ToScreen()
  287. pos.y = pos.y - 50 -- Move the text up a few pixels to compensate for the height of the text
  288.  
  289. if GAMEMODE.Config.showname and not ply.DarkRPVars.wanted then
  290. draw.DrawText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
  291. draw.DrawText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  292. draw.DrawText(LANGUAGE.health ..ply:Health(), "DarkRPHUD2", pos.x + 1, pos.y + 21, Color(0, 0, 0, 255), 1)
  293. draw.DrawText(LANGUAGE.health..ply:Health(), "DarkRPHUD2", pos.x, pos.y + 20, Color(255,255,255,200), 1)
  294. end
  295.  
  296. if GAMEMODE.Config.showjob then
  297. local teamname = team.GetName(ply:Team())
  298. draw.DrawText(ply.DarkRPVars.job or teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, Color(0, 0, 0, 255), 1)
  299. draw.DrawText(ply.DarkRPVars.job or teamname, "DarkRPHUD2", pos.x, pos.y + 40, Color(255, 255, 255, 200), 1)
  300. end
  301.  
  302. if ply.DarkRPVars.HasGunlicense then
  303. surface.SetMaterial(Page)
  304. surface.SetDrawColor(255,255,255,255)
  305. surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
  306. end
  307. end
  308.  
  309. local function DrawWantedInfo(ply)
  310. if not ply:Alive() then return end
  311.  
  312. local pos = ply:EyePos()
  313. if not pos:RPIsInSight({LocalPlayer(), ply}) then return end
  314.  
  315. pos.z = pos.z + 14
  316. pos = pos:ToScreen()
  317.  
  318. if GAMEMODE.Config.showname then
  319. draw.DrawText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, Color(0, 0, 0, 255), 1)
  320. draw.DrawText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
  321. end
  322.  
  323. draw.DrawText(LANGUAGE.wanted.."\nReason: "..tostring(ply.DarkRPVars["wantedReason"]), "DarkRPHUD2", pos.x, pos.y - 40, Color(255, 255, 255, 200), 1)
  324. draw.DrawText(LANGUAGE.wanted.."\nReason: "..tostring(ply.DarkRPVars["wantedReason"]), "DarkRPHUD2", pos.x + 1, pos.y - 41, Color(255, 0, 0, 255), 1)
  325. end
  326.  
  327. /*---------------------------------------------------------------------------
  328. The Entity display: draw HUD information about entities
  329. ---------------------------------------------------------------------------*/
  330. local function DrawEntityDisplay()
  331. local shootPos = LocalPlayer():GetShootPos()
  332. local aimVec = LocalPlayer():GetAimVector()
  333.  
  334. for k, ply in pairs(player.GetAll()) do
  335. if not ply:Alive() then continue end
  336. local hisPos = ply:GetShootPos()
  337.  
  338. ply.DarkRPVars = ply.DarkRPVars or {}
  339. if ply.DarkRPVars.wanted then DrawWantedInfo(ply) end
  340.  
  341. if GAMEMODE.Config.globalshow and ply ~= LocalPlayer() then
  342. DrawPlayerInfo(ply)
  343. -- Draw when you're (almost) looking at him
  344. elseif not GAMEMODE.Config.globalshow and hisPos:Distance(shootPos) < 400 then
  345. local pos = hisPos - shootPos
  346. local unitPos = pos:GetNormalized()
  347. if unitPos:Dot(aimVec) > 0.95 then
  348. local trace = util.QuickTrace(shootPos, pos, LocalPlayer())
  349. if trace.Hit and trace.Entity ~= ply then return end
  350. DrawPlayerInfo(ply)
  351. end
  352. end
  353. end
  354.  
  355. local tr = LocalPlayer():GetEyeTrace()
  356.  
  357. if tr.Entity:IsOwnable() and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 200 then
  358. tr.Entity:DrawOwnableInfo()
  359. end
  360. end
  361.  
  362. /*---------------------------------------------------------------------------
  363. Zombie display
  364. ---------------------------------------------------------------------------*/
  365. local function DrawZombieInfo()
  366. if not LocalPlayer().DarkRPVars.zombieToggle then return end
  367. for x=1, LocalPlayer().DarkRPVars.numPoints, 1 do
  368. local zPoint = LocalPlayer().DarkRPVars["zPoints".. x]
  369. if zPoint then
  370. zPoint = zPoint:ToScreen()
  371. draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
  372. draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x + 1, zPoint.y - 21, Color(255, 0, 0, 255), 1)
  373. end
  374. end
  375. end
  376.  
  377. /*---------------------------------------------------------------------------
  378. Actual HUDPaint hook
  379. ---------------------------------------------------------------------------*/
  380. function GM:HUDPaint()
  381. DrawHUD()
  382. DrawZombieInfo()
  383. DrawEntityDisplay()
  384.  
  385. self.BaseClass:HUDPaint()
  386. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement