PDA

View Full Version : Basic Pascal Reflection Tutorial



Kyle
01-20-2015, 02:15 PM
Basic Pascal Script Scripting tutorial


Please Note: This tutorial is many months old, the information "should" still be relevant for the include, since not much has changed since then, but please do be aware of that.

I will break the guide down into three sections:


How to download, setup and get reflection working with simba
How to use the various functions within the include
Antirandoms







Downloading and setup:


Well the most important part is to download and get the include setup properly to run with simba!

The first step is to go to github where the include is posted, which is found here (https://github.com/Elfyyy/OSR-Reflection-PascalScript)
After that, you are going to want to download the .zip file from:

I suggest saving it to your desktop, so it is easier to find once you go to extract it. From where ever you decide to save the .zip, you are going to want to extract is using your favorite unzip program (.7zip or Winrar work fine.)
You will want to extract it to Simba/Includes/SRL-OSR/SRL.
Once there, you will need to rename it to "reflection" without the "". Your /SRL folder should now look like:

http://elfyyy.com/reflecsetup

To test that everything was download properly you can run:

program R_Test;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/Reflection/Reflection.simba}


begin
setupsrl;
SetupReflection;
end.

You shouldn't get any errors, and it will either say that you are up to date with reflection or that a update has been downloaded!




Writing Scripts With Reflection:


Now that everything is downloaded and running properly, you can begin to start scripting using reflection functions!

So, as you saw in the Test example, in order to use any of the functions, you must include {$I SRL-OSR/SRL/Reflection/Reflection.simba} under {$I SRL-OSR/SRL.Simba} at the top of your script.

You also must call SetupReflection; in your main loop BEFORE SetupSrl. This checks if there are any updates that need to be downloaded (Which it will do automatically.)




Tiles:


Most of the functions in here are used in other functions throughout the include, but some of them are still very useful for different things.

function R_TileToMs(Tp: Tpoint): Tpoint;

Another usefull function, it returns the tpoint of the current tile that we are standing on. This can be used to just determine where we are for use with other functions, or you can write your own within your script with it.
R_GetTileGlobal

The rest of the tile functions are fairly self explanatory, but if you want me to go over any, just let me know.





MapWalk:


By far the most important reason that one will choose to use reflection, is the ability that it has to be used for mapwalking features. For the most part, reflection walking "should" be 100% accurate and won't fail. The reason I say "should" is because stuff happens, and it is still good to use failsafes.

The first function is simply R_WalkPath(Path: TPointArray): boolean; this function will walk along a path designated by the TPointArray in the parameters. In order to know the points in order to walk, we can use a great tool written by Turpinator. This tool can be found it reflection/tools. What this does, is when the script is started, each time you enable SMART, a new point is made.

This array of points can then be used with R_WalkPath in order to walk along it.

An example of a path from Varock East bank to the west bank: R_WalkPath([Point(3245, 3429), Point(3231, 3429), Point(3216, 3428), Point(3206, 3428), Point(3195, 3429), Point(3185, 3429), Point(3184, 3437)]);

It is VERY important to know, each point must be showing on the minimap from the previous point, so you can't "skip" points when making a path.

R_BlindWalk(P: TPoint): Boolean; This simply, makes a array of points from our current location to the final point, and walks it using R_WalkPath. This is great to use when you need to walk a straight line. It will NOT go around walls/obstacles.

The last MapWalk function is R_TileOnMM(Tile: TPoint): boolean; This returns true if the given point is on the Minimap. Usefull mainly for Failsafes.




Player:


Another nice feature of reflection, is being able to get data about your player without switching tabs or any other method. Most of these are self explainitory, so I will only discuss some in which may need more explanation.

Returns True if our player is animating.
R_IsAnimating:Boolean




Npc:



For this section, the best way I think to explain it, is to write a small example script of a monster killing snippet.

procedure AttGuard;
var
Guard: TNPC;
Tp : Tpoint;
begin
if R_FindNpc('Guard', Guard) then // Loads the record for Guard.
begin
if Guard.InCombat then // if he is in combat, don't attack, since we are on a loop, This acts as a wait also
exit;
Tp := Guard.Tile; //Get guard tile location
Tp := R_TileToMs(Tp); //Changes Tile into a Onscreen Point
Mmouse(Tp.x, Tp.y, 0, 0);
if R_WaitUptext('Guard', 200) then
ClickMouse2(Mouse_Left);
while (Guard.InCombat) and (R_InFight) do // waits until guard is dead to move on
wait(500);
end;
end;

So, that's a very basic example of how you can go about using reflection to interact and find npc's quickly. When You call R_FindNpc it stores the entire record of the npc into the TNPC record. So from calling the one function, you are able to get the following data from the npc:

Type TNPC = Record
Name: String;
Tile: TPoint;
Index, Level, NpcID: Integer;
Animation, HitPoints: Integer;
Interacting: Integer;
InCombat: Boolean;
end;

Using that one function to be able to call all those individual procedures from withing the variable makes it very powerful. You just need to keep in mind, that you must R_FindNpc right before you want any of the data from it that isn't static, such as location. Being that the TNPC is a variable, it changes, so it is very important to keep that in mind.
For all the npc functions, the value that you enter to search for the npc, is what is called a "variant." So you can either enter in the npc's name, or the ID of the npc. Either way will work




Addition NPC info courtesy from Krazy_Meerkat:


There are several functions you can use, but you must know that npc's are returned in a TNPC format. So it is always wise to declare a variable as a TNPC or TNPCArray;
var
man: TNPC;
men: TNPCArray;
So now, when using npc functions, you can store the npc. There are a few npc functions and they don't all work the same..
Men:= R_GetNpcs('Man'); //returns a TNPCArray of all npc's named 'Man' in the area (sorted by player distance), I stored it into Men for this example.

if R_FindNpc('Man', Man) then //looks for npcs named 'Man' and stores the closest one in the TNPC Man. Boolean function, returns true if found, false if not.

Man:= R_FindFreeNpc('man'); //looks for the closest npc named 'Man' which isn't in combat and returns the TNPC (I stored this into Man).

R_InteractingNpc //returns the tnpc of any npc your player is interacting with, this means you can use it like R_InteractingNpc.HitPoints

Finally, when you want to call record information from your npc, you treat the TNPC array as an array of npcs as follows:
for i:= 0 to high(men) do
if men[i].HitPoints > 0 then
dosomething;
The TNPC is treated as singular, so you can just call the record info:
R_TileToMs(man.tile);




Misc:


Most of the functions in here are used for other functions throughout the include. There are however, some that are quite useful for many things. They are:

R_GetSettingArray
R_GetSetting
R_GetPlayerName
R_GetUptext
R_ChooseOption

These are for various "setting's" within the runescape client. By using R_GetSetting, you can determine if your character is running, casting spells, auto retaliating, and many more. I will go into more detail on the use of this later, because tbh, there are so many, I don't know enough of them yet.

I also only wrote one of the uptext functions and choose options, as these are used the exact same way as SRL except with using reflection, they are now 100% accurate



Objects:


In runecape there are 4 different types of objects, all of which our include now supports! They are GameObjects, WallObjects, Boundaries, and FloorDecoration. These are defined as constants and should be called in scripts as such!


OBJ_GAME = 0;
OBJ_WALL = 1;
OBJ_FLOORDECORATION = 2;
OBJ_BOUNDARY = 3;

As of now, there are only three functions that should be called in scripts related to objects, they are:

function R_GetAllObjects(ObjType: integer): TRSObjectArray;
function R_GetObjectAt(ObjType: integer; Tile: TPoint): TRSObject;
function R_GetObjectsDistance(ObjType, Distance: integer): TRSObjectArray;

They should be pretty self explanatory so I won't go into any detail on the specifics of each function, but feel free to ask if you have any questions. When any of the functions are called, it returns either a TRSObject or a TRSObjectArray. Within a TRSObject is contained the "ID," "Tile," and "ObjectType." I will soon be adding to this list a few more param's but for now, I believe those to be the most useful!

Now, on what each of the objects are... They seem to vary a lot throughout Runescape, but here is a general rule of thumb that I have found, but you will still wan't to check yourself for each one!:

GameObject: Most interactable objects that are not on walls: Bank booths, chests, crates, some non interactable such as crates and rocks.
WallObject: Most interactable objects on walls and decoration on walls: Doors, levers, pictures, windows, ect....
Boundaries: Anything "Wall like" that blocks our path: Walls, fences, some doors and gates.
FloorDecoration: Anything on floor that doesn't fall into a category above: Some Rocks, bushes, stones ect....

kriss1993
02-03-2015, 07:03 AM
@elfyyy R_WalkPath seems to be bit buggy it clicks the same position multiple times it 2nd clicks it if its closer to it usually at fflag ~10 even if next walkpoint is visible.

kriss1993
02-24-2015, 07:46 PM
The NPC example code is briliant wish u could write an example of finding the objects aswell and clicking on them

kriss1993
06-09-2015, 07:09 PM
looking forward for ps resizeable mode fix :)

randalthor
08-13-2015, 05:44 AM
Can anyone good with debugging help me? I get the error: Error: "Don't know which overloaded method to call with params (Extended) at line 145
Compiling failed." when trying to run his sample code after downloading the reflection bundle.

mellower
02-10-2017, 05:04 PM
Same problem with randalthor

MapWalk file
"Error: Don't know which overloaded method to call with params (Extended) at line 145
Compiling failed."

Kyle
02-10-2017, 05:30 PM
This tutorial is much outdated as it uses the depreciated include for Pascal Script. Please refer to the new tutorial here (https://villavu.com/forum/showthread.php?t=111664), which uses the newer lape version on the include that can be found here (https://github.com/KyleHunter/OSR-Reflection).

--Thread Closed--