@name A Totally Harmless Lantern
@inputs 
@outputs 
@persist P:array [Target]:entity Mode Number Death:entity
@model models/XQM/cylinderx1.mdl
interval(10)

if(first())
{
    Number = 10
    
    E = entity()
    E:setAng(ang(0,0,0))
    E:setPos(E:pos() + vec(0,0,5))
    E:propFreeze(1)
    
    holoCreate(1, E:massCenter()+E:up()*3, vec(1.5, 1.5, 2), E:angles(), vec(255,255,0))
    holoModel(1, "hqcylinder")
    
    holoCreate(2, E:massCenter()+E:up()*3, vec(1.55, 1.55, 0.3), E:angles(), vec(30,10,10))
    holoModel(2, "hqcylinder")
    
    holoCreate(3, E:massCenter()-E:up()*9, vec(1.55, 1.55, 0.3), E:angles(), vec(30,10,10))
    holoModel(3, "hqcylinder")
    
    holoCreate(4, E:massCenter()+E:up()*15, vec(1.55, 1.55, 0.3), E:angles(), vec(30,10,10))
    holoModel(4, "hqcylinder")
    
    holoCreate(5, E:massCenter()+E:up()*15, vec(1.3, 1.3, 1.3), E:angles(), vec(30,10,10))
    holoModel(5, "dome")
    
    holoCreate(6, E:massCenter()+E:up()*3+E:right()*8.7, vec(0.3, 0.1, 2), E:angles(), vec(30,10,10))
    holoModel(6, "hqcylinder")
    
    holoCreate(7, E:massCenter()+E:up()*3-E:right()*8.7, vec(0.3, 0.1, 2), E:angles(), vec(30,10,10))
    holoModel(7, "hqcylinder")
    
    holoCreate(8, E:massCenter()+E:up()*3-E:forward()*8.7, vec(0.1, 0.3, 2), E:angles(), vec(30,10,10))
    holoModel(8, "hqcylinder")
    
    holoCreate(9, E:massCenter()+E:up()*3+E:forward()*8.7, vec(0.1, 0.3, 2), E:angles(), vec(30,10,10))
    holoModel(9, "hqcylinder")
    
    Mode = 1
    
    for(I=1, 9)
    {
        holoParent(I, E)
    }
}

P = players()

if(Mode == 1)
{
    for(I=1, P:count())
    {
        Distance = P[I, entity]:pos():distance(entity():pos())
        if(P[I, entity]:aimEntity() == entity() & Distance < 100 & P[I, entity]:keyUse())
        {
            Target = P[I, entity]
            Mode = 2
        }
    }
}
elseif(Mode == 2)
{
    if(clk("A"))
    {
        Selection = randint(1, 1)
    }
    
    if(changed(Selection))
    {
        if(Selection == 1)
        {
            for(I=11, 16)
            {
                holoCreate(I, Target:pos() + vec(sin(I*60)*100, cos(I*60)*100, 5), vec(3, 3, 0.5), (holoEntity(I):pos()-Target:pos()):toAngle(), vec(255, 255,255))
                holoModel(I, "hqcylinder")
            
                holoCreate(I+6, Target:pos() + vec(sin(I*60)*100, cos(I*60)*100, 30), vec(0.1,0.1, 3), (holoEntity(I):pos()-Target:pos()):toAngle(), vec(255, 255,255))
                holoModel(I+6, "hqcylinder")
            
                holoCreate(I+12, Target:pos() + vec(sin(I*60)*100, cos(I*60)*100, 50), vec(2,2, 2), (holoEntity(I):pos()-Target:pos()):toAngle() + ang(0,180,0), vec(255, 255,255))
                holoModel(I+12, "models/props_c17/doll01.mdl")
            }
        
            holoEntity(11):soundPlay(1,soundDuration("/npc/fast_zombie/fz_scream1.wav") , "/npc/fast_zombie/fz_scream1.wav")
            
            timer("B", 3000)
        }
        
        if(Selection == 2)
        {
            holoEntity(10):soundPlay(1, 1, "/npc/fast_zombie/gurgle_loop1.wav")
            
            holoCreate(1, Target:pos() +Target:eye():setZ(0)*1000+ vec(0, 0, 5), vec(3, 3, 0.5), (holoEntity(1):pos()-Target:pos()):toAngle(), vec(255, 255,255))
            holoModel(1, "hqcylinder")
            
            holoCreate(2, Target:pos() +Target:eye():setZ(0)*1000 +vec(0,0, 30), vec(0.1,0.1, 3), (holoEntity(2):pos()-Target:pos()):toAngle(), vec(255, 255,255))
            holoModel(2, "hqcylinder")
            
            holoCreate(3, Target:pos() +Target:eye():setZ(0)*1000 +vec(0, 0, 50), vec(2,2, 2), (holoEntity(3):pos()-Target:pos()):toAngle()*-1, vec(255, 255,255))
            holoModel(3, "models/props_c17/doll01.mdl")
            
            timer("B", 200)
        }
        
        if(Selection == 3)
        {
            timer("B", 100)
        }
    }
    
    if(clk("B"))
    {
        entity():setAlpha(0)
        holoDeleteAll()
        
        holoCreate(10, Target:pos() - Target:forward()*100)
        holoParent(10, Target)
        holoVisible(10, players(), 0)
        
        if(Selection == 2)
        {
            soundPurge()
        }
        
        Selection = 0
        
        timer("A", Number * 1000)
        Number-=1
        
        if(changed(Number) & Number == 0)
        {
            Death = propSpawn("models/props_phx/ww2bomb.mdl", Target:pos(), 1)
            Death:propBreak()
            soundPurge()
            selfDestruct()
        }
        
    }
}

if(changed(Mode) & Mode == 2)
{
    entity():propFreeze(0)
    entity():applyForce(((Target:pos() - entity():pos())-vec(0,0,20))*-4000)
    entity():soundPlay(1,soundDuration("/npc/fast_zombie/fz_scream1.wav") , "/npc/fast_zombie/fz_scream1.wav")
    
    holoCreate(10, Target:pos() - Target:forward()*100)
    holoParent(10, Target)
    holoVisible(10, players(), 0)
    
    timer("A", 5000)
}
