Log in

View Full Version : Need help to SPS



Bot4Fun
06-19-2012, 05:22 PM
When i try to run this script, http://villavu.com/forum/showthread.php?t=82983 , it opens a new tab named "sps" and i get this error,

[Error] C:\Simba\Includes\sps/sps.simba(38:17): Unknown type 'T4DIntegerArray' at line 37
Compiling failed.
[Error] (38:17): Unknown type 'T4DIntegerArray' at line 37
Compiling failed.

It is this script, it opens in the new tab:


*
SPS ~ SRL Positioning System
============================

Concept and original work done by marpis @ SRL-Forums.

*)

{$loadlib sps}

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

// Supported SPS surfaces
RUNESCAPE_SURFACE = 1;
DUNGEON_ESSENCE_MINE = 2;
DWARVEN_MINE = 3;
RUNECRAFTING_ALTARS = 4;
DOMINION_TOWER = 5;

type
TSPSSurface = record
Name, ImagePath: string;
Constant: integer;
FactorX, FactorY: integer; // used in SPS_LocalToGlobal
TileOffsetX, TileOffSetY: extended; // used for tile <-> SPS conversions
Tolerance: extended;
end;

// SPS Global variables
var
SPS_Loaded, SPS_Debug, SPS_Continue: boolean;
SPS_Areas: TStringArray;
SPS_Surface: TSPSSurface;
SPS_Worldmap: T4DIntegerArray;

procedure SPS_DebugStr(msg: string);
begin
if (SPS_Debug) then
Writeln('[SPS] '+msg);
end;

// Should be called in scripts to setup SPS
// Needs to be called each time the surface changes (i.e. from runescape_surface to essence_mine)
procedure SPS_Setup(surface: integer; areas: TStringArray);
begin
SPS_Areas := areas;

case surface of
RUNESCAPE_SURFACE:
with SPS_Surface do
begin
Name := 'Runescape Surface';
ImagePath := SPS_IMG_PATH + 'runescape_surface\';
FactorX := 400;
FactorY := 400;
TileOffsetX := -1;
TileOffSetY := -1;
Tolerance := 0.3;
end;

DUNGEON_ESSENCE_MINE:
with SPS_Surface do
begin
Name := 'Essence Mine';
ImagePath := SPS_IMG_PATH + 'essence_mine\';
FactorX := 400;
FactorY := 1;
TileOffsetX := -1;
TileOffSetY := -1;
Tolerance := 0.5;
end;

DWARVEN_MINE:
with SPS_Surface do
begin
Name := 'Dwarven Mine';
ImagePath := SPS_IMG_PATH + 'dwarven_mine\';
FactorX := 400;
FactorY := 340;
TileOffsetX := -1;
TileOffSetY := -1;
Tolerance := 0.35;
end;

RUNECRAFTING_ALTARS:
with SPS_Surface do
begin
Name := 'Runecrafting Altars';
ImagePath := SPS_IMG_PATH + 'runecrafting_altars\';
FactorX := 400;
FactorY := 400;
TileOffsetX := -1;
TileOffSetY := -1;
Tolerance := 0.5;
end;

DOMINION_TOWER:
with SPS_Surface do
begin
Name := 'Dominion Tower';
ImagePath := SPS_IMG_PATH + 'dominion\';
FactorX := 400;
FactorY := 400;
TileOffsetX := -1;
TileOffSetY := -1;
Tolerance := 0.3;
end;
end;

SPS_Surface.Constant := surface;

if (SPS_Debug) then
begin
SPS_DebugStr('[SPS] SPS_Surface: ' + SPS_Surface.Name);
SPS_DebugStr('[SPS] SPS_Areas: ' + toStr(SPS_Areas));
end;

SPS_Loaded := false;
end;

procedure SPS_WarnUser(proc, error: string);
begin
if (not SPS_Continue) then
begin
ShowMessage('SPS: ' + error + ' in ' + proc + #10+#13+#10+#13+
'Please run Simba as an administrator by right clicking and ' + #10+#13+
'choosing "Run as administrator." You may also have to restart ' + #10+#13+
'Simba a few times. ' + #10+#13+#10+#13+'Sorry for the inconvenience.');
TerminateScript();
end;
end;

// Gets the map pieces that appear on the minimap
function SPS_GatherMinimap: T3DIntegerArray;
var
bmp: TMufasaBitmap;
c: TClient;
begin
try
bmp := TMufasaBitmap.Create;
bmp.SetSize(100, 100);

c := getTClient;
bmp.CopyClientToBitmap(
c.IOManager, false, 0,0, MMCX-50, MMCY-50, MMCX+50, MMCY+50
);

Result := SPS_BitmapToMap(bmp);
finally
bmp.free;
except
SPS_DebugStr('[ERROR] in SPS_GatherMinimap: '+ExceptionToString(ExceptionType, ExceptionParam));
SPS_WarnUser('SPS_GatherMinimap', ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

procedure SPS_GetAreaCoords(Area: string; var x, y: integer);
var
p: integer;
begin
p := pos('_', Area);
if (p <= 0) then
// raise an exception if Area is of wrong format
RaiseException(erCustomError, 'Invalid Area passed: ' + area);

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

SPS_DebugStr(format('[SPS] Area coords (%d, %d)', [x, y]));
end;

// 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 * SPS_Surface.FactorX + x;
Result.y := cy * SPS_Surface.FactorY + y;
end;

// Gets SPS ready to be used (this doesn't have to be called in scripts)
procedure SPS_Load;
var
L, i, timer : integer;
img: TMufasaBitmap;
begin
timer := getSystemTime;
L := Length(SPS_Areas);

if (L <= 0) then
begin
SPS_DebugStr('[SPS] WARNING: SPS_Areas hasn''t been set');
exit;
end;

if (SPS_Surface.Name = '') then
begin
SPS_DebugStr('[SPS] WARNING: SPS_Surface isn''t set! Using Runescape Surface as default');
SPS_Setup(RUNESCAPE_SURFACE, SPS_Areas);
end;

// clean up the old one just in case, we do not want copies in wrong places.
SetLength(SPS_WorldMap, 0);
SetLength(SPS_Worldmap, L);

for i := L-1 downto 0 do
begin
try
img := TMufasaBitmap.Create;
img.LoadFromFile(SPS_Surface.ImagePath + SPS_Areas[i] + SPS_IMG_FMT);
SPS_Worldmap[i] := SPS_BitmapToMap(img);
finally
img.free;
except
SPS_DebugStr('[SPS] ERROR: SPS_Load: '+ExceptionToString(ExceptionType, ExceptionParam));
SPS_WarnUser('SPS_Load', ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

SPS_DebugStr('[SPS] Maps loaded in '+ToStr(getSystemTime - timer)+'ms.');
SPS_Loaded := True;
end;

// Returns the SPS position of the player
function SPS_GetMyPos: TPoint;
var
Minimap: T3DIntegerArray;
t, map, ang: integer;
begin
Result := Point(-1, -1);

if not LoggedIn then
Exit;

if not SPS_Loaded then
SPS_Load;

// we should just rotate the minimap according to the minimap angle.
ang := round(rs_GetCompassAngleDegrees());
SPS_DebugStr('[SPS] Compass Angle: '+toStr(ang));

if (inRange(ang, 10, 350)) then
{$IFDEF SRL5}
ClickNorth(SRL_ANGLE_HIGH);
{$ELSE}
ClickNorth(True);
{$ENDIF}

t := getSystemTime;
Minimap := SPS_GatherMinimap;
if (High(Minimap) < 0) then
begin
SPS_DebugStr('[SPS] Did not gather Minimap.');
Exit;
end;

try
map := SPS_FindMapInMapEx(
Result.X, Result.Y, SPS_Worldmap, Minimap, SPS_Surface.Tolerance
);

if ((Result.X > 0) and (Result.Y > 0)) then
begin
Result := SPS_LocalToGlobal(SPS_Areas[map], Result.X, Result.Y);
end;

SPS_DebugStr(format('[SPS] GetMyPos: Finished in %d ms. Location = %s',
[getSystemTime - t, toStr(result)]));

except
SPS_DebugStr('[SPS] ERROR in SPS_GetMyPos: ' + ExceptionToString(ExceptionType, ExceptionParam));
SPS_WarnUser('SPS_GetMyPos', ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

// Converts an SPS pos to a tile
function SPS_PosToTile(pos: TPoint): TPoint;
begin
result := point(-1, -1);

if (SPS_Surface.TileOffsetX = -1) then
begin
SPS_DebugStr('No conversion available for ' + SPS_Surface.Name);
exit;
end;

result.X := round(SPS_Surface.TileOffsetX + (pos.x / 4));
result.Y := round(SPS_Surface.TileOffsetY - (pos.y / 4));
end;

// Converts a tile to and SPS point, or "pos"
function SPS_TileToPos(tile: TPoint): TPoint;
begin
result := point(-1, -1);

if (SPS_Surface.TileOffsetX = -1) then
begin
SPS_DebugStr('No conversion available for ' + SPS_Surface.Name);
exit;
end;

result.X := round((tile.x - SPS_Surface.TileOffsetX) * 4);
result.Y := round((SPS_Surface.TileOffsetY - tile.y) * 4);
end;

// Converts a tile path to an SPS path
function SPS_TilePathToPos(tiles: TPointArray): TPointArray;
var
i: integer;
begin
setLength(result, length(tiles));

for i := 0 to high(result) do
result[i] := SPS_TileToPos(tiles[i]);
end;

// Finds position P in minimap by checking your own location
function SPS_PosToMM(P: TPoint): TPoint;
var
MyPos: TPoint;
begin
if not LoggedIn then Exit;
Result := Point(-1, -1);
MyPos := SPS_GetMyPos;
if Distance(MyPos.X, MyPos.Y, P.X, P.Y) < 72 then
Result := Point(MMCX + P.X - MyPos.X,
MMCY + P.Y - MyPos.Y);
end;

// Walks to position. If walking paths, please use WalkPath.
function SPS_WalkToPos(P: TPoint): boolean;
var
MM: TPoint;
begin
if not LoggedIn then Exit;
MM := SPS_PosToMM(P);

if (MM.X > 0) then
begin
Mouse(MM.X, MM.Y, 0, 0, True);
if WaitFunc(@IsMoving, 1, 3000 + random(500)) then
while IsMoving do
Flag;
Result := True;
end;
end;

// 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;

// Walks the path "Path"; always walks to the furthest point possible
function SPS_WalkPath(Path: TPointArray): boolean;
var
I, H, T, D: integer;
P, MM: TPoint;
begin
H := High(Path);
T := GetSystemTime + 20000 + Random(5000);
while (not Result) and (GetSystemTime < T) do
begin
RunEnergy(20);
FindNormalRandoms();

P := SPS_GetMyPos;
for I := H downto 0 do
begin
MM.X := MMCX + Path[I].X - P.X;
MM.Y := MMCY + Path[I].Y - P.Y;

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

if (D < 10) then
break
else begin
if (D < 70) then
begin
MouseFlag(MM.X, MM.Y, 0, 0, Integer(I<>H)*15);
T := getSystemTime + 20000 + Random(1000);
Break;
end;
end;
end;

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

putonajonny
06-19-2012, 05:34 PM
I think this is a plugins problem, make sure you have sps.dll in your Simba\Plugins folder, and make sure it is up to date...

This issue also comes if you have SPS1 and are trying to run a script that uses SPS2 I think...

Bot4Fun
06-19-2012, 06:47 PM
I downloaded sps1 once, cause some script was running with that. But when i prees update sps it says no updates is avaible, so it must be updatet again?

putonajonny
06-19-2012, 09:00 PM
I downloaded sps1 once, cause some script was running with that. But when i prees update sps it says no updates is avaible, so it must be updatet again?

If you are still getting that error then I don't think you have...

The SPS2 .dll file (to go in your plugins folder can be found here: https://github.com/SRL/SPS/blob/master/plugin/sps.dll?raw=true)