@name Telekinetic Physgun
@inputs PYR:vector Num:wirelink
@outputs Take Move XYZ:vector Self:entity Pos:vector
#@outputs Ang:angle Pitch Roll Local:angle Ang1:angle AngDist:angle 
@persist Take Move Self:entity
@trigger 
runOnTick(1)
O=owner()
runOnChat(1)
Use=O:keyUse()
Phys=O:weapon():type():find("physgun")
A1=O:keyAttack1()
A2=O:keyAttack2()
Chat=O:lastSaid()
Crowbar=O:weapon():type():find("crowbar")
if((Use&Crowbar&!A1&!A2)|(chatClk()&Chat=="!tkp")){
    Take=!Take
    if(Take){Self=O:aimEntity()}
}
if(!O:isAlive()){
    
}
if(Crowbar){
    if(A2&!A1){
        Move-=1
    }elseif(A1&!A2){
        Move+=1
    }else{Move=0}
}
if(Chat=="t"){Move-=1} #draw closer
if(Chat=="y"){Move+=1} #push away
if(Take){
    R=50
    #Self=entity():isConstrainedTo()
    #if(!Self){Self=entity()}
    #runOnTick(1)
    #PYR=vec(0,0,0)
    P=PYR:x()
    Y=PYR:y()
    R=PYR:z()
    if(abs(R)==180){R=0}
    Time=1500/1000
    interval(Time*1000)
    InertiaConstant = 27.05307927383
    TargetAng=angnorm(ang(P,Y,R))
    Local=Self:toLocal(Self:angles())
    AngDist=TargetAng-Local
    #AngDist=TargetAng-Self:angles()
    Inertia = InertiaConstant*ang(Self:inertia():y(),Self:inertia():z(),Self:inertia():x())
    AngVel = AngDist/Time
    Self:applyAngForce(Inertia*(AngVel-Self:angVel()))

    Speed=100
    
    XYZ=O:shootPos()+O:eye()*(100+Move)
    
    Self:applyForce(Speed*(XYZ-Self:pos())-Self:vel()*Self:mass())
}
