@name Multi Parent by Freezebug
@inputs 
@outputs 
@persist ParentEnts:array BaseEnt:entity OW:string Parenting KU KR Ka2 I
@trigger 
runOnTick(1)
OW = owner():weapon():type()
KU = owner():keyUse()
KR = owner():keyReload()
Ka2 = owner():keyAttack2()
if (OW=="weapon_physcannon") {
if (changed(KU) & KU) {
if (owner():aimEntity():isValid() & !owner():aimEntity():isPlayer() & owner():aimEntity():owner()==owner()) {
if (owner():aimEntity()!=BaseEnt) {
ParentEnts:pushEntity(owner():aimEntity())
owner():aimEntity():setColor(255,0,0)
owner():aimEntity():setAlpha(150)
} else {print("[MP]: Error, Cannot set parent entity to base entity.")}
} else {print("[MP]: Entity was invalid, Or was player")}
    }
    if (changed(KR) & KR) {
    if (owner():aimEntity():isValid() & !owner():aimEntity():isPlayer() & owner():aimEntity():owner()==owner()) {
    BaseEnt:setAlpha(255)
    BaseEnt:setColor(255,255,255)
    BaseEnt = owner():aimEntity()
owner():aimEntity():setColor(0,255,0)
owner():aimEntity():setAlpha(150)

    } else {print("[MP]: Entity was invalid, Or was player")}
    }
    if (changed(Ka2) & Ka2) {
    if (BaseEnt) {
    if (ParentEnts:count() > 0) {
    if (!Parenting) {
        print("[MP]: -=Starting Parent!=-")
        Parenting = 1
        } else {print("[MP]: Already Parenting.")}
    } else {print("[MP]: Error, No entities selected to parent")}
    
} else {print("[MP]: Error, No entity selected to parent to.")}
}
}
if (changed(Parenting)) {I=0}
if (Parenting==1) {

I++
  print("[MP]: -=Parenting.... ["+I+"/"+ParentEnts:count()+"].")
ParentEnts:entity(I):setColor(255,255,255)
ParentEnts:entity(I):setAlpha(255)
ParentEnts:entity(I):parentTo(BaseEnt)

if (I==ParentEnts:count()) {
Parenting=0
BaseEnt:setColor(255,255,255)
BaseEnt:setAlpha(255)
I=0
  print("[MP]: -=Parent Complete=-")
ParentEnts:clear()
}
}

if (first()) {
print("-=====Instruction=====-")
print("Use the gravgun as the parent tool")
print("Aim at a prop and press R to set it as the base prop (What everything will be parented to)")
print("Aim at a prop and press your use key to select it to be parented.")
print("After setting up props, Right click and it will parent eveything.")
}
