Sin
06-14-2015, 07:32 PM
SPS never really seems to work for me, since (from what I assume) I am running a cracked version of W8.0. After compiling and running my script which needs SPS, I get this error:
'---- Path exists (C:\Simba\Includes\SPS\img\runescape_other\fish.pn g)
---- FATAL ERROR: sps.setup(): Unable to load map or bitmap to map failed
'
With masterBB's help, sometime in October, we modified SPS so that it'd function. It worked, but it seems to have broken again. I still have the modified version:
{$loadlib sps}
{$include_once srl-6/lib/interfaces/minimap.simba}
{$include_once srl-6/lib/core/debug.simba}
{$include_once srl-6/lib/core/players.simba}
{$include_once srl-6/lib/utilities/drawing.simba}
type
TSPSArea = record
__mapPath: string;
__areaMap: T3DIntegerArray;
_accuracy: integer;
_tolerance, _minMatchPercent: extended;
isSetup: boolean;
end;
const
SPS_IMG_PATH = IncludePath + 'SPS\img\';
SPS_IMG_FMT = '.png';
const
RUNESCAPE_SURFACE = 'runescape_surface\';
RUNESCAPE_OTHER = 'runescape_other\';
const
__DEFAULT_ACCURACY: integer = 4;
__DEFAULT_TOLERANCE: extended = 600.0;
__DEFAULT_MIN_MATCH_PERCENT: extended = 0.40;
var
spsAnyAngle: boolean = false;
spsMultiMouse: boolean = true;
var
sps: TSPSArea;
(*
Returns the name of the TSPSArea variable.
Example:
writeln(sps.getName());
*)
function TSPSArea.getName(): string;
begin
result := between('"', '"', toStr(@self));
end;
(*
Loads and setups the TSPSArea.
Example:
sps.setup('my_map_name', RUNESCAPE_SURFACE, 4, 600.0, 0.40);
*)
procedure SPS_MakeColorBox2(bmp: TMufasaBitmap; x1, y1, SideLength: integer; var res: TIntegerArray);
var
x, y, C, R, G, B: integer;
begin
SetLength(Res, 3);
for x := (x1 + SideLength - 1) downto x1 do
for y := (y1 + SideLength - 1) downto y1 do
begin
C := bmp.GetPixel(x, y);
ColorToRGB(C, R, G, B);
Res[0] := Res[0] + R;
Res[1] := Res[1] + G;
Res[2] := Res[2] + B;
end;
end;
procedure SPS_BitmapToMap2(bmp: TMufasaBitmap; SideLength: integer; var res: T3DIntegerArray);
var
X, Y, HighX, HighY: integer;
begin
HighX := Trunc(bmp.getWidth() / (SideLength * 1.0));
HighY := Trunc(bmp.getHeight() / (SideLength * 1.0));
SetLength(Res, HighX);
for X := 0 to HighX - 1 do
begin
SetLength(Res[X], HighY);
for Y := 0 to HighY - 1 do
begin
SPS_MakeColorBox2(bmp, X * SideLength, Y * SideLength, SideLength, Res[X][Y]);
end;
end;
end;
procedure TSPSArea.setup(imgName, imgFolder: string; accuracy: integer; tolerance, minMatchPercent: extended);
var
ibmp: Integer;
bmp: TMufasaBitmap;
t: integer;
m: extended;
begin
print(self.getName()+'.init()', TDebug.HEADER);
t := getSystemTime();
if (fileExists(SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT)) then
begin
print('Path exists ('+SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT+')');
self._accuracy := accuracy;
self._tolerance := tolerance;
self._minMatchPercent := minMatchPercent;
self.__mapPath := SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT;
if (spsAnyAngle) then
self._minMatchPercent := 0.10;
ibmp := LoadBitmap(self.__mapPath);
bmp := GetMufasaBitmap(ibmp);
writeln(self._accuracy);
SPS_BitmapToMap2(bmp, self._accuracy, self.__areaMap);
//except
//print(self.getName()+'.setup(): Unable to load map or bitmap to map failed', TDebug.FATAL);
//finally
bmp.free();
// end;
self.isSetup := true;
end else
print(self.getName()+'.setup(): Unable to find map, searched path '+ SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT, TDebug.FATAL);
print('Setup area "' + imgName + '" in ' + intToStr(getSystemTime() - t) + 'ms');
print(self.getName()+'.init()', TDebug.FOOTER);
end;
(*
Overloaded: Loads and setups the TSPSArea without the need for accuracy, tolerance, and min match percent variables.
Example:
sps.setup('my_map_name', RUNESCAPE_SURFACE);
*)
procedure TSPSArea.setup(imgName, imgFolder: string); overload;
begin
self.setup(imgName, imgFolder, __DEFAULT_ACCURACY, __DEFAULT_TOLERANCE,
__DEFAULT_MIN_MATCH_PERCENT);
end;
(*
Gathers a 140x140 bitmap of the minimap.
Example:
bmp := SPS_GatherMinimap(true, 50.0);
*)
function SPS_GatherMinimap(const rotated: boolean; const deg: extended): TMufasaBitmap;
var
temp: TMufasaBitmap;
begin
result.init();
if (rotated) and (inRange(deg, 10.0, 350.0)) then
begin
temp.init();
try
temp.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
temp.rotateBitmap(radians(deg), result);
finally
temp.free();
end;
end else
result.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
end;
(*
Debugs your players postion on the loaded map.
Example:
sps.debugPlayerPos();
*)
procedure TSPSArea.debugPlayerPos();
var
b: TBox;
bmp, w, h, t, timeTook: integer;
mid, pos: TPoint;
begin
t := getSystemTime();
pos := self.getPlayerPos();
timeTook := (getSystemTime() - t);
if (pos.equals(point(-1, -1))) or (not isLoggedIn()) then
exit();
bmp := loadBitmap(self.__mapPath);
if (bitmapExists(bmp)) then
begin
getBitmapSize(bmp, w, h);
dec(w);
dec(h);
try // draw player pos, the minimap area and crop the bitmap
getMufasaBitmap(bmp).drawCircle(pos, 2 , true, clLime);
getMufasaBitmap(bmp).drawBox(intToBox(max(1, pos.x - 70), max(1, pos.y - 70),
min(w, pos.x + 70), min(h, pos.y + 70)), false, clLime);
cropBitmap(bmp, max(1, pos.x - 150), max(1, pos.y - 150), min(w, pos.x + 150), min(h, pos.y + 150));
except
print('Exception on drawing/cropping TSPSArea.debugPlayerPos()', TDebug.ERROR);
end;
getBitmapSize(bmp, w, h);
setBitmapSize(bmp, getMufasaBitmap(bmp).getWidth() + 160, getMufasaBitmap(bmp).getHeight()); // add more width so we can print infomation on
getMufasaBitmap(bmp).copyClientToBitmap(client.get IOManager(), false, w + 10, 10, // draw picture of client on bitmap
minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
getMufasaBitmap(bmp).drawText('Map: '+between('\', '.', between('runescape_', 'png', self.__mapPath)), point(w + 10, 160), clRed); // draw infomation
getMufasaBitmap(bmp).drawText('Pos: ('+toStr(pos.x) + ', '+toStr(pos.y) + ')', point(w + 10, 180), clRed);
getMufasaBitmap(bmp).drawText('Took: '+toStr(timeTook) + 'ms', point(w + 10, 200), clRed);
debugBitmap(bmp);
freeBitmap(bmp);
end;
end;
(*
Gets the players postion.
Example:
writeln(sps.getPlayerPos());
*)
function TSPSArea.getPlayerPos(): TPoint;
var
foundMatches, wid, hei, t: integer;
bmp: TMufasaBitmap;
map: T3DIntegerArray;
p: TPoint;
searches, a: extended;
begin
result := [-1, -1];
if (not isLoggedIn()) then
exit();
if (not self.isSetup) then
begin
print('Unable to get players postion, sps isn''t setup', TDebug.ERROR);
exit();
end;
t := getSystemTime();
a := minimap.getAngleDegrees();
if (inRange(a, 10.0, 350.0)) and (not spsAnyAngle) then
begin
print(self.getName()+'.getPlayerPos(): Angle is at '+floatToStr(a)+', Setting angle to 0 degrees');
minimap.clickCompass();
mainScreen.setAngle(MS_ANGLE_HIGH);
end;
bmp := SPS_GatherMinimap(spsAnyAngle, a);
wid := bmp.getWidth();
hei := bmp.getHeight();
SPS_BitmapToMap(bmp, self._accuracy, map);
if (length(map) > 0) then
begin
foundMatches := SPS_FindMapInMap(p.x, p.y, self.__areaMap, map, self._tolerance);
searches := ((wid / self._accuracy) * (hei / self._accuracy));
if ((foundMatches / searches) > self._minMatchPercent) then
begin
result.x := (p.x * self._accuracy + (wid div 2));
result.y := (p.y * self._accuracy + (wid div 2));
end else
print(self.getName()+'.getPlayerPos(): Didn''t find enough matches accurately calc your postion', TDebug.WARNING);
end;
bmp.free();
print(self.getName()+'.getPlayerPos(): result = ' + toStr(result) + ', took ' + intToStr(getSystemTime() - t) + ' ms');
end;
(*
Converts a postion onto the minimap, based on the players pos.
Example:
SPS_PosToMM(point(50, 50), sps.getPlayerPos(), p);
*)
function SPS_PosToMM(pos, playerPos: TPoint; out res: TPoint): boolean;
var
a: extended;
begin
if (spsAnyAngle) then
begin
a := minimap.getAngleRadians();
if (not inRange(degrees(a), 8, 352)) then // no need to rotate
res := [minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y]
else
res := rotatePoint([minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y], a, minimap.cx, minimap.cy);
end else
res := [minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y];
result := minimap.isPointOn(res);
if (not result) then
res := [-1, -1];
end;
(*
Walks to postion 'pos', judged on the players postion.
Example:
sps.walkToPos(point(250, 250), sps.getPlayerPos());
*)
function TSPSArea.walkToPos(pos: TPoint; playerPos: TPoint): boolean;
var
p: TPoint;
begin
result := false;
if (SPS_PosToMM(pos, playerPos, p)) then
begin
result := true;
// if distance is less than 10 then there is no real point walking.
if (distance(p, minimap.getCenterPoint()) < 10) then
exit;
if (spsMultiMouse) then
multiClick(p, 25, 3)
else
mouse(p, MOUSE_LEFT);
if (minimap.isFlagPresent(3000 + random(500))) then
minimap.waitPlayerMoving();
if (minimap.isFlagPresent()) then //case failed
minimap.waitPlayerMoving();
end;
print(self.getName()+'.walkToPos(): result = '+boolToStr(result));
end;
(*
Overloaded function, reqiures no playerPos var, will automaticly call self.getPlayerPos().
Example:
sps.walkToPos(point(250, 250));
*)
function TSPSArea.walkToPos(pos: TPoint): boolean; overload;
begin
result := self.walkToPos(pos, self.getPlayerPos());
end;
(*
Walks a path of points.
Example:
sps.walkPath([point(50, 50), point(100, 100)]);
*)
function TSPSArea.walkPath(path: TPointArray): boolean;
var
p, lastPos, mmPoint: TPoint;
t, fails, h, l, i: integer;
begin
result := false;;
h := high(path);
l := low(path);
t := (getSystemTime() + randomRange(15000, 20000));
repeat
if (not isLoggedIn()) then
exit(false);
p := self.getPlayerPos();
for i := h downto l do
if (SPS_PosToMM(path[i], p, mmPoint)) then
begin
if (distance(minimap.getCenterPoint(), mmPoint) >= 10) then
begin
if (spsMultiMouse) then
multiClick(mmPoint, 25, 3)
else
mouse(mmPoint, MOUSE_LEFT);
if (minimap.isFlagPresent(2500 + random(500))) then
minimap.waitFlag(10 + random(25));
end;
t := (getSystemTime() + randomRange(15000, 20000));
result := (i = h) or (distance(path[i], path[h]) < 10);
if (result) then
break(2)
else
break();
end;
if (p.x = lastPos.x) and (p.y = lastPos.y) then
inc(fails);
lastPos := p;
until (getSystemTime() > t) or (fails > 5);
if (minimap.isFlagPresent()) or (minimap.isPlayerMoving()) then
minimap.waitPlayerMoving();
print(self.getName()+'.walkPath(): result = '+boolToStr(result));
end;
(*
Walks blindly to point 'pos'.
Example:
sps.blindWalk(point(50, 50));
*)
function TSPSArea.blindWalk(pos: TPoint): boolean;
var
tries: integer;
ctrlPoints: TPointArray;
p: TPoint;
begin
result := false;
repeat
if (not isLoggedIn()) then
exit();
p := self.getPlayerPos();
inc(tries);
if ((tries) > 10) then
break();
until (not p.equals([-1, -1]));
if (tries <= 10) then
begin
ctrlPoints := TPABetweenPoints(p, pos, 15 + random(25), 15);
result := self.walkPath(ctrlPoints);
end;
print(self.getName()+'.blindWalk(): result = '+boolToStr(result));
end;
And now I seem to get an access violation everytime I run a script which requires SPS:
Access violation at:
...
wid := bmp.getWidth();
hei := bmp.getHeight();
SPS_BitmapToMap(bmp, self._accuracy, map); //here, line 263
Any ideas?
'---- Path exists (C:\Simba\Includes\SPS\img\runescape_other\fish.pn g)
---- FATAL ERROR: sps.setup(): Unable to load map or bitmap to map failed
'
With masterBB's help, sometime in October, we modified SPS so that it'd function. It worked, but it seems to have broken again. I still have the modified version:
{$loadlib sps}
{$include_once srl-6/lib/interfaces/minimap.simba}
{$include_once srl-6/lib/core/debug.simba}
{$include_once srl-6/lib/core/players.simba}
{$include_once srl-6/lib/utilities/drawing.simba}
type
TSPSArea = record
__mapPath: string;
__areaMap: T3DIntegerArray;
_accuracy: integer;
_tolerance, _minMatchPercent: extended;
isSetup: boolean;
end;
const
SPS_IMG_PATH = IncludePath + 'SPS\img\';
SPS_IMG_FMT = '.png';
const
RUNESCAPE_SURFACE = 'runescape_surface\';
RUNESCAPE_OTHER = 'runescape_other\';
const
__DEFAULT_ACCURACY: integer = 4;
__DEFAULT_TOLERANCE: extended = 600.0;
__DEFAULT_MIN_MATCH_PERCENT: extended = 0.40;
var
spsAnyAngle: boolean = false;
spsMultiMouse: boolean = true;
var
sps: TSPSArea;
(*
Returns the name of the TSPSArea variable.
Example:
writeln(sps.getName());
*)
function TSPSArea.getName(): string;
begin
result := between('"', '"', toStr(@self));
end;
(*
Loads and setups the TSPSArea.
Example:
sps.setup('my_map_name', RUNESCAPE_SURFACE, 4, 600.0, 0.40);
*)
procedure SPS_MakeColorBox2(bmp: TMufasaBitmap; x1, y1, SideLength: integer; var res: TIntegerArray);
var
x, y, C, R, G, B: integer;
begin
SetLength(Res, 3);
for x := (x1 + SideLength - 1) downto x1 do
for y := (y1 + SideLength - 1) downto y1 do
begin
C := bmp.GetPixel(x, y);
ColorToRGB(C, R, G, B);
Res[0] := Res[0] + R;
Res[1] := Res[1] + G;
Res[2] := Res[2] + B;
end;
end;
procedure SPS_BitmapToMap2(bmp: TMufasaBitmap; SideLength: integer; var res: T3DIntegerArray);
var
X, Y, HighX, HighY: integer;
begin
HighX := Trunc(bmp.getWidth() / (SideLength * 1.0));
HighY := Trunc(bmp.getHeight() / (SideLength * 1.0));
SetLength(Res, HighX);
for X := 0 to HighX - 1 do
begin
SetLength(Res[X], HighY);
for Y := 0 to HighY - 1 do
begin
SPS_MakeColorBox2(bmp, X * SideLength, Y * SideLength, SideLength, Res[X][Y]);
end;
end;
end;
procedure TSPSArea.setup(imgName, imgFolder: string; accuracy: integer; tolerance, minMatchPercent: extended);
var
ibmp: Integer;
bmp: TMufasaBitmap;
t: integer;
m: extended;
begin
print(self.getName()+'.init()', TDebug.HEADER);
t := getSystemTime();
if (fileExists(SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT)) then
begin
print('Path exists ('+SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT+')');
self._accuracy := accuracy;
self._tolerance := tolerance;
self._minMatchPercent := minMatchPercent;
self.__mapPath := SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT;
if (spsAnyAngle) then
self._minMatchPercent := 0.10;
ibmp := LoadBitmap(self.__mapPath);
bmp := GetMufasaBitmap(ibmp);
writeln(self._accuracy);
SPS_BitmapToMap2(bmp, self._accuracy, self.__areaMap);
//except
//print(self.getName()+'.setup(): Unable to load map or bitmap to map failed', TDebug.FATAL);
//finally
bmp.free();
// end;
self.isSetup := true;
end else
print(self.getName()+'.setup(): Unable to find map, searched path '+ SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT, TDebug.FATAL);
print('Setup area "' + imgName + '" in ' + intToStr(getSystemTime() - t) + 'ms');
print(self.getName()+'.init()', TDebug.FOOTER);
end;
(*
Overloaded: Loads and setups the TSPSArea without the need for accuracy, tolerance, and min match percent variables.
Example:
sps.setup('my_map_name', RUNESCAPE_SURFACE);
*)
procedure TSPSArea.setup(imgName, imgFolder: string); overload;
begin
self.setup(imgName, imgFolder, __DEFAULT_ACCURACY, __DEFAULT_TOLERANCE,
__DEFAULT_MIN_MATCH_PERCENT);
end;
(*
Gathers a 140x140 bitmap of the minimap.
Example:
bmp := SPS_GatherMinimap(true, 50.0);
*)
function SPS_GatherMinimap(const rotated: boolean; const deg: extended): TMufasaBitmap;
var
temp: TMufasaBitmap;
begin
result.init();
if (rotated) and (inRange(deg, 10.0, 350.0)) then
begin
temp.init();
try
temp.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
temp.rotateBitmap(radians(deg), result);
finally
temp.free();
end;
end else
result.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
end;
(*
Debugs your players postion on the loaded map.
Example:
sps.debugPlayerPos();
*)
procedure TSPSArea.debugPlayerPos();
var
b: TBox;
bmp, w, h, t, timeTook: integer;
mid, pos: TPoint;
begin
t := getSystemTime();
pos := self.getPlayerPos();
timeTook := (getSystemTime() - t);
if (pos.equals(point(-1, -1))) or (not isLoggedIn()) then
exit();
bmp := loadBitmap(self.__mapPath);
if (bitmapExists(bmp)) then
begin
getBitmapSize(bmp, w, h);
dec(w);
dec(h);
try // draw player pos, the minimap area and crop the bitmap
getMufasaBitmap(bmp).drawCircle(pos, 2 , true, clLime);
getMufasaBitmap(bmp).drawBox(intToBox(max(1, pos.x - 70), max(1, pos.y - 70),
min(w, pos.x + 70), min(h, pos.y + 70)), false, clLime);
cropBitmap(bmp, max(1, pos.x - 150), max(1, pos.y - 150), min(w, pos.x + 150), min(h, pos.y + 150));
except
print('Exception on drawing/cropping TSPSArea.debugPlayerPos()', TDebug.ERROR);
end;
getBitmapSize(bmp, w, h);
setBitmapSize(bmp, getMufasaBitmap(bmp).getWidth() + 160, getMufasaBitmap(bmp).getHeight()); // add more width so we can print infomation on
getMufasaBitmap(bmp).copyClientToBitmap(client.get IOManager(), false, w + 10, 10, // draw picture of client on bitmap
minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
getMufasaBitmap(bmp).drawText('Map: '+between('\', '.', between('runescape_', 'png', self.__mapPath)), point(w + 10, 160), clRed); // draw infomation
getMufasaBitmap(bmp).drawText('Pos: ('+toStr(pos.x) + ', '+toStr(pos.y) + ')', point(w + 10, 180), clRed);
getMufasaBitmap(bmp).drawText('Took: '+toStr(timeTook) + 'ms', point(w + 10, 200), clRed);
debugBitmap(bmp);
freeBitmap(bmp);
end;
end;
(*
Gets the players postion.
Example:
writeln(sps.getPlayerPos());
*)
function TSPSArea.getPlayerPos(): TPoint;
var
foundMatches, wid, hei, t: integer;
bmp: TMufasaBitmap;
map: T3DIntegerArray;
p: TPoint;
searches, a: extended;
begin
result := [-1, -1];
if (not isLoggedIn()) then
exit();
if (not self.isSetup) then
begin
print('Unable to get players postion, sps isn''t setup', TDebug.ERROR);
exit();
end;
t := getSystemTime();
a := minimap.getAngleDegrees();
if (inRange(a, 10.0, 350.0)) and (not spsAnyAngle) then
begin
print(self.getName()+'.getPlayerPos(): Angle is at '+floatToStr(a)+', Setting angle to 0 degrees');
minimap.clickCompass();
mainScreen.setAngle(MS_ANGLE_HIGH);
end;
bmp := SPS_GatherMinimap(spsAnyAngle, a);
wid := bmp.getWidth();
hei := bmp.getHeight();
SPS_BitmapToMap(bmp, self._accuracy, map);
if (length(map) > 0) then
begin
foundMatches := SPS_FindMapInMap(p.x, p.y, self.__areaMap, map, self._tolerance);
searches := ((wid / self._accuracy) * (hei / self._accuracy));
if ((foundMatches / searches) > self._minMatchPercent) then
begin
result.x := (p.x * self._accuracy + (wid div 2));
result.y := (p.y * self._accuracy + (wid div 2));
end else
print(self.getName()+'.getPlayerPos(): Didn''t find enough matches accurately calc your postion', TDebug.WARNING);
end;
bmp.free();
print(self.getName()+'.getPlayerPos(): result = ' + toStr(result) + ', took ' + intToStr(getSystemTime() - t) + ' ms');
end;
(*
Converts a postion onto the minimap, based on the players pos.
Example:
SPS_PosToMM(point(50, 50), sps.getPlayerPos(), p);
*)
function SPS_PosToMM(pos, playerPos: TPoint; out res: TPoint): boolean;
var
a: extended;
begin
if (spsAnyAngle) then
begin
a := minimap.getAngleRadians();
if (not inRange(degrees(a), 8, 352)) then // no need to rotate
res := [minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y]
else
res := rotatePoint([minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y], a, minimap.cx, minimap.cy);
end else
res := [minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y];
result := minimap.isPointOn(res);
if (not result) then
res := [-1, -1];
end;
(*
Walks to postion 'pos', judged on the players postion.
Example:
sps.walkToPos(point(250, 250), sps.getPlayerPos());
*)
function TSPSArea.walkToPos(pos: TPoint; playerPos: TPoint): boolean;
var
p: TPoint;
begin
result := false;
if (SPS_PosToMM(pos, playerPos, p)) then
begin
result := true;
// if distance is less than 10 then there is no real point walking.
if (distance(p, minimap.getCenterPoint()) < 10) then
exit;
if (spsMultiMouse) then
multiClick(p, 25, 3)
else
mouse(p, MOUSE_LEFT);
if (minimap.isFlagPresent(3000 + random(500))) then
minimap.waitPlayerMoving();
if (minimap.isFlagPresent()) then //case failed
minimap.waitPlayerMoving();
end;
print(self.getName()+'.walkToPos(): result = '+boolToStr(result));
end;
(*
Overloaded function, reqiures no playerPos var, will automaticly call self.getPlayerPos().
Example:
sps.walkToPos(point(250, 250));
*)
function TSPSArea.walkToPos(pos: TPoint): boolean; overload;
begin
result := self.walkToPos(pos, self.getPlayerPos());
end;
(*
Walks a path of points.
Example:
sps.walkPath([point(50, 50), point(100, 100)]);
*)
function TSPSArea.walkPath(path: TPointArray): boolean;
var
p, lastPos, mmPoint: TPoint;
t, fails, h, l, i: integer;
begin
result := false;;
h := high(path);
l := low(path);
t := (getSystemTime() + randomRange(15000, 20000));
repeat
if (not isLoggedIn()) then
exit(false);
p := self.getPlayerPos();
for i := h downto l do
if (SPS_PosToMM(path[i], p, mmPoint)) then
begin
if (distance(minimap.getCenterPoint(), mmPoint) >= 10) then
begin
if (spsMultiMouse) then
multiClick(mmPoint, 25, 3)
else
mouse(mmPoint, MOUSE_LEFT);
if (minimap.isFlagPresent(2500 + random(500))) then
minimap.waitFlag(10 + random(25));
end;
t := (getSystemTime() + randomRange(15000, 20000));
result := (i = h) or (distance(path[i], path[h]) < 10);
if (result) then
break(2)
else
break();
end;
if (p.x = lastPos.x) and (p.y = lastPos.y) then
inc(fails);
lastPos := p;
until (getSystemTime() > t) or (fails > 5);
if (minimap.isFlagPresent()) or (minimap.isPlayerMoving()) then
minimap.waitPlayerMoving();
print(self.getName()+'.walkPath(): result = '+boolToStr(result));
end;
(*
Walks blindly to point 'pos'.
Example:
sps.blindWalk(point(50, 50));
*)
function TSPSArea.blindWalk(pos: TPoint): boolean;
var
tries: integer;
ctrlPoints: TPointArray;
p: TPoint;
begin
result := false;
repeat
if (not isLoggedIn()) then
exit();
p := self.getPlayerPos();
inc(tries);
if ((tries) > 10) then
break();
until (not p.equals([-1, -1]));
if (tries <= 10) then
begin
ctrlPoints := TPABetweenPoints(p, pos, 15 + random(25), 15);
result := self.walkPath(ctrlPoints);
end;
print(self.getName()+'.blindWalk(): result = '+boolToStr(result));
end;
And now I seem to get an access violation everytime I run a script which requires SPS:
Access violation at:
...
wid := bmp.getWidth();
hei := bmp.getHeight();
SPS_BitmapToMap(bmp, self._accuracy, map); //here, line 263
Any ideas?