@name Prop Defense
@inputs Own:entity
@outputs 
@persist W:array
@trigger 
Time=30/1000
interval(Time*1000)
#Own=entity():owner()

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=entity():isConstrainedTo()
if(!E){selfDestruct() print("stick me onto a prop!")}
#Color="!c" 
#Break=" "
#Color1=Chat:find(Color)
#Break1=Chat:find(Break)
#if(Color&Break&K){
#    X=Chat:explode(Break)[2,string]:toNumber()
#    Y=Chat:explode(Break)[3,string]:toNumber()
#    Z=Chat:explode(Break)[4,string]:toNumber()
#    Color2=vec(X,Y,Z)
#E:setColor(Color2)
#}
#E:setMass(1)
#E:setAlpha(0)
#if(!Own){selfDestructAll()}
#E:setAlpha(0)
Stand=vec(0,0,E:radius()+100)
Crouch=vec(0,0,5)
Speed=20
if(!Own:isCrouch()){XYZ=Own:pos()+Stand}else{XYZ=Own:aimPos()+Crouch E:setMass(200)}
W1=W[1,entity]
WO=W1:owner()
WT=W1:type()
WD=W1:pos():distance(Own:pos())
if(W:count()&WO!=Own){
    if((WT==RPG|WT==AR2)&WD<1000){XYZ=W1:pos()+Time*W1:vel()*2}
    if((WT==Frag|WT==Bolt|WT==Ball)&WD<300){XYZ=W1:pos()+Time*W1:vel()}
    if(WT==Bolt){print("Incoming Bolt!")}
    
}
E:applyForce((Speed*(XYZ-E:pos())-E:vel())*E:mass()+Own:vel())

