@name APFGL
@persist [E T H]:entity [V V1]:vector [A]:angle Act Act2
@persist [P N]:array L
@model models/flag/briefcase.mdl
if(first())
{
    runOnTick(1)
    
    E = entity()
    E:propFreeze(0)
    E:setMass(10000)
    E:setSkin(2)
    
    T = findPlayerByName("leif")
    
    Act = T:isValid()
    Act2 = 1
    
    H = holoCreate(1,E:toWorld(vec(0,0,15)))
    holoModel(1,"models/weapons/w_models/w_grenadelauncher.mdl")
    holoParent(1,E)
    
    function entity:turnTo(Tarang:angle)
    {
        local V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
        This:applyTorque((100*V-20*This:angVelVector())*This:inertia()/3)
    }
}

if(Act)
{
    applyForce((V1-(E:vel()/20))*E:mass())
    E:turnTo(A)
    holoAng(1,(T:shootPos()-vec(0,0,12.5)-holoEntity(1):pos()):toAngle())
    
    V = T:pos()+vec(0,0,30)
    
    local R = rangerOffset(50000,H:pos(),H:forward())
    if(R:entity()==T&!L&(V:setZ(0):distance(E:pos():setZ(0))<750))
    {
        H:soundPlay("sht",0.6,"weapons/grenade_launcher_shoot.wav")
        local TP = propSpawn("models/weapons/w_models/w_grenade_grenadelauncher.mdl",H:toWorld(vec(0,0,2)),H:angles(),0)
        TP:applyForce(TP:forward()*2000*TP:mass())
        TP:setTrails(150,0,2,"trails/laser",vec(255,0,0),255)
        P:pushEntity(TP)
        N:pushNumber(300)
        L = 1
        timer("ul",1500)
    }
    
    if(Act2)
    {
        V1 = vec(0,0,((V:z()+40)-E:pos():z())/5)+E:forward()*(V:setZ(0):distance(E:pos():setZ(0))>500)*50
        A = (V-E:pos()):toAngle():setPitch(0)
    }
}

if(clk("ul"))
{
    stoptimer("ul")
    L = 0
}

foreach(I,G:entity = P)
{
    N[I,number] = N[I,number]-1
    if(!N[I,number]|G:pos():distance(T:pos())<75)
    {
        propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",G:pos(),1):propBreak()
        G:propDelete()
    }
}
