SRL Archive - First Scripts

[In Progress] [Dev Log] [Help Me Script This] Runespan Siphoner [RS3] [Runecrafting]


vwxz

2014-01-22 02:21:12

So this thread is a mix between a script demo, a progress log, and a help request. If there's a better forum for it, mods please help me move it.

I was looking at some recent work and comments in this thread and I got interested in writing a script for Runespan. Fortunately, I recently got a 90+ RC account to test stuff with, so I'm good to go.

Here is my progress so far. It includes just the exp tracking main loop, since I will need that both for siphoning detection and progress tracking. This script is completely passive, but I've been running it while manually Runespanning to verify that it works.

program RunespanSiphoner;
{$define SMART}
{$I SRL-6/SRL.Simba}

{
vwxz's Runespan Siphoner
in development - not a release
}

var
LastExpSeen, TotalExpGained: Integer;
StartTime, LastExpChangeTime: TTimeMarker;
SiphonTimeout: Integer;

{
TRSChatBox.GetXP
by Ashaman88, Janilabo, and others
from http://villavu.com/forum/showthread.php?t=107292
Gets the current exp value from the exp counter.
The counter must be placed in the top right of the chat box header bar.
}
function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,cts,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);
findColorsTolerance(tpa, 14013909, b, 4,colorSetting(2, 0.00, 0.00));
if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;
atpa := tpa.cluster(5);
b:= atpa.getbounds;
b.edit(-2,-2,+2,+3);
s:=Replace(tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS), ' ', '', [rfReplaceAll]);
P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);
print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

{
UpdateExpSeen
Checks current exp displayed in exp counter and
update the internal totals and timers regarding experience gain.
}
procedure UpdateExpSeen;
var
CurrentExpSeen, CurrentExpGained: Integer;
begin
CurrentExpSeen := ChatBox.GetXP;
CurrentExpGained := CurrentExpSeen - LastExpSeen;
if (CurrentExpGained > 0) then begin
LastExpChangeTime.Start;
end
LastExpSeen := CurrentExpSeen;
TotalExpGained := TotalExpGained + CurrentExpGained;
end;

{
IsCurrentlySiphoning
Whether or not we believe we are currently siphoning something,
inferred from recent experience gain.
}
function IsCurrentlySiphoning: Boolean;
begin
UpdateExpSeen;
Result := LastExpChangeTime.GetTime <= SiphonTimeout;
end;

procedure SetUpAll;
begin
ClearDebug;
SmartEnableDrawing := True;
SetUpSRL;
SiphonTimeout := 5000;
StartTime.Start;
LastExpChangeTime.Start;
LastExpSeen := ChatBox.GetXP;
TotalExpGained := 0;
end;

procedure MainLoopIteration;
begin
UpdateExpSeen;
Print(IntToStr(TotalExpGained));
Print(BoolToStr(IsCurrentlySiphoning));
Sleep(5000 + Random(1000));
end;

begin
SetUpAll;
repeat
MainLoopIteration
until False;
end.

My next step is to add object finding. Some replies at this thread were really helpful.

Any advice, comments, encouragement, etc. would be great. Thanks guys!

vwxz

2014-01-22 04:47:48

I am quite happy with myself. After a large quantity of trial and error on the approach, I've gotten object finding working. Updated code follows.

I appreciate all feedback.

BTW, is it just me or do the two soul esswraiths have different colors?

program RunespanSiphoner;
{$define SMART}
{$I SRL-6/SRL.Simba}

{
vwxz's Runespan Siphoner
in development - not a release
very likely to go all kersplodey on you
}

{
Many thanks to the following:

}

type
TSiphonTarget = record
Name: String;
IsNode: Boolean;
Colors: Array of Integer;
ColorTolerance: Integer;
end;

var
LastExpSeen, TotalExpGained: Integer;
StartTime, LastExpChangeTime: TTimeMarker;
SiphonTimeout: Integer;
TargetSoul: TSiphonTarget;

procedure InitTargetData
begin
//Soul Esswraith
TargetSoul.Name := 'Soul esswraith';
TargetSoul.IsNode := False;
TargetSoul.Colors := [12494138, 5480907];
TargetSoul.ColorTolerance := 10;
end;

{
TRSChatBox.GetXP
by Ashaman88, Janilabo, and others
from http://villavu.com/forum/showthread.php?t=107292
Gets the current exp value from the exp counter.
The counter must be placed in the top right of the chat box header bar.
}
function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,cts,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);
findColorsTolerance(tpa, 14013909, b, 4,colorSetting(2, 0.00, 0.00));
if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;
atpa := tpa.cluster(5);
b:= atpa.getbounds;
b.edit(-2,-2,+2,+3);
s:=Replace(tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS), ' ', '', [rfReplaceAll]);
P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);
print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

{
UpdateExpSeen
Checks current exp displayed in exp counter and
update the internal totals and timers regarding experience gain.
}
procedure UpdateExpSeen;
var
CurrentExpSeen, CurrentExpGained: Integer;
begin
CurrentExpSeen := ChatBox.GetXP;
CurrentExpGained := CurrentExpSeen - LastExpSeen;
if (CurrentExpGained > 0) then begin
LastExpChangeTime.Start;
end
LastExpSeen := CurrentExpSeen;
TotalExpGained := TotalExpGained + CurrentExpGained;
end;

{
IsCurrentlySiphoning
Whether or not we believe we are currently siphoning something,
inferred from recent experience gain as reported by UpdateExpSeen.
}
function IsCurrentlySiphoning: Boolean;
begin
UpdateExpSeen;
Result := LastExpChangeTime.GetTime <= SiphonTimeout;
end;

{
}
function FindTarget(TargetToFind: TSiphonTarget; var ResultTPA: TPointArray): Boolean;
var
PrimaryColor, SecondaryColor: Integer;
PrimaryColorTPA, SecondaryColorTPA: TPointArray;
PrimaryColorATPA: T2DPointArray;
PrimaryIdx, SecondaryIdx: Integer;
CandidateTPA: TPointArray;
CandidatePoint: TPoint;
CandidateBox: TBox;
SecondariesFound: Boolean;
begin
Result := False;
PrimaryColor := TargetToFind.Colors[Low(TargetToFind.Colors)];
if FindColorsTolerance(PrimaryColorTPA, PrimaryColor, MainScreen.GetBounds, TargetToFind.ColorTolerance) then begin
PrimaryColorATPA := PrimaryColorTPA.ToATPA(40);
SortATPAFromMidPoint(PrimaryColorATPA, MainScreen.PlayerPoint);
//SmartImage.DebugATPA(PrimaryColorATPA);
for PrimaryIdx := Low(PrimaryColorATPA) to High(PrimaryColorATPA) do begin
CandidateTPA := PrimaryColorATPA[PrimaryIdx];
//SmartImage.DebugTPA(CandidateTPA);
CandidatePoint := MedianTPA(CandidateTPA);
CandidateBox := IntToBox(CandidatePoint.X - 30, CandidatePoint.Y - 30, CandidatePoint.X + 30, CandidatePoint.Y + 30);
SecondariesFound := True;
for SecondaryIdx := Low(TargetToFind.Colors) + 1 to High(TargetToFind.Colors) do begin
SecondaryColor := TargetToFind.Colors[SecondaryIdx];
FindColorsTolerance(SecondaryColorTPA, SecondaryColor, CandidateBox, TargetToFind.ColorTolerance);
//SmartImage.DebugTPA(SecondaryColorTPA);
if Length(SecondaryColorTPA) < 5 then begin
SecondariesFound := False;
break;
end;
end;
if SecondariesFound then begin
Result := True;
ResultTPA := CandidateTPA;
SmartImage.DebugTPA(ResultTPA);
break;
end;
end;
end;
end;

procedure SetUpAll;
begin
ClearDebug;
SmartEnableDrawing := True;
SetUpSRL;
InitTargetData;
SiphonTimeout := 5000;
StartTime.Start;
LastExpChangeTime.Start;
LastExpSeen := ChatBox.GetXP;
TotalExpGained := 0;
end;

procedure MainLoopIteration;
begin
UpdateExpSeen;
Print(IntToStr(TotalExpGained));
Print(BoolToStr(IsCurrentlySiphoning));
Sleep(5000 + Random(1000));
end;

var
TestPoints: TPointArray;

begin
SetUpAll;
FindTarget(TargetSoul, TestPoints);
end.

Clarity

2014-01-23 20:41:19

Good luck with this! I took a break from mine (got it to about 45k xp/hr at lvl 95, max at 99 is 55k/hr) to work on a more interesting/useful script but I plan to come back when that's done and released. Optimizing is quite a challenge.