SRL Archive - Reflection Help

Creating a procedure location check


Daedolon

2010-12-04 19:31:03

Okay, so I have my fire crafter script functioning at the bare bones basic (link here). It crafts, it banks, it repeats, simple right? Now there's easily a million things I want to add to this script, but I'm going to start from the most essential and then consider any other additions later on.

The biggest porblem I'm facing right now is a fail safe to check my location. I want to be able to use the script, have it log in at any location, and start working; I don't want to constantly have to restart it at the bank. This is also important for future fail safes I will be adding in.

Unfortantely I don't know how to go about doing this and that's why I am asking for help from anyone who knows how to approach this problem.



I originally had the notion to create a procedure at the beginning of the script. After logging into it would check the location it is currently at and go directly to the procedure correlating with it's location.

Example: If I log into the fire altar, I want it to check where it is. After determining it's at the fire altar, I want it to skip the procedures of "walking from the bank" + "entering the fire altar", and just begin crafting at the altar. (If it's at a location that does not fit into any of the procedures it will log itself out.)

How do I do that?:confused:



I don't know if I'm looking at it wrong or not because I think that once the script loop's and get's back to the bank it will check to see if it's at the altar and then mess up. There's something I'm missing here and I can't wrap my head around it.

i luffs yeww

2010-12-04 19:35:15

In the reflection include there's stuff to see your current tile. You can basically just do GetMe.Tile (I think that's what it is.. check around the include ;)) and then see if that's InRange in the boxes you have predetermined for the different areas. So if it's in rage of the bank tiles (as in it's inside of the box you chose), it's at the bank. Near/in fire altar, it's there. You could also see if it's in between two points. :3 I could help you more later (gonna be going to my mom's soon), but I'm sure someone else will help you faster.

Cstrike

2010-12-04 19:37:39

One way I'd do it is use "MeInBox"

{*******************************************************************************
function MeInBox(Bounds: TBox): boolean;
By: Drags111
Description: Results true if your char is in the box of tiles. TOP LEFT TO
BOTTOM RIGHT.
*******************************************************************************}
function MeInBox(Bounds: TBox): boolean;

So in your code you'd do something like this:

... MeInBox(IntToBox(TopLeftX, TopLeftY, BottomRightX, BottomRightY));

Where the x/y values are the tile locations you want to check in.

EX:
MeInBox(IntToBox(3200, 3245, 3258, 3288));

If you're in the box, it will return true.


+See iluffsyeww

Boreas

2010-12-04 19:39:59

IMO you need to be looking at what you have to determine where you need to go.

Daedolon

2010-12-04 20:03:43

All, very good answers. But is there not a function that can skip procedures?

Example:

I would use what Cstrike suggested:
MeInBox(IntToBox(TopLeftX, TopLeftY, BottomRightX, BottomRightY));

If false, then I would write the function ( fake name) "skipToProcedure" that would look like this:

SkipToProcedure(string);



Is there something like that?

Frement

2010-12-04 20:09:11

If (not MeInBox(...)) then begin
SkipToProcedure('thestringasd');
end else begin
DoOthers;
end;

Why can't you do it like that?

Daedolon

2010-12-04 20:12:10

Well that's what I am asking lol. So I can do it like that then? :)

Frement

2010-12-04 20:27:16

From: Daedolon
Well that's what I am asking lol. So I can do it like that then? :)


Well, the best way to approach this depends alot on what you are trying to achieve.

i luffs yeww

2010-12-04 20:38:18

From: Daedolon
All, very good answers. But is there not a function that can skip procedures?

Example:

I would use what Cstrike suggested:
Simba Code:
[LEFT]MeInBox(IntToBox(TopLeftX, TopLeftY, BottomRightX, BottomRightY));
[/LEFT]


If false, then I would write the function ( fake name) "skipToProcedure" that would look like this:

SCAR Code:
[LEFT]SkipToProcedure(string);
[/LEFT]




Is there something like that?


What other languages have you scripted in? Any OOP languages?

Daedolon

2010-12-04 20:39:52

I'm trying to make a script where you can log in anywhere *I use that term loosely* and have the script start at that point. It beats having to reset your character back at the bank everytime you want to run it.

I think it will greatly remove the chance of error in the script too.

Frement

2010-12-04 20:41:19

From: Daedolon
I'm trying to make a script where you can log in anywhere *I use that term loosely* and have the script start at that point. It beats having to reset your character back at the bank everytime you want to run it.

I think it will greatly remove the chance of error in the script too.


Teleport to lumbridge, then walk from there?

i luffs yeww

2010-12-04 20:52:12

From: Daedolon
I'm trying to make a script where you can log in anywhere *I use that term loosely* and have the script start at that point. It beats having to reset your character back at the bank everytime you want to run it.

I think it will greatly remove the chance of error in the script too.


No, I know what you're doing, it just seems like Simba is the first thing you've scripted for, or you've scripted an OOP language possibly.

Daedolon

2010-12-04 20:57:53

From: i luffs yeww
No, I know what you're doing, it just seems like Simba is the first thing you've scripted for, or you've scripted an OOP language possibly.


That is correct, I have never scripted befor in my life. I did take Java in grade 11, but I dropped out and did homeschooling no more than 1 month into Gr.11, And that was 2 years ago, so i've forgotten anything I've learned.

It was merely a stroke of luck I produced what I did, and even then I had to get some help. But I'm reading the tutorial sections constantly trying to pick up stuff.

i luffs yeww

2010-12-04 21:00:31

:p Well never mind. It's just because of how you seem to think it works. You can call any procedure/function whenever you please (you actually need to order procedures correctly in PascalScript, which is kinda lame but whatever), and just general things. If you want personal help, [email]panic._@live.com[/email]. :)

Daedolon

2010-12-04 21:06:47

Thank you very much :)

And yeah, I have a big predisposition for over complicated things that I don't understand fully.

Boreas

2010-12-04 21:11:34

You could have checks for stuff in each procedure that clicks something, like below, but you end up with a lot of ifs.
function nearbank:boolean;
begin
if FindSymbol{In}(x,y,'bank'{,620,67,669,115}) then
begin
result:=true;
exit;
end;
if not (findsymbol(x,y,'quest') or(findsymbol(x,y,'fish'))) then
exit;
result:=true;
end;

Function GetCompassAngle: Extended; //Wizzup?
Var
Compass: TPointArray;
tmpPoint: TPoint;
Begin
FindColorsTolerance(Compass, 1911089, 540, 2, 590, 40, 0);
If Length(Compass) < 1 Then
Exit;
tmpPoint := MiddleTPA(Compass);
Result := Degrees(ArcTan2(tmpPoint.Y - 20, tmpPoint.X - 561)) + 90;
If (Result < 0) Then
Result := 90 - (Result * -1) + 270
End;

Function FindFourBankers(Direction:string):Tpoint;
var myy,myx,dist,DTMBankers:integer;
angle:extended;
begin
DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A98A16AFEFC6102D38C503E6323116ABA885053' +
'4D580D005F4D15F0'); //3 akbank4
{
DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A98A06AFEFC81B018A17CC64622D47411A1A69A' +
'B01A005E1515EC'); //2}
{ DTMBankers := DTMFromString('78DA636C66626058CB8002FEFFFFCFF01F483' +
'342D8FF195B116A18A16AFEFC6142E1333612A1A68B0835D584D5' +
'00005CDD15E8'); }
if not FindDTMRotated(DTMBankers,myx,myy,mmx1,mmy1,mmx2,mmy2,0,180,2.0,angle) then
begin
freedtm(DTMBankers);
exit;
end;
freedtm(DTMBankers);
angle:=GetCompassAngle;
case lowercase(Direction[1]) of
'e': angle:=angle-270.0;
'w': angle:=angle-90.0;
's': angle:=angle-180.0;
end;
dist:=5+random(7);
result.x:=myx+round((dist)*sin(radians(angle)));
result.y:=myy-round((dist)*cos(radians(angle)));
end;

function TanScreen: Boolean;
var TanText, Tx, Ty:Integer;
begin
TanText := BitmapFromString(29, 1, 'z78DA7373B3B430747303' +
'930660E04684888985B1ABB131A6384EF5962606C626101259169' +
'344568F290E0045F426A7');

Result := FindBitMapToleranceIn(TanText, Tx, Ty, 127, 28, 180, 48 ,40);
FreeBITMap(TanText);
end;

Function NPCFindNClick( NPCColor1, NPCColor2:integer; UpText1,UpText2, COption:string;RepeatUntil, RightOrLeft:boolean;
HMTolerance:integer):boolean;
var
TMT :Integer;
Coord123X :Integer;
Coord123Y :Integer;
T:integer;
begin
TMT:=0;
repeat
if repeatuntil then
begin
result:=true;
exit;
end;
FindTalk;
TMT:=TMT + 1
Wait(50+random(10));
if FindObjCustom(Coord123X, Coord123Y, [Uptext1, Uptext2], [NPCColor1, NPCColor2],HMTolerance) then//Thanks killerDou!:)
begin
T := GetSystemTime;
Wait(50+random(10));
Mouse(Coord123X, Coord123Y, 1, 1, RightOrLeft);

Wait(50+random(10));
if (RightOrLeft=False) then
begin
if ChooseOption(COption) then
begin
Result:=True;
WriteLn('Found Npc');
fflag(0);
ftwait(3);
if repeatuntil then Break;
end;
end;
end;
until (RepeatUntil) or (TMT>5)
if RepeatUntil then Result:=true;
Writeln(IntToStr(GetSystemTime - T));
end;



var HideDTM:integer;
procedure SetupScript;
begin
SetUpSRL;
symbolaccuracy:=0.6;
DeclarePlayers;
activateclient;
if (not(LoggedIn)) then
LoginPlayer;
MouseSpeed:=15;
makecompass('w');
HideDTM:= DTMFromString('78DA63FCC1C8C090CA800618914820FD87083' +
'5EC4C0C0CD904D47000D5E411A1269F801A36A09A72026A58806A' +
'6A89F057030135DF80AC3A026A3E00595504D4BC6724EC2F90398' +
'4C2F02D90558C5F0D0017680DC8');
end;
function HaveHides:boolean;
var tmpx,tmpy:integer;
begin
gametab(4);
if not FindDTM(HideDTM,tmpx,tmpy,mix1,miy1,mix2,miy2) then
exit;
if getcolor(tmpx+2,tmpy+4)<>getcolor(tmpx+2,tmpy+5) then
result:=true;
end;

function HaveLeathers:boolean;
var tmpx,tmpy:integer;
begin
gametab(4);
if not FindDTM(HideDTM,tmpx,tmpy,mix1,miy1,mix2,miy2) then
exit;
if getcolor(tmpx+2,tmpy+4)=getcolor(tmpx+2,tmpy+5) then
result:=true;
end;

function ToTanShop:boolean;
var tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToTanShop-Start');
if (not HaveHides) and (not HaveLeathers) then
begin
writeln('ToTanShop-No hides/leathers, false');
result:=false;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,660,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
if HaveLeathers or TanScreen then
begin
writeln('ToTanShop-Already done tanning, true')
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'quest',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx+56,tmpy+35) then
begin
writeln('ToTanShop- clicking NW of quest');
mouse(tmpx+56,tmpy+35,3,3,true);
SetRun(true);
fflag(2);
end;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,667,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
if {FindSymbol(tmpx,tmpy,'cook')
or }FindSymbol(tmpx,tmpy,'kebab shop') then
begin
if rs_OnMinimap(tmpx,tmpy+35) then
begin
writeln('ToTanShop- clicking E of cook/kebab');
mouse(tmpx,tmpy+35,3,7,true);
fflag(5);
end;
end;
if FindSymbolIn(tmpx,tmpy,'minigame',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx+32,tmpy-7) then
begin
writeln('ToTanShop- clicking NW of minigame');
mouse(tmpx+32,tmpy-7,3,3,true);
fflag(2);
end;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,mmy1,692,mmy2) then
begin
writeln('ToTanShop-Already close enough to tannery, true');
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'furnace',mmx1,52,667,mmy2) then
begin
writeln('ToTanShop-Already close enough to furnace, true');
result:=true;
exit;
end;
end;

function ToEllis:boolean;
var yellows,yellows3:tpointarray;
var tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToEllis-Start');
if HaveLeathers or TanScreen then
begin
writeln('ToEllis-Already done tanning, true')
result:=true;
exit;
end;
if not FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
if not FindSymbolIn(tmpx,tmpy,'furnace',mmx1,53,mmx2,mmy2) then
begin
writeln('ToEllis-Cant find tannery or furnace, false');
result:=false;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
begin
FindColorsTolerance(yellows,195836,mmx1,mmy1,mmx2,mmy2,0);
writeln(inttostr(getarraylength(yellows))+' yellow pixels');
yellows3:=ReArrangeandShortenArrayEx(yellows,4,4);
writeln(inttostr(getarraylength(yellows3))+' yellow dots');
SortTPAFrom(yellows3,IntToPoint(tmpx,tmpy));
setarraylength(yellows3,2);
SortTPAFrom(yellows3,IntToPoint(mmx2,mmcy));
Mouse(yellows3[0].x,yellows3[0].y,1,1,true);
highestangle;
fflag(0);
end;
if HaveLeathers or TanScreen then
begin
writeln('ToEllis-Already done tanning, true')
result:=true;
exit;
end;
result:=true;
end;

function FindEllis:boolean;
begin
if not loggedin then exit;
writeln('FindEllis-Start');
if HaveLeathers or TanScreen then
begin
writeln('FindEllis-Already done tanning, true')
result:=true;
exit;
end;
if (not HaveHides) and (not HaveLeathers) then
begin
writeln('FindEllis-No hides/leathers, false');
result:=false;
exit;
end;
NPCFindNClick(5208281,4747209,'alk-to Ellis','Ellis','Trade',TanScreen,false,13);
if TanScreen then
writeln('FindEllis-Tanscreen, true')
else
writeln('FindEllis-Failed to find Ellis, false');
result:=tanscreen;
end;

function TanHides:boolean;
begin
writeln('TanHides-Start');
if not loggedin then exit;
if HaveLeathers then
begin
result:=true;
writeln('TanHides-Already got leathers, true');
exit;
end;

if (Players[CurrentPlayer].Booleans[0]) then
begin
writeln('TanHides-Tanning all your hides to green leather.');
//MMouse(93, 237{105},5,5);
ftwait(1);
Mouse(93, 237{105},5,5,false);
Wait(500+random(300));
ChooseOption('All');
Ftwait(4);
result:=HaveLeathers;
end;

if not(Players[CurrentPlayer].Booleans[0]) then
begin
Status('Tanning all your hides to hard leather.');
// MMouse(208, 104,5,5);
Mouse(208, 104,5,5,false);
Wait(500+random(300));
ClickOption('All', 1);
FindNormalRandoms;
Wait(1000+random(250));
end;
end;

function ToBank:boolean;
var i,tmpx,tmpy:integer;
begin
if not loggedin then exit;
writeln('ToBank-Start');
if (HaveHides and (not HaveLeathers)) or TanScreen then
begin
writeln('ToBank- Not done tanning yet, false');
result:=false;
exit;
end;
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
if findsymbol(tmpx,tmpy,'kebab shop') then
begin
writeln('ToBank-heading SW of kebab shop');
mouse(tmpx-(15+random(10)),tmpy+10+random(5),0,0,true);
fflag(5);
end;
if nearbank then
begin
result:=true;
exit;
end;
if FindSymbolIn(tmpx,tmpy,'minigame',mmx1,mmy1,mmx2,mmy2) then
begin
if rs_OnMinimap(tmpx-21,tmpy-40) then
begin
writeln('ToBank- clicking NE of minigame');
mouse(tmpx-21,tmpy-40,3,3,true);
fflag(2);
end;
end;
if nearbank then
begin
result:=true;
exit;
end;
repeat
i:=i+1;
Mouse(590,100,5,5,True);
FindNormalRandoms;
fflag(5);
until (nearbank) or (i>4);
result:=nearbank;
end;

function FindBankers:boolean;
var pt:tpoint;
begin
writeln('FindBankers-Start');
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
if FindSymbol(x,y,'bank') then
begin
writeln('FindBankers-clicking near bank symbol');
Mouse(x,y,3,3,true);
fflag(5);
end;
pt:=FindFourBankers('e');
if (pt.x<>0) and (pt.y<>0) then
begin
writeln('FindBankers-Found DTM, true');
mouse(pt.x,pt.y,0,0,true);
lowestangle;
fflag(0);
result:=true;
end;
end;

function MyOpenBank:boolean;
var i:integer;
begin
if not loggedin then exit;
writeln('OpenBank-Start');
if BankScreen then
begin
writeln('ToBank-Bank already open, true');
result:=true;
exit;
end;
repeat
i:= + 1;
mousespeed:=10;
mmouse(88+random(160),80+random(50),0,0);
OpenBankGlass('akb', false, false);
mousespeed:=15;
if (not BankScreen) and (i >=2) then
begin
FindBankers;
end
until (GetColor(238, 43) = 2070783) or (i >= 4) or (BankScreen);
if BankScreen then
begin
writeln('OpenBank-Opened bank, true');
result:=true;
exit;
end;
if not BankScreen then
begin
writeln('OpenBank-failed to find bank, false');
result:=false;
exit;
end;
end;

function DepositLeathers:boolean;
begin
if not loggedin then exit;
writeln('DepositLeathers-Start');
if HaveLeathers then
begin
getmousepos(x,y);
if not( ((y>221)and(y<239)) and ((x>611)and(x<634)) ) then
Mmouse(665,227,5,5)
getmousepos(x,y);
mouse(x,y,0,0,false);
ClickOption('All', 2);
mmouse(35+49,27+38,1,1);
repeat
Wait(100+random(50));
until (not Bankscreen) or (Not Haveleathers);
TannedLeather:= TannedLeather + 27;
Progress;
end;
FixBank;
Withdraw(1, 1, 0);
CloseBank;
repeat
Wait(100+random(50));
until (not Bankscreen) or (HaveHides);
result:=HaveHides;
end;

procedure Reset;
begin
writeln('Reset');
Logout;
wait(1000);
LoginPlayer;
MouseSpeed:=15;
makecompass('w');


end;
var errors:integer;
begin
SetupScript;
repeat
//yea i know, not indented, but it looks neater this way
if ToTanShop then
if ToEllis then
if FindEllis then
if TanHides then
if ToBank then
if FindBankers then
if MyOpenBank then
if DepositLeathers then
errors:=0;
errors:=errors+1;
if errors>4 then
Reset;
until(Players[CurrentPlayer].Integers[0]<(TannedLeather));
end.

You could also have a main loop like this

repeat
Status := GetStatus;
case Status of
1: do this
2: do that
etc
end;
until
Where GetStatus looks at inventory and location and decides what to do.

You could also layer the decision making and have a very simple main loop (the top layer).

repeat
if HaveMaterials then
DoActivity
else
DoBank
until
Where in DoBank you would have more decision making. If not at bank, then go to bank. Deposit anything that isn't a part of HaveMaterials. Withdraw stuff needed for HaveMaterials. In DoActivity you also have more logic. If not at location, then go to location. If at location, then DoSomething. The third layer is the logic in GoToBank and GoToLocation, which is easy with reflection. just have a TPA path, and instead of starting at one end or another, start at the closet point to your current position (which will be one end or another when everything is normal). If the closest point to your current position is out of sight, blind click towards it. If you aren't getting closer with each click, then you are lost so set player false (unless you have a world walker with a node near you and a node near the location).