0xymoron

0xray - A Garry's Mod Propkill Xray

Sep 6th, 2015
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.17 KB | None | 0 0
  1. /*
  2.  
  3.     0xray - A simple & clean propkilling xray
  4.     by 0xymoron
  5.    
  6.     THIS IS PUBLICLY RELEASED, NO YOU DID NOT LEAK THIS.
  7.    
  8.     I got bored & decided to make this & release it.
  9.    
  10. */
  11.  
  12. local xray = {}
  13.  
  14. local g = table.Copy( _G )
  15. local r = g.debug.getregistry()
  16.  
  17. xray.Props = { -- Add models here
  18.     ["models/props/de_tides/gate_large.mdl"] = true,
  19.     ["models/props_combine/breendesk.mdl"] = true,
  20.     ["models/props_junk/sawblade001a.mdl"] = true,
  21.     ["models/props_junk/sawblade001a.mdl"] = true,
  22.     ["models/props_junk/TrashDumpster01a.mdl"] = true,
  23.     ["models/props_lab/blastdoor001c.mdl"] = true,
  24.     ["models/props_interiors/VendingMachineSoda01a.mdl"] = true,
  25.     ["models/props_c17/furnitureStove001a.mdl"] = true,
  26.     ["models/props_canal/canal_bars004.mdl"] = true,
  27.     ["models/props/de_train/lockers_long.mdl"] = true,
  28.     ["models/props/de_train/lockers001a.mdl"] = true,
  29.     ["models/props_c17/Lockers001a.mdl"] = true,
  30.     ["models/props_c17/FurnitureCouch001a.mdl"] = true,
  31.     ["models/props_phx/construct/metal_angle360.mdl"] = true,
  32.     ["models/props_phx/construct/plastic/plastic_angle_360.mdl"] = true,
  33.     ["models/props_phx/construct/glass/glass_angle360.mdl"] = true,
  34.     ["models/props_borealis/door_wheel001a.mdl"] = true,
  35.     ["models/props_wasteland/laundry_dryer002.mdl"] = true,
  36. }
  37.  
  38. xray.Hooks = {}
  39.  
  40. xray.Colors = {
  41.     ["Red"] = g.Color( 255, 0, 0 ),
  42.     ["SexyRed"] = g.Color( 205, 54, 54 ),
  43.     ["Blue"] = g.Color( 0, 52, 255 ),
  44.     ["Yellow"] = g.Color( 225, 205, 0 ),
  45.     ["White"] = g.Color( 255, 255, 255 ),
  46.     ["Green"] = g.Color( 0, 225, 0, 255 ),
  47.     ["Purple"] = g.Color( 255, 255, 0, 255 ),
  48.     ["Cyan"] = g.Color( 0, 255, 255, 255 ),
  49.     ["Grey"] = g.Color( 100, 100, 100, 255 ),
  50.     ["lightBlue"] = g.Color( 155, 205, 248 ),
  51.     ["lightGreen"] = g.Color( 174, 255, 0, 255 ),
  52.     ["iceBlue"] = g.Color( 116, 187, 251, 255 ),
  53. }
  54.  
  55. g.surface.CreateFont( "0xray_$HUD", { size = 25, weight = 0, antialias = true, shadow = false, font = "Tahoma" } )
  56.  
  57.  
  58. /************************
  59.  
  60.     Backend functions
  61.  
  62. *************************/
  63.  
  64. function xray.LoadProps()
  65.  
  66.     if !g.file.Exists( "0xray_props.txt", "DATA" ) then
  67.        
  68.         g.file.Write( "0xray_props.txt", g.util.TableToJSON( xray.Props ) )
  69.         g.chat.AddText( xray.Colors.lightBlue, "[0xray] ", xray.Colors.lightGreen, "Created prop list." )
  70.    
  71.     else
  72.        
  73.         xray.Props = g.util.JSONToTable( g.file.Read( "0xray_props.txt", "DATA" ) )
  74.         g.chat.AddText( xray.Colors.lightBlue, "[0xray] ", xray.Colors.lightGreen, "Loaded prop list." )
  75.    
  76.     end
  77.    
  78. end
  79.  
  80. function xray.SaveProps()
  81.    
  82.     if g.file.Exists( "0xray_props.txt", "DATA" ) then
  83.        
  84.         g.file.Write( "0xray_props.txt", g.util.TableToJSON( xray.Props ) )
  85.         g.MsgC( xray.Colors.SexyRed, "[0xray] Saved props list\n" )
  86.        
  87.     end
  88.  
  89. end
  90.  
  91. function xray.Add( model )
  92.  
  93.     xray.Props[model] = true
  94.     g.MsgC( xray.Colors.iceBlue, "[0xray] " )
  95.     g.MsgC( xray.Colors.White, "Added model '" .. model .. "' to props list\n" )       
  96.     xray.SaveProps()
  97.  
  98. end
  99.  
  100. function xray.Remove( model )
  101.    
  102.     xray.Props[model] = nil
  103.     g.MsgC( xray.Colors.Red, "[0xray] " )
  104.     g.MsgC( xray.Colors.White, "Removed model '" .. model .. "' to props list\n" )     
  105.     xray.SaveProps()
  106.    
  107. end
  108.  
  109. local hookName
  110. function xray.AddHook( Type, Function )
  111.  
  112.     hookName = g.tostring( Function )
  113.     xray.Hooks[Type] = hookName
  114.    
  115.     return g.hook.Add( Type, hookName, Function )  
  116.    
  117. end
  118.  
  119. /*********************
  120.    
  121.     Visual backend
  122.    
  123. **********************/
  124.  
  125. local trace = {}
  126. local ret
  127. function xray.IsVisible( ent )
  128.  
  129.     trace.start = g.LocalPlayer():GetShootPos()
  130.     trace.endpos = ent:GetPos() + g.Vector( 0, 0, 5 )
  131.     trace.filter = { g.LocalPlayer(), ent }
  132.     trace.mask = g.MASK_SHOT
  133.    
  134.     ret = g.util.TraceLine( trace )
  135.    
  136.     return ret.Fraction == 1
  137.    
  138. end
  139.  
  140. function xray.GetColor( ent )  
  141.  
  142.     if ent:GetVelocity():Length() != 0 then
  143.    
  144.         if !xray.IsVisible( ent ) then
  145.          
  146.             return g.Color( 200, 0, 0, 150 )
  147.            
  148.         else
  149.        
  150.             return g.Color( 0, 200, 0, 150 )
  151.            
  152.         end
  153.        
  154.     else   
  155.    
  156.         return g.Color( 200, 200, 0, 150 )
  157.        
  158.     end
  159.  
  160. end
  161.    
  162. /************************
  163.  
  164.     Hooked functions   
  165.    
  166. ************************/
  167.  
  168. local col
  169. local tracePos = {}
  170. local traceDraw
  171. local pos
  172. local mySpeed
  173. function xray.HUDPaint()
  174.    
  175.     for k, v in g.next, g.ents.GetAll() do 
  176.    
  177.         if v:IsPlayer() or xray.Props[v:GetModel()] then   
  178.        
  179.             -- Prop Chams
  180.             if xray.Props[ v:GetModel() ] then
  181.                
  182.                 col = xray.GetColor( v )
  183.  
  184.                 g.cam.Start3D( g.EyePos(), g.EyeAngles() )
  185.                     g.render.SuppressEngineLighting( true )
  186.                    
  187.                     v:SetColor( col )
  188.                    
  189.                     g.render.SetColorModulation( col.r / 255, col.g / 255, col.b / 255 )           
  190.                     g.render.SetBlend( col.a / 255 )
  191.                    
  192.                     r.Entity.SetMaterial( v, "models/debug/debugwhite" )
  193.                     r.Entity.DrawModel( v )
  194.                    
  195.                     g.render.SuppressEngineLighting( false )
  196.                 g.cam.End3D()      
  197.                
  198.             -- Player chams
  199.             elseif v:IsPlayer() && v:Alive() && v != g.LocalPlayer() && v:Team() != g.TEAM_SPECTATOR then
  200.    
  201.                 col = g.team.GetColor( v:Team() )  
  202.                 pos = v:GetPos():ToScreen()
  203.  
  204.                 g.cam.Start3D( g.EyePos(), g.EyeAngles() ) 
  205.                     g.render.SuppressEngineLighting( true )
  206.                    
  207.                     v:SetColor( col )
  208.                    
  209.                     g.render.SetColorModulation( col.r / 255, col.g / 255, col.b / 255 )           
  210.                     g.render.SetBlend( col.a / 255 )
  211.                    
  212.                     r.Entity.SetMaterial( v, "models/debug/debugwhite" )
  213.                     r.Entity.DrawModel( v )
  214.                    
  215.                     -- Laser to roof of map
  216.                     g.render.SetMaterial( g.Material( "trails/laser" ) )
  217.                     g.render.DrawBeam( v:GetShootPos(), v:GetPos() + g.Vector( 0, 0, 850 ), 30, 1, 1, g.Color( 255, 0, 255 ) )             
  218.                    
  219.                     g.render.SuppressEngineLighting( false )
  220.                 g.cam.End3D()
  221.                        
  222.                 -- Traditional XRay WordBox esp
  223.                 g.draw.WordBox( 1, pos.x - g.surface.GetTextSize( v:Nick() ) / 2, pos.y, v:Nick(), "default", g.Color( 0, 0, 0, 150 ), g.Color( 255, 255, 255, 255 ) )
  224.                
  225.             end
  226.            
  227.         else   
  228.        
  229.             continue
  230.            
  231.         end
  232.    
  233.     end
  234.    
  235.     r.Entity.SetMaterial( g.LocalPlayer():GetViewModel(), "models/wireframe" )
  236.     r.Entity.SetColor( g.LocalPlayer():GetViewModel(), xray.Colors.iceBlue )
  237.    
  238.     mySpeed = "Speed: " .. g.math.Round( g.LocalPlayer():GetVelocity():Length() )
  239.     g.draw.WordBox( 1, g.ScrW() / 2 - g.surface.GetTextSize( mySpeed ), 5, mySpeed, "0xray_$HUD", g.Color( 0, 0, 0, 150 ), g.Color( 255, 255, 255 ) )
  240.        
  241. end
  242.  
  243. function xray.CreateMove( cmd )
  244.    
  245.     if !g.LocalPlayer():IsOnGround() && g.LocalPlayer():GetMoveType() != g.MOVETYPE_LADDER then
  246.         cmd:SetButtons( g.bit.band( cmd:GetButtons(), g.bit.bnot( g.IN_JUMP ) ) )
  247.     end
  248.    
  249. end
  250.  
  251. /*************************
  252.    
  253.     Loading the script
  254.    
  255. *************************/ 
  256.  
  257. function xray.Start()  
  258.  
  259.     g.chat.AddText( xray.Colors.iceBlue, "[0xray] ", xray.Colors.White, "Loaded! ", xray.Colors.lightGreen, "Coded by 0xymoron @ mpgh.net" )
  260.     g.chat.AddText( xray.Colors.lightBlue, "[0xray] Commands - ", xray.Colors.Green, "0x_addmodel <model path> - 0x_removemodel <model path>" )
  261.     g.surface.PlaySound( "ambient/fire/ignite.wav" )
  262.  
  263.     xray.LoadProps()
  264.    
  265.     g.concommand.Add( "0x_addmodel", function( ply, cmd, tbl, args )
  266.         xray.Add( args )
  267.     end )
  268.    
  269.     g.concommand.Add( "0x_removemodel", function( ply, cmd, tbl, args )
  270.         xray.Remove( args )
  271.     end )
  272.    
  273.     xray.AddHook( "HUDPaint", xray.HUDPaint )
  274.     xray.AddHook( "CreateMove", xray.CreateMove )  
  275.    
  276. end
  277.  
  278. xray.Start()
Advertisement
Add Comment
Please, Sign In to add comment