@name CRONUS BPROP ASSIGNMENT V2
@inputs Props:array Point:vector
@outputs BodyProps:array Scale
@persist P RP Vary [V1 V2]:vector Sizes:array

if(first()){
        #Base sizes
    Sizes:pushVector(vec(17,14,15))
    Sizes:pushVector(vec(36,36,1))
    Sizes:pushVector(vec(19,19,6))
    Sizes:pushVector(vec(24,12,12))
    Sizes:pushVector(vec(24,12,12))
    Sizes:pushVector(vec(24,12,12))
    Sizes:pushVector(vec(24,12,12))
    
    Vary=0.12 #Standard variance for prop sizes (%)
    
    runOnTick(1)
    Scale=1
}
rangerFilter(BodyProps)

    #BodyProp Status
if(!RP){
    M=1
    while(M<=Sizes:count() & !RP){
        Prop=BodyProps[M,entity]
        
            #Drop and search for new body prop if:
                #Prop has been destroyed
                #Prop has been frozen
                #Prop has been constrained
        if(!Prop|Prop:isFrozen()|Prop:hasConstraints()){
            RP=M
            Size=Sizes[RP,vector]*Scale
                V1=Size-(Size*Vary)
                V2=Size*(Vary+1)
        }
        M++
    }
}

    #Body prop replacement
if(RP){
    M=0
    while(P<=Props:count() & M<=10 & RP){
        Ent=Props[P,entity]
        
            #Body Prop Check
        BPC=1
        if(BodyProps:count()){
            Z=0
            while(Z<=Sizes:count()){
                if(Ent==BodyProps[Z,entity]){
                    BPC=0
                }
                Z++
            }
    }
        #True if not a body prop
    
    #Constraint check
    if(BPC){
        Count=Ent:hasConstraints()
                    
        if(!Count){
        #True if unconstrained
            Froze=Ent:isFrozen()
            
            if(!Froze){
            #True if unfrozen
                ECen=Ent:toWorld(Ent:boxCenter())
                    R=rangerOffset(Point,ECen)
                    
                if(R:entity()==Ent){
                #True of visible
                    if(BodyProps:count()){
                        EBox=Ent:boxSize()
                            SC=max(EBox,V2)==V2
                            SC+=min(EBox,V1)==V1
                    }
                    else{
                        SC=1
                    }
                    #True if good size
                }
            }
        }
    }
    
    if(BPC & SC){
        BodyProps[RP,entity]=Ent
        Ent:setMaterial("models/debug/debugwhite")
        Ent:setAlpha(255*(RP/7))
        RP=0
    }
    
    P++
    M++
    }
    if(P>=Props:count()){P=0}
}

    #Rescaling
if(BodyProps:count()){
    M=0
    Scaling=array()
    while(M<=Sizes:count()){
        Comp=Sizes[M,vector]
        Vec=BodyProps[M,entity]:boxSize()
        
        V=Vec/Comp
        Var=(V:x()+V:y()+V:z())/3
        Scaling[M,number]=Var
        M++
    }
    if(Scaling:count()==Sizes:count()){
        Scale=Scaling:average()
    }
}
