@name Fuwa Fuwa Tippy the Bunny-sama~
@persist [E P Dri B]:entity PWrk VSV Ign VelLL Mul Ntrpl Ear
@persist [Holos Clips]:table HolosSpawned HolosStep LastHolo TotalHolos
@model models/hunter/blocks/cube2x4x1.mdl

interval(90)

if(duped() | dupefinished())
{
    reset()
}

if(first())
{
    Ntrpl = 90/(500/33)
    
    E = entity()
    P = entity():isConstrainedTo()
    
    E:setMass(5000)
    E:propFreeze(0)
    E:setColor(0,0,0,0)
    
    rangerHitWater(1)
    rangerPersist(1)
    
    soundPlay("idl",0,"vehicles/diesel_loop2.wav")
    soundPlay("thr",0,"ambient/machines/turbine_loop_2.wav")
    soundPitch("idl",0)
    soundPitch("thr",0)
    
    B = holoCreate(900, E:toWorld(vec()), vec(), E:toWorld(ang(0, -90, 0)))
    holoParent(900, E)
    
    runOnLast(1)
    
    function number addHolo(Pos:vector, Scale:vector, Colour:vector4, Angles:angle, Model:string, Material:string, Parent:number)
    {
        if (holoRemainingSpawns() < 1) {error("This model has too many holos to spawn! (" + TotalHolos + " holos!)"), return 0}
        
        holoCreate(LastHolo, B:toWorld(Pos), Scale, B:toWorld(Angles))
        holoModel(LastHolo, Model)
        holoMaterial(LastHolo, Material)
        holoColor(LastHolo, vec(Colour), Colour:w())
        holoDisableShading(LastHolo,1)

        if (Parent > 0) {holoParent(LastHolo, Parent)}
        else {holoParent(LastHolo, B)}

        local Key = LastHolo + "_"
        local I=1
        while (Clips:exists(Key + I))
        {
            holoClipEnabled(LastHolo, 1)
            local ClipArr = Clips[Key+I, array]
            holoClip(LastHolo, I, holoEntity(LastHolo):toLocal(E:toWorld(ClipArr[1, vector])), holoEntity(LastHolo):toLocalAxis(E:toWorldAxis(ClipArr[2, vector])), 0)
            I++
        }
        
        return LastHolo
    }

    ##########
    # HOLOGRAMS
    

    #[   ]#    Holos[1, array] = array(vec(-39.5869, 0.0000, 36), vec(3.7030, 6.7496, 8.5298), vec4(255, 255, 255, 255), ang(0.0000, 0.0000, 0.0000), "hq_dome", "", 0)
    #[   ]#    Holos[2, array] = array(vec(-39.5870, 17.3090, 99.4050), vec(6.2210, 2.0020, 0.2500), vec4(229, 165, 192, 255), ang(-98.4230, -90.0000, 90.0000), "hq_sphere", "", 0)
    #[   ]#    Holos[3, array] = array(vec(-39.5870, 17.3090, 99.4050), vec(6.6874, 2.4628, 1.4375), vec4(255, 255, 255, 255), ang(-98.4226, -90.0000, 90.0000), "hq_dome", "", 0)
    #[   ]#    Holos[4, array] = array(vec(-23.7542, -13.1050, 68.4600), vec(1.3), vec4(0, 0, 0, 255), ang(), "hq_sphere", "", 0)
    #[   ]#    Holos[5, array] = array(vec(-39.5870, -17.3090, 99.4050), vec(6.6874, 2.4630, 1.4380), vec4(255, 255, 255, 255), ang(98.4230, -90.0000, 90.0000), "hq_dome", "", 0)
    #[   ]#    Holos[6, array] = array(vec(0.0000, 0.0000, 0.0000), vec(19.3403, 11.9044, 6.1677), vec4(255, 255, 255, 255), ang(0.0000, 0.0000, 0.0000), "hq_rcube_thick", "", 0)
    #[   ]#    Holos[7, array] = array(vec(-23.7540, 13.1050, 68.4600), vec(1.3), vec4(0, 0, 0, 255), ang(), "hq_sphere", "", 0)
    #[   ]#    Holos[8, array] = array(vec(-19.4240, 5.2350, 55.4460), vec(1.0000, 1.0000, 1.0000), vec4(0, 0, 0, 255), ang(0.0000, 90.0000, 58.2314), "hq_torus", "", 0)
    #[   ]#    Holos[9, array] = array(vec(-19.4240, -5.2353, 55.4460), vec(1.0000, 1.0000, 1.0000), vec4(0, 0, 0, 255), ang(0.0000, 90.0000, 58.2314), "hq_torus", "", 0)
    #[   ]#    Holos[10, array] = array(vec(-39.5870, -17.3090, 99.4050), vec(6.2206, 2.0020, 0.2500), vec4(229, 165, 192, 255), ang(-98.4230, 90.0000, 90.0000), "hq_sphere", "", 0)
    
    ##########
}

if(PWrk)
{
    Dri = P:driver()
    Act = P:driver():isValid()
    
    if(Act)
    {
        W = Dri:keyForward()
        A = Dri:keyLeft()
        S = Dri:keyBack()
        D = Dri:keyRight()
        Shi = Dri:keySprint()
        Spc = Dri:keyJump()
        R = Dri:keyReload()
        M1 = Dri:keyAttack1()
        M2 = Dri:keyAttack2()
        
        if(changed(R) & R)
        {
            Ign = !Ign
            soundStop("fail")
            soundPitch("thr",0)
            soundPlay("ignv",Ign ? 0.874 : 1.13, Ign ? "hl1/fvox/activated.wav" : "hl1/fvox/deactivated.wav")
        }
        
        if(changed(M1) & M1)
        {
            Ear++
            local EE = Ear % 2 ? holoEntity(2) : holoEntity(10)
            EE:soundPlay("shoot", 0.081, "garrysmod/balloon_pop_cute.wav")
            
            local TE = propSpawn("models/props_junk/watermelon01.mdl", EE:toWorld(vec(15, 0, 0)), (Dri:aimPos() - EE:pos()):toAngle(), 0)
            
            
            TE:setTrails(150, 0, 5, "trails/laser", vec(255), 255)
            TE:propGravity(0)
            TE:setColor(0, 0, 0, 0)
            TE:setMass(150)
            TE:applyForce(((Dri:aimPos() - TE:pos()):normalized() * 20000) * TE:mass())
            
            holoCreate(TE:id(), TE:pos(), vec(1.5))
            holoModel(TE:id(), "hq_sphere")
            holoDisableShading(TE:id(), 1)
            holoParent(TE:id(), TE)
        }
    }
    
    Mul += Ign ? 0.05 : -0.05
    Mul = clamp(Mul,0,1)
    if(changed(Mul))
    {
        soundPitch("idl",Mul*150)
    }
    
    VelLL = E:vel():length()
    DV = $VelLL
    
    if(changed(P))
    {
        PWrk = P:isValid()
    }
}else
{
    findByClass("prop_vehicle_prisoner_pod")
    findSortByDistance(E:pos())
    if(find():model() == "models/nova/airboat_seat.mdl" & find():owner() == owner())
    {
        P = find()
        P:setPos(E:toWorld(vec(0,-5,25)))
        P:setAng(E:toWorld(ang(0,180,0)))
        
        timer("parent",20)
    }
    if(clk("parent"))
    {
        stoptimer("parent")
        
        P:parentTo(E)
        
        rangerFilter(array(E,P))
        
        PWrk = 1
    }
}

if(Ign)
{
    VelL = E:velL()
    VSV = clamp(-E:velL():y()/7.5,-1500,1500)
    
    if(changed(VSV))
    {
        soundPitch("thr",abs(VSV))
    }
    
    GR = rangerOffset(75, E:pos() + (E:right() * clamp(VSV,0,1500)), vec(0,0,-1))
    FR = rangerOffset(25 + clamp(VSV,0,1500), GR:pos() + E:toWorldAxis(vec(0,0,10)), E:right())
    
    applyForce(((vec(0,0,(75- GR:distance()) * GR:hit()))*0.75 + (E:right() * (W-S) * (15 + Spc*4 +  Shi*6 + FR:hit() * 3)) - E:toWorldAxis(VelL * vec(0.025,0.006125,0.045))) * E:mass() * Ntrpl)
    applyAngForce(((ang(E:angVel():yaw() / 6 - (2 * !GR:hit()), (A-D) * 8,((Spc * -25 * (W-S)) + clamp((E:angles():roll() - 35) * FR:hit() * W,-90,0))  * (W|S))  - E:angles()*ang(1,0,1))*5 - E:angVel()/ang(2.5,2.5,2)) * E:mass() * 3 * Ntrpl)
    
    if(DV < -450)
    {
        Ign = 0
        soundStop("ignv")
        soundPitch("thr",0)
        soundPlay("crash",0.8,"vehicles/v8/vehicle_impact_heavy"+randint(1,4):toString()+".wav")
        soundPlay("fail",4.176,"hl1/fvox/hev_critical_fail.wav")
    }
}

if (!HolosSpawned)
{
    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()
        Clips:clear()
        HolosSpawned = 1
    }
}

