################
# > Gravgun: A gravity gun that lets you pick up all props and fire them insanely hard.
# > How to use: Look at a prop and press E to pick it up then right click to fire it.
################

@name Gravity Gun by Runeneo
@outputs Prop:entity Hold
runOnTick(10)

OA = owner():toWorld(owner():forward()+vec(100,0,50))
Fire = owner():keyAttack2()

if (Hold == 0 & owner():aimEntity():owner() == owner()) {
    Prop = owner():aimEntity()
    Prop:setMass(50000)
}

if (Hold == 0 & owner():keyUse() == 1) { 
    Hold = 1
    owner():soundPlay("pickup",0,"weapons/physcannon/physcannon_pickup.wav")
}

if (Hold == 1 & Fire == 0) {
    Prop:applyForce(((OA-Prop:pos())*10-Prop:vel())*Prop:mass())
}

if (Hold == 1 & Fire == 1) {
    owner():soundPlay("launch",0,"weapons/physcannon/superphys_launch1.wav")
    Prop:applyForce(((owner():aimPos()-owner():pos()))*Prop:mass()*20)
    Hold = 0
}
