SRL Archive - Reflection Tutorials

Small TUT about Reflection!


JuKKa

2008-07-24 09:42:42

Hi

This tutorial is about reflection. ALWAYS WHEN USING REFLECTION YOU HAVE TO USE SMART OR IT WONT WORK.
I wont go into detail on HOW reflection works and what it does.
Reflection is what its called when its "asking" the runescape client on whats on screen or what is happening.
Reflection is a powerfull tool in runescape cheating, its being used by most runescape bots and autos, simply because its so powerfull.
Imagine finding that rock without using any color, and 10 times less code, or walking to falador from varrock using only 10 lines.
However! Whenever runescape updates, the "variables" that reflection uses often change and thus reflection breaks, making it unable to use.
This is why you shouldnt relie 100% on reflection so DO add normal fail safes like the "old" radialwalk, dtms etc.

Before you start coding with reflection what you need is THIS.

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines --||
//------------------------------------------------------------------//
// * Function GetLevel(index: integer): integer; // * by BenLand100
// * Function StringFromBytes(jbytearray: integer): string; // * by BenLand100
// * Function GetMyName: string; // * by BenLand100
// * Function GetAnimation: integer; // * by BenLand100
// * Function GetSpeed: integer; // * by Widget
// * Function CharacterMoving: boolean; // * by BenLand100
// * Procedure GetMyPos(var x, y: Integer); // * by BenLand100
// * Function GetBoxAnswer: integer; // * by BenLand100
// * Function GetMinimapAngleDeg: extended; // * by BenLand100
// * Function GetMinimapAngleRad: extended; // * by BenLand100
// * Procedure TileToMinimap(tileX, tileY: integer; var screenX, // * by BenLand100
// screenY: integer); //
// * Procedure MinimapToTile(screenX, screenY: integer; var tileX, // * by BenLand100
// tileY: integer); //
// * Procedure TileToMS(tileX, tileY, height: integer; // * by BenLand100
// var screenX, screenY: integer); //
// * Function TileOnMM(TileX, TileY : Integer) : Boolean; // * by ss23
// * Function TileOnMS(TileX, TileY, Height : Integer) : Boolean; // * by ss23
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
// * Function GetNPCs: array of TNPC; // * by Widget
// * Function GetNPCsByName: array of TNPC; // * by Widget
// * Function GetNPCsByID: array of TNPC; // * by Widget
// * Function SortNPCs(NPCs: array of TNPC): array of TNPC; // * by Widget
// * Function FindNPC(Name: string; height: integer; // * by Widget
// * var x,y:integer): Boolean; //
// * Function FindNPCTile(Name: string; var x,y:integer): Boolean; // * by Widget
// * Function ClickTile(TileX, TileY, Height : Integer; // * by ss23 and Widget
// Left : Boolean) : Boolean; //
// * Procedure WalkToTile(Tilex, Tiley : Integer); // * by ss23
// * Function MMtoMS(x, y: Integer; left: Boolean): Boolean; // * by LeeLokHin
// * Function OpenBankReflection(Bank : String): Boolean; // * by ss23
//------------------------------------------------------------------//
// NPC stuff completely re-written
//
// Added TNPC type, will use later; Improved TileOn functions - ss23
//
// Thanks to Speljohan and Quaters for making hooks that we can steal =)
//------------------------------------------------------------------//

type
TPlayer = record
x, y:integer;
animation, speed: integer;
HPRatio, height, level: integer;
Name, PrayerHeadIcon: string;
Levels, Experiences: array[1..28]{or whatever} of integer;
end;

type TNPC = record
x, y, NPCType : integer;
TheName : string;
InFight, IsMoving: boolean;
end;

const
// Global Static Hooks
BaseLayer = 'bc.f';
BaseX = 'pa.e';
BaseY = 'rb.D';
CamX = 'ph.j';
CamY = 'bb.y';
CamZ = 'bi.w';
CamPitch = 'pi.E';
CamYaw = 'sh.N';
CompassAngle = 'oj.p';
CurrentLevels = 'fd.eb';
Experiences = 'e.n';
FlagX = 'sc.Y';
FlagY = 'le.f';
GroundHeights = 'lh.N';
GroundSettings = 'ad.P';
LoopCycle = 'lg.a';
MapOffsetAngle = 'fa.m';
MaxLevels = 'hk.e';
MyPlayer = 'th.u';
NPCArray = 'gj.o';
NPCCount = 'qi.h';
NPCIndexArray = 'cf.c';
SettingsArray = 'ki.c';

// Character Hooks
CharAnim = 'cb';
CharMotion = 'pb';
CurrentX = 'Q';
CurrentY = 'Bb';
Height = 'y';
LoopCycleStatus= 'qb';

// Player Hooks
CharName = 'uc';

// NPC Hooks
NPCDef = 'Nb';

// NPCDef Hooks
GetNPCName = 'V';
GetNPCType = 'j';

// RSString Hooks
StringBytes = 'B';

//----------------------------------------------------------------------//

function GetLevel(index: integer): integer;
{*******************************************************************
Function - GetLevel(index: integer): integer;
By: BenLand100
Description: Returns the current level of your player (its a funny array)
********************************************************************}
begin
result:= SmartGetFieldArrayInt(0,CurrentLevels,index);
end;

function StringFromBytes(jbytearray: integer): string;
{*******************************************************************
Function - StringFromBytes(jbytearray: integer): string;
By: BenLand100
Description: Converts a byte[] from StringWrap to a DelphiString
(max length 256)
********************************************************************}
begin
SetLength(result, 256);
SetLength(result, SmartStringFromBytes(jbytearray,result));
end;

function GetMyName: string;
{*******************************************************************
Function - GetMyName: string;
By: BenLand100
Description: Returns last logged in player's name
********************************************************************}
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(0,MyPlayer+'.'+CharName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;

function GetAnimation: integer;
{*******************************************************************
Function - GetAnimation: integer;
By: BenLand100
Description: Returns your animation
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharAnim);
end;

function GetSpeed: integer; // :)
{*******************************************************************
Function - GetSpeed: integer;
By: Widget
Description: Gets character speed (squares per second)
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharMotion);
end;

function CharacterMoving: boolean; //:)
{*******************************************************************
Function - CharacterMoving: boolean;
By: BenLand100
Description: True if you are moving
********************************************************************}
begin
result:= (GetSpeed > 0);
end;

procedure GetMyPos(var x, y: Integer); // :)
{*******************************************************************
procedure - GetMyPos(var x, y: Integer);
By: BenLand100
Description: Calculates your x,y position or [somehugenumber] if not
logged in
********************************************************************}
var
me: Integer;
begin
me:= SmartGetFieldObject(0,MyPlayer);
x:= SmartGetFieldInt(0,BaseX) + SmartGetFieldInt(me,CurrentX) shr 7;
y:= SmartGetFieldInt(0,BaseY) + SmartGetFieldInt(me,CurrentY) shr 7;
SmartFreeObject(me);
end;

function DumpSettingArray: array[0..1999] of integer;
{*******************************************************************
function - DumpSettingArray: array[0..1999] of integer;
By: BenLand100
Description: Dumps the settings array to an integer array
********************************************************************}
var
i: integer;
begin
for i:= 0 to 1999 do
Result[i]:= SmartGetFieldArrayInt(0,SettingsArray,i);
end;

function GetBoxAnswer: integer;
{*******************************************************************
function - GetBoxAnswer: integer;
By: BenLand100
Description: Returns -1 if no box open or 0..2 for the correct
answer to the box
Comments: Yet another reason reflection is leet =) [-Widget]
********************************************************************}
var
boxIndex: Integer;
begin
boxIndex:= SmartGetFieldArrayInt(0,SettingsArray,312);
if boxIndex = 0 then
result:= -1
else
result:= (boxIndex shr 24) and $FF;
end;

function GetMinimapAngleDeg: extended;
{*******************************************************************
function - GetMinimapAngleDeg: extended;
By: BenLand100
Description: Returns the current Map angle in degrees
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * 180 / 1024;
end;

function GetMinimapAngleRad: extended;
{*******************************************************************
function - GetMinimapAngleRad: extended;
By: BenLand100
Description: Returns the current map angle in radians
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * Pi / 1024;
end;

procedure TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a minimap location
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
GetMyPos(tempX, tempY);
tempX:= (tileX - tempX) * 4 - 2;
tempY:= (tempY - tileY) * 4 - 2;
screenX:= round(tempX*cos(angle) - tempY*sin(angle)) + 629;
screenY:= round(tempX*sin(angle) + tempY*cos(angle)) + 85;
end;

procedure MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
{*******************************************************************
procedure - MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
By: BenLand100
Description: converts the screen position screenX,screenY from the minimap
to a tile
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
tempX:= (screenX - 643);
tempY:= (84 - screenY);
tileX:= round(tempX*cos(angle) - tempY*sin(angle)) / 4;
tileY:= round(tempX*sin(angle) + tempY*cos(angle)) / 4;
GetMyPos(tempX, tempY);
tileX:= tileX + tempX;
tileY:= tileY + tempY;
end;

procedure TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a mainscreen location
Height is the distance (in px) above the ground
********************************************************************}
var
cx, cy, cz, dx, dy, dz, locX, locY, layer: Integer;
pitch, yaw, sinYaw, cosYaw, sinPitch, cosPitch, rotation: extended;
begin
locX:= tileX - SmartGetFieldInt(0,BaseX);
locY:= tileY - SmartGetFieldInt(0,BaseY);
if (locX < 0) or (locY < 0) or (locX > 103) or (locY > 103) then
Exit;
layer:= SmartGetFieldInt(0,BaseLayer);
if (layer < 3) and ((2 and SmartGetFieldArray3DByte(0,GroundSettings,1,locX,locY)) = 2) then
Inc(layer);
cz:= SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY+1) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY+1);
cx:= locX * 128 + 64 - SmartGetFieldInt(0,CamX);
cy:= locY * 128 + 64 - SmartGetFieldInt(0,CamY);
cz:= (cz / 4) - height - SmartGetFieldInt(0,CamZ);
pitch:= SmartGetFieldInt(0,CamPitch) * Pi / 1024;
yaw:= SmartGetFieldInt(0,CamYaw) * Pi / 1024;
sinYaw:= sin(yaw);
cosYaw:= cos(yaw);
sinPitch:= sin(pitch);
cosPitch:= cos(pitch);
rotation:= cosYaw*cy-sinYaw*cx;
dx:= Round(sinYaw*cy+cosYaw*cx);
dy:= Round(sinPitch*cz+cosPitch*rotation);
dz:= Round(cosPitch*cz-sinPitch*rotation);
screenX:= (dx * 512) / dy + 256;
screenY:= (dz * 512) / dy + 167;
end;

Function TileOnMM(TileX, TileY : Integer) : Boolean;
{*******************************************************************
Function TileOnMM(TileX, TileY : Integer) : Boolean;
By: ss23
Description: True = Tile on MM
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MMX1, MMY1, MMX2, MMY2);
TileToMinimap(TileX, TileY, PointEx.x, PointEx.y);
Result := PointInBox(PointEx, BoxEx);
end;

Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
{*******************************************************************
Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
By: ss23
Description: True = Tile on MS
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MSX1, MSY1, MSX2, MSY2);
TileToMS(Tilex, Tiley, Height, pointex.x, pointex.y);
Result := PointInBox(PointEx, BoxEx);
end;

Function DistanceFrom(TileX, TileY: Integer) : Integer;
{*******************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
********************************************************************}
Var
MyX,MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;

function GetNPCs:array of TNPC;
{*******************************************************************
function GetNPCObjects:array of integer;
By: Widget
Description: Returns all the currently loaded NPCs
********************************************************************}
var
i,NumNPCs,Index,TheNPC,TheNPCDef,TheBytes: integer;
begin
NumNPCs := SmartGetFieldInt(0,NPCCount);
if (NumNPCs=0) then Exit;
SetArrayLength(Result,NumNPCs);
for i := 0 to (NumNPCs-1) do
begin
Index := SmartGetFieldArrayInt(0,NPCIndexArray,i);
TheNPC := SmartGetFieldArrayObject(0,NPCArray,Index);
TheNPCDef := SmartGetFieldObject(TheNPC,NPCDef);
TheBytes := SmartGetFieldObject(TheNPCDef,GetNPCName+'.'+StringBytes);
Result[i].TheName := StringFromBytes(TheBytes);
Result[i].x := (SmartGetFieldInt(0, BaseX) + (SmartGetFieldInt(TheNPC, CurrentX) shr 7));
Result[i].y := (SmartGetFieldInt(0, BaseY) + (SmartGetFieldInt(TheNPC, CurrentY) shr 7));
Result[i].NPCType := SmartGetFieldInt(TheNPCDef,GetNPCType);
Result[i].InFight := (SmartGetFieldInt(0,LoopCycle)<SmartGetFieldInt(TheNPC,LoopCycleStatus));
Result[i].IsMoving := (SmartGetFieldInt(TheNPC,CharMotion)>0);
SmartFreeObject(TheNPC);
SmartFreeObject(TheNPCDef);
SmartFreeObject(TheBytes);
end;
end;

function GetNPCsByName(name:string):array of TNPC;
{*******************************************************************
Function GetNPCsByName(name:string):array of TNPC;
By: Widget
Description: Returns NPCs matching the name.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
NPCs := GetNPCs;
if (GetArrayLength(NPCs)=0) then Exit;
for i := 0 to High(NPCs) do
if (pos(trim(name),trim(NPCs[i].TheName))>0) then
begin
SetArrayLength(result,GetArrayLength(result)+1);
result[GetArrayLength(result)-1] := NPCs[i];
end;
end;

function GetNPCsByID(TheType:integer):array of TNPC;
{*******************************************************************
Function GetNPCsByID(TheType:integer):array of TNPC;
By: Widget
Description: Returns NPCs matching the ID.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
NPCs := GetNPCs;
if (GetArrayLength(NPCs)=0) then Exit;
for i := 0 to High(NPCs) do
if (NPCs[i].NPCType=TheType) then
begin
SetArrayLength(result,GetArrayLength(result)+1);
result[GetArrayLength(result)-1] := NPCs[i];
end;
end;

function SortNPCs(NPCs:array of TNPC):array of TNPC;
{*******************************************************************
Function SortNPCs(NPCs:array of TNPC):array of TNPC;
By: Widget
Description: Sorts NPCs by distance from you.
********************************************************************}
var
i,i2,ix,iy: integer;
tpa: TPointArray;
begin
SetArrayLength(TPA,GetArrayLength(NPCs));
SetArrayLength(Result,GetArrayLength(NPCs));
for i := 0 to high(NPCs) do
TPA[i] := Point(NPCs[i].x, NPCs[i].y);
GetMyPos(ix, iy);
SortTPAFrom(TPA, Point(ix, iy));
for i := 0 to high(TPA) do
for i2 := 0 to high(NPCs) do // they really should be the same
if (TPA[i].x=NPCs[i2].x) and (TPA[i].y=NPCs[i2].y) then
Result[i] := NPCs[i2];
end;

Function FindNPCTile(Name: string; var TileX,TileY:integer):boolean;
{*******************************************************************
Function GetNPCTile(Name: string; var x,y:integer):boolean;
By: Widget
Description: Finds the tile of the named NPC, returns tile (useful for banking)
********************************************************************}
var
NPCs: array of TNPC;
begin
NPCs := SortNPCs(GetNPCsByName(Name));
result := False;
if (GetArrayLength(NPCs)=0) then
Exit;
result := true;
TileX := NPCs[0].x;
TileY := NPCs[0].y;
end;

Function FindNPC(Name: string; height:integer; var x,y:integer):boolean;
{*******************************************************************
function FindNPC(Name: string; var x,y:integer):boolean;
By: Widget
Description: Finds the tile of the named NPC, returns MS Point
********************************************************************}
var
p: TPoint;
begin
result := FindNPCTile(Name,p.x,p.y);
TileToMS(p.x,p.y,height,x,y);
end;

Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
{*******************************************************************
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
By: ss23 and Widget
Description: Clicks a tile. Height is the approximate heigh in pixels
Height doesnt matter if HighestAngle;
********************************************************************}
Var
x, y : Integer;
Begin
TileToMS(TileX, TileY, Height, x, y);
result := TileOnMs(x,y,height);
if not result then
Exit;
Mouse(x, y, 5, 5, False);
end;

Function WalkToTile(TileX, TileY : Integer): Boolean;
{*******************************************************************
Function - WalkToTile(TileX, TileY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
********************************************************************}
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;

procedure MMtoMS(MMX,MMY:integer; var MSX,MSY:integer);
{*******************************************************************
Function MMtoMS(x, y: Integer; left: Boolean): Boolean;
By: LeeLokHin
Description: Converts Coordinates x and y on the minimap
to equivilants on the MainScreen and clicks right or left according
to boolean left.
********************************************************************}
var
tx,ty:integer;
begin
MinimapToTile(MMX, MMY, tx, ty);
TileToMS(tx, ty, 5, MSX, MSY);
end;

Function OpenBankReflection(Bank : String): Boolean;
{*******************************************************************
Function OpenBankReflection(Bank : String): Boolean;
By: ss23
Description: Opens the bank. Bank = 'veb' atm. Opens nearest slot
********************************************************************}
Var
x, y : Integer;
Me : TPoint;
Tiles : TPointArray;
Begin
Case Bank of
'veb': Tiles := [Point(3251,3419), Point(3252,3419), Point(3253,3419), Point(3254,3419), Point(3255,3419), Point(3256,3419)];
'vwb': Tiles := [Point(3190,3435), Point(3190,3437), Point(3190,3439), Point(3190,3441), Point(3190,3443), Point(3181,3444), Point(3181,3442), Point(3181,3440), Point(3181,3438), Point(3181,3436)];
'fwb': Tiles := [Point(2945,3367), Point(2946,3367), Point(2947,3367), Point(2948,3367)];
'feb': Tiles := [Point(3010,3354), Point(3011,3354), Point(3012,3354), Point(3013,3354), Point(3014,3354), Point(3015,3354)];
'lum': Tiles := [Point(3208,3221)];
'dra': Tiles := [Point(3091,3419), Point(3091,3245), Point(3091,3244), Point(3091,3243), Point(3091,3242)];
'alk': Tiles := [Point(3268,3168), Point(3268,3167), Point(3268,3166), Point(3268,3165), Point(3268,3164)];
end;
GetMyPos(Me.x, Me.y);
SortTPAFrom(Tiles, Me);
If (DistanceFrom(Tiles[0].x, Tiles[0].y) > 3) then
Begin
If not(TileOnMM(Tiles[0].x, Tiles[0].y)) then
Begin
Writeln('Couldn''t find bank');
Result := False;
Exit;
end;
WalkToTile(Tiles[0].x, Tiles[0].y);
Wait(10);
Flag;
Wait(100 + Random(100));
end;
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 15)) then
Begin
SetAngle(True);
MakeCompass('n');
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 20)) then
Begin
Writeln('Couldnt'' find bank booth');
Result := False;
Exit;
end;
end;
TileToMS(Tiles[0].x, Tiles[0].y, 20, x, y);
Mouse(x, y, 5, 5, False);
// Make choose option work here
// Wait(100 + Random(100));
// ChooseOption('uic');
Result := True;
end;


This is "Reflection.Scar"

Copy paste this to scar and save it to "Scar/Includes/SRL/SRL/Misc/" As "Reflection.Scar"


Okay, when you have done that.
This is the way you use reflection in ur script.


Program ReflectionSetup;
{.Include SRL/SRL/Misc/SMART.Scar}
{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Misc/Reflection.Scar}

Procedure SetupSMART;
Begin
SmartSetupEx(136, True, True, False);
SetTargetDC(SmartGetDC);
If Not (LoggedIn) Then
While Not (SmartGetColor(360, 172) = 13158) Do
Wait(100);
End;

Begin
SetupSRL;
SetupSMART;
End.

Now you might wonder… Okay how do i use this reflection….
Simple…

To get your animation you would use something like this

Writeln('Your animation is = '+IntToStr( GetAnimation ));

This writes ur current animation to the debug box.
What you HAVE to remember is that EVERY SINGLE animation has a different number.
Meaning that GetAnimation = 621, means that you are fishing with a net.

IMPORTANT!!!
Different axes and pickaxes have different animations.
But to solve this in a easy way.
Lets say while woodcutting animation with bronze axe is 100 and iron is 101, steel 102, black 103 and so on.
We can simply do this:


Function WoodCutting: Boolean;
Begin
Result := InRange(GetAnimation, 100, 107);
End;

Please post if you missunderstood anything about getanimation.



Tiles and walking…

Okay… every single square in runescape has a tile number. Its a bit like a x, y coordinate like in math.
Well you might wonder well how do i walk using these tiles numbers.

To get your tile number (where you are standing) is simple just run this in scar


Var
X, Y: Integer;

Begin
SetupSRL;
SetupSMART;

GetMyPos(X, Y);
Writeln('Tile X = '+IntTostr(X)+' - Tile Y = '+IntToStr(Y));
End.

Remember to include the basic reflection includes and SMART!

You might wonder ok.. Whats the best way to use the tiles…
HERE

Loading your tiles to a TPA (T Point Array, you might need to read a small tutorial about that, its quite easy)

Tiles := [Point( TileX1, TileY1), Point(TileX2, TileY2), Point(TileX3, TileY3)];

OR

Tiles[0] := Point( TileX1, TileY1);
etc

or

Tiles[0].X := TileX1;
Tiles[0].Y := TileY1;

Thats 3 different ways to make a tile array

Now to use the tiles to walk on them is easy, if you have made a series of tiles like this the simpliest way to execute them is this:

For I:= 0 To High(Tiles) Do
WalkToTile(Tiles.X, Tiles.Y);

You might need to read a tutorial about arrays to fully understand this.

please POST if you didnt understand something.

Timer

2008-07-24 09:50:31

Hmm, Interesting, I know all about it already… You left alot out…

Plus, reflection.scar is changing too much, instead of showing it, give the link… http://widget.pastebin.com/

Laur€ns

2008-07-24 09:55:42

I didn't knew anything about it,, Thanks :)
And Timer, it's called "Small TUT about Reflection".

Wanted

2008-07-24 11:39:22

Nice tutorial.

{Edit: OK LOL nevermind, you did.

Good job! :D}

But could you please at least mention the color back up fail safes?

begin
if (not (LoggedIn)) then
Exit;
if (not (WalkToTile(1459, 5954))) then //Tile walking, Most relaible.
begin
WriteLn('Tile walking failed, switching to DDTM detection.');
if (not (FindDTMRotated(DDTM, ....))) then //DDTM, 2nd most relaible.
begin
WriteLn('DDTM detection failed! switching to DTM detection...');
if (not (FindDTMRotated(DTM ....))) then //DTM with tol, 3rd most relaible
begin
WriteLn('DTM detection failed! switching to Symbol detection...');
if (not (FindSymbol('Bank'...))) then //Symbol, 4th most relaible.
begin
WriteLn('Symbol detection failed! switching to map angle detection...');
if (not (AngleWalk(90, 50...))) then //Angle walk, 5th. Fails when angle detection fails.
begin
WriteLn('Map angle detection failed! Blind clicking...');
{--------------------------------}
WalkTo(585, 42); //Blind Click, never fails but is risky.
{if (not (WalkTo(585, 42))) then
begin
WriteLn('Blind click failed! All fail safes exhausted!');
WriteLn('Logging out player...');
LogOut;
Exit;
end
else
begin
WriteLn('Blind click successful!');
WalkTo(585, 42);
end;}
end
else
WriteLn('Map angle detection successful!');
end
else
begin
WriteLn('Symbol detection successful!');
WalkTo(Bank);
end;
end
else
begin
WriteLn('DTM detection successful!');
WalkTo(Bank.MM);
end;
end
else
begin
WriteLn('DDTM detection successful!');
WalkTo(Bank.MM);
end;
end
else
WriteLn('Tile walking successful!');
if (not (OpenBankReflection('FEB'))) then
begin
WriteLn('Bank detection by reflection failed! switching to color detection...');
if (not (OpenBankFast('FEB'))) then
begin
WriteLn('Color detection failed! All fail safes exhausted!');
LogOut;
Exit;
end
else
WriteLn('Color detection successful!');
end
else
WriteLn('Reflection detection successful!');
WriteLn('Opened bank!');
end;

MasterKill

2008-07-24 14:18:25

omg I love benland for making this

THANKS JUKKA for the turial :)

n3ss3s

2008-07-24 15:36:38

Good that you made a tutorial about this, the first one :)

Waddo

2008-07-25 11:54:09

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines --||
//------------------------------------------------------------------//
// * Procedure SetupReflection; // * by MasterKill
// * Function GetLevel(index: integer): integer; // * by BenLand100
// * Function StringFromBytes(jbytearray: integer): string; // * by BenLand100
// * Function GetMyName: string; // * by BenLand100
// * Function GetAnimation: integer; // * by BenLand100
// * Function GetSpeed: integer; // * by Widget
// * Function CharacterMoving: boolean; // * by BenLand100
// * Procedure GetMyPos(var x, y: Integer); // * by BenLand100
// * Function GetBoxAnswer: integer; // * by BenLand100
// * Function GetMinimapAngleDeg: extended; // * by BenLand100
// * Function GetMinimapAngleRad: extended; // * by BenLand100
// * Procedure TileToMinimap(tileX, tileY: integer; var screenX, // * by BenLand100
// screenY: integer); // º
// * Procedure MinimapToTile(screenX, screenY: integer; var tileX, // * by BenLand100
// tileY: integer); // º
// * Procedure TileToMS(tileX, tileY, height: integer; // * by BenLand100
// var screenX, screenY: integer); // º
// * Function TileOnMM(TileX, TileY : Integer) : Boolean; // * by ss23
// * Function TileOnMS(TileX, TileY, Height : Integer) : Boolean; // * by ss23
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
// * Function GetNPCs: array of TNPC; // * by Widget
// * Function GetNPCsByName: array of TNPC; // * by Widget
// * Function GetNPCsByID: array of TNPC; // * by Widget
// * Function SortNPCs(NPCs: array of TNPC): array of TNPC; // * by Widget
// * Function FindNPC(Name: string): TNPC; // * by Widget
// * Function FindNPCByID(ID: integer): TNPC; // * by Widget
// * Function ClickTile(TileX, TileY, Height : Integer; // * by ss23 and Widget
// Left : Boolean) : Boolean; // º
// * Function WalkToTile(Tilex, Tiley : Integer): Boolean; // * by ss23 and Widget
// * Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean; // * by ss23, Widget and TheGuyWhoGotOn
// * Function LongWalkEx(TileX, TileY, DisX, DisY, // * by TheGuyWhoGotOn
// Tol : integer): Boolean; // º
// * Function LongWalk(TileX, TileY, Tol : integer): Boolean; // * by TheGuyWhoGotOn
// * Function PathWalk(Path : array of TPoint; Long : boolean; // * by TheGuyWhoGotOn
// Tol : integer): Boolean; // º
// * Function MMtoMS(x, y: Integer; left: Boolean): Boolean; // * by LeeLokHin
// * Function OpenBankReflection(Bank : String): Boolean; // * by ss23 and TheGuyWhoGotOn
// * Function GetPlayers: array of TPlayer; // * by Widget
// * Function MakeCompassReflection(Direction: string; // * by Waddo
// Accuracy: integer): Boolean; // º
// * Procedure GetNPCInfo; // * by Waddo
//
//------------------------------------------------------------------//
// NPC stuff completely re-written
//
// TPlayer not used yet but eventually I'll stop being lazy -Widget
//
// Thanks to Speljohan and Quaters for making hooks that we can steal =)
//------------------------------------------------------------------//


type
TNPC = record
TileX, TileY, MSX, MSY, NPCType, height : integer;
Name : string;
InFight, IsMoving: boolean;
end;
TPlayer = record
x, y:integer;
animation, speed: integer;
HPRatio, height, level: integer;
Name: string;
Levels, Experiences: array[1..24]{or whatever} of integer;
end;

Var
BaseLayer, BaseX, BaseY, CamX, CamY, CamZ, CamPitch, CamYaw,
CompassAngle, CurrentLevels, Experiences, FlagX, FlagY, GroundHeights,
GroundSettings, LoopCycle, MapOffSetAngle, MaxLevels, MyPlayer,
NPCArray, NPCCount, NPCIndexArray, PlayerArray, PlayerCount,
PlayerIndArray, SettingsArray, CharAnim, CharMotion, CurrentX, CurrentY, CharHeight, LoopCycleStatus,
CharName, NPCDef, GetNPCName, GetNPCType, StringBytes: String;



//----------------------------------------------------------------------//

// fucntion explode my by: A G E N T 83
function Explode(Delimiter : string; Str : string) : array of string;
var
DelimPos, i : integer;
Arr1 : array of string;
begin
SetArrayLength(Arr1, 100000);
i := 0;
repeat
if (pos(Delimiter, Str) = 0) then Break;
DelimPos := pos(Delimiter, Str);
Arr1[i] := Replace((copy(Str,0,DelimPos)),Delimiter,'');
Delete(Str,1,DelimPos);
i := i + 1;
until(pos(Delimiter, Str) = 0);
Arr1[i] := Str;
SetArrayLength(Arr1, i+1);
Result := Arr1;
end;

{*******************************************************************
Procedure SetupReflection;
By: MasterKill
Description: Loads RS hooks from an text file
********************************************************************}
Procedure SetupReflection;
Var
HooksPage: String;
Hook: TStringArray;
StartTime: Integer;
Begin
StartTime := GetSystemTime;
HooksPage := GetPage('http://www.freewebs.com/srlfiles/hooks.txt');
Hook := Explode(',', HooksPage);
BaseLayer := Hook[0];
BaseX := Hook[1];
BaseY := Hook[2];
CamX := Hook[3];
CamY := Hook[4];
CamZ := Hook[5];
CamPitch := Hook[6];
CamYaw := Hook[7];
CompassAngle := Hook[8];
CurrentLevels := Hook[9];
Experiences := Hook[10];
FlagX := Hook[11];
FlagY := Hook[12];
GroundHeights := Hook[13];
GroundSettings := Hook[14];
LoopCycle := Hook[15];
MapOffsetAngle := Hook[16];
MaxLevels := Hook[17];
MyPlayer := Hook[18];
NPCArray := Hook[19];
NPCCount := Hook[20];
NPCIndexArray := Hook[21];
PlayerArray := Hook[22];
PlayerCount := Hook[23];
PlayerIndArray := Hook[24];
SettingsArray := Hook[25];
CharAnim := Hook[26];
CharMotion := Hook[27];
CurrentX := Hook[28];
CurrentY := Hook[29];
CharHeight := Hook[30];
LoopCycleStatus:= Hook[31];
CharName := Hook[32];
NPCDef := Hook[33];
GetNPCName := Hook[34];
GetNPCType := Hook[35];
StringBytes := Hook[36];
WriteLn('Setting up reflection took ' + IntToStr(GetSystemTime - StartTime) + ' ms.');
End;

function GetLevel(index: integer): integer;
{*******************************************************************
Function - GetLevel(index: integer): integer;
By: BenLand100
Description: Returns the current level of your player (its a funny array)
********************************************************************}
begin
result:= SmartGetFieldArrayInt(0,CurrentLevels,index);
end;

function StringFromBytes(jbytearray: integer): string;
{*******************************************************************
Function - StringFromBytes(jbytearray: integer): string;
By: BenLand100
Description: Converts a byte[] from StringWrap to a DelphiString
(max length 256)
********************************************************************}
begin
SetLength(result, 256);
SetLength(result, SmartStringFromBytes(jbytearray,result));
end;

function GetMyName: string;
{*******************************************************************
Function - GetMyName: string;
By: BenLand100
Description: Returns last logged in player's name
********************************************************************}
var
bytes: Integer;
begin
bytes:= SmartGetFieldObject(0,MyPlayer+'.'+CharName+'.'+StringBytes);
result:= StringFromBytes(bytes);
SmartFreeObject(bytes);
end;

function GetAnimation: integer;
{*******************************************************************
Function - GetAnimation: integer;
By: BenLand100
Description: Returns your animation
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharAnim);
end;

function GetSpeed: integer; // :)
{*******************************************************************
Function - GetSpeed: integer;
By: Widget
Description: Gets character speed (squares per second)
********************************************************************}
begin
result:= SmartGetFieldInt(0,MyPlayer+'.'+CharMotion);
end;

function CharacterMoving: boolean; //:)
{*******************************************************************
Function - CharacterMoving: boolean;
By: BenLand100
Description: True if you are moving
********************************************************************}
begin
result:= (GetSpeed > 0);
end;

procedure GetMyPos(var x, y: Integer); // :)
{*******************************************************************
procedure - GetMyPos(var x, y: Integer);
By: BenLand100
Description: Calculates your x,y position or [somehugenumber] if not
logged in
********************************************************************}
var
me: Integer;
begin
me:= SmartGetFieldObject(0,MyPlayer);
x:= SmartGetFieldInt(0,BaseX) + SmartGetFieldInt(me,CurrentX) shr 7;
y:= SmartGetFieldInt(0,BaseY) + SmartGetFieldInt(me,CurrentY) shr 7;
SmartFreeObject(me);
end;

function DumpSettingArray: array[0..1999] of integer;
{*******************************************************************
function - DumpSettingArray: array[0..1999] of integer;
By: BenLand100
Description: Dumps the settings array to an integer array
********************************************************************}
var
i: integer;
begin
for i:= 0 to 1999 do
Result[i]:= SmartGetFieldArrayInt(0,SettingsArray,i);
end;

function GetBoxAnswer: integer;
{*******************************************************************
function - GetBoxAnswer: integer;
By: BenLand100
Description: Returns -1 if no box open or 0..2 for the correct
answer to the box
Comments: Yet another reason reflection is leet =) -Widget
********************************************************************}
var
boxIndex: Integer;
begin
boxIndex:= SmartGetFieldArrayInt(0,SettingsArray,312);
if boxIndex = 0 then
result:= -1
else
result:= (boxIndex shr 24) and $FF;
end;

function GetMinimapAngleDeg: extended;
{*******************************************************************
function - GetMinimapAngleDeg: extended;
By: BenLand100
Description: Returns the current Map angle in degrees
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * 180 / 1024;
end;

function GetMinimapAngleRad: extended;
{*******************************************************************
function - GetMinimapAngleRad: extended;
By: BenLand100
Description: Returns the current map angle in radians
********************************************************************}
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * Pi / 1024;
end;

procedure TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a minimap location
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
GetMyPos(tempX, tempY);
tempX:= (tileX - tempX) * 4 - 2;
tempY:= (tempY - tileY) * 4 - 2;
screenX:= round(tempX*cos(angle) - tempY*sin(angle)) + 629;
screenY:= round(tempX*sin(angle) + tempY*cos(angle)) + 85;
end;

procedure MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
{*******************************************************************
procedure - MinimapToTile(screenX, screenY: integer; var tileX, tileY: integer);
By: BenLand100
Description: converts the screen position screenX,screenY from the minimap
to a tile
********************************************************************}
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
tempX:= (screenX - 643);
tempY:= (84 - screenY);
tileX:= round(tempX*cos(angle) - tempY*sin(angle)) / 4;
tileY:= round(tempX*sin(angle) + tempY*cos(angle)) / 4;
GetMyPos(tempX, tempY);
tileX:= tileX + tempX;
tileY:= tileY + tempY;
end;

procedure TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
{*******************************************************************
procedure - TileToMS(tileX, tileY, height: integer; var screenX, screenY: integer);
By: BenLand100
Description: Converts the tile position tileX,tileY to a mainscreen location
Height is the distance (in px) above the ground
********************************************************************}
var
cx, cy, cz, dx, dy, dz, locX, locY, layer: Integer;
pitch, yaw, sinYaw, cosYaw, sinPitch, cosPitch, rotation: extended;
begin
locX:= tileX - SmartGetFieldInt(0,BaseX);
locY:= tileY - SmartGetFieldInt(0,BaseY);
if (locX < 0) or (locY < 0) or (locX > 103) or (locY > 103) then
Exit;
layer:= SmartGetFieldInt(0,BaseLayer);
if (layer < 3) and ((2 and SmartGetFieldArray3DByte(0,GroundSettings,1,locX,locY)) = 2) then
Inc(layer);
cz:= SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY+1) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY+1);
cx:= locX * 128 + 64 - SmartGetFieldInt(0,CamX);
cy:= locY * 128 + 64 - SmartGetFieldInt(0,CamY);
cz:= (cz / 4) - height - SmartGetFieldInt(0,CamZ);
pitch:= SmartGetFieldInt(0,CamPitch) * Pi / 1024;
yaw:= SmartGetFieldInt(0,CamYaw) * Pi / 1024;
sinYaw:= sin(yaw);
cosYaw:= cos(yaw);
sinPitch:= sin(pitch);
cosPitch:= cos(pitch);
rotation:= cosYaw*cy-sinYaw*cx;
dx:= Round(sinYaw*cy+cosYaw*cx);
dy:= Round(sinPitch*cz+cosPitch*rotation);
dz:= Round(cosPitch*cz-sinPitch*rotation);
screenX:= (dx * 512) / dy + 256;
screenY:= (dz * 512) / dy + 167;
end;

Function TileOnMM(TileX, TileY : Integer) : Boolean;
{*******************************************************************
Function TileOnMM(TileX, TileY : Integer) : Boolean;
By: ss23
Description: True = Tile on MM
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MMX1, MMY1, MMX2, MMY2);
TileToMinimap(TileX, TileY, PointEx.x, PointEx.y);
Result := PointInBox(PointEx, BoxEx);
end;

Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
{*******************************************************************
Function TileOnMS(TileX, TileY, Height : Integer) : Boolean;
By: ss23
Description: True = Tile on MS
********************************************************************}
Var
PointEx : TPoint;
BoxEx : TBox;
Begin
BoxEx := IntToBox(MSX1, MSY1, MSX2, MSY2);
TileToMS(Tilex, Tiley, Height, pointex.x, pointex.y);
Result := PointInBox(PointEx, BoxEx);
end;

Function DistanceFrom(TileX, TileY: Integer) : Integer;
{*******************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
********************************************************************}
Var
MyX,MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;

function GetNPCs:array of TNPC;
{*******************************************************************
function GetNPCs:array of TNPC;
By: Widget
Description: Returns all the currently loaded NPCs
********************************************************************}
var
i,NumNPCs,Index,TheNPC,TheNPCDef,TheBytes: integer;
begin
NumNPCs := SmartGetFieldInt(0,NPCCount);
if (NumNPCs=0) then Exit;
SetArrayLength(Result,NumNPCs);
for i := 0 to (NumNPCs-1) do
begin
Index := SmartGetFieldArrayInt(0,NPCIndexArray,i);
TheNPC := SmartGetFieldArrayObject(0,NPCArray,Index);
TheNPCDef := SmartGetFieldObject(TheNPC,NPCDef);
TheBytes := SmartGetFieldObject(TheNPCDef,GetNPCName+'.'+StringBytes);
Result[i].Name := StringFromBytes(TheBytes);
Result[i].TileX := (SmartGetFieldInt(0, BaseX) + (SmartGetFieldInt(TheNPC, CurrentX) shr 7));
Result[i].TileY := (SmartGetFieldInt(0, BaseY) + (SmartGetFieldInt(TheNPC, CurrentY) shr 7));
Result[i].NPCType := SmartGetFieldInt(TheNPCDef,GetNPCType);
Result[i].Height := iabs(SmartGetFieldInt(TheNPC,CharHeight));
Result[i].InFight := (SmartGetFieldInt(0,LoopCycle)<SmartGetFieldInt(TheNPC,LoopCycleStatus));
Result[i].IsMoving := (SmartGetFieldInt(TheNPC,CharMotion)>0);
if TileOnMS(Result[i].TileX, Result[i].TileY, Result[i].Height * 2 / 3) then
TileToMS(Result[i].TileX, Result[i].TileY, Result[i].Height * 2 / 3, Result[i].MSX, Result[i].MSY);
SmartFreeObject(TheNPC);
SmartFreeObject(TheNPCDef);
SmartFreeObject(TheBytes);
end;
end;

function GetNPCsByName(name:string):array of TNPC;
{*******************************************************************
Function GetNPCsByName(name:string):array of TNPC;
By: Widget
Description: Returns NPCs matching the name.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
NPCs := GetNPCs;
if (GetArrayLength(NPCs)=0) then Exit;
for i := 0 to High(NPCs) do
if (pos(trim(name),trim(NPCs[i].Name))>0) then
begin
SetArrayLength(result,GetArrayLength(result)+1);
result[GetArrayLength(result)-1] := NPCs[i];
end;
end;

function GetNPCsByID(TheType:integer):array of TNPC;
{*******************************************************************
Function GetNPCsByID(TheType:integer):array of TNPC;
By: Widget
Description: Returns NPCs matching the ID.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
NPCs := GetNPCs;
if (GetArrayLength(NPCs)=0) then Exit;
for i := 0 to High(NPCs) do
if (NPCs[i].NPCType=TheType) then
begin
SetArrayLength(result,GetArrayLength(result)+1);
result[GetArrayLength(result)-1] := NPCs[i];
end;
end;

function SortNPCs(NPCs:array of TNPC):array of TNPC;
{*******************************************************************
Function SortNPCs(NPCs:array of TNPC):array of TNPC;
By: Widget
Description: Sorts NPCs by distance from you.
********************************************************************}
var
i,i2,ix,iy: integer;
tpa: TPointArray;
begin
if (GetArrayLength(NPCs)=0) then Exit;
SetArrayLength(TPA,GetArrayLength(NPCs));
SetArrayLength(Result,GetArrayLength(NPCs));
for i := 0 to high(NPCs) do
TPA[i] := Point(NPCs[i].TileX, NPCs[i].TileY);
GetMyPos(ix, iy);
SortTPAFrom(TPA, Point(ix, iy));
for i := 0 to high(TPA) do
for i2 := 0 to high(NPCs) do // they really should be the same
if (TPA[i].x=NPCs[i2].TileX) and (TPA[i].y=NPCs[i2].TileY) then
Result[i] := NPCs[i2];
end;

Function FindNPC(Name: string; var NPC: TNPC):boolean;
{*******************************************************************
function FindNPC(Name: string; var NPC: TNPC):boolean;
By: Widget
Description: Finds the tile of the named NPC and puts it in the NPC var.
Returns true if found, false if not. (Try walking with the MM if
it's not on the main screen.
********************************************************************}
var
NPCs: array of TNPC;
begin
NPCs := SortNPCs(GetNPCsByName(Name));
result := GetArrayLength(NPCs)<>0;
if not result then
Exit;
NPC := NPCs[0];
end;

Function FindNPCByID(ID: integer; var NPC: TNPC):boolean;
{*******************************************************************
function FindNPCByID(ID: integer; var NPC: TNPC):boolean;
By: Widget
Description: Finds the tile of the named NPC and puts it in the NPC var.
Returns true if found, false if not. (Try checking for tiles if
it's not on the mainscreen.)
********************************************************************}
var
NPCs: array of TNPC;
begin
NPCs := SortNPCs(GetNPCsByID(ID));
result := GetArrayLength(NPCs)<>0;
if not result then
Exit;
NPC := NPCs[0];
end;

Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
{*******************************************************************
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
By: ss23 and Widget
Description: Clicks a tile. Height is the approximate heigh in pixels
Height doesnt matter if HighestAngle;
********************************************************************}
Var
x, y : Integer;
Begin
TileToMS(TileX, TileY, Height, x, y);
result := TileOnMs(x,y,height);
if not result then
Exit;
Mouse(x, y, 5, 5, False);
end;

Function WalkToTile(TileX, TileY : Integer): Boolean;
{*******************************************************************
Function - WalkToTile(TileX, TileY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
********************************************************************}
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;

Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
{*******************************************************************
Function - WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
By: ss23 and Widget and TheGuyWhoGotOn
Description: Walks to the tile using minimap and tolerance.
********************************************************************}
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, Tol, Tol, True);
Result := True;
end;

function LongWalkEx(TileX, TileY, DisX, DisY, Tol : integer): boolean;
{*******************************************************************
Function - LongWalkEx(TileX, TileY, DisX, DisY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
DisX/DisY is how many tiles it will move at a time.
********************************************************************}
var TX, TY, DX, DY : integer;
begin
repeat
GetMyPos(TX, TY);
if ((DX) > (TileX - DisX)) and ((DX) < (TileX + DisX)) then else
if TileX > TX then DX := TX + DisX
else DX := TX - DisX;
if ((DY) > (-TileY - DisY)) and ((DY) < (TileY + DisY)) then else
if TileY > TY then DY := TY + DisY
else DY := TY - DisY;
WalkToTileTol(DX, DY, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
until (TileOnMM(TileX, TileY)) or (not(TileOnMM(DX, DY)));
Result := WalkToTileTol(TileX, TileY, Tol);
end;

function LongWalk(TileX, TileY, Tol : integer): boolean;
{*******************************************************************
Function - LongWalk(TileX, TileY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
********************************************************************}
begin
Result := LongWalkEx(TileX, TileY, 11, 11, Tol);
end;

function PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
{*******************************************************************
Function - PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks a path for you with LongWalk options.
********************************************************************}
var Count : integer;
begin
Count := 0;
repeat
if Long then Result := LongWalk(Path[Count].x, Path[Count].y, Tol)
else Result := WalkToTileTol(Path[Count].x, Path[Count].y, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
if not(Result) then
begin
WriteLn('Path walk failed');
Exit;
end;
Count := Count + 1;
until (not(Result)) or (Count = GetArrayLength(Path))
end;

procedure MMtoMS(MMX,MMY:integer; var MSX,MSY:integer);
{*******************************************************************
Function MMtoMS(x, y: Integer; left: Boolean): Boolean;
By: LeeLokHin
Description: Converts Coordinates x and y on the minimap
to equivilants on the MainScreen and clicks right or left according
to boolean left.
********************************************************************}
var
tx,ty:integer;
begin
MinimapToTile(MMX, MMY, tx, ty);
TileToMS(tx, ty, 5, MSX, MSY);
end;

Function OpenBankReflection(Bank : String): Boolean;
{*******************************************************************
Function OpenBankReflection(Bank : String): Boolean;
By: ss23
Description: Opens the bank. Opens nearest slot
********************************************************************}
Var
x, y : Integer;
Me : TPoint;
Tiles : TPointArray;
Begin
Case Bank of
'veb': Tiles := [Point(3251,3419), Point(3252,3419), Point(3253,3419),
Point(3254,3419), Point(3255,3419), Point(3256,3419)];
'vwb': Tiles := [Point(3190,3435), Point(3190,3437), Point(3190,3439),
Point(3190,3441), Point(3190,3443), Point(3181,3444), Point(3181,3442),
Point(3181,3440), Point(3181,3438), Point(3181,3436)];
'fwb': Tiles := [Point(2945,3367), Point(2946,3367), Point(2947,3367),
Point(2948,3367)];
'feb': Tiles := [Point(3010,3354), Point(3011,3354), Point(3012,3354),
Point(3013,3354), Point(3014,3354), Point(3015,3354)];
'lum': Tiles := [Point(3208,3221)];
'dra': Tiles := [Point(3091,3419), Point(3091,3245), Point(3091,3244),
Point(3091,3243), Point(3091,3242)];
'alk': Tiles := [Point(3268,3168), Point(3268,3167), Point(3268,3166),
Point(3268,3165), Point(3268,3164)];
end;
GetMyPos(Me.x, Me.y);
SortTPAFrom(Tiles, Me);
If (DistanceFrom(Tiles[0].x, Tiles[0].y) > 3) then
Begin
If not(TileOnMM(Tiles[0].x, Tiles[0].y)) then
Begin
Writeln('Couldn''t find bank');
Result := False;
Exit;
end;
WalkToTile(Tiles[0].x, Tiles[0].y);
Wait(10);
Flag;
Wait(100 + Random(100));
end;
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 15)) then
Begin
SetAngle(True);
MakeCompass('n');
If not(TileOnMS(Tiles[0].x, Tiles[0].y, 20)) then
Begin
Writeln('Couldnt'' find bank booth');
Result := False;
Exit;
end;
end;
TileToMS(Tiles[0].x, Tiles[0].y, 20, x, y);
Mouse(x, y, 5, 5, False);
Wait(100 + Random(100));
Result := ChooseOption('e-q');
end;

function GetPlayers: array of TPlayer;
{*******************************************************************
function - GetPlayers: array of TPlayer;
By: Widget
Description: Returns all the players on the minimap
--- DOESN'T WORK YET ---
********************************************************************}
//var
// i, IndexPos, Count, Player, Name: integer;

begin
result := result; // stops the "Variable 'Result' never used" thing
{ Count := SmartGetFieldInt(0, PlayerCount);
writeln('Number of players: '+inttostr(Count));
SetArrayLength(result, Count);
for i := 0 to (count-1) do
begin
IndexPos := SmartGetFieldArrayInt(0, PlayerIndArray, i);
writeln('Index position: '+inttostr(count));
Player := SmartGetFieldArrayObject(0, PlayerArray, IndexPos);
writeln('Player placement: '+inttostr(Player));
Name := SmartGetFieldObject(Player, CharName);
writeln(inttostr(name));
writeln(StringFromBytes(Name));
Result[indexpos].Name := StringFromBytes(Name);
SmartFreeObject(Name);
Writeln(Result[indexpos].Name);
end; }
end;

function GetPlayer(name: string): TPlayer;
{*******************************************************************
function - GetPlayer(name: string): TPlayer;
By: Widget
Description: Gets available stats for a player (Levels only work on you).
--- DOESN'T WORK YET ---
********************************************************************}
begin
result := result; // stops the "Variable 'Result' never used" thing
Function Makecompassreflection(Direction:string;Accuracy:integer): Boolean;
{*******************************************************************
Function Makecompassreflection(Direction:string;Accuracy:integer): Boolean;
By: Waddo
Description: Rotates the camera using reflection
********************************************************************}
var
clientAngle,DirDeg,mark: integer;
left:boolean;
begin
case LowerCase(Direction) of
'n': DirDeg := 0;
'w': DirDeg := 90;
's': DirDeg := 180;
'e': DirDeg := 270;
end;
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
clientangle:=clientAngle * 180 / 1024;
if clientangle=dirdeg then exit;
if (clientangle-Dirdeg)>180 then
begin
left:=false;
keydown(vk_right);
end else
begin
left:=true;
keydown(vk_left);
end;
wait(1);
MarkTime(Mark);
repeat
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
clientangle:=clientAngle * 180 / 1024;
If left then
if clientangle>DirDeg then break;
if not left then
if clientangle<DirDeg then break;
If clientangle=dirDeg then break;
Wait(1);
until (TimeFromMark(Mark) > 14000) or ( ((clientangle>dirDeg-Accuracy) or (clientangle>dirDeg-Accuracy+360)) and (clientangle<dirDeg+Accuracy));
if left then
Keyup(vk_left)
else
keyup(vk_right);
if clientangle<>dirdeg then
Makecompassreflection(direction,0);
result:=clientangle=dirDeg;
end;

Procedure GetNPCInfo;
{*******************************************************************
Procedure GetNPCInfo;
By: Waddo
Description: Displays the info of loaded NPC's.
********************************************************************}
var
i: integer;
NPCs: array of TNPC;
begin
NPCs := GetNPCs;
if (GetArrayLength(NPCs)=0) then Exit;
for i := 0 to High(NPCs) do
writeln('NPC: '+NPCs[i].Name+' ID: '+IntToStr(NPCs[i].NPCType)+
' Tile X: '+IntToStr(NPCs[i].TileX)+' Tile Y: '+IntToStr(NPCs[i].TileY));
end;

newest version

Negaal

2008-07-25 12:06:06

So still, Benland haxed runescape client, like KYAB did. So what's the point KYAB being thrown out from SRL while ago..or I misunderstood something..??!?

Now SRL seems to be on completely 2nd level..to peoples who're trying to script: I'd like to say scripting has made lot, a lot of easier! Don't say there is impossible to make that script blaah, it just make take a bit long..

Thx for tutorial JuKKa.

Queso

2008-07-25 13:01:17

Couldn't it be possible to make a "variable finder" within the reflection include to find out all the variables? Ex: you move one tile over on RS, then reflection searches for variable that changed +/- 1 (depends which way you went), and repeat until it narrows down?

Waddo

2008-07-25 13:17:59

there has got to be away to edit these variables
eg. change the id of a potatoes to the id of phat =]

Queso

2008-07-25 22:59:24

From: Waddo
there has got to be away to edit these variables
eg. change the id of a potatoes to the id of phat =]


It was done a while back.

Remember the big thing when RS2 was released about some phat "duper"? I believe that's why they change the variable names now and then.

iroki_

2008-07-26 08:59:49

I have idea, reflection could be used to mime solver. Because in this includes is somethink like GetAnimation; Function, but this function is getting player animation not NPC animation, I have one question is possible to make mime solver using reflection??

JuKKa

2008-07-27 11:37:26

yes its possible

Griff

2008-09-11 19:13:14

how do you make a scar documetn in the misc folder, instead of just notepad?

footballjds

2008-11-28 09:00:10

thanks for the tut. it helped some but i still don't feel i grasp it completly, :(

Nava2

2008-11-28 09:31:21

This is outdated, the new reflection is much more intensive and useful! :)