Portal Turret NPC

So I saw someone elses attempt at a portal turret npc and I thought I would give it a shot.
I got the laser to work, I got it to a good appropriate length, but I’m trying to make it like portal so when the turret is IDLE the laser turns off.

Heres what I have in the shared.lua:
[lua]
// basic setup.
ENT.Category = “Aperture Science”
ENT.Type = “point”
–ENT.Base = “base_anim”
ENT.PrintName = “Portal Turret”
ENT.Author = “Hax”
ENT.Contact = “icegamer0523@hotmail.com
ENT.Spawnable = false
ENT.AdminSpawnable = true
[/lua]

Heres init.lua:
[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include( “shared.lua” )

util.PrecacheModel( “models/props/turret_01.mdl”)

function ENT:Initialize( )
self.turret = ents.Create( “npc_turret_floor” )
self.turret:SetModel( “models/props/turret_01.mdl” )
self.turret:SetPos(self:GetPos())
self.turret:SetAngles(self:GetAngles())
self.turret:Spawn()
self.turret:Activate()
self:SetParent(self.turret)
end

function ENT:SpawnFunction( pl , tr )

if ( !tr.Hit ) then return end

local SpawnPos = tr.HitPos + tr.HitNormal

local turret = ents.Create( "npc_turret_floor" )
turret:SetModel( "models/props/turret_01.mdl" )
turret:SetPos( SpawnPos )
turret:Spawn()
turret:Activate()

return turret

end

function ENT:OnRemove( )
end

function ENT:Think( )
end
[/lua]

And heres the cl_init.lua (heres the laser code)
[lua]
include( ‘shared.lua’ )

function ENT:Draw()
self:DrawModel()
end

local function RenderScreenspaceEffects()

for k,v in pairs(ents.FindByClass( "npc_turret_floor" )) do
	if v:GetModel() == "models/props/turret_01.mdl" then
		cam.Start3D(EyePos(), EyeAngles())


			local attach = v:GetAttachment(v:LookupAttachment("eyes"))
			local attachlight = v:GetAttachment(v:LookupAttachment("light"))

			local tr = {}
			tr.start = attachlight.Pos
			tr.endpos = attach.Pos + ( attach.Ang:Forward() * 275 )
			tr.filter = v
			tr.mask = MASK_SHOT
			local trace = util.TraceLine( tr )

			local TexOffset = CurTime( ) * 3
			local Distance = trace.HitPos:Distance( attachlight.Pos )

			--v:SetRenderBoundsWS( trace.HitPos, attachlight.Pos, Vector()*8 )

			render.SetMaterial(Material("trails/laser"))
			render.DrawBeam(attachlight.Pos, trace.HitPos, 16, TexOffset, TexOffset + Distance / 8, Color(255, 0, 0, 255))

			local Size = 8+(math.random()*25)
			render.SetMaterial(Material("Sprites/light_glow02_add"))
			render.DrawQuadEasy(trace.HitPos, (EyePos() - trace.HitPos):GetNormal(), Size, Size, Color(255,0,0,255), 0)
			
		cam.End3D()
	end
end

end
hook.Add(“RenderScreenspaceEffects”,“PortalTurret.RenderScreenspaceEffects”,RenderScreenspaceEffects)

[/lua]

Any help is gladly appreciated :slight_smile:

You pasted the init.lua instead of the cl_init.lua. :v:

Edited the OP. Please help :slight_smile: