@name Defense Sentry
@persist Num Radius Missile:entity Intruder Block
@model models/xeon133/offroad/off-road-40.mdl
if(first()){
    #soundPlay(1,0,"/weapons/sentry_scan.wav")
    #timer("replay",3400)
    I=1
    ## Barrel Base
    holoCreate(I)
    holoModel(I, "hq_sphere")
    holoPos(I, entity():toWorld(vec(0.0000, 0.0000, 52.5668)))
    holoAng(I, entity():toWorld(ang(0.0000, 0.0000, 0.0000)))
    holoScale(I, vec(2.2500, 2.2500, 2.2500))
    holoColor(I, vec(178, 178, 178), 255)
    holoMaterial(I, "phoenix_storms/gear")
    
    ##
    I++
    holoCreate(I)
    holoModel(I, "models/props_phx/ww2bomb.mdl")
    holoPos(I, entity():toWorld(vec(21.6875, 0.0000, 46.2926)))
    holoAng(I, entity():toWorld(ang(0.0000, 0.0000, 0.0000)))
    holoScale(I, vec(1.0000, 1.0000, 1.0000))
    holoColor(I, vec(255, 255, 255), 255)
    holoParent(I, 1)
    

    I++
    ## 
    holoCreate(I)
    holoModel(I, "hexagon")
    holoPos(I, entity():toWorld(vec(-24.9814, 0.0000, 0)))
    holoAng(I, entity():toWorld(ang(90.0000, 0.0000, 0.0000)))
    holoScale(I, vec(1.5000, 1.5000, 3.5490))
    holoColor(I, vec(79, 79, 79), 255)
    holoMaterial(I, "phoenix_storms/gear")
    holoParent(I, entity())


    I++
    ## 
    holoCreate(I)
    holoModel(I, "hq_tube")
    holoPos(I, entity():toWorld(vec(20.5448, 0.0000, 52.5670)))
    holoAng(I, entity():toWorld(ang(90.0000, 0.0000, 0.0000)))
    holoScale(I, vec(1.5000, 1.5000, 5.0272))
    holoColor(I, vec(178, 178, 178), 255)
    holoMaterial(I, "phoenix_storms/gear")
    holoParent(I, 2)


    I++
    #entity():setAlpha(0)
 Radius = 1000
 runOnTick(1)
 holoCreate(200)
 holoAlpha(200,0)
 holoEntity(200):setTrails(150,250,10,"trails/laser",teamColor(owner():team()),255)
}

if(clk("replay")){
 stoptimer("replay")
 timer("replay",3400)
 soundPlay(1,0,"/weapons/sentry_scan.wav")   
}

Num+=2
entity():setAng(ang(90,Num,0))
holoPos(200,entity():pos()+vec(cos(Num)*Radius,sin(Num)*Radius,30))

if(findCanQuery()){
    findByClass("player")
    findExcludePlayer(owner())
    findSortByDistance(entity():pos())
    if(find()!=noentity()&find():pos():distance(entity():pos())<Radius){
        Intruder = 1
}else{Intruder = 0}
}

holoPos(1, entity():toWorld(vec(-52.5668, 0.0000, 0)))

if(Intruder&!first()){
 holoAng(1,((find():attachmentPos("eyes")-vec(0,0,10))-holoEntity(1):pos()):toAngle())
 if(!Block){
 Block=1
 timer("unblock",1300)
 #Missile shooting
 if(!Missile:isValid()&find():isAlive()&find():pos():distance(entity():pos())<Radius){
 propSpawnEffect(0)
 Missile = propSpawn("models/props_phx/ww2bomb.mdl",holoEntity(2):pos(),holoEntity(2):angles(),1)
 Missile:setTrails(100,0,10,"trails/laser",teamColor(owner():team()),255)
 soundPlay(2,0,"/weapons/sentry_rocket.wav")
}
}
}else{holoAng(1,ang(cos(Num/10)*15,Num/3,0))}

if(clk("unblock")){
 stoptimer("unblock")   
 Block = 0
}

if(Missile:isValid()){
    Ranger = rangerOffset(75,Missile:pos(),Missile:forward())
    Missile:setPos(Missile:pos()+Missile:forward()*200)
    if(Ranger:hit()|Missile:pos():distance(entity():pos())>Radius+500){
     Missile:propBreak()   
    }
}
