SRL Archive - Reflection Help

Reflection Questions -- Tree Finding


gerauchert

2009-01-15 16:32:32

Here is what I am currently using in my script…


Function ClickTree: Boolean;
var
ID: TIntegerArray;
i : Integer;
xy,xz: TPoint;
begin
if(not(LoggedIn))then Exit;
Status('Searching For Tree');
case Players[CurrentPlayer].Strings[0] of
'Normal': ID := [1278,1276];
'Oak' : ID := [1281];
'Willow': ID := [5553,5552,5551];
end;
for i := 0 to Length(ID)-1 do
begin
if(FindObject(xy,ID[i]))then
begin
if(TileOnMs(xy,150))then
begin
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end else
if(TileOnMM(xy))then
begin
WalkToTile(xy,2,0);
FFlag(0);
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end;
end;
end;
Result := False;
end;

This Function seems to have a few flaws in it that I would like to get kinked out. First, the function overall seems to be working great, BUT it doesnt seem to always recognize trees that are on the main screen. For example, there may be two willows on the ms and it will click the minimap to one that is far away. So I was wondering if there was a better way to code this so that it will more readily recognize ms trees verses trees on the mm.

Second, during willow chopping it seems to have trouble locating trees (mainly when the trees are being chopped down often) and it never seems to "recover" and it will just lag out until my failsafe kicks in after 60 sec for not finding the tree. Is there anyway to speed up the tree finding or anything?

Thirdly, when there isnt any trees left on the ms (normal tree chopping) it seems to click trees via the mm from the very outside of the minimap causing my char to get lost at times. Is there a way to search for the closest trees from where your characters position is?

Any help would be appreciated.

mormonman

2009-01-15 16:35:04

try findobjectex… i think you can set distance parameters… or just make your own with findobject.

gerauchert

2009-01-15 16:39:35

From: mormonman
try findobjectex… i think you can set distance parameters… or just make your own with findobject.


Wow. I had no idea there was a FindObjectEx… last time i looked there was only FindObject. Musta been an old revision though.

Thanks dude.

EDIT:

A quick question with FindObjectEx. What is the Maxlength supposed to indicate? Distance in pixels? or Tiles? or something else that im oblivious to?

NiCbaZ

2009-01-15 16:46:11

From: gerauchert
Here is what I am currently using in my script…


Function ClickTree: Boolean;
var
ID: TIntegerArray;
i : Integer;
xy,xz: TPoint;
begin
if(not(LoggedIn))then Exit;
Status('Searching For Tree');
case Players[CurrentPlayer].Strings[0] of
'Normal': ID := [1278,1276];
'Oak' : ID := [1281];
'Willow': ID := [5553,5552,5551];
end;
for i := 0 to Length(ID)-1 do
begin
if(FindObject(xy,ID[i]))then
begin
if(TileOnMs(xy,150))then
begin
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end else
if(TileOnMM(xy))then
begin
WalkToTile(xy,2,0);
FFlag(0);
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end;
end;
end;
Result := False;
end;

This Function seems to have a few flaws in it that I would like to get kinked out. First, the function overall seems to be working great, BUT it doesnt seem to always recognize trees that are on the main screen. For example, there may be two willows on the ms and it will click the minimap to one that is far away. So I was wondering if there was a better way to code this so that it will more readily recognize ms trees verses trees on the mm.

Second, during willow chopping it seems to have trouble locating trees (mainly when the trees are being chopped down often) and it never seems to "recover" and it will just lag out until my failsafe kicks in after 60 sec for not finding the tree. Is there anyway to speed up the tree finding or anything?

Thirdly, when there isnt any trees left on the ms (normal tree chopping) it seems to click trees via the mm from the very outside of the minimap causing my char to get lost at times. Is there a way to search for the closest trees from where your characters position is?

Any help would be appreciated.



Willows are hard since there are 3 ids , but use findobject ex

almost

2009-01-15 18:46:47

Here is my spiral I use for finding objects.
This is set for finding a rock but it can be changed for trees.
It returns the tile the object is on in Tile, RockType and Coal obviously won't be used, and size is how far to search (10 is a good number to find things on screen)
//finds the closest rock to you.
//set coal true to find coal or false to find mith.
function FindRock(var Tile: TPoint; var RockType: integer; Coal: boolean; Size: integer): boolean;
var
Dir: string;
RockTypes: array of integer;
Skip, i, t, c: integer;
Rock: UID;
begin
if not R_LoggedIn then
Exit;
if Coal then
RockTypes:= [31068, 31069, 31070] else
RockTypes:= [31086, 31087, 31088];
Tile:= GetMyPos;
Skip:= 1;
Dir:= 'r';
repeat
for i:= 1 to 2 do
begin
for t:= 1 to Skip do
begin
case Dir of
'r': Inc(Tile.x);
'u': Inc(Tile.y);
'l': Dec(Tile.x);
'd': Dec(Tile.y);
end;
Rock:= GetObjectAt(Tile.x, Tile.y);
RockType:= Rock.ObjType;
for c:= 0 to 2 do
if (RockType = RockTypes[c]) then
if (TileOnMS(Tile, 0)) then
if not (PlayerMiningRock(Tile, Coal)) then
begin
Result:= true;
Exit;
end;
end;
case Dir of
'r': Dir:= 'u';
'u': Dir:= 'l';
'l': Dir:= 'd';
'd': Dir:= 'r';
end;
end;
Inc(Skip);
until(Skip >= Size);
end;

mormonman

2009-01-15 19:01:28

From: gerauchert
Wow. I had no idea there was a FindObjectEx… last time i looked there was only FindObject. Musta been an old revision though.

Thanks dude.

EDIT:

A quick question with FindObjectEx. What is the Maxlength supposed to indicate? Distance in pixels? or Tiles? or something else that im oblivious to?


maxlength is tiles

Heysus

2009-01-15 20:00:19

The best way to find the closest tree would probrably be to add the tiles of all the trees on the MM to a TPointArray and then do SortTPAFrom.

Function ClickTree: Boolean;
var
ID: TIntegerArray;
i : Integer;
xy,xz: TPoint;
Trees: TPointArray;
begin
if(not(LoggedIn))then Exit;
Status('Searching For Tree');
case Players[CurrentPlayer].Strings[0] of
'Normal': ID := [1278,1276];
'Oak' : ID := [1281];
'Willow': ID := [5553,5552,5551];
end;
for i := 0 to Length(ID)-1 do
begin
if(FindObject(xy, ID[i]))then
begin
SetArrayLength(Trees, GetArrayLength(Trees) + 1);
Trees[High(Trees)] := xy;
end;
end;
if GetArrayLength(Trees) = 0 then
begin
Result := false;
exit;
end;
SortTPAFrom(Trees, GetMyPos);
xy := Trees[0];
if(TileOnMs(xy, 150))then
begin
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end else
if(TileOnMM(xy))then
begin
WalkToTile(xy,2,0);
FFlag(0);
xz := TileToMs(xy,150);
MMouse(xz.x+40,xz.y-35,15,15);
if(RandMouse('hop'))then
begin
Status('');
Result := True;
Exit;
end;
end;
end;

ZaSz

2009-01-15 20:12:48

lol u guys!

if FindObject(xy, ID[i]) and (DistanceFrom(p) < 6) then
begin
v := TileToMS(p, Random(5));
mouse(v.x,v.y,3,3,true);
end;

almost

2009-01-15 20:15:37

If you don't have very many trees, use Haysus's.
If there are lots of them use mine.
Mine was made for the mining guild where there are tons of rocks.

gerauchert

2009-01-21 18:07:32

thanks for all your help guys! :D

Nava2

2009-01-21 18:30:30

Make sure you have all of the ids. Second, filter through each point, setting up a FindObjects would probably be best,

Anyways, Good Luck! :)