@name Elevator
@persist Pos:vector Ang:angle X Y Z Diff Prop:entity Ent:entity Ply:entity
@trigger all

if (first()) {
    runOnTick(1)
    runOnChat(1)
    Prop = entity():isWeldedTo()
    rangerFilter(Prop)
    Ent = rangerOffset(Prop:massCenter(), Prop:massCenter() - vec(0,0,200)):entity()
    X = Y = 0
}

if (chatClk()) {
    if (lastSpoke():pos():distance(Prop:massCenter()) < 50) {
        Msg = lastSaid():lower():explode(" ")
        if (Msg:string(1) == ".floor") {
            X = Msg:string(2):toNumber()
        }
    }
}

Y = X * 105

if (Z != Y) {
    Diff = sign(round(Y-Z))
    Z+=Diff*1.5
}

if (tickClk()) {
    Pos = (Ent:massCenter():setZ(Z+10) - Prop:massCenter()) * 2000
    Ang = Prop:angles() * -10000
    Prop:applyForce(Pos+$Pos*10)
    Prop:applyAngForce(Ang*3+$Ang*30)
}
