@name Holo Maker
@inputs
@outputs
@persist HoloArray:array
@trigger

## Parent everything you want copied to this chip
## Reset the program by clicking the E2 tool on the chip again
## Type "/print holos" in chat (no quotes)
## Check console, copy from @name to the last "}", paste it over existing E2
     
if(first()|dupefinished()) {
    runOnChat(1)

    function fillHoloArray() {
        TempArray = entity():getConstraints()
        Counter = 1
        foreach(K,V:entity=TempArray){
            if(V:parent() == entity()) {
                HoloArray[Counter,entity]=V
                Counter++
            }
        }
    }

    function displayHoloArray() {
        EmptyLine = "#"
        NameLine = "@name Holos"
        ComLine = "## Prerendered holos, do not change anything"
        IfLine = "if(first()|dupefinished()) {"
        EntLine = "E=entity()"
        EndLine = "}"
        print(_HUD_PRINTCONSOLE,NameLine)
        print(_HUD_PRINTCONSOLE,EmptyLine)
        print(_HUD_PRINTCONSOLE,ComLine)
        print(_HUD_PRINTCONSOLE,EmptyLine)
        print(_HUD_PRINTCONSOLE,IfLine)
        print(_HUD_PRINTCONSOLE,EntLine)

        E = entity()

        foreach(K,V:entity=HoloArray){
            Hcreate = "holoCreate("+K+")"
            EntPos = round(E:toLocal(V:pos()),4):toString()
            Hpos = "holoPos("+K+",E:toWorld(
                vec("+EntPos:sub(2,EntPos:length()-1)+")))"
            EntAng = round(V:angles(),4):toString()
            Hang = "holoAng("+K+",E:toLocal(
                ang("+EntAng:sub(2,EntAng:length()-1)+")))"
            Hparent = "holoParent("+K+",E)"
            Hmodel = "holoModel("+K+",\""+V:model()+"\")"
            Hmaterial = "holoMaterial("+K+",\""+V:getMaterial()+"\")"
            EntColor = V:getColor():toString()
            Hcolor = "holoColor("+K+",vec(
                "+EntColor:sub(2,EntColor:length()-1)+"))"
            print(_HUD_PRINTCONSOLE,Hcreate)
            print(_HUD_PRINTCONSOLE,Hpos)
            print(_HUD_PRINTCONSOLE,Hang)
            print(_HUD_PRINTCONSOLE,Hparent)
            print(_HUD_PRINTCONSOLE,Hmodel)
            if (V:getMaterial()){
                print(_HUD_PRINTCONSOLE,Hmaterial)
            }
            print(_HUD_PRINTCONSOLE,Hcolor)
        }
        print(_HUD_PRINTCONSOLE,EndLine)
    }
}

if(lastSpoke() == owner()) {
    if(lastSaid() == "/print holos"){
        fillHoloArray()
        
    }
}
