Advertisement
Exho

Untitled

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