SRL Archive - OSR Help

Door Function


YoHoJo

2011-09-12 23:18:41

Need/Need help with a function.

I'm standing right outside of a door.
Function needs to check if door is open or closed.
If open, continue on with script.
If closed, open it, continue on with script.

~LazyAssHo

TRiLeZ

2011-09-12 23:28:41

Check the door's actions to determine if it's open or closed. If it's closed, click it with model clicking or a combination of colour + reflection.

Flight

2011-09-12 23:31:10

From: TRiLeZ
Check the door's actions to determine if it's open or closed. If it's closed, click it with model clicking or a combination of colour + reflection.


Are doors always on a specific tile? Because this certain door I've had some trouble finding it with a simple object-finding script. I wonder if it lies in the center of two tiles… Although, I don't see how that's possible. Everything, as far as I know, has one specific tile they're assigned to.

TRiLeZ

2011-09-12 23:48:04

From: Flight
Are doors always on a specific tile? Because this certain door I've had some trouble finding it with a simple object-finding script. I wonder if it lies in the center of two tiles… Although, I don't see how that's possible. Everything, as far as I know, has one specific tile they're assigned to.


Most doors remain on a single tile as they are opened/closed, but there are some which move onto an adjacent tile. Use on-screen object debugging to find out what's going on with the door you're working with.

mormonman

2011-09-13 00:47:25

Some doors also used to change IDs. But its been a long time since I dealt with them so I'm not sure anymore.

YoHoJo

2011-09-13 00:49:25

Just checked, the door changes ID when open/closed.
Shouldn't be too hard to figure out I'll read a tut/check out some ref scripts as example.

mormonman

2011-09-13 00:51:29

From: YoHoJo
Just checked, the door changes ID when open/closed.
Shouldn't be too hard to figure out I'll read a tut/check out some ref scripts as example.


Just do

if R_FindObject(ClosedID, 30, OBJ_INTERACTABLE, ObjVar) then
begin
//interacting code here
end;

TRiLeZ

2011-09-13 00:57:21

Some doors change IDs; others don't.

KingKong

2011-09-13 01:00:37

Here is a door opener i wrote for one my scripts(ref1) but it should be enough to get the idea across. What it basically does is search for the color of the door within the 4 tiles it borders(2 when closed, 2 when opened), and then if the options are open, then the door is closed.. etc.
function OpenDoor(Which: String): Boolean;
var
a, b, c, d, x, y: Integer;
Colors: TIntegerArray;
TL, DR: TPoint;
TPA, TPA2: TPointArray;
ATPA : T2DPointArray;
begin
case Which of
'ned':
begin
Colors:= [2117479, 2184046];
TL:= TileToMSEx(Tile(3101, 3259), 0, 0, 0);
DR:= TileToMSEx(Tile(3102, 3257), 1, 1, 0);
end;
'aggie':
begin
Colors:= [2117479, 2184046];
TL:= TileToMSEx(Tile(3088, 3259), 0, 0, 0);
DR:= TileToMSEx(Tile(3089, 3257), 1, 1, 0);
end;
'prisonout':
begin
Colors:= [6716292, 6716292];
TL:= TileToMSEx(Tile(3128, 3248), 0, 0, 0);
DR:= TileToMSEx(Tile(3129, 3246), 1, 1, 0);
end;
'prisonin':
begin
Colors:= [4934735, 5789788];
TL:= TileToMSEx(Tile(3123, 3245), 0, 0, 0);
DR:= TileToMSEx(Tile(3124, 3243), 1, 1, 0);
end;
end;
while(a < 6) and (Result = False) do
begin
Result:= False;
while (Length(TPA) < 1) or ( b < 6) do
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Colors[0], TL.x, TL.y, DR.x, DR.y, 15);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, Colors[1], TL.x, TL.y, DR.x, DR.y, 15);
TPA:= CombineTPA(TPA, TPA2);
Inc(b);
if Length(TPA) > 0 then
break;
end;
b:= 0;
ATPA := TPAtoATPA(TPA, 15);
c := High(ATPA);
for d:= 0 to c do
begin
MiddleTPAEx(ATPA[d], x, y);
Mouse(x, y, 0, 0, False);
if ChooseOptionMultiEx(['Open Door', 'Open Prison Door'], 'all', ClickLeft) then
begin
Result:= True;
break;
end else
if ChooseOptionMultiEx(['Close Door'], 'all', Nothing) then
begin
Result:= True;
break;
end;
end;
while (b < 6) and (CharacterMoving) do
begin
wait(300 + RandomRange(100, 150));
Inc(b);
end;
b:= 0;
if Result = True then
begin
wait(400 + RandomRange(120, 210));
break;
end;
Inc(a);
end;
end;

Coh3n

2011-09-13 01:22:28

This is what I used in my Pottery script. Keep in mind it's for R1.

function handleDoor(): boolean;
var
door: TRSObject;
p: TPoint;
begin
if (not loggedIn) then
exit;

door := getObjectAt(point(3259, 3400), OBJECT_TYPE_WALLOBJECT);

if (door.id > 0) then
begin
makeCompass('w');
p := tileToMS(door.tile, 5);

mmouse(p.x, p.y, 3, 3);
getMousePos(p.x, p.y);

result := click('pen', 'pen', point(p.x, p.y));
end else
result := true;

wait(randomRange(300, 500));
end;

YoHoJo

2011-09-13 01:29:00

^ That doesn't check for door ID and then if its OpenID continue and if it's ClosedID click it right?

That just finds the door based on it's tile/point(?), moves mouse onto it, and uses the uptext to determine weather or not it's open or closed?

Coh3n

2011-09-13 01:35:45

From: YoHoJo
^ That doesn't check for door ID and then if its OpenID continue and if it's ClosedID click it right?

That just finds the door based on it's tile/point(?), moves mouse onto it, and uses the uptext to determine weather or not it's open or closed?
No, not at all. :p

If door.id is greater than 0, then the door is closed, otherwise it's open.

YoHoJo

2011-09-13 01:40:19

Whaa Rreally?
For the door I was add Id was like (ex) 1459 open and 1460 closed.
What was your door open ID? 0? Negative? Wat?

Coh3n

2011-09-13 02:03:05

From: YoHoJo
Whaa Rreally?
For the door I was add Id was like (ex) 1459 open and 1460 closed.
What was your door open ID? 0? Negative? Wat?
I don't remember, it was a long time ago. Nevertheless, you can just replace the 0 with 1460 and it would work.

I also don't know how the R2 object functions work, so that may have something to do with it as well.

Home

2011-09-13 05:00:21

function OpenDoor: Boolean;
var
Door: TRSObject;
TP: TPoint;
x, y: Integer;
begin
if not LoggedIn then Exit;
Door := R_GetObjectAt(Point(3253, 3398), OBJ_WALLOBJECT); // Gets ID of the door.
if Door.ID = Door_ID then begin // If Door ID matches to Closed door ID then begin
TP := R_TileToMS(Door.Tile, 0); // Tile To MS
MMouse(TP.x, TP.y - 28, 4, 2);
Wait(RandomRange(100, 250));
if R_OptionExists('Open') or R_IsUpTextMulti(['Open', 'pen D'])// UpText check.
then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, False); // Open.
if R_WaitOption('Open', RandomRange(200, 350)) then
R_Flag;
end;
end;
end;


~Home

lordsaturn

2011-09-13 10:36:32

The way I did in my rune mysteries runner was using DoorProfiles. I would try to walk past the door, and then Flag; or whatever. Then using DoorProfiles, check if I was behind the door. If so, open it and continue.

bevardis

2011-09-13 11:14:37

Iirc door had different id closed and opened. So it's either by ID or by uptext.

KingKong

2011-09-13 17:35:08

in ref2 you can also do r_canreach to see if the door is open or not.

YoHoJo

2011-09-14 20:56:27

Door := R_GetObjectAt(Point(3253, 3398), OBJ_WALLOBJECT);
What point would I use?
Doors exist 'between' points. Can someone explain please, and a picture would help a lot too!

KingKong

2011-09-14 21:38:59

From: YoHoJo
Door := R_GetObjectAt(Point(3253, 3398), OBJ_WALLOBJECT);
What point would I use?
Doors exist 'between' points. Can someone explain please, and a picture would help a lot too!


Search for the color of the door(and store it in tpa) within the four tiles it surrounds. then loop through the tpa and do an uptext check.

YoHoJo

2011-09-15 01:29:12

From: KingKong
Search for the color of the door(and store it in tpa) within the four tiles it surrounds. then loop through the tpa and do an uptext check.


I want it done all ref. This is just one situation in which I just think reflection is the clearly easier and simpler answer. With Ref I don't have to hover the door or check any text, ref can just check (without mouse) if door is open or closed and either continue or click it.

So anyone answer my question in the above post?

mormonman

2011-09-15 02:06:56

From: YoHoJo
I want it done all ref. This is just one situation in which I just think reflection is the clearly easier and simpler answer. With Ref I don't have to hover the door or check any text, ref can just check (without mouse) if door is open or closed and either continue or click it.

So anyone answer my question in the above post?


Except sometimes the click option is not to open the door.

Shuttleu

2011-09-15 17:05:13

Tile(2816, 3438) is the tile the door is on when its closed
Tile(2816, 3439) is the tile the door is on when its open

function DoorOpen: Boolean;
var
Temp: TRSObject;
begin
Temp:= R_GetObjectAt(tile(2816, 3438), OBJ_WALLOBJECT);
if (Temp.ID=1530) then
Result:= False
else
begin
Temp:= r_GetObjectAt(tile(2816, 3439), OBJ_WALLOBJECT);
if (Temp.ID=1531) then
Result:= True
end;
end;

procedure OpenDoor;
var
DoorPos: TPoint;
begin
if DoorOpen then Exit;
if (not(R_TileOnMS(Tile(2816, 3438), 0))) then
if (not(R_TileOnMM(Tile(2816, 3438)))) then
begin
r_WindWalk(Tile(2816, 3438));
end else
R_WalkToTile(Tile(2816, 3438), 0, 0);
Flag;
Wait(200+Random(500));
if (not(DoorOpen)) then
begin
DoorPos:= R_TileToMS(Tile(2816, 3439), 0);
Mouse(DoorPos.x-5, DoorPos.y-5, 11, 11, False);
R_ChooseOption('Open');
end;
end;

door is one tile north when its open, and has a different id than when its shut
when it needs to open the door just rotate the camera and hover over the tile the door is on when its open
diagram
(top square is door open, bottom is door closed)

picture
(red dot is where the mouse clicks)

~shut

Brandon

2011-09-15 18:28:07

Below stuff works flawlessly for me :P Never misses a single door.. All you need is the Close ID of the door.. it'll check to see if the object exists.. if it does, the door is closed and it will open it.. if not, it will just exit the procedure.


Function AdjacentTile(Tile: TTile): Boolean;
var
MyPos, NewTile: TTile;

begin
MyPos:= R_GetMyPos;
NewTile := Point((MyPos.x - Distance(Tile.X, 0, MyPos.X, 0)), MyPos.y);
if(NewTile = Tile) then
begin
Result:= true;
end;

NewTile := Point((MyPos.x + Distance(Tile.X, 0, MyPos.X, 0)), MyPos.y);
if(NewTile = Tile) then
begin
Result:= true;
end;

NewTile := Point(MyPos.X, (MyPos.y - Distance(0, Tile.Y, 0, MyPos.Y)));
if(NewTile = Tile) then
begin
Result:= true;
end;

NewTile := Point(MyPos.X, (MyPos.Y + Distance(0, Tile.Y, 0, MyPos.Y)));
if(NewTile = Tile) then
begin
Result:= true;
end;
end;

Function AdjacentDirection(Tile: TTile): string;
var
MyPos, NewTile: TTile;

begin
MyPos:= R_GetMyPos;
NewTile := Point((MyPos.x - Distance(Tile.X, 0, MyPos.X, 0)), MyPos.y);
if(NewTile = Tile) then
begin
Result:= 'w';
end;

NewTile := Point((MyPos.x + Distance(Tile.X, 0, MyPos.X, 0)), MyPos.y);
if(NewTile = Tile) then
begin
Result:= 'e';
end;

NewTile := Point(MyPos.X, (MyPos.y - Distance(0, Tile.Y, 0, MyPos.Y)));
if(NewTile = Tile) then
begin
Result:= 's';
end;

NewTile := Point(MyPos.X, (MyPos.Y + Distance(0, Tile.Y, 0, MyPos.Y)));
if(NewTile = Tile) then
begin
Result:= 'n';
end;
end;

Function OpenDoor(DoorID: Integer; Destination: TTile): Boolean;
var
Door: TRSObject;
begin
if(R_CanReach(Destination, true)) then
exit;
if(R_FindObject(DoorID, 2, 20, Door)) then //WallObject.
if(AdjacentTile(Door.Tile)) then
begin
R_MakeCompass(AdjacentDirection(Door.Tile)); //Makes the Camera Rotate to Face the Door.
SmartMoveMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y); // Adjust Tile Height To Suit.
if(R_isUptext('Open')) then
begin
SmartClickMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y , true);
end else
if(Not R_isUptext('Walk')) then
begin
SmartMoveMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y);
if(R_OptionExists('Open')) then //Work around for if someone places a plant marker.. it will right click to open.
begin
SmartClickMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y, false);
R_ChooseOption('Open');
end;
end else
begin
writeln('We aren''t Near The Door; Walking To it Now..');
R_WalkToTile(Door.Tile, 1, 1);
if(R_TileOnMS(Door.Tile, 0) and (R_GetMyPos <> Door.Tile)) then
begin
SmartMoveMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y);
if(R_isUptext('Walk')) then
begin
SmartClickMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y, true);
end else
begin
SmartClickMouse(R_TileToMS(Door.Tile, 0).x, R_TileToMS(Door.Tile, 0).y , false);
R_ChooseOption('Walk');
end;
end;
end;
end;
end;