SRL Archive - OSR Help

TPoint range


CephaXz

2012-06-23 23:42:12

IDK what title to put, sorry if that confuse you :p

Let's say my function returns a TPoint: Point(100, 200).

Is there any math or whatever function that can make a radius of the TPoint? For example, If I want to only fight or walk or do any skill in a range of 10 tiles away from the TPoint, I want to have a radius of 10 of the TPoint.

Tell me if you couldn't understand. I just don't know how to explain my question lol :norris:

Nebula

2012-06-23 23:44:21

MouseCircle?

CephaXz

2012-06-23 23:45:56

The TPoint is the position of SPS. How does MouseCircle works on this?

EDIT: In fact, I did look up on functions like MouseCircle, MouseOval, Smart_DrawCircle/Ellipse. But I just need more explanation and understanding towards this.

Nebula

2012-06-23 23:48:28

Don't quite understand what you're asking…

MouseCircle(MidX, MidY, Radius, clickType: Integer);

Example:

MouseCircle(100, 100, 5, 1); would click anywhere 5 pixels around the point (100, 100)

CephaXz

2012-06-23 23:52:22

SPS_GetMyPos returns a Tpoint, which is my current position. And from that Tpoint, I want to create a radius of X around it, so that I will always be in X tiles away from the TPoint. If I am outside the range, I will walk back inside again.

I didn't want to click on anything. Just wanted to have a radius around a TPoint.

Nebula

2012-06-23 23:57:35

Oh

Just use Distance(xs, ys, xe, ye: Integer);

If Distance(xCoordOfPointYouWantToStayNear, yCoordOfPointYouWantToStayNear, SPS_GetMyPos.x, SPS_GetMyPos.y) > Radius then
Blah;

Edit: Forgot that you can't use SPS_GetMyPos.x/.y

You'd have to do this:

Var
CurrentSPSPos: TPoint;
begin
CurrentSPSPos := SPS_GetMyPos;
If Distance(xCoordOfPointYouWantToStayNear, yCoordOfPointYouWantToStayNear, CurrentSPSPos.x, CurrentSPSPos.y) > Radius then
SPS_WalkToPos(Point(xCoordOfPointYouWantToStayNear, yCoordOfPointYouWantToStayNear));
end;

Runaway

2012-06-24 00:08:57

I'm not on my computer so I can't check if this function actually exists, but you could try PointInCircle or PointInBox to do what Nebula said. (Literally exactly what his does, just figured I'd add that in :p)

CephaXz

2012-06-24 00:09:31

Thanks! I always see people use Distance in their script, but didn't quite understand how Distance function actually works. I'll try playing with it. :D


From: Runaway
I'm not on my computer so I can't check if this function actually exists, but you could try PointInCircle or PointInBox to do what Nebula said. (Literally exactly what his does, just figured I'd add that in :p)


I only found PointInBox. Box does not always make sure you're in X tile away from the TPoint, or I just don't know how to do the math. Thanks :D

Nebula

2012-06-24 00:14:19

Well, since I have nothing better to do, I'll explain what it does. Or at least what I think it does, since Simba doesn't allow you to look at the code behind it.

(again this is all a hypothesis..)

It most likely takes two points, and uses the Pythagorean theorem to return the distance between the two points.

this can be simplified to the distance formula, which you have probably seen before in a math class.

Basically, result := the formula above, with x1 y1 x2 y2 being xs ys xe ye.

Daniel

2012-06-24 00:31:48

From: Nebula
since Simba doesn't allow you to look at the code behind it.

What? :S

And you are correct on your definition. In fact, that's all it does: Sqrt( Pow() …, etc).

Nebula

2012-06-24 00:36:21

From: Daniel
What? :S

And you are correct on your definition. In fact, that's all it does: Sqrt( Pow() …, etc).


when you double click on it in the function list, it doesn't show the source like it does for most things..

CephaXz

2012-06-24 00:40:14

I think I just started to know how to calculate it. Already forgot those maths when I left school. I'm studying something that doesn't use those complicated symbols/equations :p

Nebula

2012-06-24 00:43:32

From: CephaXz
I think I just started to know how to calculate it. Already forgot those maths when I left school. I'm studying something that doesn't use those complicated symbols/equations :p


You don't need to know the math behind it.. just do what I said and it should work fine.

CephaXz

2012-06-24 00:48:56

I wouldn't continue until I totally understand something I wanted to know :p

Your explanation at the 6th post kind of confused me, but I understood now. I'll just do GetMyPos at the start. Then GetMyPos again when checking position, so that it can compare the 2 points. I was wondering what CoordOfPointYouWantToStayNear will be, since there are so many points lol.

P1ng

2012-06-24 01:57:48

Is what you are trying to fight or walk to on the mainscreen? Couldn't you just determine the co-ords of FindDTM or FindColor or whatever function you're using to find them with MSCX-10,MSCY-10,MSCX+10,MSCY+10 as your area to search in because the middle of your player will always be the middle of the mainscreen?

Obviously need a larger area than 20x20 pixels because that wouldn't even reach the bouds outside your character, but you get the idea?

If you want to see the box use paintsmart include and SMART_DrawBox

Daniel

2012-06-24 02:02:05

From: CephaXz
I wouldn't continue until I totally understand something I wanted to know :p

Your explanation at the 6th post kind of confused me, but I understood now. I'll just do GetMyPos at the start. Then GetMyPos again when checking position, so that it can compare the 2 points. I was wondering what CoordOfPointYouWantToStayNear will be, since there are so many points lol.


Distance get's the distance between two points (given by [x1,y1] and [x2,y2]).

See Wikipedia for more details.

CephaXz

2012-06-24 07:20:06

From: p1ng
Is what you are trying to fight or walk to on the mainscreen? Couldn't you just determine the co-ords of FindDTM or FindColor or whatever function you're using to find them with MSCX-10,MSCY-10,MSCX+10,MSCY+10 as your area to search in because the middle of your player will always be the middle of the mainscreen?

Obviously need a larger area than 20x20 pixels because that wouldn't even reach the bouds outside your character, but you get the idea?

If you want to see the box use paintsmart include and SMART_DrawBox


I think you didn't understand my question :p
I'm not trying to find the coords of the obj or npc, I'm getting the coords of my current position at the start of the script. If you ever used AutoFighterPro or Perfecticus Fighter of nexus client, you can set the tiles away from your position at the start of the script, which is the area you want to fight. So that when you're fighting, you don't get lost. This applies to WC bots as well. A powerchopper will always chop whatever trees it sees on the mainscreen, if no area is set, you will start from draynor and end up at lumbridge. That is where the function comes in handy.

A box that is made out of a point, the distance/length between the outlines of the box and the center point will not always be fixed. But a circle always has a same distance/length from the center to the outline.

Hope that make things clear about what I wanted.


From: Daniel
Distance get's the distance between two points (given by [x1,y1] and [x2,y2]).

See Wikipedia for more details.


Thanks :D

Gu3st...

2012-06-24 07:32:32

From: Nebula
You don't need to know the math behind it.. just do what I said and it should work fine.
Just use Distance(x1, y1, x2, y2) instead of doing sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))? much easier that way.

Also; https://github.com/MerlijnWajer/Simba ?

P1ng

2012-06-24 08:38:12

You could try making a DTM positioning system and then if you are a certain distance away from the x,y co-ordinate make it walk back to there?

Have a look at J J's barbarian basic dev blog for his function that he is using, it looks really cool and i plan on implementing it into my next script

CephaXz

2012-06-24 12:24:40

I plan not to rely on dtm for anything, whether it is item or object or position finding. I find dtm use up a lot of resources in the long run. But I will try to look at it. Thanks :D