SRL Archive - OSR Help

FindObjTPA closest to character?


Brotein

2012-04-23 23:03:17

So I'm making a script right now. The area it works off of looks like this…
X=Resource
P=Player
S=Spot
[X][X][X][X][X][X][X]
[P]


So I'm using FindObjTPA right now, but I want it only to go to the Resources within 1 square of the player(left right or forward). Right now it will go for any of the areas to mine whether it be close or far. The script as of now is doing M1D1, so the mouse will move to the inventory after it mines. I'm also using the same x,y variable for both functions(for mining and dropping), could that be an issue for when it rescans the mainscreen for the TPA?

Flight

2012-04-23 23:14:13

I would understand it better if you had a picture of what you're trying to accomplish. Would you mind posting one please?

Brandon

2012-04-23 23:17:25

Considering the function your using well.. You'd have to modify it or make your own so that it searches only within a box..

Also that function is a bit weird:

tCTS := GetColorToleranceSpeed;
CTS := Integer(CTS * 9 mod 3 <> 0); //Will always return 0..
ColorToleranceSpeed(CTS);

Your better off writing your own.

Abu

2012-04-24 11:24:30

Wouldn't you just Create a box which would be directly in front of your player?

Then replace MSX1, MSY1, MSX2, MSY2 in your function with the co-ordinates of your box.

Valithor

2012-04-24 12:30:09

From: Brotein
So I'm using FindObjTPA right now, but I want it only to go to the Resources within 1 square of the player(left right or forward).


So, what I understand about what you want to do is you wanna mine the closest rock to your player. To go about doing so I would suggest you defining your "x" and "y" variables as "MSCX" and "MSCY". These are predefined coordinates in Simba (or SRL?) for the MainScreen Center.

A quick idea for your script would be…
procedure FindRock;
var
x, y: integer;

begin
x:= MSCX;
y:= MSCY;

if FindObjTPA(x, y, Color, 0, 0, 0, 0, 0, ['ock']) then
ClickRock;
end;

This way when FindColorsSpiralTolerance() is called in FindObjTPA() it'll start searching from the center of the MainScreen (where your character is) and spiral out. It'll almost always find the closet rock.

I think that should just about do it. If you have any other questions feel free to send me a PM.

Edit:
From: Brotein
I'm also using the same x,y variable for both functions(for mining and dropping), could that be an issue for when it rescans the mainscreen for the TPA?


Using this way… if your "x" and "y" are both defined as global variables (why would you even do this?) then… yes. I could see how that might screw things up a bit. Otherwise, if they are local variables there is nothing to worry about. (to my knowledge)

jakeyboy29

2012-04-24 13:20:16

From: Valithor
So, what I understand about what you want to do is you wanna mine the closest rock to your player. To go about doing so I would suggest you defining your "x" and "y" variables as "MSCX" and "MSCY". These are predefined coordinates in Simba (or SRL?) for the MainScreen Center.

A quick idea for your script would be…
procedure FindRock;
var
x, y: integer;

begin
x:= MSCX;
y:= MSCY;

if FindObjTPA(x, y, Color, 0, 0, 0, 0, 0, ['ock']) then
ClickRock;
end;

This way when FindColorsSpiralTolerance() is called in FindObjTPA() it'll start searching from the center of the MainScreen (where your character is) and spiral out. It'll almost always find the closet rock.

I think that should just about do it. If you have any other questions feel free to send me a PM.

Edit:


Using this way… if your "x" and "y" are both defined as global variables (why would you even do this?) then… yes. I could see how that might screw things up a bit. Otherwise, if they are local variables there is nothing to worry about. (to my knowledge)


you got it

Brotein

2012-04-24 16:08:09

Thanks for the help guys, I really start to over think this one. I got it working the way I wanted now, thanks for the explanations and clear ups!