Skip to content

Instantly share code, notes, and snippets.

@Lexicality
Created July 23, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lexicality/7549334a2f0d6f2197588c5d3f3a5bb6 to your computer and use it in GitHub Desktop.
Save Lexicality/7549334a2f0d6f2197588c5d3f3a5bb6 to your computer and use it in GitHub Desktop.
AddCSLuaFile()
DEFINE_BASECLASS( "base_anim" )
ENT.PrintName = "Portable Hole"
ENT.Author = "Lexi"
ENT.Spawnable = true
ENT.Category = "Fun + Games"
if ( SERVER ) then
function ENT:Initialize()
self:SetModel( "models/hunter/plates/plate1x1.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
end
return
end
function ENT:Initialize()
self.dumpster = ClientsideModel( "models/props_junk/trashdumpster02.mdl" )
self.dumpster:SetNoDraw( true )
self.dumpster:SetModelScale( 0.5 )
end
function ENT:OnRemove()
self.dumpster:Remove()
end
function ENT:DrawMask()
local pos = self:GetPos()
+ self:GetUp() * 1.6
+ self:GetForward() * -23.7
+ self:GetRight() * -23.7
local ang = self:GetAngles()
cam.Start3D2D( pos, ang, 0.25 )
surface.SetDrawColor( color_white )
surface.DrawRect( 0, 0, 190, 190 )
cam.End3D2D()
end
function ENT:DrawInterior()
self.dumpster:SetPos( self:GetPos() + self:GetUp() * -28 )
self.dumpster:SetAngles( self:GetAngles() )
render.SuppressEngineLighting( true )
cam.IgnoreZ( true )
self.dumpster:DrawModel()
cam.IgnoreZ( false )
render.SuppressEngineLighting( false )
end
function ENT:Draw()
self:DrawModel()
if ( halo.RenderedEntity() == self ) then
return
end
-- Reset everything to known good
render.SetStencilWriteMask( 0xFF )
render.SetStencilTestMask( 0xFF )
-- render.SetStencilReferenceValue( 0 )
render.SetStencilCompareFunction( STENCIL_ALWAYS )
render.SetStencilPassOperation( STENCIL_KEEP )
render.SetStencilFailOperation( STENCIL_KEEP )
render.SetStencilZFailOperation( STENCIL_KEEP )
render.ClearStencil()
-- Write successes to the stencil buffer
-- We go for successes here to allow proper z indexing
render.SetStencilEnable( true )
render.SetStencilReferenceValue( 1 )
render.SetStencilPassOperation( STENCIL_REPLACE )
-- Draw the face we want to use as a window
self:DrawMask()
-- Use the window
render.SetStencilPassOperation( STENCIL_KEEP )
render.SetStencilCompareFunction( STENCIL_EQUAL )
-- Draw our "interior"
self:DrawInterior()
-- Let everything render normally again
render.SetStencilEnable( false )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment