function CheckTarget()
    Target = memoryReadIntPtr(proc, 0x0094ABD0, 316);
	if( Target == 1 and TargetSelected == 0 ) then
 	mouseRClick();
 	rest(10);
 	mouseSet(511, 440);
 	mouseSet(511, 270);
    end
    
    TargetSelected = memoryReadIntPtr(proc, 0x0094ABD4, 316);
    if( TargetSelected == 1 ) then
    rest(100);
    end

    if( Target == 0 and TargetSelected == 0 ) then
    X = math.random(1000);
    Y = math.random(700);
    if( X > 400 and X < 565) then
	mouseSet(0,0);
    end
    if( Y > 285 and Y < 439 ) then
    mouseSet(0,0);
    end
    mouseSet(X, Y);
    rest(10);
    end
end

function Heal()
    HP = memoryReadIntPtr(proc, 0x0094ACC4, 108);
    if( HP < 50 ) then
    keyboardPress( key.VK_4 );
    rest(50);
    end
end


function main()
  attach( findWindow("FW Client - Beta - Final : *") );
  proc = openProcess( findProcess("FW Client - Beta - Final : *") );
  setPriority(PRIORITY_HIGH);

  while(true) do
  CheckTarget();
  Heal();
  rest(2);
  end
end

startMacro(main, true);