Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.40 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 cvars = cvars
  10. local draw = draw
  11. local GetConVar = GetConVar
  12. local Lerp = Lerp
  13. local localplayer
  14. local pairs = pairs
  15. local SortedPairs = SortedPairs
  16. local string = string
  17. local surface = surface
  18. local table = table
  19. local tostring = tostring
  20.  
  21. CreateClientConVar("weaponhud", 0, true, false)
  22.  
  23. local function ReloadConVars()
  24. ConVars = {
  25. background = {0,255,0,},
  26. Healthbackground = {0,0,0,200},
  27. Healthforeground = {140,0,0,180},
  28. HealthText = {255,255,255,200},
  29. Job1 = {0,0,150,200},
  30. Job2 = {0,0,0,255},
  31. salary1 = {0,150,0,200},
  32. salary2 = {0,0,0,255}
  33. }
  34.  
  35. for name, Colour in pairs(ConVars) do
  36. ConVars[name] = {}
  37. for num, rgb in SortedPairs(Colour) do
  38. local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
  39. table.insert(ConVars[name], CVar:GetInt())
  40.  
  41. if not cvars.GetConVarCallbacks(name..num, false) then
  42. cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
  43. end
  44. end
  45. ConVars[name] = Color(unpack(ConVars[name]))
  46. end
  47.  
  48.  
  49. HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
  50. HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
  51.  
  52. if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
  53. cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
  54. cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
  55. end
  56. end
  57. ReloadConVars()
  58.  
  59. local function formatNumber(n)
  60. if not n then return "" end
  61. if n >= 1e14 then return tostring(n) end
  62. n = tostring(n)
  63. local sep = sep or ","
  64. local dp = string.find(n, "%.") or #n+1
  65. for i=dp-4, 1, -3 do
  66. n = n:sub(1, i) .. sep .. n:sub(i+1)
  67. end
  68. return n
  69. end
  70.  
  71.  
  72. local Scrw, Scrh, RelativeX, RelativeY
  73. /*---------------------------------------------------------------------------
  74. HUD Seperate Elements
  75. ---------------------------------------------------------------------------*/
  76. local licence = Material("boowman/licence.png")
  77. local function GunLicense()
  78. if localplayer:getDarkRPVar("HasGunlicense") then
  79. surface.SetMaterial(licence)
  80. surface.SetDrawColor(255, 255, 255, 255)
  81. surface.DrawTexturedRect(20,ScrH() - 85,150,50)
  82. end
  83. end
  84.  
  85. local function Agenda()
  86. local DrawAgenda, AgendaManager = DarkRPAgendas[localplayer:Team()], localplayer:Team()
  87. if not DrawAgenda then
  88. for k,v in pairs(DarkRPAgendas) do
  89. if table.HasValue(v.Listeners or {}, localplayer:Team()) then
  90. DrawAgenda, AgendaManager = DarkRPAgendas[k], k
  91. break
  92. end
  93. end
  94. end
  95. if DrawAgenda then
  96. draw.RoundedBox(10, 10, 10, 460, 110, Color(0, 0, 0, 155))
  97. draw.RoundedBox(10, 12, 12, 456, 106, Color(51, 58, 51,100))
  98. draw.RoundedBox(10, 12, 12, 456, 20, Color(0, 0, 70, 100))
  99.  
  100. draw.DrawText(DrawAgenda.Title, "DarkRPHUD1", 30, 12, Color(255,0,0,255),0)
  101.  
  102. local AgendaText = {}
  103. for k,v in pairs(team.GetPlayers(AgendaManager)) do
  104. if not v.DarkRPVars then continue end
  105. table.insert(AgendaText, v:getDarkRPVar("agenda"))
  106. end
  107.  
  108. local text = table.concat(AgendaText, "\n")
  109. text = text:gsub("//", "\n"):gsub("\\n", "\n")
  110. text = GAMEMODE:TextWrap(text, "DarkRPHUD1", 440)
  111. draw.DrawText(text, "DarkRPHUD1", 30, 35, Color(255,255,255,255),0)
  112. end
  113. end
  114.  
  115. local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
  116. local function DrawVoiceChat()
  117. if localplayer.DRPIsTalking then
  118. local chbxX, chboxY = chat.GetChatBoxPos()
  119.  
  120. local Rotating = math.sin(CurTime()*3)
  121. local backwards = 0
  122. if Rotating < 0 then
  123. Rotating = 1-(1+Rotating)
  124. backwards = 180
  125. end
  126. surface.SetTexture(VoiceChatTexture)
  127. surface.SetDrawColor(ConVars.Healthforeground)
  128. surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
  129. end
  130. end
  131.  
  132. local function LockDown()
  133. local chbxX, chboxY = chat.GetChatBoxPos()
  134. if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
  135. local cin = (math.sin(CurTime()) + 1) / 2
  136. local chatBoxSize = math.floor(ScrH() / 4)
  137. draw.DrawText(DarkRP.getPhrase("lockdown_started"), "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
  138. end
  139. end
  140.  
  141. local Arrested = function() end
  142.  
  143. usermessage.Hook("GotArrested", function(msg)
  144. local StartArrested = CurTime()
  145. local ArrestedUntil = msg:ReadFloat()
  146.  
  147. Arrested = function()
  148. if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then
  149. draw.DrawText(DarkRP.getPhrase("youre_arrested", math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1)
  150. elseif not localplayer:getDarkRPVar("Arrested") then
  151. Arrested = function() end
  152. end
  153. end
  154. end)
  155.  
  156. local AdminTell = function() end
  157.  
  158. usermessage.Hook("AdminTell", function(msg)
  159. local Message = msg:ReadString()
  160.  
  161. AdminTell = function()
  162. draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, Color(0, 0, 0, 200))
  163. draw.DrawText(DarkRP.getPhrase("listen_up"), "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1)
  164. draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 80, Color(200, 30, 30, 255), 1)
  165. end
  166.  
  167. timer.Simple(10, function()
  168. AdminTell = function() end
  169. end)
  170. end)
  171.  
  172. /*---------------------------------------------------------------------------
  173. Drawing the HUD elements such as Health etc.
  174. ---------------------------------------------------------------------------*/
  175. surface.CreateFont( "SBPName", {
  176. font = "Arial",
  177. size = 20,
  178. weight = 700,
  179. antialias = true,
  180. shadow = true,
  181. } )
  182.  
  183. surface.CreateFont( "SBPName2", {
  184. font = "Arial",
  185. size = 20,
  186. weight = 700,
  187. antialias = true,
  188. shadow = true,
  189. } )
  190.  
  191. /*---------------------------------------------------------------------------
  192. Change HUD Colours
  193. ---------------------------------------------------------------------------*/
  194. local healthbg = Color(0,0,0,200)
  195. local armorbg = Color(0,0,0,200)
  196. local jobs = Color(0,0,0,200)
  197. local salr = Color(0,0,0,200)
  198. local mon = Color(0,0,0,200)
  199. local hpbar = Color(255,0,0,255)
  200. local arbar = Color(0,150,255,255)
  201.  
  202. local function DrawHealth()
  203. LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}
  204. local ply = LocalPlayer()
  205. local HP,AR = ply:Health(),ply:Armor()
  206. local slujba = LocalPlayer().DarkRPVars.job or "Unemployed"
  207. local salar = formatNumber(LocalPlayer().DarkRPVars.salary) or "NONE"
  208. local bani = formatNumber(LocalPlayer().DarkRPVars.money) or "NONE"
  209.  
  210. draw.RoundedBox(0,10,ScrH() - 30,200,25,healthbg)
  211. draw.RoundedBox(0,220,ScrH() - 30,200,25,armorbg)
  212. draw.RoundedBox(0,10,ScrH() - 60,200,25,jobs)
  213. draw.RoundedBox(0,10,ScrH() - 120,100,25,salr)
  214. draw.RoundedBox(0,10,ScrH() - 90,200,25,mon)
  215. //--Health
  216. draw.RoundedBox(0,14.5,ScrH() - 25,math.Clamp(HP,0,100)*1.9,15,hpbar)
  217. draw.DrawText(""..HP.."","SBPName",65,ScrH() - 27,Color(0,0,0,0),TEXT_ALIGN_CENTER)
  218. surface.SetDrawColor(255,255,255,255)
  219. surface.DrawOutlinedRect(10,ScrH() - 30,200,25)
  220. //--Armor
  221. draw.RoundedBox(0,224.5,ScrH() - 25,math.Clamp(AR,0,100)*1.9,15,arbar)
  222. draw.DrawText("Armor: "..AR.."%","SBPName",275,ScrH() - 27,Color(0,0,0,0),TEXT_ALIGN_CENTER)
  223. surface.SetDrawColor(255,255,255,255)
  224. surface.DrawOutlinedRect(220,ScrH() - 30,200,25)
  225. //--Money
  226. draw.DrawText("Wallet: "..bani.."","SBPName",15,ScrH() - 87,Color(255,255,255),TEXT_ALIGN_LEFT)
  227. surface.SetDrawColor(255,255,255,255)
  228. surface.DrawOutlinedRect(10,ScrH() - 90,200,25)
  229. //--Job
  230. draw.DrawText(slujba,"SBPName",15,ScrH() - 57,Color(255,255,255),TEXT_ALIGN_LEFT)
  231. surface.SetDrawColor(255,255,255,255)
  232. surface.DrawOutlinedRect(10,ScrH() - 60,200,25)
  233. //--Salary
  234. draw.DrawText("Salary: "..salar,"SBPName",15,ScrH() - 117,Color(255,255,255),TEXT_ALIGN_LEFT)
  235. surface.SetDrawColor(255,255,255,255)
  236. surface.DrawOutlinedRect(10,ScrH() - 120,100,25)
  237. //--Licence
  238. if ply:getDarkRPVar("HasGunlicense") then
  239. surface.SetMaterial(licence)
  240. surface.SetDrawColor(255, 255, 255, 255)
  241. surface.DrawTexturedRect(20,ScrH() - 85,150,50)
  242. end
  243.  
  244. end
  245.  
  246. local function DrawHUD()
  247. localplayer = localplayer and IsValid(localplayer) and localplayer or LocalPlayer()
  248. if not IsValid(localplayer) then return end
  249.  
  250. local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_HUD")
  251. if shouldDraw == false then return end
  252.  
  253. Scrw, Scrh = ScrW(), ScrH()
  254. RelativeX, RelativeY = 0, Scrh
  255.  
  256. DrawHealth()
  257. GunLicense()
  258. Agenda()
  259. DrawVoiceChat()
  260. LockDown()
  261.  
  262. Arrested()
  263. AdminTell()
  264. end
  265.  
  266. /*---------------------------------------------------------------------------
  267. Entity HUDPaint things
  268. ---------------------------------------------------------------------------*/
  269. plyMeta.drawPlayerInfo = plyMeta.drawPlayerInfo or function(self)
  270. local pos = self:EyePos()
  271.  
  272. pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
  273. pos = pos:ToScreen()
  274. if not self:getDarkRPVar("wanted") then
  275. -- Move the text up a few pixels to compensate for the height of the text
  276. pos.y = pos.y - 50
  277. end
  278.  
  279. if GAMEMODE.Config.showname then
  280. local nick, plyTeam = self:Nick(), self:Team()
  281. draw.DrawNonParsedText(nick, "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  282. draw.DrawNonParsedText(nick, "DarkRPHUD2", pos.x, pos.y, RPExtraTeams[plyTeam].color or team.GetColor(plyTeam) , 1)
  283. end
  284.  
  285. if GAMEMODE.Config.showhealth then
  286. local health = DarkRP.getPhrase("health", self:Health())
  287. draw.DrawNonParsedText(health, "DarkRPHUD2", pos.x + 1, pos.y + 21, colors.black, 1)
  288. draw.DrawNonParsedText(health, "DarkRPHUD2", pos.x, pos.y + 20, colors.white1, 1)
  289. end
  290.  
  291. if GAMEMODE.Config.showjob then
  292. local teamname = self:getDarkRPVar("job") or team.GetName(self:Team())
  293. draw.DrawNonParsedText(teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, colors.black, 1)
  294. draw.DrawNonParsedText(teamname, "DarkRPHUD2", pos.x, pos.y + 40, colors.white1, 1)
  295. end
  296.  
  297. if self:getDarkRPVar("HasGunlicense") then
  298. surface.SetMaterial(Page)
  299. surface.SetDrawColor(255,255,255,255)
  300. surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
  301. end
  302. end
  303.  
  304. -- Draw wanted information above a player's head
  305. -- This syntax allows for easy overriding
  306. plyMeta.drawWantedInfo = plyMeta.drawWantedInfo or function(self)
  307. if not self:Alive() then return end
  308.  
  309. local pos = self:EyePos()
  310. if not pos:isInSight({localplayer, self}) then return end
  311.  
  312. pos.z = pos.z + 10
  313. pos = pos:ToScreen()
  314.  
  315. if GAMEMODE.Config.showname then
  316. draw.DrawNonParsedText(self:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
  317. draw.DrawNonParsedText(self:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(self:Team()), 1)
  318. end
  319.  
  320. local wantedText = DarkRP.getPhrase("wanted", tostring(self:getDarkRPVar("wantedReason")))
  321.  
  322. draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x, pos.y - 40, colors.white1, 1)
  323. draw.DrawNonParsedText(wantedText, "DarkRPHUD2", pos.x + 1, pos.y - 41, colors.red, 1)
  324. end
  325.  
  326. /*---------------------------------------------------------------------------
  327. The Entity display: draw HUD information about entities
  328. ---------------------------------------------------------------------------*/
  329. local function DrawEntityDisplay()
  330. local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_EntityDisplay")
  331. if shouldDraw == false then return end
  332.  
  333. local shootPos = localplayer:GetShootPos()
  334. local aimVec = localplayer:GetAimVector()
  335.  
  336. for k, ply in pairs(player.GetAll()) do
  337. if not ply:Alive() then continue end
  338. local hisPos = ply:GetShootPos()
  339. if ply:getDarkRPVar("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 IsValid(tr.Entity) and 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:getDarkRPVar("zombieToggle") then return end
  367. local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_ZombieInfo")
  368. if shouldDraw == false then return end
  369.  
  370. for x=1, localplayer:getDarkRPVar("numPoints"), 1 do
  371. local zPoint = localplayer.DarkRPVars["zPoints".. x]
  372. if zPoint then
  373. zPoint = zPoint:ToScreen()
  374. draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x, zPoint.y - 20, Color(255, 255, 255, 200), 1)
  375. draw.DrawText("Zombie Spawn (" .. x .. ")", "DarkRPHUD2", zPoint.x + 1, zPoint.y - 21, Color(255, 0, 0, 255), 1)
  376. end
  377. end
  378. end
  379.  
  380. /*---------------------------------------------------------------------------
  381. Actual HUDPaint hook
  382. ---------------------------------------------------------------------------*/
  383. function GM:HUDPaint()
  384. DrawHUD()
  385. DrawZombieInfo()
  386. DrawEntityDisplay()
  387.  
  388. self.BaseClass:HUDPaint()
  389. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement