SRL Archive - OSR Help

A newby question about FindObj().


Etrnl Fear

2012-07-29 13:00:16

I followed Griff's tutorial on 'Scripting down your first tree' and found that ..


FindObj(x, y, 'hop_down_Oak', 3623506, 35)

//Instead of ...

FindObj(x, y, 'hop', 3623506, 35)

.. works more accurately for chopping down specifically oak trees (for example), since the colours on trees are so similar.

Is there a better way of making it more accurate? Any reason I SHOULDN'T do this?

Any advice is appreciated. :)

riwu

2012-07-29 17:41:28

The color tolerance of 35 is pretty high, u can try use ACA and autocolor and reduce the tolerance such that the color dont conflict with other trees. Also u can just change the up text check to 'Oak' or similar to fasten the search. (unless there are other items with similar color to oak trees and has 'Oak' as their up text too)

Usually for skills like wc/mining we use spiral functions so that it starts searching from the centre (i.e. closest tree to you) but for a first script you may not want to go into that yet ;)

Etrnl Fear

2012-07-30 12:02:45

Hmm. I did some messing around and found that a tolerance of 13-17 works much better than 35; so thanks for that tip. :)

About the up text thing.. I noticed that when it finds the colour and recognizes it as an Oak tree, it right clicks and selects chop, like it should. But, if the mouse happens to move off of the tree (thus removing the up text of 'Oak'), it starts the search all over again. In all logic by the way I have my loop scripted, this SHOULD happen.


procedure CutOak;

begin
repeat
if FindObj(x, y, 'hop down Oak', 3623506, 15) then
Mouse(x, y, 2, 2, false);
ChooseOption('hop down Oak');
repeat
Wait(1200 + Random(250));
until not IsUpText('Oak') or (InvFull); //Based on this line, of course.
until (InvFull);
end;

Would there be a better way to script this so it will actually wait for the tree to finish being cut? I've looked into pixel shift a little, but don't completely have that down. Maybe I'll take another look at the tutorial on it. However, if there's a better way, please let me know. :)

PS: I've tried using DTMs to find Oak trees. I can get it pretty accurate, but I can't see to find the right points to be spot on, without detecting a normal (or any other) tree.

riwu

2012-07-30 18:17:45

procedure CutOak;
var
t: Integer;
begin
repeat
if FindObj(x, y, 'hop down Oak', 3623506, 15) then
begin //need a begin to perform >1 actions after a conditional statement
Mouse(x, y, 2, 2, false);
WaitOption('hop down Oak',1000); //in case of lag the option wont appear right after u click
t:=GetSystemTime+RandomRange(10000,15000);
repeat
Wait(1200 + Random(250));
if t<GetSystemTime then break;
until not IsUpText('Oak') or (InvFull); //Based on this line, of course.
until (InvFull);
end;
I've added a break that it will break out of the wait after 10-15 sec (u can change the timing), uptext check would be highly unreliable though as your character will move when u run to the tree and ur mouse will be off the tree right away. AveragePixelShift is the most reliable/efficient method but u can use a loop with GetXpBar to make it stop until say, no xp gained for 5sec, not to efficient if u take quite long to cut the tree though.

Etrnl Fear

2012-07-30 20:52:06

Great tip on the WaitOption.

A question though, just for clarity:
I couldn't find an explained documentation for GetSystemTime, but I'm assuming that the line " t:=GetSystemTime+RandomRange(10000,15000); " sets the integer 't' to the current system time + anywhere between 10 and 15 seconds? If this is the case, then does the line " if t<GetSystemTime then break; " mean that if t (system time + 10-15 seconds) becomes less than the new current system time, it will stop the current loop to prevent an accidental infinite loop?

Sorry if it's a dumb question; I just learn by asking. ;)

With that said…
Is this debug written correctly?

t := GetSystemTime+RandomRange(10000,15000);
repeat
Wait(1200 + Random(250));
if t < GetSystemTime then
begin
Break;
Writeln('Waited too long, ending loop');
end;
until not IsUpText('ak') or (InvFull);

riwu

2012-07-31 06:24:55

From: Etrnl Fear
Great tip on the WaitOption.

A question though, just for clarity:
I couldn't find an explained documentation for GetSystemTime, but I'm assuming that the line " t:=GetSystemTime+RandomRange(10000,15000); " sets the integer 't' to the current system time + anywhere between 10 and 15 seconds? If this is the case, then does the line " if t<GetSystemTime then break; " mean that if t (system time + 10-15 seconds) becomes less than the new current system time, it will stop the current loop to prevent an accidental infinite loop?

Sorry if it's a dumb question; I just learn by asking. ;)

Yeah you are right, you can also use MarkTime and TimeFromMark to achieve the same effect, though an extra variable will have to be created to exit on a RandomRange.
From: Etrnl Fear

With that said…
Is this debug written correctly?

t := GetSystemTime+RandomRange(10000,15000);
repeat
Wait(1200 + Random(250));
if t < GetSystemTime then
begin
Break;
Writeln('Waited too long, ending loop');
end;
until not IsUpText('ak') or (InvFull);

You should put the writeln before the break, because once it breaks its going to ignore everything within that loop so writeln wont be executed.

Etrnl Fear

2012-07-31 09:54:11

Hah, yeah I caught that later on.

It runs better than it did, so thanks for the help. :)