@name Player Turret
@inputs 
@outputs S Targets:array On
@persist S Targets:array On
@trigger all
Time=15
interval(Time)
Self=entity():owner()
Chat = entity():owner():lastSaid()
#K = curtime() - entity():owner():lastSaidWhen() < (Time*1000*1)
K=chatClk()
runOnChat(1)
C=Chat:find("track")
Off=Chat:find("stop")
findInSphere(Self:pos(),100000)
findIncludeClass("npc")
#findPlayerByName("Bot")
findSortByDistance(Self:pos())
Targets=findToArray()

if(C&K){ On=1}
if((Off&K)|!Targets:count()){On=0}
Target=Targets:entity(1)
if((Target:health()<=0)&(Target:isNPC()|Target:isPlayer())){
Targets:remove(1) Target=Targets:entity(1)}

if(Target:isNPC()|Target:isPlayer()){Offset=vec(0,0,Target:height()*6/9)}
Ang=(Target:pos()-Self:shootPos()+Offset):toAngle()

if(On){Self:setEyeAngle(Ang)

Target=entity():owner():aimEntity()
if(Self:isAlive()){
if(Target:isAlive()&!S) {S=1 concmd("+attack")}}}
if(Target:isAlive()&S){S=0 concmd("-attack")}

#Pitch goes from 90 to -90 Z+ and 90 Z- is down
#Yaw goes from 0 to 360 where 0 is east or +x and 90 is North or +y
