SRL Archive - OSR Help

IYO The Best Door Finding Methods?


GREEN GIANT

2013-07-17 09:35:53

Hi guys,

I'm currently working on my first script and it will involve a lot of door detection, including detecting whether the door is open or closed and reacting accordingly.

I would like some input on what methods you (the community) have had most success with in relation to:

- Door detection methods (DTM, ColorFinding, ObjectFinding etc)
- Checking the status of the door (Open/Closed)
- Failsafes (If someone opens the door or closes it after i have already done my check.

Any input is appreciated but my main search is for good, solid, door finding/detection methods as the ones i have tried are a little intermittent.

Thanks.

Flight

2013-07-17 09:51:39

Uh…. give me a couple minutes and I'll make an example for ya. I'll edit this post so heads up.


Ok well this is one of many ways to go about determining if a door is open. This will lightly use tpas & atpas and a tad bit of math. It's possibly vulnerable so you'll want to make things a bit more specific in it, but this is the basic idea.


function getDoorState: String;
var
b : TBox;
cts,i,h,w: Integer;
tpa,tpa2 : TPointArray;
atpa : T2DPointArray;
begin
Result := 'I have no bloody idea...'; // By default
cts := getToleranceSpeed;

// First, let's get a TPA of the "TOP" of the door
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.07, 0.49);
FindColorsSpiralTolerance(MSCX, MSCY, tpa, 1725035, MSx1, MSy1, MSx2, MSy2, 3);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

// Door colors not found, I quit...
if (Length(tpa) < 1) then
Exit;

// Let's group this TPA
SplitTPAWrap(tpa, 10, atpa);
b := getATPABounds(atpa); // Get the boundry of the ATPA
h := b.Y2-b.Y1; // "h" = height
w := b.X2-b.X1; // "w" = width

if (h > w) then // If the heigth of the door is longer than the width, it must be open!
Result := 'Open'
else if (h < w) then // ...or closed
Result := 'Closed';
end;


// Usage:
Writeln('The door is '+getDoorState);

In visual form:

Our original TPA of the door (I tried to get just the top frame for this):


Next, a visualization of the ATPA that was found. You can clearly see the height is greater than the width:


So, using the logic that if the height of that ATPA is > the width (the top of the door is verticle) we can assume the door is open, otherwise if the top of the door is horizontal (width > height) then it's closed.



Of course you can use uptext, DTMs, color counting, and so forth if you'd like. And one last thing, if you make fun of my snazzy bunny ears I'll de-rep you like no tomorrow… [/joke]

GREEN GIANT

2013-07-17 10:53:02

Thankyou 'Flight' that was very helpful, i have been using uptext in my detection but i felt there must be a better, or even just another method for a failsafe.

If i may ask, what method do you find most reliable for actually finding the door in the first instance, i've been using DTMS but find them very unreliable :(

As for the Bunny Ears….meh…each to their own i guess ;)

Flight

2013-07-17 11:03:39

From: GREEN GIANT
Thankyou 'Flight' that was very helpful, i have been using uptext in my detection but i felt there must be a better, or even just another method for a failsafe.

If i may ask, what method do you find most reliable for actually finding the door in the first instance, i've been using DTMS but find them very unreliable :(

As for the Bunny Ears….meh…each to their own i guess ;)


Happy to help. I think if I really wanted a safe detection system for doors I'd use 3 methods combined. First a light check with DTMs (search for a DTM of the top of the door), one for horizontal and one for vertical. Of course these would depend on your map angle, and obviously you would not use 'FindDTMRotated' in this instance. If neither of those two DTMs were found then go to the second stage, the one I posted above: TPA length & width dimensions. Should that function fail or result in a closed door I would go to stage three: uptext check.

GREEN GIANT

2013-07-17 11:09:37

From: Flight
Happy to help. I think if I really wanted a safe detection system for doors I'd use 3 methods combined. First a light check with DTMs (search for a DTM of the top of the door), one for horizontal and one for vertical. Of course these would depend on your map angle, and obviously you would not use 'FindDTMRotated' in this instance. If neither of those two DTMs were found then go to the second stage, the one I posted above: TPA length & width dimensions. Should that function fail or result in a closed door I would go to stage three: uptext check.


Alas, i keep finding myself in the same position, there is no ONE method for success :( I will have to hone my skills developing methods that have failsafes.

Thanks again.

bob_dole

2013-07-17 21:19:09

My law running script encounters the castle wars door that is sometimes closed and needs to be opened. My solution is to attempt to walk outside of the door and then if the SPS X is below a certain number it means the script has failed to walk out meaning the door is closed. It will then attempt to open the door and walk out again. This loop repeats until the SPS X-coordinate is above the certain number or until 60 seconds has past.

Element17

2013-07-19 12:06:21

You could also use MMtoMs I believe. I have used that to open doors before, could use it to move the mouse there and check the door.

GREEN GIANT

2013-07-20 19:03:25

Any chance of a worked example 'Element17'?

Haven't the foggiest idea how i would go about using MMtoMS? The only mention in the SRL documentation points toward GetMMDotsOnMS.

Ian

2013-07-20 19:53:39

From: GREEN GIANT
Any chance of a worked example 'Element17'?

Haven't the foggiest idea how i would go about using MMtoMS? The only mention in the SRL documentation points toward GetMMDotsOnMS.


Here is a basic example to show you how you can use it, but note that this is not a guaranteed way to find what you want. Why? See how it uses NPCArray[0]? This will use the first item of the array, but that may not be the one you want.


NPCArray := GetMiniMapDots('yellow'); //This is a TPointArray
NPCTPoint := Point(NPCArray[0].x, NPCArray[0].y); //This is the first TPoint in the TPointArray called NPCArray
MSTPoint := MMToMS(NPCTPoint); //This turns the TPoint on the Minimap into that TPoints's Mainscreen TPoint
MMouse(MSTPoint.x, MSTPoint.y, 5, 5); //This moves the mouse to the main screen TPoint with some randomness.

GREEN GIANT

2013-07-20 20:40:15

Hey BMWxi,

Thanks for the input, but two questions if i may.

I wanted to see this code in action so compiled the following and hit play, it ran but did nothing. why?
And secondly, how would i use this to find a door?

var
NPCArray: Tpointarray;
NPCTPoint: TPoint;
MSTPoint: TPoint;

Procedure llkk ;
begin
NPCArray := GetMiniMapDots('yellow'); //This is a TPointArray
NPCTPoint := Point(NPCArray[0].x, NPCArray[0].y); //This is the first TPoint in the TPointArray called NPCArray
MSTPoint := MMToMS(NPCTPoint); //This turns the TPoint on the Minimap into that TPoints's Mainscreen TPoint
Mouse(MSTPoint.x, MSTPoint.y, 5, 5, false); //This moves the mouse to the main screen TPoint with some randomness.
end;

begin
setupsrl;
llkk;
end.