Flight
2012-03-27 09:33:49
Hiya, I got the idea to do my first "script blog" posting each step I take to create a certain script, in this case an Essence-Miner for Yanille. I got the general idea from Sir RM's blog so I'm gonna have my own go at it. :)
Pure essence is increasing a crazy rate, and I'm sure my fellow Rune-Crafters would agree with me: enough is enough. Once completed the script will offer an alternative to the increasing market price, so let's keep our fingers crossed that the script turns out to be a success! :) By the way, it will be public, obviously.
-[3-27-12]-
8:30 PM
Added final branches of script loop Added Function 'AboveGround'
10:00 PM
-[3-28-12]-
8:30 AM
Added FindMage & TeleToMine
If you have any suggestions let 'em roll in.
Pure essence is increasing a crazy rate, and I'm sure my fellow Rune-Crafters would agree with me: enough is enough. Once completed the script will offer an alternative to the increasing market price, so let's keep our fingers crossed that the script turns out to be a success! :) By the way, it will be public, obviously.
-[3-27-12]-
8:30 PM
- Script skeleton fabricated
- Main script loop taking form
Procedure ScriptLoop;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if AboveGround then
begin
//Setup runescape_surface SPS
if NearBank then
begin
end;
if InGuild then
begin
end;
end;
if not AboveGround then
begin
//Setup essence_mine SPS
end;
end;
Procedure ScriptLoop;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if AboveGround then
begin
{Is there a way to check if our surface map is already set?}
SPS_Setup(RUNESCAPE_SURFACE, ['5_10']);
SPS_Continue := True;
if NearBank then
begin
if InvFull then
HandleBank
else
WalkToGuild;
end;
if InGuild then
begin
if InvFull then
begin
if HandleDoor then
WalkToBank;
end else
TeleToMine;
end;
end;
if not AboveGround then
begin
{Is there a way to check if our SPS map is already set?}
SPS_Setup(ESSENCE_MINE, ['0_1']);
SPS_Continue := True;
if not InvFull then
begin
if WalkToMine then
MineEssence;
end else
if WalkToPortal then
ExitMine;
end;
end;
Function AboveGround: Boolean;
begin
Result := (PercentBlackMM < 20);
end;
10:00 PM
- Imported RSG's MMToMS functions
- Added GetPortalMM and FindPortal functions
Function GetPortalMM(Var X,Y: Integer): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
i: Integer;
ATPA: T2DPointArray;
begin
Result := False;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
{Find the basic MM symbol color}
FindColorsSpiralTolerance(MMCX, MMCY, TPA, 12632256, MMX1, MMY1, MMX2, MMY2, 5);
if (Length(TPA) < 1) then
Exit;
{Split the TPA into 10x10 boxes, each represent a MM symbol}
ATPA := SplitTPAEx(TPA, 10, 10);
SortATPAFromFirstPoint(ATPA, Point(MSCX,MSCY));
for i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
{Search inside each MM symbol for the unique, secondary color}
with B do
begin
FindColorsSpiralTolerance(MMCX, MMCY, TPA2, 5001797, B.X1, B.Y1, B.X2, B.Y2, 5);
if (Length(TPA2) > 0) then
begin
MiddleTPAEx(TPA2, X, Y);
Result := True;
Exit;
end;
end;
end;
end;
Function FindPortal: Boolean;
var
TBA: TBoxArray;
TIA: TIntegerArray;
PortalMM,PortalMS,
MidBox: TPoint;
TPA: TPointArray;
I,J: Integer;
begin
Result := False;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
{First we find the portal MM symbol and store the point}
if not GetPortalMM(PortalMM.X, PortalMM.Y) then
Exit;
{Next, split the MS into 35x35 boxes}
TBA := AreaToBoxArray(MSX1, MSY1, MSX2, MSY2, 35, 35);
TIA := PixelShiftMulti(TBA, 300);
for I := 0 to High(TBA) do
begin
{Search each box for a certain amount of pixelshift}
if (TIA[I] > 100) then
begin
{For each 'shifting box' add the center point to a new TPA}
MidBox := MiddleBox(TBA[I]);
SetArrayLength(TPA, Length(TPA)+1);
TPA[High(TPA)] := MidBox;
end;
end;
if (Length(TPA) < 1) then Exit;
{Now using the portal's MM symbol point we get a 'general' MS tile location}
if MMToMSTileEx(PortalMS.X, PortalMS.Y, PortalMM.X, PortalMM.Y) then
begin
SortTPAFrom(TPA, PortalMS);
{Sort the TPA starting from the portals MMToMS mid tile}
for J := 0 to High(TPA) do
begin
HumanMMouse(TPA[J].X, TPA[J].Y, 5, 5);
if WaitUpTextMulti(['nter', 'ortal', 'Ent', 'Port', 'P'], 500) then
begin
Result := True;
Exit;
end;
end;
end;
end;
11:30 PM- Added FindDoor & HandleDoor functions
Function FindDoor(Var X, Y: Integer): Boolean;
Var
TPA,PBox: TPointArray;
i,a,CTS: Integer;
ATPA: T2DPointArray;
Cols,Tols: TIntegerArray;
HMods,SMods: Array of Extended;
begin
Result := False;
if not LoggedIn then Exit;
if BelowGround then Exit;
if IsUpTextMultiCustom(['Open', 'agic', 'guild', 'door']) then
begin
Result := True;
Exit;
end;
PBox := TPAFromBox(IntToBox(240, 130, 275, 185));
CTS := GetColorToleranceSpeed;
Cols := [2637658, 2177881];
Tols := [5, 6];
HMods := [0.07, 0.06];
SMods := [0.24, 1.26];
for i := 0 to High(Cols) do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(HMods[i], SMods[i]);
FindColorsSpiralTolerance(MSCX-50, MSCY, TPA, Cols[i], MSX1, MSY1, MSX2, MSY2, Tols[i]);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
TPA := ClearTPAFromTPA(TPA, PBox);
if (Length(TPA) > 0) then break;
end;
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, 30, 30);
SortATPAFromFirstpoint(ATPA, Point(MSCX-50, MSCY));
for a := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[a], X, Y);
HumanMMouse(X, Y, 7, 7);
if WaitUpTextMulti(['Open', 'agic', 'guild', 'door'], 500) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end;
end;
end;
Function HandleDoor: Boolean;
Var
X,Y: Integer;
Me_Start,Me_New: TPoint;
label
Search;
begin
Result := False;
Me_Start := SPS_GetMyPos;
Search:
if not LoggedIn then Exit;
if BelowGround then Exit;
if FindDoor(X, Y) then
begin
ClickMouse2(True);
if not DidRedClick then
goto Search;
WaitFunc(@IsMoving_F, 10, 1000);
While IsMoving_F do
Wait(1);
if (Me_Start.X > 2220) then {Entering the guild}
begin
Me_New := SPS_GetMyPos;
if (Me_New.X > 2220) then
goto Search
else if (Me_New.X <= 2220) then
Result := True;
end else if (Me_Start.X <= 2220) then {Exiting the guild}
begin
Me_New := SPS_GetMyPos;
if (Me_New.X <= 2220) then
goto Search
else if (Me_New.X > 2220) then
Result := True;
end;
end;
end;
-[3-28-12]-
8:30 AM
- Updated HandleDoor to work off SPS for both enter & exiting the guild
- Added BelowGround (for the sake of WaitFunc) & NearGuild
Function BelowGround: Boolean;
begin
Result := (PercentBlackMM > 20);
end;
Function NearGuild: Boolean;
Var
Me: TPoint;
Dist: Integer;
begin
Result := False;
if not LoggedIn then Exit;
if BelowGround then Exit;
Me := SPS_GetMyPos;
Dist := Distance(Me.X, Me.Y, 2220, 4315);
Result := (Dist <= 20);
end;
Function FindMage(Var X, Y: Integer): Boolean;
Var
TPA,PBox: TPointArray;
i,a,CTS,F: Integer;
ATPA: T2DPointArray;
Cols,Tols: TIntegerArray;
HMods,SMods: Array of Extended;
begin
Result := False;
if not LoggedIn then Exit;
if BelowGround then Exit;
for F := 4 downto 1 do
begin
PBox := TPAFromBox(IntToBox(240, 130, 275, 185));
CTS := GetColorToleranceSpeed;
Cols := [14325800];
Tols := [13];
HMods := [0.01];
SMods := [1.39];
for i := 0 to High(Cols) do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(HMods[i], SMods[i]);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Cols[i], MSX1, MSY1, MSX2, MSY2, Tols[i]);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
TPA := ClearTPAFromTPA(TPA, PBox);
if (Length(TPA) > 0) then break;
end;
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, 20, 45);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));
for a := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[a], X, Y);
HumanMMouse(X, Y, 5, 5);
if WaitUpTextMulti(['Talk-t', 'izard', 'Diste', 'stent', 'entor'], 500) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end;
end;
end;
end;
Function TeleToMine: Boolean;
Var
X,Y: Integer;
Me: TPoint;
label
Search;
begin
Result := False;
Search:
if not LoggedIn then Exit;
if BelowGround then Exit;
Me := SPS_GetMyPos;
if (Me.X > 2220) then
HandleDoor;
if FindMage(X, Y) then
begin
ClickMouse2(False);
if not WaitOptionMulti(['Telep', 'elepo', 'leport'], 500) then
goto Search;
WaitFunc(@IsMoving_F, 10, 1000);
While IsMoving_F do
Wait(1);
Result := WaitFunc(@BelowGround, 10, 5000);
end;
end;
11:30 PM- Added full support for pouch-handling & repairing
- Banking routines completed
If you have any suggestions let 'em roll in.