@name Chaqua Player Mounted Nade Launcher
@inputs [GL1 GL2]:wirelink
@persist [E B O]:entity [Pos VVel]:vector [Ang AVel]:angle [P N]:array
@persist [Holos]:table HolosSpawned HolosStep LastHolo TotalHolos
@model models/props_c17/SuitCase001a.mdl

interval(50)

if(first() | duped())
{
    function number addHolo(Pos:vector, Scale:vector, Colour:vector4, Angles:angle, Model:string, Material:string, ParentNo:number)
    {        
        local Parent = (ParentNo > 0) ? holoEntity(ParentNo) : B

        holoCreate(1 + LastHolo, Parent:toWorld(Pos), Scale, Parent:toWorld(Angles))
        holoModel(1 + LastHolo, Model)
        holoMaterial(1 + LastHolo, Material)
        holoColor(1 + LastHolo, vec(Colour), Colour:w())
        holoParent(1 + LastHolo, Parent)
        
        return LastHolo
    }
    
    Holos[1, array] = array(vec(32.0000, 0.0000, 0.0000), vec(0.6000, 0.6000, 0.6000), vec4(255, 255, 255, 255), ang(90.0000, -0.0000, 0.0000), "hq_torus", "phoenix_storms/fender_chrome", 0)
    Holos[2, array] = array(vec(0.7210, 0.0000, 0.0000), vec(0.6000, 0.6000, 0.3470), vec4(255, 255, 255, 255), ang(90.0000, -0.0000, 0.0000), "hq_dome", "models/props_combine/metal_combinebridge001", 0)
    Holos[3, array] = array(vec(5.5932, 0.0000, 5.3222), vec(0.0610, 0.0610, 1.0000), vec4(255, 255, 255, 255), ang(-90.0000, -0.0000, 0.0000), "hq_cylinder", "phoenix_storms/fender_chrome", 0)
    Holos[4, array] = array(vec(-4.4867, 0.0000, 4.5214), vec(0.0610, 0.0610, 0.7095), vec4(255, 255, 255, 255), ang(79.0840, 0.0000, 0.0000), "hq_cylinder", "phoenix_storms/fender_chrome", 0)
    Holos[5, array] = array(vec(-14.2969, 0.0000, 6.4829), vec(0.3099, 0.3099, 0.3099), vec4(255, 255, 255, 255), ang(-45.0000, 0.0000, 0.0000), "hq_cylinder", "models/alyx/emptool_glow", 0)
    Holos[6, array] = array(vec(17.7340, 0.0000, 0.0000), vec(0.4500, 0.4500, 2.6000), vec4(255, 255, 255, 255), ang(90.0000, -0.0000, 0.0000), "hq_cylinder", "models/props_combine/metal_combinebridge001", 0)
    Holos[7, array] = array(vec(28.0000, 0.0000, 0.0000), vec(0.7500, 0.7500, 0.7500), vec4(255, 255, 255, 255), ang(90.0000, -0.0000, 0.0000), "hq_torus", "phoenix_storms/fender_chrome", 0)
    Holos[8, array] = array(vec(-7.6779, 0.0000, 0.0000), vec(0.7570, 0.7570, 1.4180), vec4(255, 255, 255, 255), ang(90.0000, -0.0000, 0.0000), "hexagon", "models/props_combine/metal_combinebridge001", 0)
    Holos[9, array] = array(vec(19.3017, -0.0000, 3.8349), vec(0.0610, 0.0610, 1.3200), vec4(255, 255, 255, 255), ang(-79.0836, 0.0000, -0.0000), "hq_cylinder", "phoenix_storms/fender_chrome", 0)
    Holos[10, array] = array(vec(-11.6028, 0.0000, 3.7889), vec(0.3284, 0.3284, 0.3284), vec4(255, 255, 255, 255), ang(-45.0000, 0.0000, 0.0000), "hq_cubinder", "models/props_combine/metal_combinebridge001", 0)
    Holos[11, array] = array(vec(-15.7150, 0.0000, 7.9010), vec(0.3280, 0.3280, 0.0276), vec4(255, 255, 255, 255), ang(-45.0000, 0.0000, 0.0000), "hq_cylinder", "models/props_combine/metal_combinebridge001", 0)
    
    LastHolo = 1
    
    TotalHolos = Holos:count()
    
    E = entity()
    
    O = owner()
    
    B = holoCreate(1, O:pos() + vec(0,0,110))
    holoColor(1,vec4())
    VVel = -(O:shootPos() + vec(0,0,40))/2
    
    rangerIgnoreWorld(1)
    rangerFilter(array(E, B, O))
    rangerPersist(1)
}

if(HolosSpawned)
{
    if(~GL1)
    {
        GL1:entity():setPos(B:pos())
        GL1:entity():setAng(B:toWorld(ang(90, 0, 0)))
        GL1:entity():setColor(vec4())
        GL1:entity():propNotSolid(1)
        timer("parent", 100)
    }
    
    if(clk("parent"))
    {
        GL1:entity():parentTo(B)
    }
    
    if(~GL2)
    {
        GL2:entity():setPos(B:pos())
        GL2:entity():setAng(B:toWorld(ang(90, 0, 0)))
        GL2:entity():setColor(vec4())
        GL2:entity():propNotSolid(1)
        timer("parent", 100)
    }
    
    if(clk("parent"))
    {
        GL2:entity():parentTo(B)
    }
    
    Pos = B:pos()
    VVel += $Pos / 2
    VVel *= 0.6
    
    Ang = B:angles()
    AVel += angnorm($Ang) / 1.5
    AVel *= 0.4
    
    TarVec = mix(O:shootPos() + vec(0,0,40),B:pos(),1/3)
    TarAng = mix((O:aimPos() - B:pos()):toAngle(), B:angles(), 1/3)
    TarAng = (O:aimPos() - B:pos()):toAngle()
    holoPos(1,TarVec + VVel)
    holoAng(1,TarAng + AVel)
    
    local S = O:keySprint() & O:keyWalk() & O:isAlive() & P:count() < 5 & propCanCreate()
    
    if(changed(S) & S)
    {
        #[
        GL1["Fire HEI", number] = S
        GL2["Fire HEI", number] = S
        ]#
        
        #local TE = propSpawn("models/sprops/geometry/sphere_12.mdl",B:toWorld(vec(32,0,0)),B:angles(),0)
        local TE = propSpawn("models/hunter/misc/sphere025x025.mdl",B:toWorld(vec(32,0,0)),B:angles(),0)
        TE:setTrails(128,0,3,"trails/laser",vec(200,225,225),255)
        TE:setMaterial("models/alyx/emptool_glow")
        TE:setMass(100)
        TE:applyForce(B:forward() * 1500 * TE:mass())
        #TE:propGravity(0)
        
        B:soundPlay("fire",1.55,"weapons/grenade_launcher/grenadefire/grenade_launcher_fire_1.wav")
        
        P:pushEntity(TE)
        N:pushNumber(80)
    }
    
    if(P:count() > 0)
    {
        if(changed(P:count()))
        {
            rangerFilter(array(E, O, B):merge(P))
        }
        
        foreach(I, TE:entity = P)
        {
            N[I,number] = N[I,number] - 1
            
            if(N[I,number] <= 0 | !TE:isValid() | TE:vel():length() < 1050)
            {
                if(TE:isValid())
                {
                    propSpawn("models/props_phx/mk-82.mdl",TE:pos(),1):propBreak()
                }
                TE:propDelete()
                N:remove(I)
                P:remove(I)
            }
        }
    }
}
else
{
    while (LastHolo <= Holos:count() & holoCanCreate() & perf())
    {
        local Ar = Holos[LastHolo, array]
        addHolo(Ar[1, vector], Ar[2, vector], Ar[3, vector4], Ar[4, angle], Ar[5, string], Ar[6, string], Ar[7, number])
        LastHolo++
    }
    
    if (LastHolo > Holos:count())
    {
        Holos:clear()
        HolosSpawned = 1
    }
}


