Advertisement
NeatNit

sentsandbox.lua

Dec 3rd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.85 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. DEFINE_BASECLASS( "base_anim" )
  4.  
  5. ENT.PrintName = "Test Box"
  6. ENT.Author = "NeatNit"
  7. ENT.Category = "Fun + Games"
  8.  
  9. ENT.Spawnable = true
  10. ENT.AdminOnly = false
  11. ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
  12.  
  13. -- This is the spawn function. It's called when a client calls the entity to be spawned.
  14. -- If you want to make your SENT spawnable you need one of these functions to properly create the entity
  15. --
  16. -- ply is the name of the player that is spawning it
  17. -- tr is the trace from the player's eyes
  18. --
  19. function ENT:SpawnFunction( ply, tr, ClassName )
  20.  
  21.     if not tr.Hit then return end
  22.  
  23.     local SpawnPos = tr.HitPos + tr.HitNormal * 100
  24.     local SpawnAng = ply:EyeAngles()
  25.     SpawnAng.p = 0
  26.     SpawnAng.y = SpawnAng.y + 180
  27.  
  28.     local ent = ents.Create( ClassName )
  29.     ent:SetCreator( ply )
  30.     ent:SetPos( SpawnPos )
  31.     ent:SetAngles( SpawnAng )
  32.     ent:Spawn()
  33.     ent:Activate()
  34.  
  35.     ent:DropToFloor()
  36.  
  37.     return ent
  38.  
  39. end
  40.  
  41. --[[---------------------------------------------------------
  42.     Name: Initialize
  43. -----------------------------------------------------------]]
  44. function ENT:Initialize()
  45.     -- Sets what model to use
  46.     self:SetModel( "models/props_junk/wood_crate001a.mdl" )
  47.  
  48.     -- Physics stuff
  49.     self:SetMoveType( MOVETYPE_VPHYSICS )
  50.     self:SetSolid( SOLID_VPHYSICS )
  51.  
  52.     -- Init physics only on server, so it doesn't mess up physgun beam
  53.     if ( SERVER ) then self:PhysicsInit( SOLID_VPHYSICS ) end
  54.  
  55.     -- Make prop to fall on spawn
  56.     local phys = self:GetPhysicsObject()
  57.     if ( IsValid( phys ) ) then phys:Wake() end
  58. end
  59.  
  60. --[[---------------------------------------------------------
  61.     Name: OnTakeDamage
  62. -----------------------------------------------------------]]
  63. -- function ENT:OnTakeDamage( dmginfo )
  64.  
  65. --  -- React physically when shot/getting blown
  66. --  self:TakePhysicsDamage( dmginfo )
  67.  
  68. -- end
  69.  
  70. --[[---------------------------------------------------------
  71.     Name: Use
  72. -----------------------------------------------------------]]
  73. -- function ENT:Use( activator, caller )
  74. --  -- self:RebuildPhysics()
  75. --  -- self:Remove()
  76.  
  77. --  -- if ( activator:IsPlayer() ) then
  78.  
  79. --  --  -- Give the collecting player some free health
  80. --  --  local health = activator:Health()
  81. --  --  activator:SetHealth( health + 5 )
  82. --  --  activator:SendLua( "achievements.EatBall()" )
  83.  
  84. --  -- end
  85.  
  86. -- end
  87.  
  88. if ( SERVER ) then return end -- We do NOT want to execute anything below in this FILE on SERVER
  89.  
  90.  
  91. local sents = {}
  92. local drawing = false
  93.  
  94. function ENT:ShouldDraw()
  95.     return drawing or self == halo.RenderedEntity()
  96. end
  97.  
  98. function ENT:Draw()
  99.     if self:ShouldDraw() then self:DrawModel() return end
  100.     error("Why is this running?")
  101. end
  102.  
  103. function ENT:DrawTranslucent()
  104.     if self:ShouldDraw() then self:DrawModel() return end
  105.     sents[self] = true
  106. end
  107.  
  108. local mat_refract = Material("pp/morph/refract")
  109. local mat_copy = Material("pp/copy")
  110. local mat_blur = Material("pp/blurscreen")
  111. local tex_morph = render.GetScreenEffectTexture()
  112. local tex_store = render.GetMorphTex1()
  113.  
  114. hook.Add("PreDrawViewModel", "Draw morphed sents",function()
  115.     if not next(sents) then return end -- list is empty
  116.     drawing = true
  117.     mat_refract:SetTexture("$fbtexture", tex_store)
  118.     mat_refract:SetTexture("$normalmap", tex_morph)
  119.  
  120.     local r = TimedSin(0.5, 30, 225, 0)
  121.     local g = TimedSin(0.5, 30, 225, math.pi / 2)
  122.  
  123.  
  124.     for ent, _ in pairs(sents) do
  125.         render.CopyRenderTargetToTexture(tex_store)
  126.         render.UpdateScreenEffectTexture()
  127.  
  128.         render.PushRenderTarget(tex_morph)
  129.             render.Clear(128, 128, 128, 255, false, true)   -- keep depth, clear stencil
  130.  
  131.             render.SetStencilEnable(true)
  132.                 render.SetStencilTestMask(2)
  133.                 render.SetStencilWriteMask(2)
  134.                 render.SetStencilReferenceValue(2)
  135.  
  136.                 render.SetStencilCompareFunction(STENCIL_ALWAYS)
  137.                 render.SetStencilZFailOperation(STENCIL_ZERO)
  138.                 render.SetStencilPassOperation(STENCIL_REPLACE)
  139.  
  140.                 render.OverrideDepthEnable(true, false)
  141.                 ent:DrawModel()
  142.                 render.OverrideDepthEnable(false)
  143.  
  144.                 render.SetStencilCompareFunction(STENCIL_EQUAL)
  145.                 render.SetStencilPassOperation(STENCIL_KEEP)
  146.                 render.SetStencilFailOperation(STENCIL_KEEP)
  147.                 render.SetStencilZFailOperation(STENCIL_KEEP)
  148.  
  149.                 render.ClearBuffersObeyStencil(r, g, 128, 255, true)
  150.  
  151.                 render.SetStencilEnable(false)
  152.                 cam.Start2D()
  153.                     surface.SetDrawColor(128, 128, 128)
  154.                     surface.DrawOutlinedRect(0, 0, ScrW(), ScrH())
  155.                 cam.End2D()
  156.                 render.SetStencilEnable(true)
  157.  
  158.                 render.SetMaterial(mat_blur)
  159.                 mat_blur:SetTexture("$basetexture", tex_morph)
  160.                 for i = 20, 1, -1 do
  161.                     mat_blur:SetFloat("$blur", i)
  162.                     mat_blur:Recompute()
  163.                     render.DrawScreenQuad()
  164.                 end
  165.             render.SetStencilEnable(false)
  166.         render.PopRenderTarget()
  167.  
  168.         mat_copy:SetTexture("$basetexture", tex_store)
  169.         render.SetMaterial(mat_copy)
  170.         render.DrawScreenQuad()
  171.  
  172.         render.SetMaterial(mat_refract)
  173.         render.DrawScreenQuad()
  174.     end
  175.     sents = {}
  176.     drawing = false
  177. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement