Advertisement
Exho

Untitled

Oct 12th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. ---- TTT Hover Stats ----
  4. -- Author: Exho
  5. -- V: 9/11/14
  6.  
  7.  
  8. ------ CONFIGURATION ------
  9. local Range = 500 -- How close you have to be to the weapon to see the stats
  10.  
  11. local NameCol = Color( 255, 255, 255, 255 ) -- The Guns title, default white
  12. local DmgCol = Color( 220, 80, 80, 255 ) -- Red
  13. local ClipCol = Color( 128, 255, 0, 255 ) -- Green
  14. local RecoilCol = Color(0, 191, 255, 255 ) -- Blue
  15. local AutoCol = Color(204, 204, 0, 255 ) -- Yellow
  16. local SpreadCol = Color( 205, 61, 205, 255 ) -- Pink
  17.  
  18. local Base = 400 -- This is the default height of the stats
  19. local BounceHigh = Base + 50 -- The height it goes up to when bouncing
  20. local BounceLow = Base - 50 -- Guess what this one does
  21. ------ //END CONFIGURATION//------
  22.  
  23.  
  24. ------ DECLARING VARIABLES ------
  25. local enable = CreateClientConVar("hs_enabled", "1", true, true)
  26. local bounce = CreateClientConVar("hs_bounce", "1", true, true)
  27. local numbers = CreateClientConVar("hs_numbers", "0", true, true)
  28. local name
  29. local dmg
  30. local recoil
  31. local clip
  32. local maxclip
  33. local cone
  34. local auto
  35. local none = "ERROR" -- Nil fixer
  36. local nfix = {} -- TTT uses language variables instead of names for some weps, this fixes that.
  37. -- Custom weapons wont have this problem unless you did use languages in which case add it at the bottom.
  38. -- Example: nfix.translationname = "New Name"
  39. nfix.rifle_name, nfix.sipistol_name, nfix.shotgun_name, nfix.pistol_name = "Rifle", "S. Pistol", "Shotgun", "Pistol"
  40. nfix.defuser_name, nfix.newton_name, nfix.tele_name, nfix.flare_name = "Defuser", "Newton", "Teleporter", "Flare Gun"
  41. nfix.knife_name, nfix.grenade_fire, nfix.grenade_smoke = "Knife", "Incendinary", "Smoke"
  42. ------ //END DECLARING VARIABLES// ------
  43.  
  44.  
  45. if CLIENT then -- Creates fonts
  46. surface.CreateFont( "GunFont", {
  47. font = "Arial",
  48. size = 30,
  49. weight = 500,
  50. antialias = true,
  51. } )
  52.  
  53. surface.CreateFont( "GunTitle", {
  54. font = "Arial",
  55. size = 50,
  56. weight = 500,
  57. antialias = true,
  58. } )
  59. end
  60.  
  61.  
  62. local function IsTTTWep( ent )
  63. -- Checks to make sure only TTT weapons recieve these stats
  64. if not IsValid( ent ) then return end
  65. if not ent:IsWeapon() then return end
  66.  
  67. local class = string.lower(ent:GetClass())
  68. if string.sub( class, 1, 10 ) == "weapon_ttt" or "weapon_zm" then
  69. if not ent.Primary then -- If its not a weapon, this doesnt happen.
  70. return false
  71. else
  72. return true
  73. end
  74. else
  75. return false
  76. end
  77. end
  78.  
  79. -- The bouncing effect
  80. local Goal = 350
  81. local Counting = false -- Constantly counting is inefficient
  82. hook.Add( "Tick", "BouncyBalls", function()
  83. if not bounce:GetBool() then return false end
  84.  
  85. if Counting then
  86. Base = math.Approach(Base, Goal, 2)
  87.  
  88. -- These variables are referenced from the Config area
  89. if Base == BounceLow then
  90. Goal = BounceHigh
  91. elseif Base == BounceHigh then
  92. Goal = BounceLow
  93. end
  94. end
  95. end)
  96.  
  97. ------ DRAWING STATS ------
  98. local function DrawYourStats()
  99. local ply = LocalPlayer()
  100.  
  101. -- Tracing. No eye trace this time cause I need range
  102. local pos = ply:GetShootPos()
  103. local ang = ply:GetAimVector()
  104. local tracedata = {}
  105. tracedata.start = pos
  106. tracedata.endpos = pos+(ang*Range)
  107. tracedata.filter = ply
  108. local trace = util.TraceLine(tracedata)
  109.  
  110. local gun = trace.Entity
  111.  
  112. -- Enabled check
  113. if enable:GetBool() ~= true then return false end
  114.  
  115. -- Checking if the target is a valid weapon and if we should display stats
  116. if IsTTTWep( gun ) then
  117. Counting = true
  118. -- Set each of the variables that I reference later
  119. name = gun.PrintName or none
  120. dmg = (gun.Primary.Damage * gun.Primary.NumShots) or none
  121. recoil = gun.Primary.Recoil or none
  122. auto = gun.Primary.Automatic or none
  123. clip = gun:Clip1() or none
  124. maxclip = gun.Primary.DefaultClip or none
  125. cone = gun.Primary.Cone or none
  126.  
  127. if clip == -1 then
  128. clip = maxclip
  129. end
  130.  
  131. if numbers:GetBool() then
  132. recoil = math.Round(recoil, 2)
  133. elseif recoil <= 1.4 then -- Make recoil have a fancy name instead of numbers
  134. recoil = "Low"
  135. elseif recoil > 1.4 and recoil <= 1.9 then
  136. recoil = "Average"
  137. elseif recoil > 1.9 and recoil <= 5 then
  138. recoil = "High"
  139. elseif recoil > 5 then
  140. recoil = "Very High"
  141. else recoil = none
  142. end
  143.  
  144. if numbers:GetBool() then
  145. cone = math.Round(cone, 3)
  146. elseif cone <= 0.02 then -- Same deal, cause numbers wont mean anything
  147. cone = "Great"
  148. elseif cone > 0.02 and cone <= 0.05 then
  149. cone = "Good"
  150. elseif cone > 0.05 and cone <= 0.7 then
  151. cone = "Average"
  152. elseif cone > 0.07 and cone <= 0.9 then
  153. cone = "Poor"
  154. elseif cone > 0.9 then
  155. cone = "Horrible"
  156. else cone = none end
  157.  
  158. if auto == true then
  159. auto = "Yes"
  160. else
  161. auto = "No"
  162. end
  163.  
  164. -- Fix all the screwed up names
  165. for k,v in pairs( nfix ) do
  166. if k == name then
  167. name = v
  168. end
  169. end
  170. if name == "UMP Prototype" then -- Some names I could not use for keys
  171. name = "UMP"
  172. elseif name == "H.U.G.E-249" then
  173. name = "HUGE-249"
  174. elseif name == "Discombobulator" then
  175. name = "Discombob"
  176. end
  177.  
  178. -- Minor calculations to make the thing actually stand up
  179. local pos = gun:GetPos() + Vector(0,0,90)
  180. local eyeang = LocalPlayer():EyeAngles().y - 90
  181. local ang = Angle( 0, eyeang, 90 )
  182.  
  183. -- Start drawing
  184. cam.Start3D2D(pos, ang, 0.1)
  185. surface.SetDrawColor( 0, 0, 0, 150) -- A near-transparent black works nicely
  186. surface.DrawRect(-200 , Base - 100, 250, 330 ) -- Base is used in the bouncing effect
  187. surface.SetDrawColor( 255,255, 255, 255)
  188. surface.DrawLine( -150, Base - 30, 0, Base - 30 ) -- The line under the gun name
  189.  
  190. draw.DrawText( name, "GunTitle", -75, Base -80 , NameCol, TEXT_ALIGN_CENTER )
  191.  
  192. draw.DrawText( "Damage:", "GunFont", -180, Base, DmgCol, TEXT_ALIGN_LEFT )
  193. draw.DrawText( dmg, "GunFont", 30, Base, DmgCol, TEXT_ALIGN_RIGHT )
  194.  
  195. draw.DrawText( "Clip:", "GunFont", -180, Base + 40, ClipCol, TEXT_ALIGN_LEFT )
  196. draw.DrawText( clip.."/"..maxclip, "GunFont", 30, Base + 40, ClipCol, TEXT_ALIGN_RIGHT )
  197.  
  198. draw.DrawText( "Recoil:", "GunFont", -180, Base + 80, RecoilCol, TEXT_ALIGN_LEFT )
  199. draw.DrawText( recoil, "GunFont", 30, Base + 80, RecoilCol, TEXT_ALIGN_RIGHT )
  200.  
  201. draw.DrawText( "Automatic:", "GunFont", -180, Base + 120, AutoCol, TEXT_ALIGN_LEFT )
  202. draw.DrawText( auto, "GunFont", 30, Base + 120, AutoCol, TEXT_ALIGN_RIGHT )
  203.  
  204. draw.DrawText( "Accuracy:", "GunFont", -180, Base + 160, SpreadCol, TEXT_ALIGN_LEFT )
  205. draw.DrawText( cone, "GunFont", 30, Base + 160, SpreadCol, TEXT_ALIGN_RIGHT )
  206. cam.End3D2D()
  207. else
  208. Counting = false -- If you are not looking at a valid gun, dont count.... Duh
  209. end
  210. end
  211. hook.Add( "PostDrawOpaqueRenderables", "PopUpBlockerFailed", DrawYourStats )
  212. ------ //END DRAWING STATS// ------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement