@name MultIndexing Test
@inputs 
@outputs [Units Unit TempArray]:array
@outputs [A E Crouch KA2 KA1 Scale]
@outputs [Pos AimPos TempVec]:vector
@outputs [Ang]:angle
@outputs [AimEnt]:entity
@persist 
@trigger 
interval(100)

if($A){
    Unit=glonDecode(Units[A,string])
    if(Unit[1,number]==1){
        holoCreate(A*10)
        holoCreate(A*10+1)
        holoCreate(A*10+2)
        holoCreate(A*10+3)
        
        holoScaleUnits(A*10,vec(7,4,2)*Scale)
        holoScaleUnits(A*10+1,vec(4,3,2)*Scale)
        holoScaleUnits(A*10+2,vec(4,1,1)*Scale)
        holoScaleUnits(A*10+3,vec(8,8,0.01)*Scale)
        
        holoModel(A*10+3,"hqtorus2")
        
        for(I=A*10,A*10+3){
            holoMaterial(I,"models/debug/debugwhite")
        }
        for(I=3,30){
            Unit[I,number]=1
        }
        Units[A,string]=glonEncode(Unit)
    }
}
for(I=1,A){
    Unit=array()
    Unit=glonDecode(Units[I,string])
    if(Unit[1,number]==1){
        Pos=Unit[2,vector]
        Ang=Unit[3,angle]
        Unit[4,vector]=Pos+Ang:forward()*100
        Unit[5,angle]=(Unit[4,vector]-holoEntity(I*10+1):pos()):toAngle()
        holoPos(I*10,Pos) 
        holoAng(I*10,Ang)
        holoPos(I*10+1,holoEntity(I*10):toWorld(vec(-1,0,0.75)*Scale))
        holoAng(I*10+1,Unit[5,angle]:setPitch(Ang:pitch()))
        holoPos(I*10+2,holoEntity(I*10+1):toWorld(vec(2,0,0.5)*Scale))
        holoAng(I*10+2,Unit[5,angle])
        if($KA1&KA1){
            if((AimPos-Pos):length()<10){
                Unit[7,number]=1
                holoEntity(I*10):soundPlay(I,1,"ambient/water/drip1.wav")
            }
            elseif(!Crouch){
                Unit[7,number]=0
            }
        }
        if($KA2&KA2&Unit[7,number]){
            Unit[8,vector]=AimPos
        }
        Ranger1=rangerOffset(Pos+vec(0,0,3)*Scale,holoEntity(I*10):toWorld(vec(10,10,3)*Scale))
        Ranger2=rangerOffset(Pos+vec(0,0,3)*Scale,holoEntity(I*10):toWorld(vec(10,-10,3)*Scale))
        TempVec=(Ranger1:position()+Ranger2:position())/2
        Unit[3,angle]=(TempVec-(Pos+vec(0,0,3)*Scale)):toAngle()
        Unit[3,angle]=Unit[3,angle]-ang(0,holoEntity(I*10):bearing(Unit[8,vector])*0.1,0)
        TempMult=(Unit[8,vector]-Pos):length()*0.1
        TempMult=clamp(TempMult,0,3)
        if(TempMult<0.5){TempMult=0}
        Unit[2,vector]=Unit[2,vector]+Ang:forward()*TempMult*Scale
        holoAlpha(I*10+3,Unit[7,number]*255)
        holoPos(I*10+3,Pos)

        
        Units[I,string]=glonEncode(Unit)
    }
}
E=owner():keyUse()
AimEnt=owner():aimEntity()
AimPos=owner():aimPos()
Crouch=owner():isCrouch()
KA2=owner():keyAttack2()
KA1=owner():keyAttack1()
if($E&E&AimEnt==entity()){
    TempArray=array()
    TempArray[1,number]=1
    TempArray[2,vector]=entity():pos()
    Units:pushString(glonEncode(TempArray))
}
A=Units:count()
