@name Airburst grenade launcher
@inputs Fire LO Reload
@persist Dist Arm D1 D2
@persist E:entity
@persist V:vector
@persist M:string
@model models/hunter/blocks/cube025x025x025.mdl
if(first())
{
    runOnTick(1)
    Dist = fromUnit("m",3)
    M = "models/weapons/w_models/w_grenade_grenadelauncher.mdl"
    
    holoCreate(1)
    holoCreate(2)
    
    holoModel(1,"sphere")
    holoModel(2,"sphere")
    
    holoScale(2,vec(3))
    
    holoColor(1,vec(255,0,0),150)
    holoColor(2,vec(0,255,255),150)
    
    holoVisible(1,players(),0)
    holoVisible(1,owner(),1)
    holoVisible(2,players(),0)
    holoVisible(2,owner(),1)
}

LO = owner():keyUse()
Fire = owner():keyReload()

RD = owner():eyeTrace()
holoPos(1,RD:pos())

if(changed(LO)&LO)
{
    V = RD:pos()
    D1 = RD:distance()
    holoPos(2,V)
}
D2 = owner():shootPos():distance(RD:pos())

print(_HUD_PRINTCENTER,toString(D1)+" | "+toString(D2))

if(E:isValid())
{
    if(clk("shoot"))
    {
        stoptimer("shoot")
        E:propFreeze(0)
        E:applyForce(owner():eye()*50000*E:mass())
    }
    rangerFilter(E)
    ERD = rangerOffset(Dist+50,E:pos(),E:vel():normalized())
    if(!Arm)
    {
        Arm = E:pos():distance(V)<Dist+25
    }else
    {
        Det = E:pos():distance(V)>300
    }
    if(Det|ERD:hit())
    {
        Arm = 0
        Det = 0
        B = propSpawn("models/props_phx/amraam.mdl",E:pos(),1)
        B:propBreak()
        E:propBreak()
    }
}else
{
    if(changed(Fire)&Fire)
    {
        E = propSpawn(M,owner():shootPos()+owner():eye()*100,owner():eyeAngles(),1)
        E:setTrails(15,1,3,"trails/smoke",vec(255,0,0),255)
        
        timer("shoot",100)
    }
}
