@name Prop Defense
@inputs 
@outputs Intercept:vector [Alert]:entity Dist Gun
@persist W:array
@trigger 
#@model models//props_combine/breenglobe.mdl
@model models/Roller.mdl
Time=30/1000
interval(Time*1000)
Own=entity():owner()


for(C=1,players():count()){
    if(players()[C,entity]:aimEntity()==Own){Alert=players()[C,entity]}

}
E=entity()
#if(!E){selfDestruct() print("stick me onto a prop!")}

if(Alert){
        
    if(Alert:aimEntity()==Own){
        Intercept=(Alert:aimPos()-Alert:shootPos())*0.9+Alert:shootPos()
        Dist=Own:shootPos():distance(Intercept)
    }
    if((Alert:aimEntity()==Own|Alert:aimEntity()==E)&Dist>25){
        
        #holoCreate(1,Intercept)
    }else{
        Intercept=vec()
        #holoDelete(1)
    }
}



entity():setAlpha(0)
Ball="prop_combine_ball"
Frag="npc_grenade_frag"
RPG="rpg_missile"
AR2="grenade_ar2"
Bolt="crossbow_bolt"

findInSphere(Own:pos(),3000)
findIncludeClass(Ball)
findIncludeClass(Frag)
findIncludeClass(RPG)
findIncludeClass(AR2)
findIncludeClass(Bolt)
findSortByDistance(Own:pos())
W=findToArray()

#runOnChat(1)
#K=chatClk()
#Chat=Own:lastSaid()


E:setMass(1)
E:setAlpha(0)
if(!Own){selfDestructAll()}

Stand=vec(0,0,E:radius()+100)
Crouch=vec(0,0,5)
Speed=40

if(Own:isCrouch()&Own:weapon():type():find("physgun")){XYZ=Own:aimPos()+Crouch E:setMass(200)}else{XYZ=Own:pos()+Stand}
W1=W[1,entity]
WO=W1:owner()
WT=W1:type()
WD=W1:pos():distance(Own:pos())
if(Intercept&players()){XYZ=Intercept} #Anti-sniping if perchance someone shall look at you, it will leap to your defense!
if(W:count()&WO!=Own){
    
    if(WT==Bolt){XYZ=W1:pos()+Time*W1:vel()*2 print("Incoming Bolt!")}
    if((WT==RPG|WT==Ball|WT==AR2)&WD<1000){XYZ=W1:pos()+Time*W1:vel()*2}
    if((WT==Frag)&WD<300){XYZ=W1:pos()+Time*W1:vel()*2}
    #if(WT==Bolt){print("Bolt Velocity: "+W1:vel())}
    
}

E:applyForce((Speed*(XYZ-E:pos())-E:vel())*E:mass()+Own:vel())

