@name Missile Turret
@inputs Fire
@outputs
@persist M1:entity M1R:ranger
runOnTick(1)
if(first()){
    holoCreate(1)
    holoModel(1,"models/props_phx/amraam.mdl")
    holoPos(1,entity():toWorld(vec(0,0,5)))
    #holoColor(1, vec(0,0,0),0)
    holoParent(1,entity())
}

if(owner():lastSaid() == "!on"){
    TargetPos = owner():aimPos()
    CurrentPos = entity():pos()
    Diff = TargetPos-CurrentPos 
    Dist = Diff:length()
    holoAng(1,Diff:toAngle()+ang(0,0,0))
}
if(changed(Fire)&Fire==1|clk("refire")){timer("fire",250)}

if (clk("fire")){
    M1=propSpawn("models/props_phx/amraam.mdl",holoEntity(1):pos(),holoEntity(1):angles(),0)
    M1:setTrails(10,0,1.5,"trails/smoke",vec(255,255,255),255)
    holoEntity(1):soundPlay(1,2,"weapons/ar2/npc_ar2_altfire.wav")
    timer("fire2",250)
}
M1:applyForce((M1:forward())*5000000)
M1R = rangerOffset(100, M1:pos(),M1:vel():normalized())

if (M1R:hit()==1){M1:propBreak()}
