SRL Archive - Help and Support

Something in my script...


RISK

2012-02-27 14:25:21

There's something in my script that just isn't right. Every time I attempt to display a paint report on the screen and then do an object mousing function, it will make the paint disappear. But when I attempt to do the same thing but instead of an object mousing function, I make it do a progress report that just deals with the debug, it won't disappear.

Is there any reason to this? Here's the script:
(*
R_RangeGuilder
ver 1.0.5
Created by RISK
*)
program R_RangeGuilder;
{$i SRL/SRL/MISC/SMART.simba}
{$i SRL/SRL.simba}
{$i SRL/SRL/MISC/PAINTSMART.simba}
{$i SRL/SRL/MISC/DEBUG.simba}
{$i SPS/SPS.simba}

var
breakRounds, totalBreaks, competitionsDone, startingTickets,
expLastReport, comInc, compsLastReport, compsDone, startTickets,
curTickets, gained, expGained, expThisReport, comExp, comComps,
compsThisReport, maxComps, loopT, loopTT: Integer;

const
WORLD = 40; // What world do you wish to auto on? 0 = random

STATS_USER = ''; // What is your SRL stats username? Leave blank if you have none
STATS_PASS = ''; // What is your SRL stats password? Leave blank if you have none

ENABLE_BREAKS = True; // Do you want to enable taking breaks?
(* Ignore these settings if you aren't taking breaks *)
BREAK_IN = 35; // Break in how many minutes?
BREAK_FOR = 10; // Break for how many minutes?
RAND_IN = 5; // How many minutes in randomness on BREAK_IN?
RAND_FOR = 5; // How many minutes in randomness on BREAK_FOR?
(* *)

AUTO_RETALIATE = True; // True = On, False = Off
ENABLE_MOUSE_PAINT = True; // Do you want to have a paint trail behind the mouse?
ENABLE_DEBUG_MODE = False; // Do you want to enable debugging?
// This will disable debug clearing when making a progress report

(* Do not edit this segment *)
MIN_CLICK_WAIT = 0;
MAX_CLICK_WAIT = 1;
MIN_TARGET_WAIT = 2;
MAX_TARGET_WAIT = 3;
HOW_MANY_COMPS = 4;
CHECK_FOR_ARROWS = 0;
SCRIPT_VERSION = '1.0.5';
(* *)

procedure DeclarePlayers();
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := ''; // What is your character's username?
Pass := ''; // What is your character's password?

LampSkill := SKILL_RANGE;
BoxRewards := ['xp', 'exp', 'mote', 'clothes', 'charms'];

Integers[HOW_MANY_COMPS] := 500; // How many competitions do you wish to do?
Booleans[CHECK_FOR_ARROWS] := False; // Disable this if you want to use your
// own arrows. Remember they must be bronze!

(* These settings are best to leave default, but you can edit them if you desire *)
// If you are experiencing a lot of misclicks, you can raise 'MIN_TARGET_WAIT'
// and 'MAX_TARGET_WAIT' to be customized to your lag and computer
// The same goes for MIN_CLICK_WAIT and MAX_CLICK_WAIT.
Integers[MIN_CLICK_WAIT] := 150;
Integers[MAX_CLICK_WAIT] := 200;
Integers[MIN_TARGET_WAIT] := 800;
Integers[MAX_TARGET_WAIT] := 1200;

(* Each of these settings I have adjusted to work well, in what I think, will be
good for everyone's purposes. But everyone has different computers and desire,
so if you truly wish to make the script faster in clicking and wait times or slower,
then you can modify the settings. Here is a short little 'Tutorial' on each
setting:

Remember, each of these options are in milliseconds. So 1000 is one second
and so on.

MIN_CLICK_WAIT = Minimum amount of time to wait before it clicks the target
again.

MAX_CLICK_WAIT = Maximum amount of time to wait before it clicks the target
again.

MIN_TARGET_WAIT = The minimum amount of time that the target screen is up before
it attempts to close it. This is to make sure it closes the target screen if it's
open for too long.

MAX_TARGET_WAIT = The maximum amount of time that the target screen is up before
it attempts to close it. This is to make sure it closes the target screen if it's
open for too long.
(* *)

Active := True;
end;
end;

(*


You do not need to and should not edit beyond this point.


*)

procedure Write(T: string);
begin
WriteLn(TheTime + ': ' + T);
end;

function TicketAmount: Integer;
var
DTM: Integer;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

DTM := DTMFromString('mbQAAAHicY2VgYMhlYmAoBeJ8IE4E4mQglmZkYJABYnUgVgZicSDOa4sEqmZCwfxAEh0zYsFgAABgUwRn');

GameTab(25);
Result := (ItemAmount('inv', 'dtm', DTM, []));

FreeDTM(DTM);
end;

Procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour: integer);
var
mx, my, Pic, I, B, H, TPH, Numb: Integer;
TTP: TPointArray;
Canvas: TCanvas;
begin
SmartSetDebug(True);
GetClientDimensions(mx, my);
Pic := BitmapFromString(mx, my, '');
TPH := High(TP);
for I := 0 to TPH do
begin
TTP := LoadTextTPA(TP[i], SmallChars, H);
for B := 0 to High(TTP) do
begin
Numb := ((I + 1) * 13);
FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1, 660515);
FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
end;
end;
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
FreeBitmap(Pic);
end;

procedure PaintReport;
var
XPH, CPH: Integer;
timeRan: string;
begin
SMART_ClearCanvas;

compsDone := (competitionsDone);
timeRan := (MSToTime(GetTimeRunning, Time_Bare));
startTickets := (startingTickets);
curTickets := (TicketAmount);
gained := (curTickets - startTickets);
expGained := (Gained * 5);

// Borrowed from Nebula's Range Guilder
CPH := (Round((competitionsDone) * 3600) / ((GetTimeRunning) / 1000));
XPH := (Round(gained * 5 * 3600) / ((GetTimeRunning) / 1000));

PrintOnSmart(['RISK''s Range Guilder',
'Version: ' + SCRIPT_VERSION,
'Time ran: ' + timeRan,
'Tickets gained: ' + ToStr(gained),
'Exp gained: ' + ToStr(expGained), 'Exp/h: ' + ToStr(XPH),
'Competitions/h: ' + ToStr(CPH)],
Point(550, 350), 9359257);
end;

// Five minute report
procedure Report();
var
XPH, CPH: Integer;
timeRan: string;
begin
if (not(ENABLE_DEBUG_MODE)) then
ClearDebug;

compsDone := (competitionsDone);
timeRan := (MSToTime(GetTimeRunning, Time_Bare));
startTickets := (startingTickets);
curTickets := (TicketAmount);
gained := (curTickets - startTickets);
expGained := (Gained * 5);

// Borrowed from Nebula's Range Guilder
CPH := (Round((competitionsDone) * 3600) / ((GetTimeRunning) / 1000));
XPH := (Round(gained * 5 * 3600) / ((GetTimeRunning) / 1000));

WriteLn('__________________________');
WriteLn('');
WriteLn(' RISK''s Range Guilder');
WriteLn(' Script version: ' + SCRIPT_VERSION);
WriteLn(' Time ran: ' + timeRan);
WriteLn(' Competitions done: ' + ToStr(compsDone));
WriteLn(' Competitions/h: ' + ToStr(CPH));
WriteLn(' Tickets gained: ' + ToStr(gained));
WriteLn(' EXP gained: ' + ToStr(expGained));
WriteLn(' EXP/h: ' + ToStr(XPH));
WriteLn('__________________________');
end;


(*
BenLand's function, modified by Flight(?) to have a paint trail, re-modified
by RISK to disable the paint option completely if the user is not using SMART
*)
procedure WindMouse2(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: extended);
var
veloX, veloY, windX, windY, veloMag, dist, randomDist, lastDist, step: extended;
lastX, lastY: integer;
sqrt2, sqrt3, sqrt5: extended;
begin
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
while hypot(xs - xe, ys - ye) > 1 do
begin
dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, dist);
if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
if (maxStep < 3) then
begin
maxStep:= random(3) + 3.0;
end else
begin
maxStep:= maxStep / sqrt5;
end;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;
if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;
lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;
if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
MoveMouse(Round(xs), Round(ys));
step:= hypot(xs - lastX, ys - lastY);
wait(round((maxWait - minWait) * (step / maxStep) + minWait));
lastdist:= dist;

{$IFDEF SMART}
if (ENABLE_MOUSE_PAINT) then
SMART_DrawDotsEx(False, [Point(lastX, lastY)], clWhite);
{$ENDIF}

end;
if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));

end;

(*
Credits to Flight
*)
procedure HumanMMouse(eX, eY, ranX, ranY: Integer);
var
randSpeed: extended;
X,Y,X2,Y2,A,Dist,MP: integer;
begin
SMART_ClearCanvas;
A := MouseSpeed;
GetMousePos(X, Y);
Dist := Distance(X, Y, eX, eY);
MP := Round(Dist/150);
if MP < 0 then
MP := 1;

randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
X2 := RandomRange(eX-(A*MP), eX+(A*MP));
Y2 := RandomRange(eY-(A*MP), eY+(A*MP));
WindMouse2(X, Y, X2, Y2, 11, 8, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed);
GetMousePos(X, Y);
MMouse(eX, eY, ranX, ranY);
MouseSpeed := A;
end;

procedure SetCTS(Hue, Saturation: Extended);
begin
SetColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hue, Saturation);
end;

procedure RevertCTS();
begin
SetColorSpeed2Modifiers(0.2, 0.2);
SetColorToleranceSpeed(1);
end;

procedure ExitPlayer(Message: string);
begin
Write(Message);
Players[CurrentPlayer].Active := False;
Logout;
end;

procedure RClickMM;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

// Mouses to the minimap and right clicks
MouseBox(MMX1, MMY1, MMX2, MMY2, MOUSE_RIGHT);
Wait(RandomRange(300, 400));
MouseBox(MSX1, MSY1, MSX2, MSY2, MOUSE_MOVE);
end;

procedure RClickChat;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (FindNPCChatText('.', Nothing)) then
Exit;

// Moves the mouse to the chat and right clicks
MouseBox(MCX1, MCY1, MCX2, MCY2, MOUSE_RIGHT);
Wait(RandomRange(200, 300)); // A random wait
MouseBox(MSX1, MSY1, MSX2, MSY2, MOUSE_MOVE);
end;

procedure RandomSpacebar;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (FindNPCChatText('.', Nothing)) then
Exit;

// Presses the spacebar
KeyDown(1);
Wait(RandomRange(75, 100));
KeyUp(1);

// Waits before backspacing
Wait(RandomRange(750, 1150));

// Backspaces to remove the space we have just typed
KeyDown(1);
Wait(RandomRange(300, 400));
KeyUp(1);
end;

(*
Credits to Kyle Undefined
*)
function RandomRangeEx(rFrom, rTo : Variant) : Variant;
var
r : Variant;
begin
r := RandomRange(Floor(rFrom), Ceil(rTo));
r := r + RandomE;

repeat
begin
if r <= rFrom then
r := r + RandomE
else if r >= rTo then
r := r - RandomE;
end;
until ((r >= rFrom) and (r <= rTo))

r := (Trunc(r * 100) / 100.00)

Result := r;
end;

// 33.0 ~ 46.7
procedure FixCompass();
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

MakeCompass(RandomRangeEx(33.0, 46.7));
end;

procedure AntiBan();
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

case (Random(375)) of
0 : RandomRClick;
1 :
begin
BoredHuman;
SetAngle(SRL_ANGLE_LOW);
end;
2 : ExamineInv;
3 :
begin
HoverSkill('Ranged', False);
Wait(RandomRange(4000, 7000)); // Random wait to 'View' the skill information
end;
4 : RClickChat;
5 : RClickMM;
6 .. 13 : RandomSpaceBar;
14 .. 39 : Wait(RandomRange(1000, 8000));
39 .. 70 : MouseSpeed := (RandomRange(10, 14));
end;
end;

function GetATPA(Col, Tol, W, H: Integer; Hue, Sat: Extended): T2DPointArray;
var
X, Y: Integer;
TPA: TPointArray;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

SetCTS(Hue, Sat);
FindColorsSpiralTolerance(X, Y, TPA, Col, MSX1, MSY1, MSX2, MSY2, Tol);
RevertCTS;

Result := (SplitTPAEx(TPA, W, H));
end;

// Updated 2/26/2012 - Added a maximum pixel limit along side the already in
// place minimum pixel limit to help with mousing over the judge instead of the
// guards
function R_MouseTPA(Text: string; Col, Tol, W, H: Integer; Hue, Sat: Extended): Boolean;
var
R, I, T, maxT, TT, maxTT: Integer;
P: TPoint;
ATPA: T2DPointArray;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

I := 0;
T := 0;
TT := 0;
maxT := (RandomRange(15000, 25000));
maxTT := (RandomRange(6500, 7500));
Result := False;

repeat
MarkTime(T);

repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (TimeFromMark(T) >= maxT) then
begin
Result := False;
Exit;
end;

ATPA := (GetATPA(Col, Tol, W, H, Hue, Sat));
if (Length(ATPA) > 0) then
Break;

Write('Object was not detected. Waiting.');
AntiBan;
Wait(RandomRange(500, 1500));
until(False);

MarkTime(TT);

// What to do if the length of ATPA is greater than 0
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
if (ENABLE_DEBUG_MODE) then
DebugATPABounds(ATPA);
for I := 0 to High(ATPA) do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if ((Length(ATPA[I]) < 15) and (Length(ATPA[I]) > 40)) then
Continue;

P := (MiddleTPA(ATPA[I]));
HumanMMouse(P.X, P.Y, 5, 5);
Result := (WaitUpText(Text, RandomRange(750, 1500)));

if (Result) then
Break;

if (TimeFromMark(TT) >= maxTT) then
begin
Write('Max time passed. Let''s wait and try to find the object again.');
AntiBan;
Wait(RandomRange(500, 1500));
Break;
end;

Wait(RandomRange(450, 750));
end;

Inc(R);
until((Result) or (R >= (RandomRange(4, 6))) or (not(LoggedIn)));
end;

// Non CTS 2 version of R_MouseTPA
function R_MouseObj(Text: string; Col, Tol, W, H: Integer): Boolean;
var
X, Y, I, T, maxT: Integer;
P: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

I := 0;
T := 0;
maxT := (RandomRange(15000, 25000));

MarkTime(T);

repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (TimeFromMark(T) >= maxT) then
begin
Write('We were unable to find the object.');
Result := False;
Exit;
end;

FindColorsSpiralTolerance(X, Y, TPA, Col, MSX1, MSY1, MSX2, MSY2, Tol);
if (Length(TPA) > 0) then
Break;

Write('The object is not on the screen. Waiting.');
AntiBan;
Wait(RandomRange(500, 1500));
until(False);

// What to do if the length of TPA is greater than 0
ATPA := (TPAToATPAEx(TPA, W, H));
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
if (ENABLE_DEBUG_MODE) then
DebugATPABounds(ATPA);
for I := 0 to High(ATPA) do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

P := (MiddleTPA(ATPA[I]));
HumanMMouse(P.X, P.Y, 5, 5);
Result := (WaitUpText(Text, RandomRange(850, 1500)));

if (Result) then
Break;

AntiBan;
Wait(RandomRange(250, 500));
end;

if (not(Result)) then
Write('We were unable to mouse the object.');
end;

// Point(2525, 2945), Point(2520, 2979)
// Updated 2/26/2012 thanks to Nebula's tip.
procedure SPS_FixPosition;
var
Path: TPointArray;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

Path := [Point(2525, 2945), Point(2520, 2979)];

if (SPS_WalkPath(Path)) then
begin
FixCompass;
SetAngle(SRL_ANGLE_LOW);
end else
ExitPlayer('SPS repositioning failed. Logging out.');
end;

// Created as the main method of fixing our position instead of SPS
procedure DTM_FixPosition;
var
X, Y, DTM, T, maxT: Integer;
E: Extended;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

T := 0;
maxT := (RandomRange(3000, 5000));

DTM := DTMFromString('mggAAAHicY2NgYLAAYi8gFgdiHgYIAPHVgVgAiLWgYiJALAXE1TU6DAnV2gypiaoM2SGODB1VgQx5fYYM/EA5bJgJiBmxYAgAAG0ICHo=');
MarkTime(T);
repeat
if (not(LoggedIn)) then
Exit;
FindNormalRandoms;

if (TimeFromMark(T) >= maxT) then
begin
Write('DTM repositioning failed. Let''s try SPS.');
FreeDTM(DTM);
SPS_FixPosition;
end;

Wait(RandomRange(75, 200));
until(FindDTMRotated(DTM, X, Y, MMX1, MMY1, MMX2, MMY2, - Pi / 4, Pi / 4, Pi / 60, E));

FreeDTM(DTM);

HumanMMouse(X, Y, 5, 5);
ClickMouse2(MOUSE_LEFT);
FFlag(5);
FixCompass;
end;

// Fixes the chats so that we can detect if we have a new competition or not
procedure FixChats;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

SetAllChats('All', 'Off', 'Off', 'Off', 'Off', 'Off', '');
end;

procedure HandleNoArrows;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (not(FindNPCChatText('standard', Nothing))) then
Exit;

ExitPlayer('We have run out of arrows to use.');
Exit;
end;

function TargetScreen(): Boolean;
begin
Result := (CountColorTolerance(4500223, MSX1, MSY1, MSX2, MSY2, 10) > 100);
end;

procedure CloseTargetScreen();
var
X, Y, DTM, I, T, maxT: Integer;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (not(TargetScreen)) then
Exit;

T := 0;
maxT := (RandomRange(150000, 250000));
DTM := DTMFromString('mbQAAAHicY2VgYHjKyMDwFojvQ+l7QKwJFDeEYmUoVpQRZeDk5IRj' +
'A01FBi6gODpmxILBAAA7xwas');

MarkTime(T);

while (TargetScreen) do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (TimeFromMark(T) >= maxT) then
begin
FreeDTM(DTM);
ExitPlayer('We were unable to close the target screen.');
Exit;
end;

if (FindDTM(DTM, X, Y, MSX1, MSY1, MSX2, MSY2)) then
begin
HumanMMouse(X, Y, 3, 3);
if (not(WaitUpText('Close', RandomRange(500, 800)))) then
begin
FreeDTM(DTM);
Exit;
end;

ClickMouse2(MOUSE_LEFT);
for I := 0 to 5 do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (not(TargetScreen)) then
begin
FreeDTM(DTM);
Exit;
end;

Wait(RandomRange(500, 600));
end;
end;
end;

FreeDTM(DTM);
end;

procedure FireAtTargets();
var
minW, maxW, minC, maxC, I, maxI, T, TT, maxT, TTT, maxTTT, TTTT, maxTTTT: Integer;
startP, curP: TPoint;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

minW := (Players[CURRENTPLAYER].Integers[MIN_TARGET_WAIT]);
maxW := (Players[CURRENTPLAYER].Integers[MAX_TARGET_WAIT]);
minC := (Players[CURRENTPLAYER].Integers[MIN_CLICK_WAIT]);
maxC := (Players[CURRENTPLAYER].Integers[MAX_CLICK_WAIT]);

I := 0;
T := 0;
maxT := (RandomRange(150000, 250000));
TT := 0;
TTT := 0;
TTTT := 0;
maxTTTT := (RandomRange(4000, 6000));
maxTTT := (RandomRange(10000, 20000));

MarkTime(T);
MarkTime(TTTT);

repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

HandleNoArrows;

if (TargetScreen) then
CloseTargetScreen;

if (TimeFromMark(T) >= maxT) then
begin
ExitPlayer('We were unable to fire at the targets.');
Exit;
end;

if (R_MouseObj('Fire-a', 5041405, 10, 10, 10)) then
Break;

if (TimeFromMark(TTTT) >= maxTTTT) then
begin
Write('We were unable to find any targets. We might be out of the area.');
DTM_FixPosition;

TTTT := 0;
maxTTTT := (RandomRange(4000, 6000));
MarkTime(TTTT);

AntiBan;
Wait(RandomRange(550, 850));
end;

Write('Unable to mouse over a target. Let''s wait.');
//if (not(CheckCompass))) then
// FixCompass;
AntiBan;
Wait(RandomRange(500, 1500));
until(False);

GetMousePos(startP.X, startP.Y);
MarkTime(TT);

repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

GetMousePos(curP.X, curP.Y);

HandleNoArrows;

if (TimeFromMark(TT) >= maxT) then
begin
ExitPlayer('We were unable to fire at the targets.');
Exit;
end;

case (Random(30)) of
1 :
begin
GetMousePos(curP.X, curP.Y);
curP.X := (curP.X + Random(2));
curP.Y := (curP.Y + Random(2));
HumanMMouse(curP.X, curP.Y, 0, 0);
end;

2 :
begin
GetMousePos(curP.X, curP.Y);
curP.X := (curP.X - Random(2));
curP.Y := (curP.Y - Random(2));
HumanMMouse(curP.X, curP.Y, 0, 0);
end;

3 :
begin
GetMousePos(curP.X, curP.Y);
curP.X := (curP.X - Random(2));
curP.Y := (curP.Y + Random(2));
HumanMMouse(curP.X, curP.Y, 0, 0);
end;

4 :
begin
GetMousePos(curP.X, curP.Y);
curP.X := (curP.X + Random(2));
curP.Y := (curP.Y - Random(2));
HumanMMouse(curP.X, curP.Y, 0, 0);
end;
end;

// Checking to see if we have clicked to a different position
if (FindNPCChatText('meant', Nothing)) then
begin
Write('We have moved out of the shooting range. Repositioning.');
DTM_FixPosition;
end;

// Misclick handling
if (not(IsUpText('Fire-a')) and (not(TargetScreen))) then
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

HandleNoArrows;

Wait(RandomRange(500, 1500));

if (not(IsUpText('Fire-a')) and (not(TargetScreen))) then
if (not(R_MouseObj('Fire-a', 5041405, 10, 10, 10))) then
begin
DTM_FixPosition;
if (not(R_MouseObj('Fire-a', 5041405, 10, 10, 10))) then
begin
ExitPlayer('We have misclicked and we were unable to fix our position.');
Exit;
end;
end else
begin
GetMousePos(startP.X, startP.Y);
GetMousePos(curP.X, curP.Y);
end;
end;

// Target screen handling
if (TargetScreen) then
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

HandleNoArrows;

// We have this here to make sure the while .. do loop works properly
I := 0;
maxI := (RandomRange(minW, maxW));
MarkTime(TTT);

while (not(I >= maxI)) do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

// Randomizes the waiting time per 'loop-thru' of the fail-safe
maxI := (RandomRange(minW, maxW));

if (TimeFromMark(TTT) >= maxTTT) then
begin
ExitPlayer('Error in detecting the target screen.');
Exit;
end;

if (not(TargetScreen)) then
Break;

Wait(100);
IncEx(I, 100);
end;

if ((I >= maxI) and ((TargetScreen))) then
begin
Write('The target screen has been up for ' + ToStr(maxI) + ' second(s). Closing it.');
CloseTargetScreen;
HumanMMouse(startP.X, startP.Y, 5, 5);
end;
end;

// Over the maximum amount of distance from center of target handling
if (Distance(curP.X, curP.Y, startP.X, startP.Y) >= 10) then
begin
Write('Mouse is too far from the center of the target. Fixing it.');
HumanMMouse(startP.X, startP.Y, 5, 5);
end;

// Clicking handling
ClickMouse2(MOUSE_LEFT);
Wait(RandomRange(minC, maxC));
until(FindNPCChatText('Sorry', Nothing) or (not(LoggedIn)));
end;

function ArrowsEquipped: Boolean;
var
X, Y, DTM: Integer;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

DTM := DTMFromString('mbQAAAHicY2VgYJjIxMAwG4j7gbgTiGcC8Sug+AsgfgLEb4H4HRAbKCgwuKpzAllMYDpOmJeBH8hDx4xYMBgAAO7dCag=');
GameTab(26);

Result := (FindDTM(DTM, X, Y, MIX1, MIY1, MIX2, MIY2));

FreeDTM(DTM);
end;

procedure EquipArrows();
var
DTM, I, T, maxT: Integer;
P: TPoint;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

I := 0;
T := 0;
maxT := (RandomRange(15000, 25000));
DTM := DTMFromString('mbQAAAHicY2VgYJjIxMAwG4j7gbgTiGcC8Sug+AsgfgLEb4H4HRAbKCgwuKpzAllMYDpOmJeBH8hDx4xYMBgAAO7dCag=');

MarkTime(T);

repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);


if (TimeFromMark(T) >= maxT) then
begin
FreeDTM(DTM);
ExitPlayer('There are no arrows in our inventory and none are equipped. - Perhaps a DTM failure.');
Exit;
end;

if (FindDTM(DTM, P.X, P.Y, MIX1, MIY1, MIX2, MIY2)) then
begin
HumanMMouse(P.X, P.Y, 3, 3);
if (WaitUpText('ze ar', RandomRange(750, 1500))) then
begin
ClickMouse2(MOUSE_LEFT);
for I := 1 to 5 do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (not(FindDTM(DTM, P.X, P.Y, MIX1, MIY1, MIX2, MIY2))) then
begin
Write('We have equipped the arrows.');
FreeDTM(DTM);
Exit;
end;

Wait(RandomRange(100, 400));
end;
end;
end;

Write('There are no arrows in our inventory.');
AntiBan;
Wait(RandomRange(750, 1500));

if (ArrowsEquipped) then
begin
Write('We already have arrows equipped.');
Break;
end;
until(False);

FreeDTM(DTM);
end;

// Remade 2/24/2012 to make it less 'One shot'
// Modified 2/26/2012 - Removed some of the getting a new competition checks
// due to my new obtained knowledge that you don't need to click the green
// button or do anything after that to start a new competition. I'm sorry for
// including it in the first place, I was unaware of this.
procedure GetCompetition();
var
T, TT, TTT, maxT, maxTT, maxTTT, X, Y, iTR, cTR: Integer;
B, BB: Boolean;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

maxT := (RandomRange(60000, 65000));
maxTT := (RandomRange(4000, 5000));

T := 0;
TT := 0;
TTT := 0;
iTR := 0;
cTR := 0;

B := False;
BB := False;

MarkTime(T);
MarkTime(TT);
repeat

// Attempts to mouse and interact with the judge
repeat
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (TargetScreen) then
CloseTargetScreen;


// Exits the character if we are unable to get a new competition
if (TimeFromMark(T) >= maxT) then
begin
ExitPlayer('We were unable to get a new competition.');
Exit;
end;

// Fixes the position of our character if we are unable to see the judge
if (TimeFromMark(TT) >= maxTT) then
begin
Write('We might be unable to see the judge. Let''s fix our location.');
DTM_FixPosition;
TT := 0;
maxTT := (RandomRange(4000, 5000));

AntiBan;
Wait(RandomRange(500, 850));
end;

if (R_MouseTPA('Judge', 6906979, 9, 15, 15, 0.31, 0.08)) then
begin
ClickMouse2(MOUSE_RIGHT);

maxTTT := (RandomRange(1500, 2000));
MarkTime(TTT);

// Waits for the option that the judge always has upon right click to show
while (not(OptionsExist(['k-to Comp'], False))) do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

if (TimeFromMark(TTT) >= maxTTT) then
Break;

Write('Judge options not detected. Waiting.');
Wait(100);
end;

if ((TimeFromMark(TTT) >= maxTTT) and (not(OptionsExist(['k-to Comp'], False)))) then
begin
Write('We might have moused over the wrong object. Trying again.');
Continue;
end;

if (not(WaitOption('ete Comp', RandomRange(850, 1250)))) then
begin
Write('We have a competition already.');
Exit;
end;

Break; // Breaks out of the first repeat .. until to complete the procedure
end;

Write('Waiting for the object to be on the screen.');
AntiBan;
Wait(RandomRange(500, 1500));
until(False);

// Handles waiting for the pay confirmation dialogue to appear
for iTR := 1 to 5 do
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

B := (FindText(X, Y, '1', StatChars, MCX1, MCY1, MCX2, MCY2));
if (B) then
Break;

Write('Waiting for the pay confirmation dialogue to show.');
Wait(RandomRange(750, 1250));
end;

// Continues if we have timed out after waiting for the pay confirmation dialogue
if ((iTR >= 5) and (not(B))) then
Continue;

// Handles clicking 'Yes' for the pay confirmation dialogue
// We use MMouse here instead of HumanMMouse as HumanMMouse does not look
// like a human would when choosing a dialoge option.
MMouse(X, Y, 25, 7);
ClickMouse2(MOUSE_LEFT);

if (B) then
begin
Write('We have started a new competition!');
Exit;
end;
until(False);
end;

procedure StartGame();
var
Checking: Boolean;
begin
if (not(LoggedIn)) then
Exit;
if (FindNormalRandoms) then
SetAngle(SRL_ANGLE_LOW);

Checking := (Players[CURRENTPLAYER].Booleans[CHECK_FOR_ARROWS]);

GetCompetition;
if (Checking) then
EquipArrows;
end;

// Created by Echo_, modified by Flight
function BreakHandler(BreakIn, BreakFor, randBreakIn, randBreakFor: Integer): Boolean;
var
realTime, w, x, y, z: Integer;
begin
if not LoggedIn then
Exit;

w := (BreakIn * 60000);
x := (BreakFor * 60000);
y := RandomRange(-randBreakIn * 60000, randBreakIn * 60000);
z := RandomRange(-randBreakFor * 60000, randBreakFor * 60000);
realTime := ((x + z) / 60000);

if (HowManyPlayers = 1) then
begin
if (GetTimeRunning < ((w) + (y) + BreakRounds)) then Exit
else
if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
begin
Writeln('Taking a break for about ' + IntToStr(realTime) + ' minutes.');
Logout;
Wait((x) + (z));
Writeln('Logging in.');
LoginPlayer;
Result := LoggedIn;
FindNormalRandoms;
IncEx(BreakRounds, (w) + (x));
IncEx(TotalBreaks, 1);
Writeln('The next break will occur in about ' + IntToStr(realTime) + ' minutes.');
end;
end;

if (HowManyPlayers > 1) then
begin
if (GetTimeRunning < ((w) + (y) + BreakRounds)) then Exit
else
if (GetTimeRunning > ((w) + (y) + BreakRounds)) then
begin
Writeln('Taking a break for about ' + IntToStr(BreakFor) + ' minutes.');
Logout;
IncEx(BreakRounds, (w));
IncEx(TotalBreaks, 1);
NextPlayer(True);
Exit;
while (LoggedIn) do
Wait((x) + (z));
NextPlayer(True);
end;
end;
end;

procedure Commit();
begin
compsDone := (competitionsDone);
startTickets := (startingTickets);
curTickets := (TicketAmount);
gained := (curTickets - startTickets);
expGained := (Gained * 5);

// Keeps track of per commit experience gained and competitions done
expThisReport := (expGained);
compsThisReport := (compsDone);
if (not(comInc = 0)) then
begin
comExp := (expThisReport - expLastReport);
comComps := (compsThisReport - compsLastReport);
end else
begin
comExp := (expThisReport);
comComps := (compsThisReport);
end;

expLastReport := (expThisReport);
compsLastReport := (compsThisReport);


stats_IncVariable('Ranged EXP (Gained)', comExp);
stats_IncVariable('Total EXP Gained', comExp);
stats_IncVariable('Competitions Done', comComps);
if (stats_Commit) then
Write('We have committed stats to SRL stats!');

comExp := 0;
comComps := 0;

Inc(comInc);
end;

begin
SMART_Server := WORLD;
SMART_Members := True;

AddOnTerminate('Report');
SetupSRL;
SetupSRLStats(836, STATS_USER, STATS_PASS);
//SetupStats();
SPS_Setup(RUNESCAPE_SURFACE, ['6_7']);
MouseSpeed := (RandomRange(10, 12));
DeclarePlayers;
LoginPlayer;
SetAngle(SRL_ANGLE_LOW);
ClearDebug;
FixCompass;

// Testing section, just place an 'Exit;' after the testing line
PaintReport();
Report();
Exit;
// End of testing section

repeat
maxComps := (Players[CURRENTPLAYER].Integers[HOW_MANY_COMPS]);
competitionsDone := 0;
comInc := 0;
startingTickets := (TicketAmount);

MarkTime(loopT);
MarkTime(loopTT);
FixChats;
Retaliate(AUTO_RETALIATE);

// loopT is the MarkTime integer that we use to keep track of the 5 minute
// limit per commit. Every 5 minutes we commit stats and then set loopT back
// to 0.
// This is also used for the 5 minute progress report.

// loopTT is the integer that we use to keep track of the per minute paint
// report. Every paint report we do each minute, we set loopTT back to 0.

repeat
Inc(CompetitionsDone);

StartGame;
Wait(RandomRange(300, 500));
FireAtTargets;
Wait(RandomRange(300, 500));
AntiBan;

// Per minute paint report
if (TimeFromMark(loopTT) >= 60000) then
begin
PaintReport();
loopTT := 0;
end;

// Per 5 minute progress report & stat commiting
if (TimeFromMark(loopT) >= 300000) then
begin
Report();
Commit();
loopT := 0;
end;
until((competitionsDone >= maxComps) or (not(LoggedIn)));

ExitPlayer('');
Write('If you have encountered an error, please enable debug mode in the script setup and rerun the script.');
Write('Thank you!');
until(AllPlayersInactive);
end.

Some explanation for the functions:
R_MouseTPA is used when finding a judge,
R_MouseObj is used when finding a target,
GetCompetition(), of course, finds the judge and gets a new competition,
FireAtTargets() fires at the targets, of course.

Both R_MouseTPA and R_MouseObj make the paint disappear.

Along with that, I'm still having problems with variable sending with my stat reporting. These two things I just can't get it work for some strange reason. I'm completely unsure if I'm just using the things wrong or what.


Thanks for any help.


E: Oops, created a new thread when I forgot I had my other thread named 'Stats' open. Sorry about that!

Hero

2012-02-27 20:51:23

Try removing SMART_ClearCanvas;

RISK

2012-02-27 20:53:24

Nope, I have debug disabled whenever I try it.

Flight

2012-02-27 20:58:05

Look in the HumanMMouse procedure, at the very beginning you have this:

SMART_ClearCanvas;

So every time you use that to move your mouse it'll clear the screen. What you could do is simply do your PaintReport immediately after clearing the screen of the mouse trail.

Brandon

2012-02-27 20:58:07

Smart_ClearCanvas is in the HumanMouse function.. and that's going to clear the entire smart canvas whether there is a proggy or not printed on it.. thus every time the mouse moves, it will clear the canvas..

damn.. lol.. Ninja'd:ninja:

RISK

2012-02-27 21:01:37

Gasp. I didn't think to look in that part of the script. Thank you all very much. I feel very silly right now.

Thanks again!

Flight

2012-02-27 21:04:46

From: ggzz
Smart_ClearCanvas is in the HumanMouse function.. and that's going to clear the entire smart canvas whether there is a proggy or not printed on it.. thus every time the mouse moves, it will clear the canvas..

damn.. lol.. Ninja'd:ninja:


Ah ha, I finally ninja'd someone else! :spot:

RISK, I'm not sure where your onscreen progress report is painted, but if it's in the chat box or your inventory screen what you could do is have HumanMMouse clear just the MS area after painting the mouse trail. That way the trail is cleared but your onscreen report remains.

Check this out for the most recent changes to SMART painting: http://villavu.com/forum/showthread.php?t=71762

Hero

2012-02-27 21:07:08

As soon as I saw it I was going to ninja you Flight since I saw you looking at the thread and I knew you would find the answer. :P late refresh sadly.

RISK

2012-02-27 21:07:25

Will do. Thanks for the suggestion. I really appreciate it, Flight.