SRL Archive - SRL Archives

plant solver


Shuttleu

2008-08-06 12:10:30

i noticed that srl doesnt have a plant solver and i have had a perfectly working one for nearly a year
so here it is
program PlantFinder;
{.include srl/srl.scar}

function Find2TPApoints(TPA1, TPA2: TPointArray; w, h: Integer): TPointArray;
var i1, i2, l1, l2, r: LongInt;
begin
l1 := High(TPA1);
l2 := High(TPA2);
r := 0;
for i1 := 0 to l1 do
begin
for i2 := 0 to l2 do
begin
if (ABS(TPA1[i1].x - TPA2[i2].x) <= w) and (ABS(TPA1[i1].y - TPA2[i2].y) <= h) then
begin
Inc(r);
SetLength(Result, r + 1);
result[r].x := ((TPA1[i1].x + TPA2[i2].x) div 2);
result[r].y := ((TPA1[i1].y + TPA2[i2].y) div 2);
end;
end;
end;
end;

function ItemCoordsDtm(area: string; dtm: Integer): TPointArray;
var
startx, starty, rowsize, colsize, colnumber, rownumber, col, row: Integer;
x1, y1, x2, y2: Integer;
itemx, itemy: Integer;
i: Integer;
begin
SetArrayLength(Result, 0);
if (CheckArea(area)) then
begin
AreaInfo(area, startx, starty, rowsize, colsize, colnumber, rownumber);
for row := 0 to rownumber - 1 do
for col := 0 to colnumber - 1 do
begin
x1 := startx + col * colsize;
y1 := starty + row * rowsize;
x2 := x1 + colsize;
y2 := y1 + rowsize;
if (FindDTM(dtm, itemx, itemy, x1, y1, x2, y2)) then
begin
i := GetArrayLength(Result);
SetArrayLength(Result, i + 1);
Result[i].x := x1;
Result[i].y := y1;
end;
end;
end;
end;

function CountItemsDtm(area: string; dtm: Integer): Integer;
var
coords: TPointArray;
begin
coords := ItemCoordsDtm(area, dtm);
Result := GetArrayLength(coords);
end;
function StrangePlantFinder: Boolean;

var
l, spx, spy, StartSPF, FruitCount, FruitDTM: integer;
TPA1, TPA2, TPA3: TPointArray;
Begin
if not LoggedIn then exit;
result := false
spx := MSCX;
spy := MSCY;
if FindColorTolerance(spx, spy, 945749, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) and FindColorTolerance(spx, spy, 743503, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) then
begin
FindColorsSpiralTolerance(spx, spy, TPA1, 945749, MSX1, MSY1, MSX2, MSY2, 4);
FindColorsSpiralTolerance(spx, spy, TPA2, 743503, MSX1, MSY1, MSX2, MSY2, 4);
SetLength(TPA1, High(TPA1) + 1);
SetLength(TPA2, High(TPA2) + 1);
TPA3 := Find2TPApoints(TPA1, TPA2, 18, 18);
l := High(TPA3);
if l >= 0 then
begin
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
writeln('Found Strange Plant attempting to Pick fruit.');
FruitDTM := DTMFromString('78DA63E4646060E0654001B30A8E30B001694' +
'620FE0F048CDC400633031A60442281B40090E026A08607488812' +
'50C30A244408A861C67433BA1A008467066B');
FruitCount := CountItemsDtm('inv', FruitDTM);
Result := True;
MarkTime(StartSPF);
repeat
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
MMouse(spx, spy, 1, 1);
wait(250 + Random(250));
if IsUpText('trange') then
begin
wait(250 + Random(250));
Mouse(spx, spy, 1, 1, false);
wait(250 + Random(250));
ChooseOption('ick');
wait(500 + Random(600));
if Pos('ready to', GetBlackChatMessage) > 5 then
wait(2000 + Random(1000)) else //Text: The fruit isn't ready to be picked yet...
if (Pos('fruit from', GetBlackChatMessage) > 5) or (CountItemsDtm('inv', FruitDTM) > FruitCount) then //Text: You pick the fruit from the plant.
begin
result := true;
writeln('Picked Fruit From Strange Plant.. Waiting for plant to die...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) or FindFight;
Plants := Plants + 1;
SRLRandomsReport;
exit;
end else
if Pos('unable', GetBlackChatMessage) > 5 then //Text: You're unable to pick the fruit.
begin
result := false;
writeln('The plant is not after you.. Waiting for plant to go...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) or FindFight;
exit;
end;
end;
end else break;
until (TimeFromMark(StartSPF) > 120000) or FindFight;
writeln('Failed to Pick Fruit From Strange Plant');
FreeDTM(FruitDTM);
end;
end;
end;
end;

begin
SetupSrl;
StrangePlantFinder;
end.
i hope this gets added into srl :D

~shut

EDIT: markus's fix:
program PlantFinder;
{.include srl/srl.scar}

function Find2TPApoints(TPA1, TPA2: TPointArray; w, h: Integer): TPointArray;
var
i1, i2, l1, l2, r: LongInt;
begin
l1 := High(TPA1);
l2 := High(TPA2);
r := 0;
for i1 := 0 to l1 do
begin
for i2 := 0 to l2 do
begin
if (ABS(TPA1[i1].x - TPA2[i2].x) <= w) and (ABS(TPA1[i1].y - TPA2[i2].y) <= h) then
begin
Inc(r);
SetLength(Result, r + 1);
result[r].x := ((TPA1[i1].x + TPA2[i2].x) div 2);
result[r].y := ((TPA1[i1].y + TPA2[i2].y) div 2);
end;
end;
end;
end;

function StrangePlantFinder: Boolean;
var
l, spx, spy, StartSPF, FruitCount, FruitDTM: integer;
TPA1, TPA2, TPA3: TPointArray;
Begin
if not LoggedIn then exit;
result := false
//spx := MSCX;
//spy := MSCY; //What's the use of this :p?
if FindColorTolerance(spx, spy, 945749, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) and FindColorTolerance(spx, spy, 743503, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) then
begin
FindColorsSpiralTolerance(mscx, mscy, TPA1, 945749, MSX1, MSY1, MSX2, MSY2, 4);
FindColorsSpiralTolerance(mscx, mscy, TPA2, 743503, MSX1, MSY1, MSX2, MSY2, 4);
//SetLength(TPA1, High(TPA1) + 1); Setlength(tpa, length(tpa)) ? -.-
//SetLength(TPA2, High(TPA2) + 1);
TPA3 := Find2TPApoints(TPA1, TPA2, 18, 18);
l := High(TPA3);
if l >= 0 then
begin
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
writeln('Found Strange Plant attempting to Pick fruit.');
FruitDTM := DTMFromString('78DA63E4646060E0654001B30A8E30B001694' +
'620FE0F048CDC400633031A60442281B40090E026A08607488812' +
'50C30A244408A861C67433BA1A008467066B');
FruitCount := CountItems(FruitDTM, 'dtm', [0]); //:)
Result := True;
MarkTime(StartSPF);
repeat
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
MMouse(spx, spy, 1, 1);
wait(250 + Random(250));
if IsUpText('trange') then
begin
wait(250 + Random(250));
Mouse(spx, spy, 1, 1, false);
wait(250 + Random(250));
ChooseOption('ick');
wait(500 + Random(600));
if Pos('ready to', GetBlackChatMessage) > 5 then
wait(2000 + Random(1000)) else //Text: The fruit isn't ready to be picked yet...
if (Pos('fruit from', GetBlackChatMessage) > 5) or (CountItems(FruitDTM, 'dtm', [0]) > FruitCount) then //Text: You pick the fruit from the plant.
begin
result := true;
writeln('Picked Fruit From Strange Plant.. Waiting for plant to die...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) or FindFight;
Plants := Plants + 1;
SRLRandomsReport;
exit;
end else
if Pos('unable', GetBlackChatMessage) > 5 then //Text: You're unable to pick the fruit.
begin
result := false;
writeln('The plant is not after you.. Waiting for plant to go...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, 1, 18, 18, 4, ['trange']) or FindFight;
exit;
end;
end;
end else break;
until (TimeFromMark(StartSPF) > 120000) or FindFight;
writeln('Failed to Pick Fruit From Strange Plant');
FreeDTM(FruitDTM);
end;
end;
end;
end;

begin
SetupSrl;
StrangePlantFinder;
end.

MylesMadness

2008-08-06 12:24:24

Those are some gross standards…

Shuttleu

2008-08-06 12:26:03

sorry it was made ages ago when i didnt know much about standards
i will fix it now :)

~shut

EDIT: fixed standards and made compile with the needed functions

Markus

2008-08-14 06:28:30

This fine with you?

program PlantFinder;
{.include srl/srl.scar}

function Find2TPApoints(TPA1, TPA2: TPointArray; w, h: Integer): TPointArray;
var
i1, i2, l1, l2, r: LongInt;
begin
l1 := High(TPA1);
l2 := High(TPA2);
r := 0;
for i1 := 0 to l1 do
begin
for i2 := 0 to l2 do
begin
if (ABS(TPA1[i1].x - TPA2[i2].x) <= w) and (ABS(TPA1[i1].y - TPA2[i2].y) <= h) then
begin
Inc(r);
SetLength(Result, r + 1);
result[r].x := ((TPA1[i1].x + TPA2[i2].x) div 2);
result[r].y := ((TPA1[i1].y + TPA2[i2].y) div 2);
end;
end;
end;
end;

function StrangePlantFinder: Boolean;
var
l, spx, spy, StartSPF, FruitCount, FruitDTM: integer;
TPA1, TPA2, TPA3: TPointArray;
Begin
if not LoggedIn then exit;
result := false
//spx := MSCX;
//spy := MSCY; //What's the use of this :p?
if FindColorTolerance(spx, spy, 945749, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) and FindColorTolerance(spx, spy, 743503, MSCX - 100, MSCY - 110, MSCX + 100, MSCY + 90, 4) then
begin
FindColorsSpiralTolerance(mscx, mscy, TPA1, 945749, MSX1, MSY1, MSX2, MSY2, 4);
FindColorsSpiralTolerance(mscx, mscy, TPA2, 743503, MSX1, MSY1, MSX2, MSY2, 4);
//SetLength(TPA1, High(TPA1) + 1); Setlength(tpa, length(tpa)) ? -.-
//SetLength(TPA2, High(TPA2) + 1);
TPA3 := Find2TPApoints(TPA1, TPA2, 18, 18);
l := High(TPA3);
if l >= 0 then
begin
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
writeln('Found Strange Plant attempting to Pick fruit.');
FruitDTM := DTMFromString('78DA63E4646060E0654001B30A8E30B001694' +
'620FE0F048CDC400633031A60442281B40090E026A08607488812' +
'50C30A244408A861C67433BA1A008467066B');
FruitCount := CountItems(FruitDTM, 'dtm', [0]); //:)
Result := True;
MarkTime(StartSPF);
repeat
if FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) then
begin
MMouse(spx, spy, 1, 1);
wait(250 + Random(250));
if IsUpText('trange') then
begin
wait(250 + Random(250));
Mouse(spx, spy, 1, 1, false);
wait(250 + Random(250));
ChooseOption('ick');
wait(500 + Random(600));
if Pos('ready to', GetBlackChatMessage) > 5 then
wait(2000 + Random(1000)) else //Text: The fruit isn't ready to be picked yet...
if (Pos('fruit from', GetBlackChatMessage) > 5) or (CountItems(FruitDTM, 'dtm', [0]) > FruitCount) then //Text: You pick the fruit from the plant.
begin
result := true;
writeln('Picked Fruit From Strange Plant.. Waiting for plant to die...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, -1, 18, 18, 4, ['trange']) or FindFight;
Plants := Plants + 1;
SRLRandomsReport;
exit;
end else
if Pos('unable', GetBlackChatMessage) > 5 then //Text: You're unable to pick the fruit.
begin
result := false;
writeln('The plant is not after you.. Waiting for plant to go...');
FreeDTM(FruitDTM);
repeat
BoredHuman;
wait(2000 + random(1000));
until not FindObjTPA(spx, spy, 945749, 4, 1, 18, 18, 4, ['trange']) or FindFight;
exit;
end;
end;
end else break;
until (TimeFromMark(StartSPF) > 120000) or FindFight;
writeln('Failed to Pick Fruit From Strange Plant');
FreeDTM(FruitDTM);
end;
end;
end;
end;

begin
SetupSrl;
StrangePlantFinder;
end.


EvilChicken!

2008-08-14 06:50:37

Markus, and Shut also for that sake: Doesn't that one belong to PriSoner? (His woodcutting script..)

And, I also remember that JuKKa was working on one, but I don't know about his progress. I hope he sees my post and digs it up :rolleyes:

Shuttleu

2008-08-14 08:41:16

yes that is fine as long as it still works

also it did belong to PriSoner but i asked him about me takiong over Ultra Cut n Bank and he said that i could continue the script and i could claim all the code and work
and as that plant solver was in there it now belongs to me :)

~shut

Markus

2008-08-14 08:41:54

I'll credit you both then?

Shuttleu

2008-08-14 08:43:33

sure ok

~shut

EDIT: WOOT! just noticed im rank 18 in srl stats :D

EvilChicken!

2008-08-14 08:46:28

From: Markus
I'll credit you both then?


Wait. You're including it in SRL?


Edit: If so, I'm pretty sure that you understand that you'll have to make a new var in SetUpSRL; UsePlantSolver.

Edit2: Yes! After all this time, my battle is won!

Shuttleu

2008-08-14 08:50:10

looks like it :D

~shut

Shuttleu

2008-09-26 19:38:25

bump

is this going to get added?

~shut