Log in

View Full Version : Fishing Guild Script Issue



Jukiahs
02-16-2012, 03:45 PM
Hi, I don't understand what is going on, Fishing Guild used to work flawlessly with banking too. But since banking update occurred its been non working since then. Below will be the script posted for those who know how to script to see where the error is; however, there will be once sentence that does pop up as an error while the script is functioning. You'll also see that I colored the error, so you can locate it faster.. But when it walks to the bank, it sits behind the bank and crashes. It doesn't locate bank to bank fish.



(*
Walking
=======

The Walking file includes functions & procedures that have anything to do with
walking. You'll notice the defines ({$IFDEF REFLECTION}) used throughout these
methods; these are used so MSI will still compile if the user decides to exclude
reflection or if reflection is broken. This file handles walking for both SPS
and reflection.

The source for Walking.simba can be found
`here <https://github.com/SRL/MSI/raw/master/MSI/Core/Walking.simba>`_.

*)

// Represent indexes of MSI_WalkVars
const
DIST_BETWEEN_POINTS = 20; // pixels between points in a path
DIST_FROM_END = 15;
DIST_RANDOMNESS = 10;

// had to be done :'(
function MSI_AtLocation(loc: integer; relocate: boolean): boolean; forward;

(*
MSI_Flag
~~~~~~~~

.. code-block:: pascal

procedure MSI_Flag(FlagDist: Integer);

MSI's custom flag function. It waits until the flag is within 'FlagDist' from
the player. It also works if, for some reason, the flag has gone off the minimap,
but the player is still moving.

.. note::

| Author: The MSI Team
| Last Updated: 04 October 2011 by Coh3n

Example:

.. code-block:: pascal

MSI_Flag(10);
*)
procedure MSI_Flag(FlagDist: Integer);
var
t: integer;
anim: TAnimation;
begin
if (not loggedIn) then
exit;

t := (getSystemTime + 10000);
anim := MSI_GetAnimation(ANIM_IDLE);

while (getSystemTime < t) do
begin
MSI_FindRandoms(false);
MSI_AntiBan(randomRange(200, 400), ANTI_BAN_CHANCE);

// flag is gone and not moving
if (not flagPresent) and (MSI_IsAnimating(anim)) then
break;

// danger zone warnings
if (leaveDangerZone()) then
MSI_SubDebug('Left danger zone');

// if the player is going around an obstacle and the flag goes off the minimap
if (not flagPresent) and (not MSI_IsAnimating(anim)) then
begin
MSI_Antiban(randomRange(500, 1000), ANTI_BAN_CHANCE);
continue;
end;

// close enough to the flag or not moving
if (flagDistance <= flagDist) or (MSI_IsAnimating(anim)) then
break;

MSI_SubDebug('Flag distance: '+intToStr(flagDistance));
end;
end;

(*
MSI_SetupSPS
~~~~~~~~~~~~

.. code-block:: pascal

procedure MSI_SetupSPS(surface: integer; areas: TStringArray);

An MSI wrapper function for SPS_Setup (sps.simba). Used to avoid needless
repeated code.

.. note::

| Author: Coh3n
| Last Updated: 07 October 2011 by Coh3n

Example:

.. code-block:: pascal

var
script: TScript;
begin
script := MSI_GetPlayerScript();
MSI_SetupSPS(script.pathInfo.spsSurface, script.pathInfo.spsAreas);
.
.
end;
*)
procedure MSI_SetupSPS(surface: integer; areas: TStringArray);
begin
{$IFDEF SPS}
//SPS_Debug := true;
SPS_Setup(surface, areas);

MSI_Debug('MSI_SetupSPS: Surface: '+toStr(SPS_Surface.Name)+', Areas: '+toStr(areas));
{$ELSE}
MSI_Debug('MSI_SetupSPS: SPS isn''t defined');
{$ENDIF}
end;

(*
MSI_GetMyPos
~~~~~~~~~~~~

.. code-block:: pascal

function MSI_GetMyPos(): TPoint;

Gets the player's position by using either SPS or reflection depending on how
the user has setup the script.

.. note::

| Author: Coh3n
| Last Updated: 28 August 2011 by Coh3n

Example:

.. code-block:: pascal

var
playerPos: TPoint;
begin
playerPos := MSI_GetMyPos();
...
*)
function MSI_GetMyPos(): TPoint;
begin
{$IFDEF SPS}
result := SPS_GetMyPos();
{$ENDIF}
MSI_SubDebug('MSI_GetMyPos(): '+toStr(result));
end;

(*
MSI_WalkPoint
~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_WalkPoint(T: TPoint): Boolean;

Simply walks to the point 'P' if it's on the minimap.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Nava2

Example:

.. code-block:: pascal

MSI_EnterPoint(point(1234, 4321));
*)
function MSI_WalkPoint(P: TPoint; flagDist: integer): Boolean;
{$IFDEF SPS}
var
tP: TPoint;
{$ENDIF}
begin
result := false;

{$IFDEF SPS}
tP := SPS_PosToMM(p);

result := (distance(tP.x, tP.y, MMCX, MMCY) < DIST_FROM_END);
if (not result) then
if (tP.x > 0) then
begin
mouse(tP.x, tP.y, 3, 3, true);
MSI_Flag(flagDist);
result := true;
end;
{$ENDIF}
end;

(*
MSI_SetPlayerLoc
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure MSI_SetPlayerLoc();

Returns a walkable path from the location (loc) record given. Uses the middle
point of each TLocation.SubLocs tile and sps boxes.

.. note::

| Author: Coh3n
| Last Updated: 23 August 2011 by Coh3n

Example:

.. code-block:: pascal

path := MSI_PathFromLoc(MSI_Locations[LOC_VE_MINE]);
*)
function MSI_PathFromLoc(loc: TLocation): TPointArray;
var
i: integer;
begin
if (not loggedIn) then
exit;

setLength(result, length(loc._subLocs));

for i := 0 to high(loc._subLocs) do
result[i] := middleBox(loc._subLocs[i].spsBox);

MSI_SubDebug('MSI_PathFromLoc: '+toStr(result));
end;

(*
MSI_PointOnPath
~~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_PointOnPath(var Index: integer; Path: TPointArray; P: TPoint; MaxDist: integer): boolean;

Finds the closest point (Index) in a path (Path) within MaxDist of any point in
the path.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Nava2

Example:

.. code-block:: pascal

See MSI_EnterPath in
`Walking.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Walking.simba>`_.
*)
function MSI_PointOnPath(var Index: integer; Path: TPointArray; P: TPoint; MaxDist: integer): boolean;
var
I, H, DistC, DistS: integer;
begin
H := High(Path);
Index := -1;
if (H < 0) then
Exit;

DistS := Distance(P.x, P.y, Path[0].x, Path[0].y); // distance from current Point

// look for the closest point
for I := 0 to H do
begin
DistC := Distance(P.x, P.y, Path[I].x, Path[I].y);
if DistC <= DistS then
begin
DistS := DistC;
Index := I;
end;
end;

Result := (DistS <= MaxDist);
if (not(Result)) then
Index := -1;

MSI_SubDebug('MSI_PointOnPath: Index = ' + IntToStr(Index));
end;

(*
MSI_FurthestPoint
~~~~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_FurthestPoint(tPath: TPointArray; P: TPoint; sPoint, ePoint: Integer): Integer;

Returns the index of the furthest point (that is on the minimap) in a path
between given indices.

.. note::

| Author: Nava2
| Last Updated: 18 October 2011 by Nava2

Example:

.. code-block:: pascal

See MSI_WalkTPA in
`Walking.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Walking.simba>`_.
*)
function MSI_FurthestPoint(tPath: TPointArray; P: TPoint; sPoint, ePoint: Integer): Integer;
var
i, c, h: Integer;
v: Extended;
TPA: TPointArray;
begin
// removes points that aren't in range
if (sPoint = -1) then
sPoint := low(tPath);

c := 0;
SetLength(TPA, (ePoint - sPoint + 1));
for i := sPoint to ePoint do
begin
TPA[c] := tPath[i];
Inc(c);
end;
tPath := TPA;

// finds the furthest visible point
h := high(tPath)
for i := h downto 0 do
begin
v := Sqr(tPath[i].X - P.X) + Sqr(tPath[i].Y - P.Y);

if (v < (69.0 * 69.0)) then
begin
Result := (i + sPoint);
Exit;
end;
end;

Result := -1;
end;

(*
MSI_PathBetween
~~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_PathBetween(fT, tT: TPoint; tDist, Rand: Integer): TPointArray;

Creates a TPA between points (fT and tT), tDist intervals, Rand randonmness.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Nava2

Example:

.. code-block:: pascal

See MSI_EnterPath in
`Walking.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Walking.simba>`_.
*)
function MSI_PathBetween(fT, tT: TPoint; tDist, Rand: Integer): TPointArray;
var
hyp, xR, yR: Extended;
l: Integer;
begin
if not LoggedIn then
Exit;

// set Result Length and first point at initial Point
SetLength(Result, Ceil(Distance(fT.X, fT.y, tT.X, tT.Y) * 1.0 / tDist) + 1);
Result[0] := fT;

// if no need for intermediate Points then nvm. :)
if (Distance(fT.X, fT.Y, tT.X, tT.Y) <= tDist) then
begin
Result[High(Result)] := tT;
Exit;
end;

// ratios for 'Similar Triangles' maths
hyp := Hypot(fT.X - tT.x, fT.Y - tT.Y);
xR := (tT.X - fT.X) / hyp;
yR := (tT.Y - fT.Y) / hyp;

// set points
for l := High(Result) - 1 downto 1 do
begin
Result[l].X := Round(fT.X + l * tDist * xR) + RandomRange(-Rand, Rand);
Result[l].Y := Round(fT.Y + l * tDist * yR) + RandomRange(-Rand, Rand);
end;

// last point is tT
Result[High(Result)] := tT;
end;

(*
MSI_ExpandPath
~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_ExpandPath(ctrlPoints: TPointArray; tDist, Randomness: Integer): TPointArray;

Expands ctrlPoints into a path with tDist intervals and Randomness.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Nava2

Example:

.. code-block:: pascal

See MSI_WalkTPA in
`Walking.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Walking.simba>`_.
*)
function MSI_ExpandPath(ctrlPoints: TPointArray; tDist, Randomness: Integer): TPointArray;
var
i, h: Integer;
t: T2DPointArray;
begin
Result := [];
h := High(ctrlPoints);
SetLength(t, h);

for i := 1 to h do
t[i - 1] := MSI_PathBetween(ctrlPoints[I - 1], ctrlPoints[I], tDist, Randomness);

Result := MergeATPA(t);
end;

(*
MSI_EnterPath
~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_EnterPath(PPos: TPoint; Path: TPointArray; maxDist: integer): boolean;

Simply calls the native SPS path walking method. Will walk to the path if the
player is within maxDist pixels (SPS), but not on the path.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Coh3n

Example:

.. code-block:: pascal

MSI_EnterPath(SPS_GetMyPos, [Point(1234, 4321)], 50);
*)
function MSI_EnterPath(PPos: TPoint; Path: TPointArray; maxDist: integer): boolean;
var
i: integer;
tmpPath: TPointArray;
begin
if (MSI_PointOnPath(i, Path, PPos, maxDist)) then
begin
tmpPath := MSI_PathBetween(PPos, Path[i], DIST_BETWEEN_POINTS, DIST_RANDOMNESS);

{$IFDEF SPS}
result := SPS_WalkPath(tmpPath);
{$ENDIF}

if (result) then
exit;
end;

MSI_SubDebug('MSI_EnterPath: false');
end;

(*
MSI_WalkTPA
~~~~~~~~~~~

.. code-block:: pascal

function MSI_WalkTPA(Path: TPointArray; Destination, MaxDist: Integer): Boolean;

Walks the given path (Path) to the destination index (Distination). Will walk
the entire path if Destination is set to -1. If within a maximum distance
(MaxDist) of any point in the path, will walk to that point and continue with
the rest of the path.

.. note::

| Author: Nava2
| Last Updated: 04 October 2011 by Coh3n

Example:

.. code-block:: pascal

MSI_WalkTPA(somePath, -1, 100);
*)
function MSI_WalkTPA(Path: TPointArray; Destination, MaxDist: Integer): Boolean;
var
P, DPoint: TPoint;
H, D, PointInd, pInd, Attempts, dist,failsPPs: Integer;
begin
if (not(loggedIn)) then
exit;

if (length(Path) <= 0) then
begin
MSI_SubDebug('MSI_WalkTPA: Path has no points');
result := true;
exit;
end;

MSI_AddHeader('MSI_WalkTPA');
MSI_Debug('Path: '+toStr(Path));

P := SPS_GetMyPos();

if (Destination = -1) then
D := High(Path)
else
D := Destination;

// expands path and finds new destination index
DPoint := Path[D];
Path := MSI_ExpandPath(Path, DIST_BETWEEN_POINTS, 3);
H := High(Path);
MSI_PointOnPath(D, Path, DPoint, DIST_BETWEEN_POINTS);

// finds you on a path and attempts to walk to it if possible
if (MSI_EnterPath(SPS_GetMyPos(), Path, MaxDist)) then
begin
MSI_PointOnPath(pInd, Path, P, DIST_BETWEEN_POINTS);

if (pInd > D) then
begin
// sorts out walking direction
InvertTPA(Path);
D := H - D;
pInd := H - pInd;
end;

// loops through the points and walks :)
while (not Result) and (Attempts < 15) do
begin
MSI_WaitWhileResting();

PointInd := MSI_FurthestPoint(Path, P, pInd, D);

// if the furthest point is found, walk to it!
if (PointInd > -1) then
begin
MSI_Debug(Format('Next Point: %d (%d, %d)', [PointInd, Path[PointInd].X, Path[PointInd].Y]));

if (MSI_WalkPoint(Path[PointInd], RandomRange(5, 10)*Integer(PointInd<>H))) then
begin
if failsPPs <> pInd then
Attempts := 0;
failsPPs := pInd;
//writeln('path '+tostr(pind));
Wait(100 + Random(100));
P := MSI_GetMyPos();
MSI_PointOnPath(pInd, Path, P, DIST_BETWEEN_POINTS);
end;
end;

Inc(Attempts);
MSI_Debug('Attempts: '+toStr(Attempts));

dist := Distance(Path[D].X, Path[D].Y, P.X, P.Y);
MSI_Debug('Distance: '+toStr(dist));

Result := (dist <= DIST_FROM_END);
end;

MSI_Flag(7);
end;

MSI_CloseHeader('MSI_WalkTPA: '+toStr(result));
end;

(*
MSI_WalkPath
~~~~~~~~~~~~

.. code-block:: pascal

function MSI_WalkPath(pathInfo: TPath; toLoc: boolean): boolean;

Walks the entire path (PathInfo), including obstacles. Returns true if the
player is at the ending location. 'inverted' is used to determine which
obstacles to load since they may be different depending on the player's
location.

.. note::

| Author: marpis & Coh3n
| Last Updated: 05 November 2011 by Coh3n

Example:

.. code-block:: pascal

MSI_WalkPath(MSI_Scripts[SCRIPT_VE_MINE].PathInfo, true);
*)
function MSI_WalkPath(pathInfo: TPath; toLoc: boolean): boolean;
var
tmpPath: T2DPointArray;
tmpAreas: array of TStringArray;
locPath, tmpLoc: TPointArray;
i, h, endLocation, attempts: integer;
done: boolean;
intObs, tmpSurfaces: TIntegerArray;
obs: TObstacle;
begin
if (not loggedIn) then
exit;

if (toLoc) then
MSI_AddHeader('MSI_WalkPath: '+pathInfo.name)
else
MSI_AddHeader('MSI_WalkPath: (Reverse) '+pathInfo.name);

locPath := MSI_PathFromLoc(MSI_Locations[pathInfo.endLoc]);

// make sure we're passing the right obstacles
if (toLoc) then
begin
endLocation := pathInfo.endLoc;
intObs := pathInfo.obstacles[OBS_LOC_TO];

tmpLoc := locPath;
tmpPath := pathInfo.spsPath;
tmpAreas := pathInfo.spsAreas;
tmpSurfaces := pathInfo.spsSurfaces;
end else begin
endLocation := pathInfo.startLoc;
intObs := pathInfo.obstacles[OBS_LOC_FROM];

// invert the paths
tmpLoc := MSI_MirrorTPA(locPath);
tmpPath := MSI_MirrorATPA(pathInfo.spsPath);
tmpAreas := MSI_MirrorATSA(pathInfo.spsAreas);
tmpSurfaces := MSI_MirrorTIA(pathInfo.spsSurfaces);
end;

// set a defaul maxDist field
if (pathInfo.maxDist <= 0) then
pathInfo.maxDist := 50;

h := high(tmpPath);

while ((not result) and (attempts < 10) and (not done)) do
begin
inc(attempts);
MSI_Debug('Walking attempts: '+toStr(attempts));

for i := 0 to h do
with MSI_Players[CurrentPlayer] do
begin
MSI_SetupSPS(tmpSurfaces[i], tmpAreas[i]);

// try walking the first leg of the path
if (MSI_WalkTPA(tmpPath[i], -1, pathInfo.maxDist)) then
begin
result := (i = h);
if (result) then
break;
end else
if ((not MSI_WalkTPA(tmpLoc, -1, pathInfo.maxDist)) and // through the sub-locations
(not MSI_WalkTPA(tmpPath[i], -1, pathInfo.maxDist))) then // through the normal path
if (i = h) then
begin
if (not MSI_AtLocation(endLocation, true)) then
done := true
else
result := true;

break;
end else
continue;

// handle the obstacle
if (i <> h) then
if (length(intObs) > 0) then
begin
obs := MSI_GetObstacle(intObs[i]);
if (not MSI_SolveObstacle(obs)) then
begin
reportInfo.falseReason := 'Failed to pass obstacle: ' + obs.name;
MSI_Debug('Failed to pass obstacle: ' + obs.name);
done := true;
break;
end;
end;
end;
end;

if (result) then
begin
result := false;
result := MSI_AtLocation(endLocation, true);
end;

MSI_CloseHeader('MSI_WalkPath: ' + boolToStr(result));
end;

(*
MSI_DeathWalk
~~~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_DeathWalk: Boolean;

Attempts to walk to the starting location for each respective script if the
player is lost. Teleports home and walks back if need be. Keep in mind that
currently this function doesn't support SPS as SPS requires the maps to be
loaded and until we can figure out a fast way to loop through EVERY bitmap, SPS
will not be supported for Death Walking.

.. note::

| Author: NCDS
| Last Updated: 05 November 2011 by Coh3n

Example:

.. code-block:: pascal

if MSI_DeathWalk then
MSI_Debug('Back on track!');
*)
function MSI_DeathWalk: Boolean;
var
script: TScript;
i: integer;
home: boolean;
begin
if (not loggedIn) then
exit;

if (not(MSI_Settings[SETUP_DEATH_WALK])) then
begin
MSI_SubDebug('MSI_DeathWalk: Function disabled');
Exit;
end;

MSI_AddHeader('MSI_DeathWalk');

script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript].Name];

with MSI_Locations[script.pathInfo.startLoc] do
begin
if (length(deathPath.spsPath) <= 0) then
begin
MSI_Debug('No death path for location: '+name);
MSI_CloseHeader('MSI_DeathWalk: '+boolToStr(result));
Exit;
end;

result := MSI_WalkPath(deathPath, true);

// teleport home!
if (not result) then
if (MSI_ClickSpell(SPELL_TELE_HOME)) then // teleport home
begin
MSI_Debug('Waiting to spawn in Lumbridge');

for i := 1 to 45 do // 45 seconds
begin
wait(1000);
if (MSI_AtLocation(LOC_LB_SPAWN, false)) then
begin
home := true;
break;
end;
end;
end;

// Walk back to the script's starting location
if (not result) then
if (home) then
begin
ClickNorth(SRL_ANGLE_HIGH);
result := MSI_WalkPath(deathPath, true);
end else begin
MSI_Debug('Didn''t spawn after 45 seconds');
result := false;
end;
end;

if (result) then
MSI_Players[CurrentPlayer].ReportInfo.FalseReason := '';

MSI_CloseHeader('MSI_DeathWalk: '+boolToStr(result));
end;

(*
MSI_PerformWalk
~~~~~~~~~~~~~~~

.. code-block:: pascal

function MSI_PerformWalk(pathInfo: TPath; toLoc: boolean): boolean;

Will walk the path "pathInfo". Takes into consideration both color and
reflection paths depending on the user's preference as well as the current
state of reflection. Also uses MSI's death walking feature.

.. note::

| Author: Coh3n
| Last Updated: 21 July 2011 by Coh3n

Example:

.. code-block:: pascal

// Walks to VE mine only if your player is set to use SCRIPT_VE_MINER
MSI_PerformWalk(MSI_Scripts[SCRIPT_VE_MINE].PathInfo, true);
*)
function MSI_PerformWalk(pathInfo: TPath; toLoc: boolean): boolean;
begin
if (not loggedIn) then
exit;

MSI_FindRandoms(true);
result := MSI_WalkPath(pathInfo, toLoc);

if (not result) then
if (MSI_DeathWalk) then
result := MSI_WalkPath(pathInfo, toLoc);

if (not result) then
with MSI_Players[currentPlayer] do
if (toLoc) then
reportInfo.falseReason := 'Failed walk to: '+pathInfo.name
else
reportInfo.falseReason := 'Failed walk from '+pathInfo.name
end;

Heavenzeyez1
02-16-2012, 03:49 PM
Use the code tags, please.

~Eerik.

Jukiahs
02-16-2012, 04:03 PM
What do u mean code tags? I highlighted the code error in red? easy to find?

Heavenzeyez1
02-16-2012, 04:06 PM
I mean that you add [/code] to the end of the script and [code] to the beginning in your original post: you can edit it. ;)

~Eerik.

Jukiahs
02-16-2012, 04:11 PM
ok done with that :D I see why now haha made it smaller lolz thx!

fretje12
02-16-2012, 10:20 PM
post it on the script thread, or you can go on script help section.

Jukiahs
02-17-2012, 01:31 AM
frethje12 can u give me the link to the thread ur talking about?