Feroc1ty
2011-03-10 18:45:30
function IsNearbyPoint(point:TPoint;tiles:integer):boolean;
begin
result := DistanceFrom(point) <= tiles;
end; function PickupItemNear(id:integer;name:string;area:integer;var count:integer):boolean;
var ground:TGroundItemArray;
item:TInvItem;
index,num:integer;
begin
ground := GetItemsNear(area);
R_ItemExists(id,item);
num := item.StackSize;
for index := 0 to high(ground) do
begin
if (ground[index].ID = id) then
begin
ClickBox(PtToBox(TileToMS(ground[index].tile,30),8),false);
result := R_WaitOption(name,300);
wait(100+random(75));
r_Flag;
R_ItemExists(id,item);
count := count + item.stacksize - num;
break;
end;
end;
wait(random(50));
end; function InteractWithTile(action:string;offset:TPoint;tile:TTile):boolean;
var pt:TPoint;
begin
result := false;
fDebug('InteractWithOBJ','Attempting to '+action+'.');
if not TileOnMS(tile,30) then WalkToTile(tile,1,0);
pt := TileToMS(tile,0);
pt.x := pt.x + offset.x;
pt.y := pt.y + offset.y;
MoveBox(PtToBox(pt,8));
Wait(100+random(125));
if R_IsUpText(action) then
begin
ClickMouse2(true);
result := true;
end else
begin
ClickMouse2(false);
result := R_ChooseOption(action);
end;
wait(500+random(150));
r_Flag;
end; function InteractWithNPC(action:string;npc:TNPC):boolean;
var t:TNPC;
begin
fDebug('InteractWithNPC','Attempting to '+action+' (to) a '+npc.name+'.');
if not TileOnMS(npc.tile,30) then
begin
WalkToTile(npc.tile,1,1);
R_Flag;
end;
MoveBox(PtToBox(TileToMS(npc.tile,30),10));
Wait(100+random(125));
if R_IsUpText(action+' '+npc.name) then
begin
ClickMouse2(true);
result := true;
end else
begin
ClickMouse2(false);
if R_ChooseOption(action+' '+npc.name) then result := true;
end;
end; procedure FinishFight(delay:integer);
var i:integer;
mob:TNPC;
begin
r_Flag;
wait(delay);
for i := 0 to 30 do
begin
if CharacterAnimating then i := 0;
wait(50);
if AreWeInteracting(mob) = false then break;
end;
end;function FightNPC(name:string):boolean;
var mobs:TNPCArray;
index:integer;
begin
index := 0;
mobs := SortNPCs(GetNPCs(name));
for index := 0 to high(mobs) do
begin
if mobs[index].fighting or mobs[index].moving then
continue;
result := InteractWithNPC('attack',mobs[index]);
if result then FinishFight(200);
fDebug('FightNPC','Finished fighting.');
break;
end;
end; Here are the box functions I use which I think all of these functions use, I use my own due to them having a higher chance of clicking the center point, and decreasing as you go out.
function PtToBox(tile:TPoint;size:integer):TBox;
begin
Result.X1 := Round(tile.x - size/2);
Result.X2 := Round(tile.x + size/2);
Result.Y1 := Round(tile.y - size/2);
Result.Y2 := Round(tile.y + size/2);
end;
function MouseInBox(box:TBox):boolean;
var pt:TPoint;
begin
GetMousePos(pt.x,pt.y);
result := PointInBox(pt, box);
end;
procedure ClickBox(box:TBox;left:boolean);
var x,y:integer;
begin
x := (box.x2 - box.x1)/2;
y := (box.y2 - box.y1)/2;
if not MouseInBox(box) then
MMouse(box.x1 + x + Random(RandomRange(-x,x)), box.y1 + y + Random(RandomRange(-y,y)), 0, 0);
ClickMouse2(left);
end;
procedure MoveBox(box:TBox);
var x,y:integer;
begin
x := (box.x2 - box.x1)/2;
y := (box.y2 - box.y1)/2;
if not MouseInBox(box) then
MMouse(box.x1 + x + Random(RandomRange(-x,x)), box.y1 + y + Random(RandomRange(-y,y)), 0, 0);
end;