@name Auto Aimed Turret PropCore
@inputs Entity:entity
@outputs Fire
@persist Player:entity Angle:angle Toggle RandAttack Array:array Hoover Mouse Aim
@trigger 
runOnChat(1)
runOnTick(1)
if(first()){
if(owner():steamID()!="STEAM_0:0:21704689" & isSinglePlayer()==1){
hint("Nice try",10)
selfDestructAll()
}
}
if (chatClk(owner())) {
    Array = owner():lastSaid():lower():explode(" ")   
    if (Array[1,string] == "/aim") {
        Player = findPlayerByName(Array[2,string])
        Aim=1
        Toggle=0
        RandAttack=0
        Mouse=0
}
    if (Array[1,string] == "/toggle") {
      if(Toggle==0){
    Toggle=1
}else{Toggle=0}
}
if (Array[1,string] == "/stop") {
    Aim=0
    RandAttack=0
    Player=noentity()
    Toggle=0
    Mouse=0
}
if (Array[1,string] == "/hoover") {
      if(Hoover==0){
    Hoover=1
}else{Hoover=0}
}
if (Array[1,string] == "/random") {
    Aim=0
    Mouse=0
    Toggle=0
    Player=noentity()
      if(RandAttack==0){
    RandAttack=1
}else{RandAttack=0}
}
if (Array[1,string] == "/mouse") {
    Aim=0
    Toggle=0
    RandAttack=0
    Player=noentity()
      if(Mouse==0){
    Mouse=1
}else{Mouse=0}
}
}

if(Player!=noentity() & RandAttack==0 & Aim==1){
if(Player:isCrouch()!=1){
Angle= (Player:pos() + vec(0,0,40) - Entity:pos()):toAngle()
}else{Angle= (Player:pos() - Entity:pos()):toAngle()
}
if(Hoover){Vector=owner():pos()+vec(0,0,120)}else
{
Vector=entity():pos()+vec(0,0,50)
}
Entity:propManipulate(Vector,Angle,1,0,1)
if(owner():keyReload()==1  | (Toggle==1 & Player:health()>0))
{
    Fire=1
}else{Fire=0}
}else{Entity:propManipulate(entity():pos()+vec(0,0,50),ang(90,0,0),1,0,0)}

if(RandAttack==1){#Attacks Random Players
Players=players()
A=1
if((Player:isAlive()==0 | (Player:pos()+vec(0,0,30)):isInWorld()==0) | Player==noentity() | Player:inVehicle()==1){

while(A<=Players:count()){
if(Players[A,entity]:health()>0 & (Players[A,entity]:pos()+vec(0,0,30)):isInWorld()& Players[A,entity]!=owner() & Players[A,entity]:inVehicle()==0){
        hint("Player selected",10)
Player=Players[A,entity]
break
}
A++
}
}
if(Player:isCrouch()!=1){
Angle= (Player:pos() + vec(0,0,40) - Entity:pos()):toAngle()
}else{Angle= (Player:pos() - Entity:pos()):toAngle()
} 
if(Hoover){Vector=owner():pos()+vec(0,0,100)}else
{
Vector=entity():pos()+vec(0,0,50)
}
Entity:propManipulate(Vector,Angle,1,0,0)
if(owner():keyReload()==1  | (Toggle==1 & Player:health()>0))
{
    Fire=1
}else{Fire=0}
}
if(Mouse){
Me=owner()

Gyro=(Me:aimPos()-Entity:pos()):toAngle()
if(Hoover){V=entity():pos()+vec(0,0,60)}else{
V=Me:pos()+vec(0,0,120)
}
Entity:propManipulate(V,Gyro,1,0,1)
if(Me:keyReload() | Toggle){Fire=1} else{Fire=0}

}





