@name VectorCrusherByGobo

@persist Ent:entity Tar:entity Mode Vector:vector AngForce:angle

@persist TimeStart ApplyForce:vector



if (first()) {  Ent = entity():isWeldedTo()

                Tar = noentity()

                Mode = 0 

                Vector = vec(0, 0, 0) 

                runOnTick(1) }



if (owner():isCrouch()) {

    findExcludeEntity(entity():isWeldedTo())

    findExcludeEntity(entity())

    findInSphere(owner():aimPos(), 100)

    Tar = findClosest(owner():aimPos())

    if (Tar != noentity() | Tar:id() != 1) {

        Mode = 1

    } else {

        hint("Could not find object.", 2)

    }

}



# Fly to Target

if (Mode == 1) {

    Vector = Tar:pos() + vec(0, 0, 150)

    Ent:applyForce(Ent:mass() * (Vector - Ent:massCenter()) - Ent:vel()*5)

    AngForce = -Ent:angles() * 500

    Ent:applyAngForce(AngForce + ($AngForce * 5))

    if (Ent:pos():distance(Tar:pos()) < 200) {

        Mode = 2

        TimeStart = curtime()

    }

}



# Hover above target

if (Mode == 2) {

    Vector = Tar:pos() + vec(0, 0, 150)

    ApplyForce = Ent:mass() * (Vector - Ent:massCenter())

    Ent:applyForce(ApplyForce + ($ApplyForce * 5))

    AngForce = -Ent:angles() * 500

    Ent:applyAngForce(AngForce + ($AngForce * 5))

}



# Slam down

if (Mode == 2 & curtime() > (TimeStart + 5)) {

    Ent:applyForce(vec(0, 0, -10000000))

    Mode = 3

    TimeStart = curtime()

}



# Turn off

if (Mode == 3 & curtime() > (TimeStart + 1)) {

    Mode = 0

}