SRL Archive - OSR Help

How To Open A Gate


SomeGuyFromHere

2012-12-21 09:44:09

Hello,

these are my first, very noobish steps to build my own script, mostly by copying or at least looking at parts of other scripts. I know there are a buttload of tutorials and tips around here and I didn't go through them all, but I hope that some of you will be kind enough to at least push me in the right direction; you can link me to tutorials or videos all you want, but please bear with me a little.

So I want to make a simple script that walks from a to b. Using SPS and the path generation program available it works (more or less), until to a point where a gate needs to be opened.

Trouble is the gate might not always be visible, the procedure needs to do the following:

a) - Check if it finds the color of the gate on the screen, if yes, continue to the next step

- If not, rotate the screen to a certain degree, then repeat the process.

"If… then… else" is the kind of loop I need for something like this, right?

b) - Click on the gate, opening the context menu

- Read the options. If one says "Open Gate" then it has found the right object.
If not: Back to a)

- Click on the "Open Gate" option and end the procedure.

Now I have some issues with this whole business, especially when it comes to two points:

1. Which function do I need to use to get the whole color detection working?
An AIO Powerminer from the public scripts section has something that looks as if it could be the solution:

If FindObjCustom(x, y, ['ne Co'], [2895406, 2105633], 3) Then... 

This video gives some information on how to use color functions, unfortunately it's only for "FindColor".
[YOUTUBE]http://www.youtube.com/watch?v=oI7xTvzFQnI[/YOUTUBE]

What are all these parameters? The SRL documentation doesn't really explain it. Also, am I on the right way or are these functions not made for what I want to do?

2. Does Simba/SRL even have an OCR module for reading the options of a context menu? It surely seems to have a few OCR functions (btw. what is "uptext"?).


Alright, as I said all these questions are not really sofisticated, but I surely hope that somebody might at least show me a map of this whole jungle of functions, options and whatnot :D

Thanks a lot!

The Killer

2012-12-21 09:47:43

http://villavu.com/forum/showthread.php?t=93333 try this?

J J

2012-12-22 14:23:32

The parameters of FindObjCustom(x, y, ['ne Co'], [2895406, 2105633], 3)
X, Y are the variables where you are going to store the result in. Both need to be Integer.
['ne Co'] is an Array of String of the possible uptexts. I suggest not using capital letters as some get misread more often as lowercase letters.
[2895406, 2105633] is an Array of Integer: The colors you want to search for
And finally 3 is an Integer, the tolerance.

To find the gate I would use a while loop and rotate the compass a maximum of 360 degrees before exiting out. So rotate 15 degrees for like 24 times or generate a random number 10-20 and add everything up.

function FindGate: boolean;
var
totalRotation, r: Integer;

begin
while totalRotation < 360 do
begin
r := RandomRange(10, 20);
totalRotation := totalRotation + r;
MakeCompass(rs_GetCompassAngleDegrees + r);
{* Try to find the object like this
if findTheObject then
begin
Result := True;
break;
end;
*}
end;
end;

SomeGuyFromHere

2012-12-26 20:24:41

Thanks to J J, your explanation of the FindObj parameters was most helpful, along with the videos of YoHoJo.

Here is how I solved the problem: After observing that the bot always comes out at a certain angle after walking the path to the gate I simply added a procedure to turn the screen. Like so:

Procedure TurnToMakeGateOpenScriptWork;
begin
KeyDown(37);
wait(1000);
KeyUp(37);
wait(3000);
end;

Then, to open the gate, I did this:

Procedure OpenGate;

var
x, y: Integer;

begin
if FindObjCustom(x, y, ['Open', 'Gate'], [3622483, 3094077], 3)
then
begin
Writeln('Yeah, I found the gate mate');
ClickMouse(x, y, mouse_Left);
Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
Wait(12000);
end;
//else Writeln('Now where is that gate? Continuing with Walking...');

end;
Works like a charm, only problem seems to be that the script won't compile if I uncomment the "else" along with the second Writeln.
Could somebody help me out?

Gucci

2012-12-26 20:39:04

Here is a better method for finding the gate, just added uptext checking. Also the else comment should work now as you must have had the semicolon behind the end.

procedure OpenGate;
var
x, y: Integer;
begin
if FindObjCustom(x, y, ['Open', 'Gate'], [3622483, 3094077], 3)
then
begin
MMouse(x, y, 0, 0); // Moves the mouse there
if WaitUpText('pen', 1000) then // Checks if it has this uptext
begin
Writeln('Yeah, I found the gate mate');
ClickMouse2(mouse_Left); // Clicks on it ( dont use MoveMouse or ClickMouse they'll get you banned)
Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
Wait(12000);
end else Writeln('Now where is that gate? Continuing with Walking...');
end;
end;

SomeGuyFromHere

2012-12-26 21:05:57

Hey,

isn't uptext checking already included in the FindObj procedure? It is using it to detect the gate after all.

Also, a little question on top: is there a big difference between "MoveMouse" and "MMouse", or is it the same?

Thanks for your suggestions, really appreciate it!

Gucci

2012-12-26 21:19:32

From: SomeGuyFromHere
Hey,

isn't uptext checking already included in the FindObj procedure? It is using it to detect the gate after all.

Also, a little question on top: is there a big difference between "MoveMouse" and "MMouse", or is it the same?

Thanks for your suggestions, really appreciate it!


Oh yeah forgot about findobj since I really don't use it often at all. MMouse is much more humanlike whereas MoveMouse is really fast and isn't that safe to use if you want to avoid a ban