@name Railgun
@inputs Fire
@outputs Refire
@persist S1 S2 S3 S4 Y1 Y2 Y3 Y4 P D:entity C F H:entity Ranger:ranger
@trigger 
@model models/hunter/plates/plate025x025.mdl
runOnTick(1)
if (first()){
    entity():setAlpha(0)
    #Barrel
    holoCreate(1)
    holoCreate(2)
    holoCreate(3)
    holoCreate(4)
    
    #firing pin
    holoCreate(5)
    
    #rotators
    holoCreate(6)
    holoCreate(7)
    holoCreate(8)
    holoCreate(9)
    holoCreate(10)
    holoCreate(11)
    holoCreate(12)
    holoCreate(13)
    
    
    
    holoModel(10,"models/props_phx/construct/metal_plate_curve180.mdl")
    holoModel(11,"models/props_phx/construct/metal_plate_curve180.mdl")
    holoModel(12,"models/props_phx/construct/metal_plate_curve180.mdl")
    holoModel(13,"models/props_phx/construct/metal_plate_curve180.mdl")
    
    holoScale(1,vec(16,0.1,0.10))
    holoScale(2,vec(16,0.1,0.10))
    holoScale(3,vec(16,0.1,0.10))
    holoScale(4,vec(16,0.1,0.10))
    
    holoScale(5,vec(3.5,0.08,0.08))
    
    holoScale(6,vec(0.05,0.05,0.05))
    holoScale(7,vec(0.05,0.05,0.05))
    holoScale(8,vec(0.05,0.05,0.05))
    holoScale(9,vec(0.05,0.05,0.05))
    
    holoScale(10,vec(0.05,0.05,0.05))
    holoScale(11,vec(0.05,0.05,0.05))
    holoScale(12,vec(0.05,0.05,0.05))
    holoScale(13,vec(0.05,0.05,0.05))
    
    holoPos(1,entity():toWorld(vec(-25,1,0)))
    holoPos(2,entity():toWorld(vec(-25,-1,0)))
    holoPos(3,entity():toWorld(vec(-25,0,1)))
    holoPos(4,entity():toWorld(vec(-25,0,-1)))
    
    holoPos(5,entity():toWorld(vec(-6,0,0)))
    
    holoPos(6,entity():toWorld(vec(-5,0,0)))
    holoPos(7,entity():toWorld(vec(-10,0,0)))
    holoPos(8,entity():toWorld(vec(-15,0,0)))
    holoPos(9,entity():toWorld(vec(-20,0,0)))
    
    holoPos(10,entity():toWorld(vec(-5,0,1)))
    holoPos(11,entity():toWorld(vec(-10,0,1)))
    holoPos(12,entity():toWorld(vec(-15,0,1)))
    holoPos(13,entity():toWorld(vec(-20,0,1)))
    
    holoAng(10,entity():toWorld(ang(90,0,0)))
    holoAng(11,entity():toWorld(ang(90,0,0)))
    holoAng(12,entity():toWorld(ang(90,0,0)))
    holoAng(13,entity():toWorld(ang(90,0,0)))
    
    holoParent(1,entity())
    holoParent(2,entity())
    holoParent(3,entity())
    holoParent(4,entity())
    holoParent(5,entity())
    
    holoParent(6,entity())
    holoParent(7,entity())
    holoParent(8,entity())
    holoParent(9,entity())
    
    holoParent(10,6)
    holoParent(11,7)
    holoParent(12,8)
    holoParent(13,9)
    Refire=1
    entity():setMass(100)
    
    
}
if (changed(Fire)&Fire==1&Refire==1){
    Refire=0
    S1=1
    P=1
    C=0
    soundPlay(1,1,"ambient/machines/thumper_startup1.wav")
    
    soundPlay(2,0,"ambient/nucleus_electricity.wav")
    soundPlay(3,7,"weapons/strider_buster/strider_buster_stick1.wav")
    soundPitch(3,25)
    soundPlay(5,7,"ambient/levels/citadel/advisor_enter_loop.wav")
    timer("S2",750)
    timer("S3",1250)
    timer("S4",2000)
    timer("fire",3500)
    
    
    holoCreate(14)
    holoCreate(15)
    holoCreate(16)
    holoCreate(17)
    
    holoPos(14,entity():toWorld(vec(-5,0,4)))
    holoPos(15,entity():toWorld(vec(-10,0,4)))
    holoPos(16,entity():toWorld(vec(-15,0,4)))
    holoPos(17,entity():toWorld(vec(-20,0,4)))
    
    holoAlpha(14,0)
    holoAlpha(15,0)
    holoAlpha(16,0)
    holoAlpha(17,0)
    
    holoParent(14,10)
    holoParent(15,11)
    holoParent(16,12)
    holoParent(17,13)
    holoEntity(14):setTrails(40,0,2,"trails/laser",vec(0,0,255),255)
}
if (clk("S2")){S2=1
    holoEntity(15):setTrails(40,0,2,"trails/laser",vec(0,0,255),255)}
if (clk("S3")){S3=1
    holoEntity(16):setTrails(40,0,2,"trails/laser",vec(0,0,255),255)}
if (clk("S4")){S4=1
    holoEntity(17):setTrails(40,0,2,"trails/laser",vec(0,0,255),255)
    }

if (S1==1){holoAng(6, holoEntity(6):toWorld(ang(0,0,Y1)))
    Y1+=0.15}
if (S2==1){holoAng(7, holoEntity(7):toWorld(ang(0,0,Y2)))
    Y2+=0.15}
if (S3==1){holoAng(8, holoEntity(8):toWorld(ang(0,0,Y3)))
    Y3+=0.15}
if (S4==1){holoAng(9, holoEntity(9):toWorld(ang(0,0,Y4)))
    Y4+=0.15}
if (S1==-1){holoAng(6, holoEntity(6):toWorld(ang(0,0,Y1)))
    Y1+=-0.15}
if (S2==-1){holoAng(7, holoEntity(7):toWorld(ang(0,0,Y2)))
    Y2+=-0.15}
if (S3==-1){holoAng(8, holoEntity(8):toWorld(ang(0,0,Y3)))
    Y3+=-0.15}
if (S4==-1){holoAng(9, holoEntity(9):toWorld(ang(0,0,Y4)))
    Y4+=-0.15}
if (Y1>60){Y1=60}
if (Y1<0){Y1=0}
if (Y2>60){Y2=60}
if (Y2<0){Y2=0}
if (Y3>60){Y3=60}
if (Y3<0){Y3=0}
if (Y4>60){Y4=60}
if (Y4<0){Y4=0}
if (P==1&Y4<60){holoPos(5,holoEntity(5):toWorld(vec(0.01*Y1/2,0,0)))}

if (clk("fire")){
    S1=-1
    S2=-1
    S3=-1
    S4=-1
    P=0
    F=0
    holoPos(5,entity():toWorld(vec(-6,0,0)))
    timer("refire",3500)
    soundPlay(3,1,"weapons/strider_buster/strider_buster_detonate.wav")
    soundPlay(4,1.5,"awp.wav")
    soundPlay(6,5,"ambient/levels/launch/warningsfx01_loop.wav")
    soundPlay(7,3,"weapons/cow_mangler_over_charge_shot.wav")
    soundPitch(4,145)
    soundPitch(3,125)
    D=propSpawn("models/hunter/plates/plate.mdl",entity():toWorld(vec(-15,0,0)),entity():toWorld(ang(0,180,0)),0)
    holoCreate(20)
    holoPos(20,D:toWorld(vec(-20,0,0)))
    holoParent(20,D)
    holoAlpha(20,0)
    rangerFilter(D)
    rangerFilter(entity())
    D:propGravity(0)
    D:setMass(100)
    D:applyForce((D:forward())*1000000^2)
    D:setTrails(50,0,4,"trails/laser",vec(255,255,255),255)
    D:setAlpha(0)
    entity():applyForce((entity():forward())*90000)
    timer("c",500)
}
D:applyForce((D:forward())*1000000^2)
if (clk("refire")){Refire=1
    holoDelete(14)
    holoDelete(15)
    holoDelete(16)
    holoDelete(17)
    holoDelete(20)
    D:propDelete()
    }
soundPitch(2,Y1*9)
soundPitch(6,Y1*6)
soundPitch(5,Y1+Y2+Y3+Y4*3)
    rangerFilter(D)
    rangerFilter(entity())

if (clk("c")){C=1}
Ranger = rangerOffset(300, D:pos(),D:vel():normalized())
if (Ranger:hit()&C==1){
    H=propSpawn("models/props_phx/amraam.mdl",D:pos(),0)
    H:propBreak()
    D:propBreak()}
