@name Controllable Melon
@inputs Cam:wirelink
@persist Snd:array
@persist [Pod E Driver]:entity
@persist V
if(first())
{
    runOnTick(1)
    
    Pod = entity():isConstrainedTo()
    if(Pod:type()!="prop_vehicle_prisoner_pod")
    {
        print("Spawn the E2 on a chair, please.")
        selfDestruct()
    }
    Pod:ejectPod()
    
    I=1
    Snd[I,string]="/common/bugreporter_failed.wav"
    I++
    Snd[I,string]="vo/npc/male01/question07.wav"
    I++
    Snd[I,string]="/vo/npc/male01/hacks01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/no01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/no02.wav"
    I++
    Snd[I,string]="/vo/npc/male01/ohno.wav"
    I++
    Snd[I,string]="/vo/npc/male01/ok01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/ok02.wav"
    I++
    Snd[I,string]="/vo/npc/male01/overhere01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/ow01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/ow02.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question02.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question03.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question04.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question05.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question06.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question07.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question08.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question09.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question10.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question11.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question12.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question13.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question14.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question15.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question16.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question17.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question18.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question19.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question20.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question21.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question22.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question23.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question24.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question25.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question26.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question27.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question28.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question29.wav"
    I++
    Snd[I,string]="/vo/npc/male01/question30.wav"
    I++
    Snd[I,string]="/vo/npc/male01/runforyourlife01.wav"
    I++
    Snd[I,string]="/vo/npc/male01/runforyourlife02.wav"
    I++
    Snd[I,string]="/vo/npc/male01/runforyourlife03.wav"
    I++
    Snd[I,string]="/vo/npc/male01/strider_run.wav"
    I++
}

Driver = Pod:driver()
Active = Driver:isValid()
Shift = Driver:keySprint()
Space = Driver:keyJump()
W = Driver:keyForward()
A = Driver:keyLeft()
S = Driver:keyBack()
D = Driver:keyRight()
Spc = changed(Space)&Space
M1 = Driver:keyAttack1()
Alt = Driver:keyWalk()

if(changed(Active))
{
    if(Active)
    {
        E = propSpawn("models/props_junk/watermelon01.mdl",Pod:toWorld(vec(0,50,0)),0)
        timer("snd",500)
    }else
    {
        E:propBreak()
        stoptimer("snd")
        soundStop("snd")
    }
    Cam["Activated",number] = Active
}
if(Active)
{
    if(changed(M1)&M1)
    {
        E:soundPlay("expl",1.7,"vo/npc/male01/runforyourlife02.wav")
        soundPitch("expl",150)
        timer("expl",1700)
    }
    
    if(clk("expl"))
    {
        stoptimer("expl")
        propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",E:pos(),1):propBreak()
        E:propBreak()
    }
    
    if(clk("snd"))
    {
        stoptimer("snd")
        timer("snd",random(3000,7500))
        soundStop("snd")
        E:soundPlay("snd",5.99,Snd[randint(Snd:count()),string])
        soundPitch("snd",150)
    }
    
    if(changed(Alt)&Alt)
    {
        V = !V
    }
    
    Cam["Position",vector] = E:pos()-(Driver:eye()*150*V)
    Cam["Angle",angle] = Driver:eyeAngles()
    
    if(!E:isValid())
    {
        Pod:hintDriver("melon is ded",5)
        Pod:ejectPod()
    }
    if(Spc)
    {
        E:applyForce(vec(0,0,250)*E:mass())
    }
    E:applyForce(((Driver:eyeAngles():right()*(D-A)*(6+Shift*10))+(Driver:eye()*(W-S)*(6+Shift*10)))*E:mass())
    
    if(Pod:pos():distance(E:pos())>750)
    {
        local Vec = E:pos()+vec(0,0,200)-Pod:pos()
        Pod:setPos(Pod:pos()+Vec:normalized()*50)
    }
}

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