@name TF2 Turret
@outputs [E Me Turret]:entity [Amodels Models]:array Phase:string [Ang Angle]:angle Pos:vector Upgrade ModelIndex
@persist Array:array Distance Result:string Times Damage HoloDist Circle X Y T H:entity Ents:array Limit Head:string 
@persist K:entity Ks:array MENU
@model models/weapons/w_models/w_toolbox.mdl
if(first() | dupefinished()){
    runOnTick(1)
    runOnChat(1)
    E = entity()
    Me = owner()   
    Amodels = array("models/buildables/sentry1_heavy.mdl","models/buildables/sentry2_heavy.mdl","models/buildables/sentry3_heavy.mdl")
    Models = array("models/buildables/sentry1_blueprint.mdl","models/buildables/sentry1.mdl","models/buildables/sentry2.mdl","models/buildables/sentry3.mdl","models/buildables/sentry3_rockets.mdl")
    ModelIndex = 1
   
    Turret = holoCreate(1)
    holoParent(1, E)
    holoModel(1,Models[ModelIndex,string])
    holoCreate(0)
Phase = "Deploy"}
if(Phase == "Deploy"){
    Ang = (Me:eyeTrace():hitNormal():toAngle() + ang(90,0,0)):setYaw((Me:aimPos() - Me:pos() ):toAngle():yaw())
    holoPos(1, Me:aimPos())
    holoAng(1, Ang)
    if(Me:aimPos():distance(Me:pos()) >= 100) #| !inrange(Ang, ang(-45,-360,-45), ang(45,360,45)))
    {holoAnim(1, 1)}else{
        holoAnim(1, 0)
        if(Me:keyAttack1()){
            Phase = "Build 1"
            Angle = Ang
            Pos = Me:aimPos()
            holoModel(1,Amodels[ModelIndex,string])
            holoAnim(1,2)
            timer("build",5000)   
            holoEntity(1):soundPlay(50,50,"vo/engineer_autobuildingsentry01.wav")
            ModelIndex++
}}}elseif(Phase == "Active"){
   Pos = Turret:toWorld(vec(0,0,30))
    Ang = -Turret:toLocal((Me:aimPos() - Pos):toAngle())
    holoSetPose(1,"aim_pitch", Ang:pitch()) 
    holoSetPose(1,"aim_yaw", Ang:yaw())    
timer("test",3000)
    Upgrade = Me:keyAttack2()
    if(changed(Upgrade) & Upgrade & ModelIndex <= 3){
        holoModel(1, Amodels[ModelIndex,string])
        holoAnim(1, "upgrade")
        timer("build",2000)    
    ModelIndex++}
   if (owner():weapon():type()=="weapon_physcannon"){
Head="anim_attachment_RH" 
        holoCreate(5)
        holoPos(5,owner():attachmentPos(Head))
        holoAng(5,owner():attachmentAng(Head))
        holoPos(5,holoEntity(5):toWorld(vec(0,0,-2+(-1*0))))
        holoAng(5,holoEntity(5):toWorld(ang(0,10,(-1*10)-0)))
        holoParentAttachment(5,owner(),Head)
        holoModel(5,"models/weapons/w_models/w_wrangler.mdl")
        holoAlpha(5,255)
    holoScale(5,vec(1,1,1))
    holoAlpha(7,0)
owner():weapon():setColor(0,0,0,0)  
        holoCreate(3)
            holoModel(3,"hqicosphere2")
            holoAlpha(3,100)
            holoColor(3,vec(240,20,20))
            holoPos(3,Pos)
            holoScale(3,vec(10,10,10))
               Pos = Turret:toWorld(vec(0,0,30))
    Ang = -Turret:toLocal((Me:aimPos() - Pos):toAngle())
    holoSetPose(1,"aim_pitch", Ang:pitch()) 
    holoSetPose(1,"aim_yaw", Ang:yaw())    
   stoptimer("test")
if (first()) {T = 1 Limit = 10}
interval(1)
if (owner():keyAttack1()) {
H = propSpawn("models/props_c17/oildrum001_explosive.mdl",1)
T++
H:setMass(50000)
Ents[T,entity] = H
H:setPos(holoEntity(1):pos() + vec(0,25,75) + entity():forward()*24)
H:setAng(ang(90,0,80) + owner():angles())
H:propFreeze(0)
H:applyForce(owner():eyeAngles():forward()*100000000*H:mass())
H:applyAngForce(-H:angles() + ang(0,curtime()*10000000,900)*H:mass())
holoEntity(1):soundPlay(1000,1000,"/weapons/sentry_shoot.wav")
timer("boom",200)}
if (owner():keyReload()) {
Ents:propDelete()
T = 1}
}else{holoScale(5,vec(1,1,1))
holoAlpha(3,0)
 Ang = (Pos + vec(0,0,25) - Me:aimPos()):toAngle() + ang(0,90,0)
 holoSetPose(1,"aim_pitch", clamp(Ang:pitch(), 0, 0)) 
    holoSetPose(1,"aim_yaw", sin(curtime()*20)*90)    
    holoAlpha(5,0)
    interval(1)
    timer("check",1)
Distance = 200
Result = ""
Times = 100

Damage = 20
interval(2000)
if (clk("check")) {
    findInSphere(entity():pos(), Distance)
    GG = findClosest(entity():pos())
    Array = findToArray()
    for(I=1,Array:count()) {
        if(Array[I,entity]:isPlayer()) {
            if(Array[I,entity]:isAlive()) {
                if (Result != "whip") {     
                    print("test")             
Ent = propSpawn("models/props_c17/oildrum001_explosive.mdl",200)
Ent:applyForce(GG:pos())
#Ent:setPos(holoEntity(1):pos() + vec(0,25,75))
holoEntity(1):soundPlay(1000,1000,"/weapons/sentry_shoot.wav")}}}}}
timer("test",3000)}}
if(clk("build")){
holoModel(1, Models[ModelIndex,string])
Phase = "Active"}
if(clk("test")){
holoEntity(1):soundPlay(20,30,"weapons/sentry_scan.wav")}
if(clk("boom")){
H:propBreak()}
if(owner():weapon():type() == "weapon_crowbar"){
    holoCreate(7)
holoPos(7,owner():attachmentPos(Head))
holoAng(7,owner():attachmentAng(Head))
holoPos(7,holoEntity(5):toWorld(vec(0,0,-2+(-1*0))))
holoAng(7,holoEntity(5):toWorld(ang(0,10,(-1*10)-0)))
holoParentAttachment(5,owner(),Head)
holoAlpha(7,255)
holoModel(7,"models/weapons/c_models/c_jag/c_jag.mdl")
owner():weapon():setColor(0,0,0,0)}
else{holoAlpha(7,0)}
   if (owner():weapon():type()=="weapon_shotgun"){
        holoCreate(10)
        holoPos(10,owner():attachmentPos(Head))
        holoAng(10,owner():attachmentAng(Head))
        holoPos(10,holoEntity(10):toWorld(vec(0,0,-2+(-1*0))))
        holoAng(10,holoEntity(10):toWorld(ang(0,10,(-1*10)-0)))
        holoParentAttachment(10,owner(),Head)
        holoModel(10,"models/weapons/c_models/c_drg_pomson/c_drg_pomson.mdl")
        holoScale(10,vec(1,1,1))
        holoAlpha(10,255)
        owner():weapon():setColor(0,0,0,0)
}else{holoAlpha(10,0)}
if (first()) {Y = 1 Limit = 4}
if (owner():keyUse()) {
if (Y <= Limit) {
K = propSpawn("models/hunter/misc/sphere025x025.mdl",1)
Y++}
K:setMass(50000)
Ks[Y,entity] = K
K:setPos(owner():pos() + vec(0,25,75) + entity():forward()*24)
K:setAng(ang(90,0,80) + owner():angles())
K:propFreeze(0)
K:applyForce(owner():eyeAngles():forward()*100000000*K:mass())
K:applyAngForce(-K:angles() + ang(0,curtime()*10000000,900)*K:mass())
K:setAlpha(0)}
if (owner():keyReload()) {
Ks:propDelete()
Y = 1}


