SRL Archive - OSR Help

(RSPS) Edited SPS doesn't want to do anything...


Twinki

2013-09-29 02:04:38

I edited SPS for a RSPS i'm scripting for, and it doesn't seem to want to do anything. I've made the functions for getting the compass angle / radios and everything. I was using Officer Barbrady's guide on editing SPS for a RSPS.

The guide: http://villavu.com/forum/showthread.php?t=105919
The RSPS: http://rage-scape.com/index.php

Here is the edited SPS:
(*
SPS ~ SRL Positioning System
============================

Concept and original work done by marpis @ SRL-Forums. Work continued by Coh3n
and members of the SRL community.

*)
{$include_once RLTools.simba}
{$loadlib sps}

const
// Path where all the SPS files are
SPS_IMG_PATH = IncludePath + 'SPS\img\';
SPS_IMG_FMT = '.png';

// Surfaces
RUNESCAPE_SURFACE = 0;
RUNESCAPE_SURFACE_FOLDER = 'runescape_surface\';

RUNESCAPE_OTHER = 1;
RUNESCAPE_OTHER_FOLDER = 'runescape_other\';

// User defined SPS global variables
var
SPS_Debug: boolean;
SPS_MultiMouse: boolean; // simulates a human like "spam-click" when walking
SPS_AnyAngle: boolean; // true = work at any angle; false = only north
SPS_ClickNorth: boolean; // call ClickNorth instead of MakeCompass to set the compass to north

// SPS Global variables
var
SPS_Areas: TStringArray;
SPS_AreaMaps: T3DIntegerArray; // Grids of the combined SPS_Areas
SPS_Tolerance, SPS_MatchesPercent: extended;
SPS_Accuracy: integer; // Splits minimap/areas into squares of this side length; used for area recognition
SPS_IsSetup: boolean; // Used to make sure the user calls SPS_Setup

// Author: marpis & Coh3n
// Returns an image of the minimap in a TMufasaBitmap
function SPS_GatherMinimap: TMufasaBitmap;
var
c: TClient;
begin
try
Result := TMufasaBitmap.Create;
Result.SetSize(150, 150);

c := getTClient;
Result.CopyClientToBitmap(
c.IOManager, false, 0, 0, 628-75, 86-75, 628+75, 86+75
);

except
Writeln('SPS_GatherMinimap ERROR: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

// Author: Ollybest & J J
// gets the rotated RS minimap and rotates to face north
// needed for SPS to work at any compass angle
function SPS_RotateMinimap: TMufasaBitmap;
var
W, H, t: Integer;
mmBMP, rBMP: TMufasaBitmap;
MiddleBMP: TPoint;
begin
try
t := getSystemTime();

//gathering minimap
mmBMP := SPS_GatherMinimap;

//rotating minimap
rBMP := GetMufasaBitmap(RotateBitmap(mmBMP.index, 0-rs_GetCompassAngleRadians))

//getting the middle of the rotated bitmap
GetBitmapSize(rBMP.Index, W, H);
MiddleBMP := Point(W/2, H/2);

//creating the result by using a 74 radius around the centre
Result := rbmp.Copy(MiddleBMP.X-74, MiddleBMP.Y-74, MiddleBMP.X+74, MiddleBMP.Y+74);

mmBMP.free
rbmp.free

If SPS_Debug Then
Writeln('Rotating map took '+toStr(getSystemTime - t)+' ms.');

except
Writeln('SPS_RotateMinimap ERROR: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

// Author: marpis & Coh3n
// Gets the starting area coordinates depending on the area image
procedure SPS_GetAreaCoords(Area: string; var x, y: integer);
var
p: integer;
begin
// if it's a specific dungeon map (i.e. name isn't 0_0, 10_2, etc.)
if (length(getNumbers(Area)) < 2) then
begin
x := 0;
y := 0;
Exit;
end;

p := pos('_', Area);

x := StrToIntDef(copy(Area, 1, p - 1), -1);
y := StrToIntDef(copy(Area, p + 1, Length(Area) - p), -1);

//writeln('SPS_GetAreaCoords: '+toStr(point(x, y)));
end;

// Author: marpis
// Converts a point from a map piece to a point on the entire map
function SPS_LocalToGlobal(Area: string; x, y: integer): TPoint;
var
cx, cy: integer;
begin
SPS_GetAreaCoords(Area, cx, cy);
Result.x := (cx * 400) + x;
Result.y := (cy * 400) + y;
end;

// Author: marpis
// Converts a point from the entire map to a point on the main screen
function SPS_GlobalToLocal(x, y: integer): TPoint;
var
cx, cy: integer;
begin
cx := Floor(x / 400);
cy := Floor(y / 400);

Result.x := x - (cx * 400);
Result.y := y - (cy * 400);
end;

// Author: marpis
// Returns the coordinates (x, y) in the form of a string
function SPS_AreaCoordsToString(x, y: integer): string;
begin
Result := IntToStr(x)+'_'+IntToStr(y);
end;

// Author: Coh3n
// Returns a TPA of the areas' values
function SPS_TPAFromAreas(areas: TStringArray): TPointArray;
var
i: integer;
begin
setLength(result, length(areas));

for i := 0 to high(areas) do
SPS_GetAreaCoords(areas[i], result[i].x, result[i].y);
end;

// Author: Coh3n
// Sorts the areas by columns, and sorts each column by rows
// Example: ['1_5', '1_3', '0_5'] results ['0_5', '1_3', '1_5']
function SPS_SortAreas(areas: TStringArray): TStringArray;
var
i, j: integer;
tpa: TPointArray;
begin
setLength(tpa, length(areas));

tpa := SPS_TPAFromAreas(areas);
clearDoubleTPA(tpa);

sortTPAByX(tpa, true); // first sort by column number

// then sort the Y values for each column number
for i := 0 to high(tpa) do
for j := i to high(tpa) do
if (tpa[i].x = tpa[j].x) then
if (tpa[i].y > tpa[j].y) then
tSwap(tpa[i], tpa[j]);

setLength(result, length(tpa));

for i := 0 to high(tpa) do
result[i] := SPS_AreaCoordsToString(tpa[i].x, tpa[i].y);

//writeln('SPS_SortAreas: '+toStr(result));
end;

// Author: Coh3n
// Loads the "Area" image
function SPS_GetArea(Area: string; surface: integer): TMufasaBitmap;
var
x, y: integer;
S: string;
begin
SPS_GetAreaCoords(Area, x, y);

case surface of
RUNESCAPE_SURFACE: s := RUNESCAPE_SURFACE_FOLDER;
RUNESCAPE_OTHER: s := RUNESCAPE_OTHER_FOLDER;
end;

try
Result := TMufasaBitmap.Create;
Result.LoadFromFile(SPS_IMG_PATH + s + Area + SPS_IMG_FMT);
except
Writeln('SPS_GetArea ERROR: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

// Author: Coh3n
// Merges the SPS 'areas' into one bitmap (makes more more accurate GetMyPos)
function SPS_MergeAreas(areas: TStringArray): TMufasaBitmap;
var
t, i, l, x, y, diffX, diffY, newWidth, newHeight: integer;
startPoint: TPoint;
newAreas: TStringArray;
xVals, yVals: TIntegerArray;
bmpTemp: TMufasaBitmap;
tmpTPA: TPointArray;
begin
if (length(areas) <= 0) then
exit;

t := getSystemTime();

// sort the areas from by columns/rows; remove duplicates
newAreas := SPS_SortAreas(areas);
l := length(newAreas);

// if there's only one area in the array
if (l = 1) then
begin
result := SPS_GetArea(areas[0], RUNESCAPE_SURFACE);
exit;
end;

// get the x and y values for each area
setLength(xVals, l);
setLength(yVals, l);

for i := 0 to high(newAreas) do
SPS_GetAreaCoords(newAreas[i], xVals[i], yVals[i]);

// get the lowest Y value so we can calculate the starting point to draw the first image
tmpTPA := SPS_TPAFromAreas(newAreas);
sortTPAByY(tmpTPA, true);

try
result := TMufasaBitmap.create();

// calculate the starting point
// x is always 0 because of how the areas are sorted
// y is relative to the lowest y value in the areas
SPS_GetAreaCoords(newAreas[0], x, y);
startPoint.x := 0;
startPoint.y := ((y - tmpTPA[0].y) * 400);

// draw the first area to the starting point on the bitmap
bmpTemp := SPS_GetArea(newAreas[0], RUNESCAPE_SURFACE);
result.SetSize(bmpTemp.width, bmpTemp.height + startPoint.y);
bmpTemp.fastDrawTransparent(startPoint.x, startPoint.y, result);
bmpTemp.free();

// loop through each area, drawing them to the result bitmap
// coordinates are calculated relative to the first area drawn (areas[0])
for i := 0 to (l - 2) do
begin
diffX := (xVals[i + 1] - xVals[0]);
diffY := (yVals[i + 1] - yVals[0]);

newWidth := 500 + (round(abs(diffX)) * 400);
newHeight := 500 + (round(abs(diffY)) * 400);

// only set the size if the width or height is increasing
if (newWidth > result.width) then
result.setSize(newWidth, result.height);

if (newHeight > result.height) then
result.setSize(result.width, newHeight);

// copy the area image to the resulting bitmap
bmpTemp := SPS_GetArea(newAreas[i + 1], RUNESCAPE_SURFACE);
bmpTemp.fastDrawTransparent(startPoint.x + (diffX * 400 + 1),
startPoint.y + (diffY * 400 + 1), result);
bmpTemp.free();
end;

//result.saveToFile('C:/Simba/test.bmp');
except
Writeln('SPS_MergeAreas ERROR: '+ExceptionToString(ExceptionType, ExceptionParam));
end;

if (SPS_Debug) then
writeln('SPS_MergeAreas: Merged areas in '+toStr(getSystemTime - t)+' ms.');
end;

// Author: Coh3n
// Returns an SPS area of lowest x and y value. Used for calculating the
// player's correct position
function SPS_GetTopLeftCoords(areas: TStringArray): string;
var
tpa: TPointArray;
begin
tpa := SPS_TPAFromAreas(areas);

if (length(tpa) <= 0) then
begin
result := '0_0';
exit;
end;

sortTPAByX(tpa, true);
result := toStr(tpa[0].x);

sortTPAByY(tpa, true);
result := result + '_'+toStr(tpa[0].y);

//writeln('SPS_GetTopLeftCoords: '+result);
end;

// Author: marpis & SRL Community
function SPS_GetMyPos(): TPoint;
var
Minimap: TMufasaBitmap;
SmallMap: T3DIntegerArray;
a, t, FoundMatches: integer;
P: TPoint;
Searches: extended;
begin
Result := Point(-1, -1);

if (not SPS_IsSetup) then
begin
writeln('SPS ERROR: SPS_Setup was never called');
exit;
end;


if (SPS_Tolerance < 1.0) then
SPS_Tolerance := 600.0;

if (SPS_MatchesPercent = 0.0) then
SPS_MatchesPercent := 0.35;

a := round(rs_GetCompassAngleDegrees);

if (SPS_AnyAngle) and (inRange(a, 10, 350)) then
Minimap := SPS_RotateMinimap()
else begin
if (inRange(a, 10, 350)) then
if (SPS_ClickNorth) then
ClickNorth(SRL_ANGLE_HIGH)
else
MakeCompass('N');

Minimap := SPS_GatherMinimap();
end;

t := getSystemTime();
SPS_FilterMinimap(Minimap);
//DrawBitmapDebugImg(Minimap.Index);
//DisplayDebugImgWindow(150, 150);

{$IFDEF SIMBAMAJOR990}
SetLength(SmallMap, 0); // Using this instead of SmallMap := [];
SPS_BitmapToMap(Minimap, SPS_Accuracy, SmallMap);
{$ELSE}
SmallMap := [];
SmallMap := SPS_BitmapToMap(Minimap, SPS_Accuracy);
{$ENDIF}

FoundMatches := SPS_FindMapInMap(P.x, P.y, SPS_AreaMaps, SmallMap, SPS_Tolerance);
Searches := ((Minimap.Width / SPS_Accuracy) * (Minimap.Height / SPS_Accuracy));
{
writeln('fx: '+toStr(p.x)+' ~ on area: '+toStr(P.X * SPS_Accuracy + (Minimap.Width / 2)));
writeln('fy: '+toStr(p.y)+' ~ on area: '+toStr(P.Y * SPS_Accuracy + (Minimap.Width / 2)));
writeln('matches: '+toStr(foundMatches));
writeln('searches: '+toStr(searches));
writeln('percent: '+toStr(FoundMatches / Searches));
}
if ((FoundMatches / Searches) > SPS_MatchesPercent) then
Result := SPS_LocalToGlobal(SPS_GetTopLeftCoords(SPS_Areas), // the top left of the total area
P.x * SPS_Accuracy + (Minimap.Width / 2),
P.y * SPS_Accuracy + (Minimap.Width / 2));

Minimap.Free;

t := (GetSystemTime - t);
if (SPS_Debug) then
Writeln('SPS_GetMyPos: Finished in '+ToStr(t)+' ms. Result = '+ToStr(Result));
end;

// Author: marpis
// Finds position P in minimap by checking your own location
function SPS_PosToMM(P: TPoint): TPoint;
var
MyPos: TPoint;
begin

Result := Point(-1, -1);
MyPos := SPS_GetMyPos;

if (Distance(MyPos.X, MyPos.Y, P.X, P.Y) < 75) then
Result := RotatePoint(Point(964 + P.X - MyPos.X, 104 + P.Y - MyPos.Y), 0-RL_GetCompassAngleRadians, 964, 104);
end;

// Author: marpis
// Walks to position, P.
function SPS_WalkToPos(P: TPoint): boolean;
var
MM: TPoint;
begin

MM := SPS_PosToMM(P);

if (MM.X > 0) then
begin
if (SPS_MultiMouse) then
MultiMouse(MM.X, MM.Y, 25, 3, false)
else
Mouse(MM.X, MM.Y, 0, 0, mouse_Left);

if WaitFunc(@IsMoving, 1, 3000 + random(500)) then
while IsMoving do
Flag;

Result := True;
end;
end;

// Author: marpis
// Returns true if the point "Pt" is on the minimap
function SPS_PosOnMM(Pt: TPoint): Boolean;
var
p: TPoint;
begin
p := SPS_PosToMM(Pt);
Result := rs_OnMinimap(p.x, p.y);
end;

// Author: marpis & Coh3n
// Walks the path "Path"; always walks to the furthest point possible
function SPS_WalkPath(Path: TPointArray): boolean;
var
I, H, T, D, Fails: integer;
P, MM, MMF: TPoint;
begin
if (not SPS_IsSetup) then
begin
writeln('SPS ERROR: SPS_Setup was never called');
exit;
end;

H := High(Path);
T := GetSystemTime + 20000 + Random(5000);
Fails := 0;

while (not Result) and (GetSystemTime < T) and (Fails < 5) do
begin

RunEnergy(20);
P := SPS_GetMyPos();

for I := H downto 0 do
begin
MM := RotatePoint(Point(964 + Path[I].X - P.X, 104 + Path[I].Y - P.Y),
0-RL_GetCompassAngleRadians, 964, 104);

if MM = MMF then
Inc(Fails);

D := Distance(MM.X, MM.Y, MMCX, MMCY);

if (D < 10) then
break
else
if (D < 70) then
begin
if (SPS_MultiMouse) then
MultiMouse(MM.X, MM.Y, 25, 3, false)
else
Mouse(MM.X, MM.Y, 5, 5, mouse_Left);

MMF := MM;
FFlag(5 + (Integer(I <> H) * 15));

T := getSystemTime + 20000 + Random(1000);
Break;
end;
end;

Result := (I = H);
end;
end;

// Walks blindly from the player's current position to the point T
function SPS_BlindWalk(P: TPoint): Boolean;
var
Tries: Integer;
M: TPoint;
ctrlPoints: TPointArray;
begin
if (not SPS_IsSetup) then
begin
writeln('SPS ERROR: SPS_Setup was never called');
exit;
end;

repeat

M := SPS_GetMyPos();

if (M.X = -1) then
Continue;

if (Length(ctrlPoints) = 0) then
ctrlPoints := TPABetweenPoints(Point(M.X, M.Y), Point(P.X, P.Y), 20 + Random(15), 10);

Inc(Tries);
if (Tries > 20) then
Exit;

Result := SPS_WalkPath(ctrlPoints);
until(Result);
end;

// Author: Coh3n
// Sets up SPS; needs to be called if you want to switch RS surfaces
function SPS_Setup(surface: integer; areas: TStringArray): boolean;
var
t: integer;
tmp: TMufasaBitmap;
begin
t := getSystemTime;

setLength(SPS_AreaMaps, 0);
setLength(SPS_Areas, 0);

SPS_MultiMouse := true;
SPS_Accuracy := 4;

if (length(areas) > 0) then
begin
if (surface = RUNESCAPE_SURFACE) then
tmp := SPS_MergeAreas(areas) // combine the SPS areas into 1; makes for a more accurate read
else
if (surface = RUNESCAPE_OTHER) then
if (length(areas) = 1) then
tmp := SPS_GetArea(areas[0], surface)
else begin
writeln('SPS_Setup(): Invalid dungeon areas. You can only select one!');
exit;
end;

SPS_IsSetup := true;
result := true;

{$IFDEF SIMBAMAJOR990}
SPS_BitmapToMap(tmp, SPS_Accuracy, SPS_AreaMaps);
{$ELSE}
SPS_AreaMaps := SPS_BitmapToMap(tmp, SPS_Accuracy);
{$ENDIF}

if (surface = RUNESCAPE_SURFACE) then
SPS_Areas := SPS_SortAreas(areas)
else
if (surface = RUNESCAPE_OTHER) then
SPS_Areas := areas;

tmp.free();

end else
writeln('SPS_Setup(): ERROR: SPS areas are not set!');

t := (getSystemTime - t);

if (SPS_Debug) and (result) then
writeln('[SPS] SPS_Setup() took '+toStr(t)+' ms. Areas: '+toStr(SPS_Areas));
end;

and the script

Program TestPath;
{$i srl/srl.Simba}
{$I RL_SPS.Simba}

var

testpath: tpointarray;


begin
testpath := [Point(107, 114), Point(125, 112), Point(143, 109)];
SPS_Setup(runescape_other, ['SPS_RageScapeBank']);
SPS_WalkPath(testpath);
end.

SPS_GetMyPos Does work and does give me the right pos (I hope) but not even SPS_RotateMinimap works… and I have no idea what's wrong.

Also here's my GetCompassAngleRadians function which works perfectly

Function RL_GetCompassAngleRadians: Extended;
var
TPA: TPointArray;
T: TPoint;
B: TBox;
begin
B := IntToBox(523, 2, 570, 48);
with B do
FindColorsSpiralTolerance(T.x, T.y, TPA, 0, x1, y1, x2, y2, 0);
if Length(TPA) < 1 then
exit;
T := MiddleTPA(TPA);
Result := ArcTan2(-(T.Y - 24), T.X - 543) + Radians(90);
Result := fixRad(Result - Pi);
end;

Twinki

2013-09-29 16:45:11

Anyone? :(

Brandon

2013-09-29 23:14:30

From: Twinki
Anyone? :(


To get help faster, it would be wise to mention the link to the guide you were following as well as the server you are scripting for. Without this information, it's more difficult to tell what exactly is wrong with your code.

It may also help on lookers who are willing to install the server or load it to see what's wrong with your code.

Twinki

2013-09-30 05:09:53

From: Brandon
To get help faster, it would be wise to mention the link to the guide you were following as well as the server you are scripting for. Without this information, it's more difficult to tell what exactly is wrong with your code.

It may also help on lookers who are willing to install the server or load it to see what's wrong with your code.


Thanks for the extra help, updated OP :)

Twinki

2013-09-30 20:47:09

Someone.. anyone…? :(

rj

2013-09-30 21:15:02

Can I se RL_Tools.simba and the map again?

Twinki

2013-10-01 21:03:51

From: Officer Barbrady
Can I se RL_Tools.simba and the map again?


I made a new map;

RLTools:
{
RL Tools Include
}
Var
RL_MIX1, RL_MIY1, RL_MIX2, RL_MIY2, RL_MMCX, RL_MMCY:Integer;
Inventory:TBoxArray;

(*
RL_InCombat
~~~~~~~~~~~

.. code-block:: pascal

Function RL_InCombat

Detects if the player is in combat using AveragePixelShift
Returns -1 if failed.

.. note::

by RL Anon for RLTools Include
Must copy the function into the script



function Rl_InCombat: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(245, 110, 285, 175);
Result := (AveragePixelShift(PBox, 300, 100) > 700);
Writeln(IntToStr(AveragePixelShift(PBox, 300, 250)));
end;
*)



(*
RLGetMMLevels
~~~~~~~~~~~

.. code-block:: pascal

Function GetMMLevels(LevelType : String;var ColorSign : String): integer;

Returns the level shown next to the minimap.
Colorsign returns the color of the text (Green,Yellow,Orange,Red).
Returns -1 if failed.

.. note::

by Raymond / Wizzup / Sabzi / NCDS

Edited by RL Anon for RLTools

Example:

.. code-block:: pascal

Value := RLGetMMLevels( 'hp' ) ; // Will retrieve your Hit Points
Value := RLGetMMLevels( 'pray' ) ; // Will retrieve your Prayer Points
Value := RLGetMMLevels( 'run' ) ; // Will retrieve your Run energy
Value := RLGetMMLevels( 'summon' ) ; // Will retrieve your Summoning Points

*)
function RLGetMMLevels(LevelType: string; var ColorSign: string): Integer;
var
Colors : TIntegerArray;
Signs: TStringArray;
P: TPointArray;
I: Integer;
B: TBox;
begin;
Result := -1;
ColorSign := '';
case LowerCase(Leveltype) of
'health', 'hp', 'hitpoints', 'constitution': B := IntToBox(722,28,744,40);
'prayer', 'pray' : B := IntToBox(735,66,762,82);
'run','energy' : B := IntToBox(735,103,762,122);
'summon', 'summoning' : B := IntToBox(719,119,745,156);
else
begin;
//srl_Warn('GetMMLevels', 'Invalid LevelType: ''' + LevelType + '', warn_AllVersions);
Exit;
end;
end;
Colors := [65280, 65535, 2070783, 255];
Signs := ['Green', 'Yellow', 'Orange', 'Red'];
for I := 0 to 3 do
begin
With B do
FindColorsTolerance(P, Colors[i], x1, y1, x2, y2, 50);
if Length(P) < 1 then
Continue;
Result := StrToIntDef(GetNumbers(GetTextAtExWrap(B.X1, B.Y1, B.X2, B.Y2, 0, 4, 4, Colors[i], 20, statChars)), -1);
if (Result > -1) then
begin
ColorSign := Signs[i];
Exit;
end;
end;
end;


function RL_FindCoins(var X, Y: Integer; Area: string): Boolean;
var
B: TBox;
CTS, I, J, H, L: Integer;
Pts, tPts: TPointArray;
ATPA: T2DPointArray;
V: array [0..1] of TVariantArray;
begin
case Lowercase(Area) of
'inv', 'inventory': B := IntToBox(RL_MIX1, RL_MIY1, RL_MIX2, RL_MIY2);
'bank': B := IntToBox(MBx1, MBy1, MBx2, MBy2);
'trade': B := IntToBox(323, 73, 509, 302);
'your trade': B := IntToBox(9, 73, 196, 302);
end;
V[0] := [1606307, 4, 0.09, 1.32]; //Darker colour (top of coins)
V[1] := [2209251, 8, 0.04, 1.08]; //Lighter colour (rest of the coins)
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetLength(tPts, 0);
try
for I := 0 to 1 do
begin
SetColorSpeed2Modifiers(V[I][2], V[I][3]);
FindColorsTolerance(Pts, V[I][0], B.X1, B.Y1, B.X2, B.Y2, V[I][1]);
if (Length(Pts) < 10) then Exit;
ATPA := SplitTPAEx(Pts, 10, 10);
h := High(ATPA);
L := High(tPts) + 1;
SetLength(tPts, L + h + 1);
for J := 0 to H do
tPts[L + j] := MiddleTPA(ATPA[J]);
end;
ATPA := SplitTPAEx(tPts, 20, 20);
H := High(ATPA);
for I := 0 to H do
if (High(ATPA[I]) = 1) then
Break;
if (I > H) then Exit;
Result := True;
MiddleTPAEx(ATPA[I], X, Y);
finally
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
end;

//-----------------------------------------------------------------\\
//-- RL Tools --\\
//-- Compass functions --\\
//-----------------------------------------------------------------\\

(*
RL_ClickNorth
~~~~~~~~~~~~~~~
Clicks on the compass to face the north position.
.. note::
by RL Anon
*)
procedure RL_ClickNorth;
begin
if (Random(4) = 1) then
begin
Mouse(545, 5, 0, 0, mouse_right);
WaitOptionMulti(['ace', 'orth'], 1200);
end else
Mouse(545, 5, 0, 0, mouse_left);
end;

(*
RL_ClickNorthAngleHigh
~~~~~~~~~~~~~~~
Clicks on the compass to face the north position and makes
the angle the highest.
.. note::
by RL Anon
*)
procedure RL_ClickNorthAngleHigh;
begin
if (Random(4) = 1) then
begin
Mouse(545, 5, 0, 0, mouse_right);
WaitOptionMulti(['ace', 'orth'], 1200);
end else
Mouse(545, 5, 0, 0, mouse_left);
Wait(500);
KeyDown(38);
wait(RandomRange(1000, 1500));
KeyUp(38);
end;

(*
RL_MoveCameraEast
~~~~~~~~~~~~~~~
Moves the camera or compass to the east position
.. note::
by RL Anon
*)
Procedure RL_MoveCameraEast;
begin
RL_ClickNorth;
wait(1000);
KeyDown(37);
wait(1000);
KeyUp(37);
end;

(*
RL_MoveCameraWest
~~~~~~~~~~~~~~~
Moves the camera or compass to the West position
.. note::
by RL Anon
*)
Procedure RL_MoveCameraWest;
begin
RL_ClickNorth;
wait(1000);
KeyDown(39);
wait(1000);
KeyUp(39);
end;

(*
RL_MoveCameraSouth
~~~~~~~~~~~~~~~
Moves the camera or compass to the South position
.. note::
by RL Anon
*)
Procedure RL_MoveCameraSouth;
begin
RL_ClickNorth;
wait(1000);
KeyDown(39);
wait(2000);
KeyUp(39);
end;

(*
RL_SetHighAngle
~~~~~~~~~~~~~~~
Sets the camera angle to the highest
.. note::
by RL Anon
*)
Procedure RL_SetHighAngle;
begin
KeyDown(38);
wait(RandomRange(1000, 1500));
KeyUp(38);
end;

(*
RL_SetLowAngle
~~~~~~~~~~~~~~~
Sets the camera angle to the lowest
.. note::
by RL Anon
*)
Procedure RL_SetLowAngle;
begin
KeyDown(40);
wait(RandomRange(1000, 1500));
KeyUp(40);
end;

(*
RL_GetCompassAngleRadians
~~~~~~~~~~~~~~~
Gets the compass angle radians
.. note::
by RL Anon
*)
Function RL_GetCompassAngleRadians: Extended;
var
TPA: TPointArray;
T: TPoint;
B: TBox;
begin
B := IntToBox(523, 2, 570, 48);
with B do
FindColorsSpiralTolerance(T.x, T.y, TPA, 0, x1, y1, x2, y2, 0);
if Length(TPA) < 1 then
exit;
T := MiddleTPA(TPA);
Result := ArcTan2(-(T.Y - 24), T.X - 543) + Radians(90);
Result := fixRad(Result - Pi);
end;

(*
RL_PrintCompassAngleRadians
~~~~~~~~~~~~~~~
Prints the Compass Angle degree
.. note::
by RL Anon
*)
function RL_PrintCompassAngleDegrees: Extended;
begin
Result := Degrees(RL_GetCompassAngleRadians());
Writeln(Result);
end;

//-----------------------------------------------------------------\\
//-- RL Tools --\\
//-- Inventory functions --\\
//-----------------------------------------------------------------\\



function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
var
r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
begin
if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
begin
w := ((bx.X2 - bx.X1) + 1);
h := ((bx.Y2 - bx.Y1) + 1);
if (rows < 1) then
rows := 1
else
if (rows > h) then
rows := h;
if (columns < 1) then
columns := 1
else
if (columns > w) then
columns := w;
w := (w div columns);
h := (h div rows);
ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
SetLength(Result, (rows * columns));
y := bx.Y1;
for r := 0 to (rows - 1) do
begin
x := bx.X1;
if ((eh > 0) and (r < eh)) then
oh := 1
else
oh := 0;
for c := 0 to (columns - 1) do
begin
if ((ew > 0) and (c < ew)) then
ow := 1
else
ow := 0;
i := ((r * columns) + c);
Result[i].X1 := x;
Result[i].X2 := (x + (w - 1) + ow);
Result[i].Y1 := y;
Result[i].Y2 := (y + (h - 1) + oh);
x := (Result[i].X2 + 1);
end;
y := (Result[i].Y2 + 1);
end;
end else
SetLength(Result, 0);
end;

function RSPS_SlotFull(slot:Integer):Boolean;
var
x, y:Integer;
begin
if FindColor(x, y, 65536, Inventory[slot].x1, Inventory[slot].y1, Inventory[slot].x2, Inventory[slot].y2) then
result := true;
end;

function rsps_Invcount:Integer;
var
i:Integer;
begin
for i := 0 to high(Inventory) do
begin
if rsps_slotFull(i) then
result := result + 1;
end;
end;

function RSPS_InvFull:Boolean;
begin
result := (rsps_invcount = 28);
end;

function RSPS_InvEmpty:Boolean;
begin
result := (rsps_invcount = 0);
end;

function RSPS_InvEmptyButOne:Boolean;
begin
result := (rsps_invcount = 1);
end;

function RSPS_CountInventoryDTM(DTMSearch:Integer):Integer;
var
i, x, y:Integer;
begin
for i := 0 to high(Inventory) do
begin
if FindDTM(DTMSearch, x, y, Inventory[i].x1, Inventory[i].y1, Inventory[i].x2, Inventory[i].y2) then
result := result + 1;
end;
end;


procedure SetupRLTools;
begin
RL_MIX1 := 548;
RL_MIY1 := 191;
RL_MIX2 := 737;
RL_MIY2 := 463;
RL_MMCX := 627;
RL_MMCY := 85;
Mousespeed := 15;
Inventory := ExplodeBox(IntToBox(557, 212, 726, 460), 7, 4);
end;

The old and new map:

[ATTACH=CONFIG]22269[/ATTACH]

[ATTACH=CONFIG]22270[/ATTACH]

Twinki

2013-10-04 10:34:47

Anyone? D:

Twinki

2013-10-06 07:10:49

Bump…..

Twinki

2013-10-25 17:54:40

Would still like some help if that's at all possible.