Advertisement
quintosh

asp xray

Jan 22nd, 2013
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.27 KB | None | 0 0
  1. local XRayEnts = {}
  2. local XRayEntTypes = {
  3.     {class = "prop", color = Color(255, 0, 0)},
  4.     {class = "npc_", color = Color(0, 0, 255)},
  5.     {class = "spawned_", color = Color(255, 255, 0)},
  6.     {class = "door", color = Color(255, 0, 0)},
  7.     {class = "gmod_wire_hologram", color = Color(255, 255, 255)}
  8. }
  9.  
  10. local Mod = ASPModule("X-Ray")
  11. ASP.Util.SetConVarToggle(Mod, "xray", 1)
  12.     Mod.IsEnabled["Draw"] = true
  13.     Mod.IsEnabled["SPEffects"] = true
  14.     Mod.HasConfig = true
  15.  
  16. function ASP.Util.AddXRayEntity(ent)
  17.     if ent and ent:IsValid() then
  18.         table.insert(XRayEnts, ent)
  19.     end
  20.     if #XRayEnts > ASP.Util.GetModValue(Mod, "maxents") then
  21.         if XRayEnts[1] != nil then
  22.             if XRayEnts[1] and XRayEnts[1]:IsValid() then
  23.                 XRayEnts[1]:SetNoDraw(false)
  24.             end
  25.         end
  26.         table.remove(XRayEnts, 1)
  27.     end
  28. end
  29.  
  30. CreateClientConVar("asp_xray_showdata", "1", true, false)
  31.    
  32. function Mod:Draw()
  33.     if GetConVar("asp_xray_showdata"):GetBool() then
  34.         surface.SetDrawColor(Color(0, 0, 0, 128))
  35.         surface.DrawRect(5, 5, 180, 20)
  36.         surface.SetFont("DefaultFixed")
  37.         if #XRayEnts < ASP.Util.GetModValue(Mod, "maxents") then
  38.             surface.SetTextColor(Color(0, 255, 0, 255))
  39.         elseif #XRayEnts == ASP.Util.GetModValue(Mod, "maxents") then
  40.             surface.SetTextColor(Color(255, 255, 0, 255))
  41.         elseif #XRayEnts > ASP.Util.GetModValue(Mod, "maxents") then
  42.             surface.SetTextColor(Color(255, 0, 0, 255))
  43.         end
  44.         surface.SetTextPos(10, 10)
  45.         surface.DrawText("XRay entity count: " .. #XRayEnts .. "/" .. ASP.Util.GetModValue(Mod, "maxents"))
  46.     end
  47. end
  48.  
  49. function Mod:SPEffects()
  50.     if ASP.Util.ModConVarEnabled(Mod, "drawlines") then
  51.         for k, v in pairs(player.GetAll()) do
  52.             if v != nil then
  53.                 if v and v:IsValid() and v:Alive() then
  54.                     cam.Start3D(EyePos(), EyeAngles())
  55.                         render.SetMaterial(LASER)
  56.                         if v == LocalPlayer() then
  57.                             render.DrawBeam(v:GetMuzzlePos(), v:GetEyeTrace().HitPos, 10, 1, 1, Color(0, 255, 0, 255))
  58.                         else
  59.                             local pos = v:EyePos()
  60.                             if v:GetBonePosition(v:LookupBone("ValveBiped.Bip01_R_Hand")) != nil then
  61.                                 pos = v:GetBonePosition(v:LookupBone("ValveBiped.Bip01_R_Hand"))
  62.                             end
  63.                             if v:GetMuzzlePos() != v:EyePos() then
  64.                                 render.DrawBeam(v:GetMuzzlePos(), v:GetEyeTrace().HitPos, 25, 1, 1, Color(0, 255, 0, 255))
  65.                             else
  66.                                 render.DrawBeam(pos, v:GetEyeTrace().HitPos, 25, 1, 1, Color(0, 255, 0, 255))
  67.                             end
  68.                         end
  69.                     cam.End3D()
  70.                 end
  71.             end
  72.         end
  73.     end
  74.     if ASP.Util.IsConVarEnabled(Mod) then
  75.         if #XRayEnts <= 0 then
  76.             RunConsoleCommand("rope_rendersolid", "1")
  77.             table.Empty(XRayEnts)
  78.             if not ASP.Util.ModConVarEnabled(Mod, "onlyspawnedprops") then
  79.                 ASP.Util.InitXRayEnts()
  80.             else
  81.                 ASP.Util.InitXRayEnts()
  82.             end
  83.         end
  84.     end
  85.     if ASP.Util.ModConVarEnabled(Mod, "drawplayers") then
  86.         for k, v in pairs(player.GetAll()) do
  87.             if v != nil then
  88.                 if v and v:IsValid() and v:Alive() then
  89.                     cam.Start3D(EyePos(), EyeAngles())
  90.                         cam.IgnoreZ(true)
  91.                             local mat = v:GetMaterial()
  92.                             render.SuppressEngineLighting(true)
  93.                             render.SetBlend(1)
  94.                             if ASP.Util.ModConVarEnabled(Mod, "custommaterial") then
  95.                                 SetMaterialOverride(Material("models/wireframe"))
  96.                                 v:SetMaterial("models/wireframe")
  97.                                 render.SetBlend(0.5)
  98.                             end
  99.                             if ASP.Util.ModConVarEnabled(Mod, "customcolor") then
  100.                                 render.SetColorModulation(0, 1, 0, 0.5)
  101.                             end
  102.                                 v:DrawModel()
  103.                             render.SetColorModulation(1, 1, 1)
  104.                             SetMaterialOverride(nil)
  105.                             render.SetBlend(0)
  106.                             render.SuppressEngineLighting(false)
  107.                             v:SetMaterial(mat)
  108.                         cam.IgnoreZ(false)
  109.                     cam.End3D()
  110.                 end
  111.             end
  112.         end
  113.     end
  114.     for k, v in pairs(XRayEnts) do
  115.         if v != nil then
  116.             if v and v:IsValid() then
  117.                 for _, ent in pairs(XRayEntTypes) do
  118.                     if string.match(v:GetClass(), ent.class) then
  119.                         local renderit = true
  120.                         if not ASP.Util.ModConVarEnabled(Mod, "drawdoors") then
  121.                             if string.match(v:GetClass(), "door") then
  122.                                 renderit = false
  123.                             end
  124.                         end
  125.                         if not ASP.Util.ModConVarEnabled(Mod, "drawnpcs") then
  126.                             if string.match(v:GetClass(), "npc") then
  127.                                 renderit = false
  128.                             end
  129.                         end
  130.                         if not ASP.Util.ModConVarEnabled(Mod, "drawprops") then
  131.                             if string.match(v:GetClass(), "prop") then
  132.                                 renderit = false
  133.                             end
  134.                         end
  135.                         if renderit then
  136.                             cam.Start3D(EyePos(), EyeAngles())
  137.                                 cam.IgnoreZ(true)
  138.                                     local mat = v:GetMaterial()
  139.                                     render.SuppressEngineLighting(true)
  140.                                     render.SetBlend(1)
  141.                                         if ASP.Util.ModConVarEnabled(Mod, "custommaterial") then
  142.                                             v:SetNoDraw(true)
  143.                                             SetMaterialOverride(Material(ASP.Util.GetModText(Mod, "material")))
  144.                                             v:SetMaterial("models/shiny")
  145.                                             render.SetBlend(0.5)
  146.                                         else
  147.                                             v:SetNoDraw(false)
  148.                                         end
  149.                                         if ASP.Util.ModConVarEnabled(Mod, "customcolor") then
  150.                                             render.SetColorModulation(ent.color.r / 255, ent.color.g / 255, ent.color.b / 255, 0.5)
  151.                                         end
  152.                                             v:DrawModel()
  153.                                         render.SetColorModulation(1, 1, 1)
  154.                                         SetMaterialOverride(nil)
  155.                                     render.SetBlend(0)
  156.                                     render.SuppressEngineLighting(false)
  157.                                     v:SetMaterial(mat)
  158.                                 cam.IgnoreZ(false)
  159.                             cam.End3D()
  160.                         end
  161.                     end
  162.                 end
  163.             else
  164.                 table.remove(XRayEnts, k)
  165.             end
  166.         else
  167.             table.remove(XRayEnts, k)
  168.         end
  169.     end
  170. end
  171.  
  172. function ASP.Util.InitXRayEnts()
  173.     XRayEnts = {}
  174.     table.Empty(XRayEnts)
  175.     for k, v in pairs(ents.GetAll()) do
  176.         for _, str in pairs(XRayEntTypes) do
  177.             if string.match(string.lower(v:GetClass()), string.lower(str.class)) then
  178.                 ASP.Util.AddXRayEntity(v)
  179.             end
  180.         end
  181.     end
  182. end
  183.  
  184. hook.Add("Think", "ASP.XRay.OnTurnedOff", function()
  185.     if not ASP.Util.IsConVarEnabled(Mod) then
  186.         if #XRayEnts > 0 then
  187.             RunConsoleCommand("rope_rendersolid", "1")
  188.             surface.PlaySound("items/nvg_off.wav")
  189.             for k, v in pairs(XRayEnts) do
  190.                 v:SetNoDraw(false)
  191.             end
  192.             table.Empty(XRayEnts)
  193.         end
  194.     end
  195. end)
  196.  
  197. hook.Add("OnEntityCreated", "ASP.XRay.AddXRayEntity", function(ent)
  198.     ASP.Data.EyePos = EyePos()
  199.     ASP.Data.EyeAngles = EyeAngles()
  200.     if ASP.Util.IsConVarEnabled(Mod) then
  201.         for _, str in pairs(XRayEntTypes) do
  202.             if ent and ent:IsValid() then
  203.                 if string.match(string.lower(ent:GetClass()), string.lower(str.class)) then
  204.                     ASP.Util.AddXRayEntity(ent)
  205.                 end
  206.             end
  207.         end
  208.     end
  209. end)
  210.  
  211. ASP.Util.AddCFGCheckBox(Mod, "Enable XRay", "enabled")
  212. ASP.Util.AddCFGSlider(Mod, "Max XRay Entities", "maxents", 10, 10, 1000)
  213. ASP.Util.AddCFGTextBox(Mod, "Override Material", "material", "models/shiny")
  214. ASP.Util.AddCFGCheckBox(Mod, "Custom Material", "custommaterial", 1)
  215. ASP.Util.AddCFGCheckBox(Mod, "Custom Color", "customcolor", 1)
  216. ASP.Util.AddCFGCheckBox(Mod, "Draw Doors", "drawdoors", 1)
  217. ASP.Util.AddCFGCheckBox(Mod, "Draw Players", "drawplayers", 1)
  218. ASP.Util.AddCFGCheckBox(Mod, "Draw Props", "drawprops", 1)
  219. ASP.Util.AddCFGCheckBox(Mod, "Draw NPCs", "drawnpcs", 1)
  220. ASP.Util.AddCFGCheckBox(Mod, "Only Spawned Props", "onlyspawnedprops", 0)
  221. ASP.Util.AddCFGCheckBox(Mod, "Tracer Lines (Barrelhack)", "drawlines", 1)
  222.  
  223. concommand.Add("asp_xray", function()
  224.     if GetConVar("asp_xray_enabled"):GetBool() then
  225.         RunConsoleCommand("asp_xray_enabled", "0")
  226.     else
  227.         RunConsoleCommand("asp_xray_enabled", "1")
  228.     end
  229. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement