@name FailCake LaserEPortal4s Cube
@outputs Main:entity Current Before Max P Curry
@persist [G2 G3 G G6]:gtable Ranger:ranger
@trigger all
@model models/hunter/blocks/cube025x025x025.mdl
runOnTick(1)
runOnLast(1)

E = entity()

if(first() | duped()){

G = gTable("e2laser",1)
G2 = gTable("e2laser2",1)
G3 = gTable("e2laser3",1)
G6 = gTable("e2laser4",1)
hint("Made By FailCake",7)   
E:setMaterial("models/dog/eyeglass")

holoCreate(1)
holoModel(1,"hqtorus")
holoPos(1,E:toWorld(vec(0,0,0)))
holoAng(1,ang(90,0,90))
holoScaleUnits(1,vec(6,6,6))
holoColor(1,vec(90,90,90))
holoParent(1,E)
  
holoCreate(4)
holoModel(4,"hqcone")
holoPos(4,E:toWorld(vec(0,-2.5,0)))
holoAng(4,ang(90,0,90))
holoScaleUnits(4,vec(5,5,5))
holoColor(4,vec(90,90,90))
holoParent(4,E)

holoCreate(2)
holoModel(2,"hqcylinder")
holoPos(2,E:toWorld(vec(0,0,10)))
holoColor(2,vec(200,0,0))
holoScaleUnits(2,vec(1,1,10))
holoParent(2,E)
holoAlpha(2,0)
holoMaterial(2,"models/debug/debugwhite")

holoCreate(3)
holoModel(3,"hqcylinder")
holoPos(3,E:toWorld(vec(0,0,10)))
holoColor(3,vec(150,0,0))
holoScaleUnits(3,vec(1,1,10))
holoParent(3,E)
holoAlpha(2,0)
holoMaterial(3,"models/debug/debugwhite")

Current = G3["Cur",number]
Before = Current
G3["Cur",number] = G3["Cur",number] + 1
G2["Max",number] = Current

print("Current = " + Current)
print("Before = "+Before)
print("Max = " + G2["Max",number])
}

Before = Current
Main = G[Current,entity] 
Main2 = G6[Current,entity] 
Max = G2["Max",number]

if(Main == E | Main2 == E){
E:setColor(0,255,0) 

holoAlpha(2,255)
holoAlpha(3,255)

holoAng(2,holoEntity(1):angles())
holoAng(3,holoEntity(1):angles())

Ranger = rangerOffset(300,E:pos(),E:right())
D=round(Ranger:distance())


if(Ranger:hit()){
    
for(P=Before,Current + 1){
G6[P,entity] = Ranger:entity()
}


holoPos(2, E:toWorld(vec(0,-4,0))+E:right()*D/2)
holoScaleUnits(2, vec(-1,-1,-D*1.0415))

holoPos(3, E:toWorld(vec(0,-4,0))+E:right()*D/2)
holoScaleUnits(3, vec(0.5,0.5,D*1.0415))

}else{

holoPos(2, E:toWorld(vec(0,-8,0))+E:right()*D/2)
holoScaleUnits(2, vec(-1,-1,-D*1.0415))

holoPos(3, E:toWorld(vec(0,-8,0))+E:right()*D/2)
holoScaleUnits(3, vec(0.5,0.5,D*1.0415))

for(P2=Current,Max){
G6[P2,entity] = noentity()
}

}

}else{
holoAlpha(2,0)
holoAlpha(3,0)
E:setColor(255,0,0)
}

if(duped()){
selfDestructAll()    
}

if(owner() == noentity()){
selfDestructAll()         
}
