@name Doory
@inputs 
@outputs 
@persist WIDTH HEIGHT A Use ID Stuff:entity Blocks:array 
@persist [CornerPos1 CornerPos2]:vector Last:entity
@trigger 
interval(100)
runOnLast(1)

E = entity()

if (first()) {
    WIDTH = 4
    HEIGHT = 8
    
    for (P = 1,WIDTH) {
        for (I = 1,HEIGHT) {
            Props = propSpawn("models/hunter/plates/plate025x025.mdl",E:toWorld(vec(2,-29.53+P*11.812,-6.15+11.812*I)),1)
            Props:setAng(E:toWorld(ang(90,0,0)))
            
            Blocks:pushEntity(Props)
        
        }
    }
    
    Last = Blocks[WIDTH*HEIGHT,entity]
    
    Scale = vec(3,3,6) * 12
    
    Holo = holoCreate(1)
    
    holoScaleUnits(1,Scale)
    holoPos(1,entity():toWorld(vec(-30,0,40)))
    holoAng(1,entity():angles())
    holoColor(1,vec(255,255,255),100)
    holoParent(1,entity())
    
    CornerPos1 = Scale / 2
    CornerPos2 = -CornerPos1
    
    CornerPos1 = Holo:toWorld(CornerPos1)
    CornerPos2 = Holo:toWorld(CornerPos2)
    
    CornerScale = vec() + 1
    
    holoCreate(2)
    holoPos(2,CornerPos1)
    holoScaleUnits(2,CornerScale)
    holoParent(2,Holo)
    
    holoCreate(3)
    holoPos(3,CornerPos2)
    holoScaleUnits(3,CornerScale)
    holoParent(3,Holo)
    
    for (Box = 1,3) {holoColor(Box,vec4(0))}
}

findInBox(CornerPos1,CornerPos2)
findIncludeClass("player")
findSortByDistance(holoEntity(1):pos())
User = find()

if (User:isPlayer()) {Use = User:keyUse()} else {Use = 0}

if (changed(Use) & Use) {
    for (I = 1,WIDTH*HEIGHT,1) {
        if (User:aimEntity() == Blocks[I,entity]) {
            Blocks[I,entity]:setPos(Blocks[I,entity]:pos()-User:aimNormal()*2)
        }
    }
}

if (Last:pos() == vec()) {selfDestruct()}

if (last()) {propDeleteAll()}
