@name Stool Turret Chip
@inputs Cur:string XYZ:vector
@outputs String:string Right Left Reload Chat:string MoveVecto:vector
@persist 
@trigger all
Time=250
if(first()){
    Self=entity()
    StoolT=Self:isConstrainedTo()
    StoolT:createWire(Self,"LeftClick","Left")
    StoolT:createWire(Self,"RightClick","Right")
    StoolT:createWire(Self,"Reload","Reload")
    StoolT:createWire(Self,"Tool","String")
    Self:createWire(StoolT,"Cur","Current")
    }
runOnChat(1)
#interval(Time)
Chat=entity():owner():lastSaid()

#K=curtime()-entity():owner():lastSaidWhen() < (Time*2)/1000
if(chatClk()){timer("chat",Time)}
Brk="<"
Tool=Chat:find("Stool")
Break=Chat:find(Brk)
Lefty=Chat:find("1")
Righty=Chat:find("2")
Reloady=Chat:find("x")
if(Tool&clk("chat")){
       if(Break){String=Chat:explode(Brk):string(2) 
        print("Tool string set to: "+String)
        print("Tool Registers as: "+Cur)}
    if(Lefty){Left=1 timer("Left",100) print("Left Clicking")}
    if(Righty){Right=1 timer("Right",100) print("Right Clicking")}
    if(Reloady){Reload=1 timer("Reload",100) print("Reloading")}

}
if(clk("Left")){Left=0}
if(clk("Right")){Right=0}
if(clk("Reload")){Reload=0}
timer("turn",20)
timer("move",20)
Off=1
if(Off|clk("turn")){
E=StoolT
Amp=100
Center=E:massCenter()
OffsetF=E:forward()*Amp
OffsetR=E:right()*Amp
Ang=ang(XYZ:x(),XYZ:y(),XYZ:z())
#MoveVector=Ang:toVector()
MoveVector=entity():owner():aimPos()
E:applyOffsetForce(MoveVector,Center+OffsetF)
E:applyOffsetForce(-MoveVector,Center-OffsetF)
E:applyOffsetForce(MoveVector,Center+OffsetR)
E:applyOffsetForce(-MoveVector,Center-OffsetR)

}
On=0
if(On|clk("move")){
E=StoolT
#E=Self
#E=entity(N1)
XYZ1=entity():owner():aimPos()
E:applyForce((20*((XYZ1-E:pos())+vec(0,0,0))-E:vel())*E:mass()+E:owner():vel()*10)

}
