SRL Archive - SRL Archives

FindObjTreeEx - Based on Sumilions Idea's


Naum

2008-08-25 11:26:15

Just Like mining.scar uses records for rock finding, I thought why not have records for tree finding aswell. Records are fast and reliable. Tree's look similar but instead of making it waste time looking for them finding the uptext why not put the exact color and RBG values.

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Woodcutting routines --//
//-----------------------------------------------------------------//
// * function FindAxe: Boolean; // * by Sumilion, edited by Rasta Magician
// * procedure FindBirdsNest; // * by Liquid and Starblaster100
// * function FindEnt(fx, fy: Integer; AvoidWhenFound: Boolean): Boolean; // * by Sumilion
// * function FindObjTreeEx(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean; // *By NaumanAkhlaQ
// * function FindObjTree(var tx, ty: Integer; TreeIndex: Integer): Boolean // *By NaumanAkhlaQ
// * Procedure procedure LoadTreeRecords; // *By NaumanAkhlaQ
// * procedure SetupWoodcutting; // * SRL


var
EquipAxe: Boolean;

var
TreeRecords: array of TAutoColorInfo;


const

Normal_Tree = 1; Oak_Tree = 2;
Willow_Tree = 3; Maple_Tree = 4;
Mahogany_Tree = 5; Yew_Tree = 6;
Magic_Tree = 7;

{*******************************************************************************
function FindAxe: Boolean;
By: Sumilion, edited by Rasta Magician
Description: Finds if there is an axe present. Axe can be wielded or unwielded.
Stores place in Boolean var EquipAxe.
*******************************************************************************}

function FindAxe: Boolean;
var
InvAxe, WieldAxe, Ix, Iy: Integer;
begin
if not LoggedIn then exit;
srl_LoadBitmaps([47, 48, 49, 50, 51, 52, 53, 54]);

GameTab(5);
for WieldAxe := 0 to 7 do
if FindBitmapToleranceIn(srl_GetBitmap(54-WieldAxe),Ix, Iy, 566, 285, 606, 327, 10) then
break;

GameTab(4)
for InvAxe := 0 to 7 do
if FindBitmapToleranceIn(srl_GetBitmap(54-InvAxe), Ix, Iy, MIX1, MIY1, MIX2, MIY2, 10) then
break;

if(InvAxe = 8)and(WieldAxe = 8)then
begin
Result := False;
Writeln('No axe was found.');
srl_FreeBitmaps;
Exit;
end;

EquipAxe := (WieldAxe - InvAxe < 0);

case Min(WieldAxe, InvAxe) of
0: WriteLn('Using Dragon axe');
1: WriteLn('Using Rune axe');
2: WriteLn('Using Addy axe');
3: WriteLn('Using Mith axe');
4: WriteLn('Using Black axe');
5: WriteLn('Using Steel axe');
6: WriteLn('Using Iron axe');
7: WriteLn('Using Bronze axe');
end;

Result := True;
srl_FreeBitmaps;
end;

{*******************************************************************************
procedure FindBirdsNest;
By: Liquid and Starblaster100
Description: If a birds nest is found, it will pick it up
*******************************************************************************}

procedure FindBirdsNest;
var
tries, x, y: Integer;
s: string;
begin
if (not (GetLastChatText(s))) then
LastChatter(s);
if (Pos(s, 'A bird') <> 0) then
begin
repeat
if not (FindObj(x, y, 'Take Bird', 3952984, 10)) or
not (FindObj(x, y, 'Take Bird', 1713706, 10)) or
not (FindObj(x, y, 'Take Bird', 1581604, 10)) then
begin
KeyDown(VK_LEFT);
Wait(700 + Random(500));
KeyUp(VK_LEFT);
Wait(400 + Random(300));
end;
if not (FindObj(x, y, 'Take Bird', 3952984, 10)) or
not (FindObj(x, y, 'Take Bird', 1713706, 10)) or
not (FindObj(x, y, 'Take Bird', 1581604, 10)) then
begin
x := 648;
y := 83;
tries := tries + 1;
FindColorSpiral(x, y, 241, 570, 5, 725, 155);
Mouse(x + 3, y + 3, 2, 2, True);
Flag;
Wait(200 + Random(100));
end;
if (FindObj(x, y, 'Take Bird', 3952984, 10)) or
(FindObj(x, y, 'Take Bird', 1713706, 10)) or
(FindObj(x, y, 'Take Bird', 1581604, 10)) then
begin
WriteLn('Birds Nest Found');
Wait(450 + Random(400));
GetMousePos(x, y);
Mouse(x, y, 0, 0, True);
Flag;
Wait(500 + Random(300));
if (Screenshots) then
SaveScreenshot('Birds Nest - SRL - ' + IntToStr(GetTimeRunning) + '.bmp');
tries := tries + 100;
Birdsnest := Birdsnest + 1;
Mouse(583, 226, 2, 2, False);
Wait(100 + Random(100));
ChooseOption('Examine');
Exit;
end;
until (FindObj(x, y, 'Take Bird', 3952984, 10)) or
(FindObj(x, y, 'Take Bird', 1713706, 10)) or
(FindObj(x, y, 'Take Bird', 1581604, 10)) or (tries > 5)
end;
end;

{*******************************************************************************
function FindEnt(fx, fy: Integer; AvoidWhenFound: Boolean): Boolean;
By: Sumilion
Description: Will look for an Ent and avoid if found.
*******************************************************************************}

function FindEnt(fx, fy: Integer; AvoidWhenFound: Boolean): Boolean;
var
x, y, EntTime, tcts: Integer;
begin
if not(LoggedIn)then
Exit;
GetMousePos(x, y);
if(x <> fx)or(y <> fy)then
MMouse(fx, fy, 0, 0);
if(IsUpText('Chop'))then
begin
tcts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.03, 0.75);
Result := (CountColorTolerance(118478, 9, 10, 124, 23, 10) > 10);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(tcts);
end;
if(Result)then
begin
WriteLn('Ent Found!!');
if(AvoidWhenFound)then
begin
Writeln('Waiting for it to go away.');
MFNF(MMCX, MMCY, -1, 1);
MarkTime(EntTime);
while(TimeFromMark(EntTime) < 35000)do
if(Random(20) > 15)then
IdleTime(500, 500, 0.4)
else
Wait(500 + Random(500));
EntsAvoided := EntsAvoided + 1;
end;
end;
end;

{*******************************************************************************
Procedure LoadTreeRecords;
By: NaumanAkhlaQ
Description: Loads Tree Records into SRL, Used in FindObjTreeEx.
*******************************************************************************}

Procedure LoadTreeRecords;
Begin
SetLength(TreeRecords, 7);

with TreeRecords[Normal_Tree] do
begin
UpText := 'ree';
MaxDist := 10;
Color := 2911326;
HueMod := 0.06;
SatMod := 1.24;
LumTol := 10;
MinR := 65; MaxR := 120;
MinG := 77; MaxG := 133;
MinB := 22; MaxB := 72;
MinX := 5.11; MaxX := 17.02;
MinY := 6.65; MaxY := 20.90;
MinZ := 1.81; MaxZ := 9.11;
end;

with TreeRecords[Oak_Tree] do
begin
UpText := 'ak';
MaxDist := 10;
Color := 2976349;
HueMod := 0.06;
SatMod := 1.69;
LumTol := 10;
MinR := 66; MaxR := 121;
MinG := 80; MaxG := 134;
MinB := 21; MaxB := 76;
MinX := 5.38; MaxX := 17.05;
MinY := 7.12; MaxY := 21.15;
MinZ := 1.83; MaxZ := 9.39;
end;

with TreeRecords[Willow_Tree] do
begin
UpText := 'illow';
MaxDist := 10;
Color := 3231556;
HueMod := 0.27;
SatMod := 0.86;
LumTol := 7;
MinR := 48; MaxR := 84;
MinG := 58; MaxG := 104;
MinB := 34; MaxB := 60;
MinX := 3.11; MaxX := 9.14;
MinY := 3.88; MaxY := 11.83;
MinZ := 2.16; MaxZ := 5.96;
end;

with TreeRecords[Maple_Tree] do
begin
UpText := 'aple';
MaxDist := 10;
Color := 7703580;
HueMod := 7.52;
SatMod := 0.20;
LumTol := 6;
MinR := 114; MaxR := 166;
MinG := 31; MaxG := 57;
MinB := 23; MaxB := 100;
MinX := 7.73; MaxX := 18.31;
MinY := 4.72; MaxY := 10.96;
MinZ := 1.35; MaxZ := 12.78;
end;

with TreeRecords[Mahogany_Tree] do
begin
UpText := 'hogan';
MaxDist := 10;
Color := 2382930;
HueMod := 0.03;
SatMod := 1.33;
LumTol := 11;
MinR := 48; MaxR := 111;
MinG := 56; MaxG := 120;
MinB := 14; MaxB := 65;
MinX := 2.80; MaxX := 13.97;
MinY := 3.59; MaxY := 16.90;
MinZ := 0.98; MaxZ := 7.39;
end;

with TreeRecords[Yew_Tree] do
begin
UpText := 'ew';
MaxDist := 10;
Color := 3964530;
HueMod := 0.03;
SatMod := 0.48;
LumTol := 15;
MinR := 67; MaxR := 153;
MinG := 74; MaxG := 166;
MinB := 38; MaxB := 95;
MinX := 5.25; MaxX := 28.44;
MinY := 6.39; MaxY := 34.41;
MinZ := 2.86; MaxZ := 15.75;
end;

with TreeRecords[Magic_Tree] do
begin
UpText := 'agi';
MaxDist := 10;
Color := 5282193;
HueMod := 0.08;
SatMod := 0.13;
LumTol := 32;
MinR := 42; MaxR := 217;
MinG := 47; MaxG := 216;
MinB := 22; MaxB := 180;
MinX := 2.19; MaxX := 60.77;
MinY := 2.67; MaxY := 66.48;
MinZ := 1.19; MaxZ := 52.28;
end;
end;

{*******************************************************************************
function FindObjTreeEx(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
By: NaumanAkhlaQ
Description: Finds the Trees using SRL's Tree Records
*******************************************************************************}

Function FindObjTreeEx(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
begin
try
Result := FindObjRecordEx(tx, ty, TreeRecords[TreeIndex], MSX1, MSY1, MSX2, MSY2, QuickSorting, RGBXYZCheck);
except
Writeln('TreeIndex ''' + IntToStr(TreeIndex) + ''' does not exist.');
end;
end;

{*******************************************************************************
function FindObjTree(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
By: NaumanAkhlaQ
Description: Finds the Trees using SRL's Tree Records
*******************************************************************************}

function FindObjTree(var tx, ty: Integer; TreeIndex: Integer): Boolean;
begin
Result := FindObjTreeEx(tx, ty, TreeIndex, False, True);
end;

{*******************************************************************************
procedure SetupWoodcutting;
By: SRL
Description: Declares Global Bitmaps.
*******************************************************************************}

procedure SetupWoodcutting;
begin
LoadTreeRecords;
end;

^ In the woodcutting Include, just like mining call SetupWoodcutting ^

Easy usage:

If FindObjTree(tx, ty, Yew_Tree) Then
Mouse(x, y, 7, 7, True);

Records have been done for 7 main tree's in runescape:

Normal_Tree, Oak_Tree, Willow_Tree, Maple_Tree, Mahogany_Tree, Yew_Tree, Magic_Tree

Here is the Seperate copy, with the test inside it.

program New;
{.include SRL/SRL.scar}

var
TreeRecords: array of TAutoColorInfo;
x, y : Integer;

const

Normal_Tree = 1; Oak_Tree = 2;
Willow_Tree = 3; Maple_Tree = 4;
Mahogany_Tree = 5; Yew_Tree = 6;
Magic_Tree = 7;


{*******************************************************************************
Procedure LoadTreeRecords;
By: NaumanAkhlaQ
Description: Loads Tree Records into SRL, Used in FindObjTreeEx.
*******************************************************************************}

Procedure LoadTreeRecords;
Begin
SetLength(TreeRecords, 8);

with TreeRecords[Normal_Tree] do
begin
UpText := 'ree';
MaxDist := 10;
Color := 2911326;
HueMod := 0.06;
SatMod := 1.24;
LumTol := 10;
MinR := 65; MaxR := 120;
MinG := 77; MaxG := 133;
MinB := 22; MaxB := 72;
MinX := 5.11; MaxX := 17.02;
MinY := 6.65; MaxY := 20.90;
MinZ := 1.81; MaxZ := 9.11;
end;

with TreeRecords[Oak_Tree] do
begin
UpText := 'ak';
MaxDist := 10;
Color := 2976349;
HueMod := 0.06;
SatMod := 1.69;
LumTol := 10;
MinR := 66; MaxR := 121;
MinG := 80; MaxG := 134;
MinB := 21; MaxB := 76;
MinX := 5.38; MaxX := 17.05;
MinY := 7.12; MaxY := 21.15;
MinZ := 1.83; MaxZ := 9.39;
end;

with TreeRecords[Willow_Tree] do
begin
UpText := 'illow';
MaxDist := 10;
Color := 3231556;
HueMod := 0.27;
SatMod := 0.86;
LumTol := 7;
MinR := 48; MaxR := 84;
MinG := 58; MaxG := 104;
MinB := 34; MaxB := 60;
MinX := 3.11; MaxX := 9.14;
MinY := 3.88; MaxY := 11.83;
MinZ := 2.16; MaxZ := 5.96;
end;

with TreeRecords[Maple_Tree] do
begin
UpText := 'aple';
MaxDist := 10;
Color := 7703580;
HueMod := 7.52;
SatMod := 0.20;
LumTol := 6;
MinR := 114; MaxR := 166;
MinG := 31; MaxG := 57;
MinB := 23; MaxB := 100;
MinX := 7.73; MaxX := 18.31;
MinY := 4.72; MaxY := 10.96;
MinZ := 1.35; MaxZ := 12.78;
end;

with TreeRecords[Mahogany_Tree] do
begin
UpText := 'hogan';
MaxDist := 10;
Color := 2382930;
HueMod := 0.03;
SatMod := 1.33;
LumTol := 11;
MinR := 48; MaxR := 111;
MinG := 56; MaxG := 120;
MinB := 14; MaxB := 65;
MinX := 2.80; MaxX := 13.97;
MinY := 3.59; MaxY := 16.90;
MinZ := 0.98; MaxZ := 7.39;
end;

with TreeRecords[Yew_Tree] do
begin
UpText := 'ew';
MaxDist := 10;
Color := 3964530;
HueMod := 0.03;
SatMod := 0.48;
LumTol := 15;
MinR := 67; MaxR := 153;
MinG := 74; MaxG := 166;
MinB := 38; MaxB := 95;
MinX := 5.25; MaxX := 28.44;
MinY := 6.39; MaxY := 34.41;
MinZ := 2.86; MaxZ := 15.75;
end;

with TreeRecords[Magic_Tree] do
begin
UpText := 'agi';
MaxDist := 10;
Color := 5282193;
HueMod := 0.08;
SatMod := 0.13;
LumTol := 32;
MinR := 42; MaxR := 217;
MinG := 47; MaxG := 216;
MinB := 22; MaxB := 180;
MinX := 2.19; MaxX := 60.77;
MinY := 2.67; MaxY := 66.48;
MinZ := 1.19; MaxZ := 52.28;
end;
end;

{*******************************************************************************
function FindObjTreeEx(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
By: NaumanAkhlaQ
Description: Finds the Trees using SRL's Tree Records
*******************************************************************************}

Function FindObjTreeEx(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
begin
try
Result := FindObjRecordEx(tx, ty, TreeRecords[TreeIndex], MSX1, MSY1, MSX2, MSY2, QuickSorting, RGBXYZCheck);
except
Writeln('TreeIndex ''' + IntToStr(TreeIndex) + ''' does not exist.');
end;
end;

{*******************************************************************************
function FindObjTree(var tx, ty: Integer; TreeIndex: Integer; QuickSorting, RGBXYZCheck: Boolean): Boolean;
By: NaumanAkhlaQ
Description: Finds the Trees using SRL's Tree Records
*******************************************************************************}

function FindObjTree(var tx, ty: Integer; TreeIndex: Integer): Boolean;
begin
Result := FindObjTreeEx(tx, ty, TreeIndex, False, True);
end;

begin
SetupSRL;
LoadTreeRecords;
If FindObjTree(x, y, Yew_Tree) Then
MMouse(x, y, 1, 1);
end.

Thanks :)

mastaraymond

2008-08-25 12:30:19

It actually works? I've had some huge problems with the ground, the grass..

Some colors of the tree are exactly the same as the grass color.. Donno if you got the same problem, but I probably guess so..

Naum

2008-08-25 12:46:35

No, It does find it for me. I used the runescape web page.
Edit: It also works for smart, it goes on the grass a 2-3 times, but finds it in less than a second.

n3ss3s

2008-08-25 13:18:28

I think after the update, the trees separate pretty well from ground? Unless I was on HD…


CTS 3 rapes Draynor willow finding for your information…

mastaraymond

2008-08-25 14:20:54

From: n3ss3s
I think after the update, the trees separate pretty well from ground? Unless I was on HD…


CTS 3 rapes Draynor willow finding for your information…

Oh I tried making one before the update.. And it pretty much got my head stuck ^_^

Naum

2008-08-26 12:57:41

CTS 3? I thought there was only CTS -1, 0, 1 and 2. CTS 2 is the most used so meh..

Claymore

2008-08-26 17:16:26

I made one, i swear to god. It worked for me XD But i find that TPA works better ;p

Naum

2008-08-31 16:29:50

Meh.. I usually Find that a really easy FindObjCustom will always find it ;)