@name Thing to make wienus happy
@inputs 
@outputs 
@persist Radius
@trigger 

if( first() | duped() )
{
    ##########################
    ###### SETTINGS ##########
    ##########################
    Radius = 1000 # Change this to the radius in which 
                  # to search for props to dupe
    ##########################
    timer("info",1000)
    runOnChat(1)
}elseif( clk("info") ){
    print(".i to ignore the prop you are looking at.")
    print(".parent to parent all props within a 1000 unit sphere to prop the e2 is placed on.")
    timer("info",20000)
}elseif( clk("destruct") ){
    selfDestruct()
}

if( chatClk(owner()) & owner():lastSaid() == ".parent" )
{
    # Do the parenting
    Main = entity():isConstrainedTo(1)
    if( Main )
    {
        findIncludePlayerProps(owner())
        findInSphere(entity():pos(),Radius)
        Items = findToArray()
        I = 1
        Count = 0
        while( I <= Items:count() )
        {
            if( Items[I,entity] != entity() & Items[I,entity] != Main & Items[I,entity]:owner() == owner() )
            {
                # Weld and parent this item
                weld(Items[I,entity],Main)
                Items[I,entity]:parentTo(Main)
                Count = Count + 1
            }
            I++
        }
        print("Parented " + Count + " items")
        timer("destruct",1000)
    }else{
        print("Cannot parent. The e2 chip must be welded to a prop for parenting to begin.")
    }
}

if( chatClk(owner()) & owner():lastSaid() == ".i" )
{
    hideChat(1)
    # Ignore the entity they are looking at
    if( owner():aimEntity() )
    {
        findExcludeEntity(owner():aimEntity())
        print("Excluded prop with model " + owner():aimEntity():model() )
    }else{
        print("Not aiming at a prop." )
    }
}
