Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. GlobalDoorTable = {}
  4.  
  5. ENT.Type = "anim"
  6. ENT.PrintName = "Key Card"
  7. ENT.Spawnable = true
  8. ENT.AdminOnly = false
  9. //ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
  10.  
  11. function ENT:Draw()
  12.     if(self.ShouldDrawScreen) then
  13.         self.RenderMat:SetTexture("$basetexture", self.RenderTarget)
  14.  
  15.         local vec = Vector(0, 1, 0)
  16.         vec:Rotate(Angle(0, self:GetAngles().y, 0))
  17.  
  18.         render.SetMaterial(self.RenderMat)
  19.         render.DrawQuadEasy(self:GetPos() + Vector(0, 0, 1) * 17, vec, 32, 32, Color(255,255,255,100), 180)
  20.     end
  21.  
  22.     self:DrawModel()
  23. end
  24.  
  25. function ENT:Think()
  26.     if(CLIENT) then
  27.         if(LocalPlayer():EyePos():DistToSqr(self:GetPos()) > 5000 || !self:GetNWBool("active")) then
  28.             self.ShouldDrawScreen = false
  29.         else
  30.             local door = self:GetNWEntity("door")
  31.             self.ShouldDrawScreen = true
  32.             render.PushRenderTarget(self.RenderTarget)
  33.             render.Clear(0,0,0,0)
  34.             self:SetNoDraw(true)
  35.  
  36.             cam.Start3D()
  37.                 render.RenderView({
  38.                     origin = door:GetPos() + door:GetForward() * -100,
  39.                     angles = (door:GetForward()):Angle(),
  40.                     x = 0, y = 0, w = 512, h = 512
  41.                 })
  42.             cam.End3D()
  43.             self:SetNoDraw(false)
  44.             render.PopRenderTarget()
  45.         end
  46.     end
  47. end
  48.  
  49. function ENT:Initialize()
  50.     self:SetModel("models/props_c17/TrapPropeller_Lever.mdl")
  51.  
  52.     self:PhysicsInit( SOLID_VPHYSICS )
  53.     self:SetMoveType( MOVETYPE_VPHYSICS )
  54.     self:SetSolid( SOLID_VPHYSICS )
  55.  
  56.     local phys = self:GetPhysicsObject()
  57.     if (phys:IsValid()) then
  58.         phys:Wake()
  59.     end
  60.  
  61.     if(SERVER) then
  62.         //self.Health = 3
  63.         self.DoorIndex = nil
  64.         self.DelayTimer = 0
  65.  
  66.         self:SetNWBool("active", false)
  67.     end
  68.  
  69.     if(CLIENT) then
  70.         self.RenderTarget = GetRenderTarget("door_render", 512, 512)
  71.         self.RenderMat = CreateMaterial("door_render_mat5", "Sprite", {["$translucent"] = 1})
  72.         self.ShouldDrawScreen = false
  73.     end
  74. end
  75.  
  76. function ENT:PhysicsCollide(coldata, phys)
  77.     if(coldata.HitEntity:GetClass() == "prop_door_rotating" && self.DelayTimer < CurTime()) then
  78.         if(self.DoorIndex == nil && (GlobalDoorTable[coldata.HitEntity:EntIndex()] == nil or !GlobalDoorTable[coldata.HitEntity:EntIndex()])) then
  79.             self.DoorIndex = coldata.HitEntity:EntIndex()
  80.             Entity(self.DoorIndex):EmitSound("doors/door_locked2.wav")
  81.             Entity(self.DoorIndex):Fire("Lock", "", "")
  82.             GlobalDoorTable[self.DoorIndex] = true
  83.             self:SetNWBool("active", true)
  84.             self:SetNWEntity("door", coldata.HitEntity)
  85.         elseif(coldata.HitEntity:EntIndex() == self.DoorIndex) then
  86.             Entity(self.DoorIndex):EmitSound("doors/door_wood_close1.wav")
  87.             Entity(self.DoorIndex):Fire("Unlock", "", "")
  88.             GlobalDoorTable[self.DoorIndex] = false
  89.             self.DoorIndex = nil
  90.             self:SetNWBool("active", false)
  91.         end
  92.  
  93.         self.DelayTimer = CurTime() + 0.5
  94.     end
  95. end
  96.  
  97. function ENT:OnRemove()
  98.     if(SERVER && self.DoorIndex) then
  99.         Entity(self.DoorIndex):EmitSound("doors/door_wood_close1.wav")
  100.         Entity(self.DoorIndex):Fire("Unlock", "", "")
  101.         GlobalDoorTable[self.DoorIndex] = false
  102.     end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement