@name SmartParent v2.0 [Jack]
@persist [ParentColor ChildColor]:vector [Props Colors]:table MR E On
if(first())
{
    ##### YOUR SETTINGS #####
    ParentColor = vec(255,0,0)
    ChildColor = vec(255,255,0)
    ##### YOUR SETTINGS #####
    runOnTick(1)    
    runOnChat(1)
    On = 1
}

if(tickClk() & On)
{
if(owner():weapon():type() == "weapon_physgun" & !owner():keyAttack1())
{
    E = owner():keyUse()
    MR = owner():keyAttack2()
    AimEnt = owner():aimEntity()
    Id = toString(AimEnt:id())
}

if(MR & $MR & AimEnt != Props["parent",entity] & AimEnt != noentity() & !AimEnt:isPlayer())
{
    soundPlay(1,0,"buttons/lightswitch2.wav")
    if(Props[Id,entity])
    {
        Props[Id,entity]:setColor(Colors[Id,vector])
        Props:remove(Id)
    }
    else
    {
        Colors[Id,vector] = AimEnt:getColor()
        AimEnt:setColor(ChildColor)
        Props[Id,entity] = AimEnt
    }
}

if(E & $E & !Props[Id,entity] & AimEnt != noentity() & !AimEnt:isPlayer())
{
    soundPlay(1,0,"buttons/button9.wav")
    if(Props["parent",entity] == AimEnt)
    {
        Props["parent",entity]:setColor(Colors["parent",vector])
        Props:remove("parent")
    }
    else
    {
        Props["parent",entity]:setColor(Colors["parent",vector])
        Colors["parent",vector] = AimEnt:getColor()
        AimEnt:setColor(ParentColor)
        Props["parent",entity] = AimEnt
    }
}
}

if(chatClk(owner()))
{
    if(lastSaid():lower() == "-parent")
    {
        soundPlay(1,0,"buttons/button1.wav")
        hideChat(1)
        foreach(K,V:entity = Props)
        {
            if(K != "parent")
            {
                V:parentTo(Props["parent",entity])
                V:setColor(Colors[K,vector])
                Props:remove(K)
            }
        }
        Props["parent",entity]:setColor(Colors["parent",vector])
        Props:remove("parent")
        hint("Parenting finished!",5)
    }
    elseif(lastSaid():lower() == "-deparent")
    {
        soundPlay(1,0,"buttons/button11.wav")
        hideChat(1)
        foreach(K,V:entity = Props)
        {
            V:deparent()
            V:setColor(Colors[K,vector])  
            Props:remove(K)  
        }
        hint("Props deparented!",5)
    }
    elseif(lastSaid():lower() == "-reset")
    {
        soundPlay(1,0,"buttons/button19.wav")
        hideChat(1)
        foreach(K,V:entity = Props)
        {
            V:setColor(Colors[K,vector])
        }
        hint("E2 Reseted!",5)
        reset()
    }
    elseif(lastSaid():lower() == "-remove")
    {
        soundPlay(1,0,"buttons/button19.wav")
        hideChat(1)
        hint("E2 Removed!",5)
        selfDestruct()
    }
    elseif(lastSaid():lower() == "-on")
    {
        hideChat(1)
        hint("Parenting on",5)
        On = 1
        entity():setColor(0,255,0)
    }
    elseif(lastSaid():lower() == "-off")
    {
        hideChat(1)
        hint("Parenting off",5)
        On = 0
        entity():setColor(255,255,255)
    }
}
