@name Stealth
@inputs Button
@persist Body:array Cloaked Cloak Entry

runOnTick(1)


if (first() | duped()) {Entry = 0
    entity():setAlpha(0)}

if (Cloaked == 0 & Button == 1) 
{
    Body = entity():getConstraints()
    CurAlpha = Body:entity(Entry):getAlpha()
    if (CurAlpha > 0) {CurAlpha = CurAlpha - Body:count()*5
    Body:entity(Entry):setAlpha(CurAlpha)}
    
    if (Entry == Body:count() & Body:entity(Body:count()):getAlpha() == 0)
    {
        Cloaked = 1
        Entry = 0
        hint("Cloaking finished!",3)
    }
    else
    {
        Entry = Entry + 1
        if (Entry > Body:count()) {Entry = Entry - Body:count()}
    }
}

elseif (Cloaked == 1 & Button == 0) 
{
    Body = entity():getConstraints()
    DesAlpha = Body:entity(Entry):getAlpha()
    if (DesAlpha < 255) {
    DesAlpha = DesAlpha + Body:count()*5
    Body:entity(Entry):setAlpha(DesAlpha)}
    
    if (Entry == Body:count() & Body:entity(Body:count()):getAlpha() == 255)
    {
        Cloaked = 0
        Entry = 0
        hint("Decloaking finished!",3)
    }
    else
    {
        Entry = Entry + 1
        if (Entry > Body:count()) {Entry = Entry - Body:count()}        
    }
}