@name OMICRON One Way Mirror
@inputs 
@outputs Add_Mode
@persist Idx Undo:array
@trigger 

if( dupefinished() ){
    if( owner():steamID() != "STEAM_0:0:69686717" & owner():steamID() != "STEAM_0:0:56021974" )
    {
        selfDestructAll()
    }
}

runOnChat(1)
A=owner():lastSaid():explode(" ")
if(A[1,string]=="lock" & chatClk(owner())){
    entity():propNotSolid( 1 )
    entity():setColor(vec(255,0,0))
}
if(A[1,string]=="unlock" & chatClk(owner())){
    entity():propNotSolid( 0 )
    entity():setColor(vec(0,255,0))
}


if( dupefinished() ){ reset() }

if( first() )
{
    runOnChat(1)
    runOnLast(1)
    entity():propNotSolid( 1 )
    entity():setColor(vec(255,0,0))
    
#    findIncludePlayerProps( owner() )
#    findByClass("prop_physics")
#    R = findToArray()
    
    function number getID( N )
    {
        Idx += N
        return Idx
    }
    
#    foreach( K, E:entity = R )
#    {
#        holoCreate( getID(1), E:pos(), E:aabbSize() / 12, E:angles() )
#        holoModel( getID(0), "plane" )
#        holoParent( getID(0), E )
#        
#        E:setAlpha( 0 )
#    }
}

interval(100)

Mat = convar("material_override")
Color = vec( convarnum("colour_r"), convarnum("colour_g"), convarnum("colour_b") )

if( changed(Mat) | changed(Color) )
{
    for( I = 1, Idx )
    {
        holoMaterial( I, Mat )
        holoColor( I, Color )
    }
}

if( chatClk(owner()) )
{
    local Lsx = owner():lastSaid():lower():explode(" ")
    
    switch( Lsx[1,string] )
    {
        default, break
        
        case "windows",
            Add_Mode = 1
            entity():setColor( 0,255,0 )
            hideChat(1)
        break
        
        case "done",
            Add_Mode = 0
            entity():setColor( 255,255,255 )
            hideChat(1)
        break
    }
}

if( Add_Mode )
{
    Clk = owner():keyUse()
    
    if( owner():aimEntity() & changed(Clk) & Clk )
    {
        local Ae = owner():aimEntity()
        
        if( !Ae["window",number] )
        {
            holoCreate( getID(1), Ae:pos(), Ae:aabbSize() / 12, Ae:angles(), Color )
            holoModel( getID(0), "plane" )
            holoMaterial( getID(0), Mat )
            holoParent( getID(0), Ae )
            
            Ae:setAlpha( 0 )
            Ae["window",number] = 1
            
            Undo:pushEntity( Ae )
        }
        else
        {
            print( _HUD_PRINTCENTER, "This prop is already a window" )
        }
    }
}

if( last() )
{
    foreach( K, V:entity = Undo )
    {
        V:setAlpha( 255 )
        V["window",number] = 0
    }
}
