Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- GlobalDoorTable = {}
- ENT.Type = "anim"
- ENT.PrintName = "Key Card"
- ENT.Spawnable = true
- ENT.AdminOnly = false
- //ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
- function ENT:Draw()
- if(self.ShouldDrawScreen) then
- self.RenderMat:SetTexture("$basetexture", self.RenderTarget)
- local vec = Vector(0, 1, 0)
- vec:Rotate(Angle(0, self:GetAngles().y, 0))
- render.SetMaterial(self.RenderMat)
- render.DrawQuadEasy(self:GetPos() + Vector(0, 0, 1) * 17, vec, 32, 32, Color(255,255,255,100), 180)
- end
- self:DrawModel()
- end
- function ENT:Think()
- if(CLIENT) then
- if(LocalPlayer():EyePos():DistToSqr(self:GetPos()) > 5000 || !self:GetNWBool("active")) then
- self.ShouldDrawScreen = false
- else
- local door = self:GetNWEntity("door")
- self.ShouldDrawScreen = true
- render.PushRenderTarget(self.RenderTarget)
- render.Clear(0,0,0,0)
- self:SetNoDraw(true)
- cam.Start3D()
- render.RenderView({
- origin = door:GetPos() + door:GetForward() * -100,
- angles = (door:GetForward()):Angle(),
- x = 0, y = 0, w = 512, h = 512
- })
- cam.End3D()
- self:SetNoDraw(false)
- render.PopRenderTarget()
- end
- end
- end
- function ENT:Initialize()
- self:SetModel("models/props_c17/TrapPropeller_Lever.mdl")
- self:PhysicsInit( SOLID_VPHYSICS )
- self:SetMoveType( MOVETYPE_VPHYSICS )
- self:SetSolid( SOLID_VPHYSICS )
- local phys = self:GetPhysicsObject()
- if (phys:IsValid()) then
- phys:Wake()
- end
- if(SERVER) then
- //self.Health = 3
- self.DoorIndex = nil
- self.DelayTimer = 0
- self:SetNWBool("active", false)
- end
- if(CLIENT) then
- self.RenderTarget = GetRenderTarget("door_render", 512, 512)
- self.RenderMat = CreateMaterial("door_render_mat5", "Sprite", {["$translucent"] = 1})
- self.ShouldDrawScreen = false
- end
- end
- function ENT:PhysicsCollide(coldata, phys)
- if(coldata.HitEntity:GetClass() == "prop_door_rotating" && self.DelayTimer < CurTime()) then
- if(self.DoorIndex == nil && (GlobalDoorTable[coldata.HitEntity:EntIndex()] == nil or !GlobalDoorTable[coldata.HitEntity:EntIndex()])) then
- self.DoorIndex = coldata.HitEntity:EntIndex()
- Entity(self.DoorIndex):EmitSound("doors/door_locked2.wav")
- Entity(self.DoorIndex):Fire("Lock", "", "")
- GlobalDoorTable[self.DoorIndex] = true
- self:SetNWBool("active", true)
- self:SetNWEntity("door", coldata.HitEntity)
- elseif(coldata.HitEntity:EntIndex() == self.DoorIndex) then
- Entity(self.DoorIndex):EmitSound("doors/door_wood_close1.wav")
- Entity(self.DoorIndex):Fire("Unlock", "", "")
- GlobalDoorTable[self.DoorIndex] = false
- self.DoorIndex = nil
- self:SetNWBool("active", false)
- end
- self.DelayTimer = CurTime() + 0.5
- end
- end
- function ENT:OnRemove()
- if(SERVER && self.DoorIndex) then
- Entity(self.DoorIndex):EmitSound("doors/door_wood_close1.wav")
- Entity(self.DoorIndex):Fire("Unlock", "", "")
- GlobalDoorTable[self.DoorIndex] = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement