SRL Archive - OSR Help

Not sure why my procedure is not working?


rotchy1

2013-05-30 20:46:44

So I made a procedure to find the gate at the chicken pen in lumbridge and check whether or not it is open, and if it is open then walk inside and if it is not then open it and walk inside. All it will do right now is hover over the gate rather than right click and choose text "open"? Can someone enlighten me on where i'm going wrong?

thanks guys

procedure OpenGateIfClosed;

var MMx, MMy, x, y: Integer;
MainScreenPointConverted: TPoint;

begin
WaitNotMoving(true);
Writeln('Looking for gate on MiniMap');
FindColorSpiral(MMx, MMy, (197874 or 3951706), MMCX, MMCY, MMCX + -25, MMCY + -25);
MainScreenPointConverted := MMToMS(Point(MMx, MMy));
if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
MMouse(MMx, MMy, 0, 0);
if IsUpText('pen') then
ClickMouse2(2);
ChooseOption('pen');
wait(RandomRange(400,600));
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end
else
begin
if FindObj(MMx, MMy, 'lose', 3951706, 7) then
MMouse(MMx, MMy, 0, 0);
if IsUpText('lose') then
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end;
end;

Sin

2013-05-30 20:49:20


if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
MMouse(MMx, MMy, 0, 0);
if IsUpText('pen') then
begin
ClickMouse2(2);
ChooseOption('pen');
wait(RandomRange(400,600));
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end;
end

You need to add begins/ends after your if blocks. Without a begin/end, it'll only execute the first line after the if statement. begin/ends are similar to ' { ' and ' } ' :)

rotchy1

2013-05-30 20:56:37

From: Sin

if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
MMouse(MMx, MMy, 0, 0);
if IsUpText('pen') then
begin
ClickMouse2(2);
ChooseOption('pen');
wait(RandomRange(400,600));
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end;
end

You need to add begins/ends after your if blocks. Without a begin/end, it'll only execute the first line after the if statement. begin/ends are similar to ' { ' and ' } ' :)


Ok, I added the begin and ends, as you said and something changed (I think good) however still not working 100%. Now after hovering the gate to get the uptext it simply ends the procedure rather than continue on to right click and open or click inside the pen. Am I using an incorrect mouseclick function?

EDIT: heres my code after I added the begin/end to the blocks

procedure OpenGateIfClosed;

var MMx, MMy, x, y: Integer;
MainScreenPointConverted: TPoint;

begin
WaitNotMoving(true);
Writeln('Looking for gate on MiniMap');
FindColorSpiral(MMx, MMy, (197874 or 3951706), MMCX, MMCY, MMCX + -25, MMCY + -25);
MainScreenPointConverted := MMToMS(Point(MMx, MMy));
if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
MMouse(MMx, MMy, 0, 0);
if IsUpText('pen') then
begin
ClickMouse2(2);
ChooseOption('pen');
wait(RandomRange(400,600));
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end;
end
else
begin
if FindObj(MMx, MMy, 'lose', 3951706, 7) then
begin
MMouse(MMx, MMy, 0, 0);
if IsUpText('lose') then
MMouse(80, 186, 10, 10);
wait(RandomRange(100,150));
Mouse(x, y, 2, 2, true);
end;
end;
end;

Sin

2013-05-30 20:59:37

Use 'writeln()'s to see what's going on.
Add ``markers", so to speak such as: writeln("Got here: Position 1");, writeln("Pos 2"); etc

rotchy1

2013-05-30 21:10:37

From: Sin
Use 'writeln()'s to see what's going on.
Add ``markers", so to speak such as: writeln("Got here: Position 1");, writeln("Pos 2"); etc


Ok, so I added the Writeln()'s and it appears to be gonig through each step however its not preforming the mouseclick? it even seems to move the mouse into the chicken pen after wards and then does not click there either? This elads me to believe Im not using the click function correctly? If you would like to test yourself I can post a script that will walk to the pen from anywhere is RS or just elt you use an account I have sitting there for the time being :). Im kinda stumped and this seems like a dumb little mistake on my end? By the way thankyou very much for helping me with this, hopefully I can figure it out.

procedure OpenGateIfClosed;

var MMx, MMy, x, y: Integer;
MainScreenPointConverted: TPoint;

begin
WaitNotMoving(true);
Writeln('Looking for gate on MiniMap');
FindColorSpiral(MMx, MMy, (197874 or 3951706), MMCX, MMCY, MMCX + -25, MMCY + -25);
MainScreenPointConverted := MMToMS(Point(MMx, MMy));
if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
Writeln('1');
MMouse(MMx, MMy, 0, 0);
Writeln('2');
if IsUpText('pen') then
Writeln('3');
begin
ClickMouse2(2);
Writeln('4');
ChooseOption('pen');
Writeln('5');
wait(RandomRange(400,600));
Writeln('6');
MMouse(80, 186, 10, 10);
Writeln('7');
wait(RandomRange(100,150));
Writeln('8');
Mouse(x, y, 2, 2, true);
Writeln('9');
end;
end
else
begin
Writeln('10');
if FindObj(MMx, MMy, 'lose', 3951706, 7) then
begin
Writeln('11');
MMouse(MMx, MMy, 0, 0);
Writeln('12');
if IsUpText('lose') then
begin
Writeln('13');
MMouse(80, 186, 10, 10);
Writeln('14');
wait(RandomRange(100,150));
Writeln('15');
Mouse(x, y, 2, 2, true);
Writeln('16');
end;
end;
end;
end;

Here is the code with the walking included, it wil ltele to lumbridge via homeport and walk to the gate if you would like to take a look.

Program Test;

{$DEFINE SMART}
{$I SRL/SRL.simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := '';
Pass := '';
Active := True;
end;
end;

procedure Setup;
begin
Smart_FixSpeed := True;
ClearDebug;
SetupSRL;
DeclarePlayers;
LogInPlayer;
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
CloseAllScreens;
FindNormalRandoms;
ToggleActionBar(False);
Wait(RandomRange(200, 500));
ToggleMoneyPouch(False);
Wait(RandomRange(200, 500));
ToggleXPBar(False);
Wait(RandomRange(200, 500));
Retaliate(True);
Wait(RandomRange(200, 500));
end;

procedure TeleHome;
begin
OpenLodeStoneScreen;
Lodestoneteleport('Lumbridge');
Wait(RandomRange(15000, 16000));
end;

function VinesFound: Boolean;
var
Vines, i, l, r, T: integer;
VinesTPA: TPointArray;
begin
Vines := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.05, 0.11);

FindColorsTolerance(VinesTPA, 4025693, MSX1, MSY1, MSX2, MSY2, 3);

SetColorToleranceSpeed(Vines);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(VinesTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(VinesTPA[r].x, VinesTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 1, lets go to position 2!');
Result := True
end;

function LightPostFound: Boolean;
var
LightPost, i, l, r, T: integer;
LightPostTPA: TPointArray;
begin
LightPost := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.02, 0.08);

FindColorsTolerance(LightPostTPA, 4219252, MSX1, MSY1, MSX2, MSY2, 9);

SetColorToleranceSpeed(LightPost);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(LightPostTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(LightPostTPA[r].x, LightPostTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find lightpost at position 2');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 2, lets go to position 3!');
Result := True
end;

function StumpFound: Boolean;
var
Stump, i, l, r, T: integer;
StumpTPA: TPointArray;
begin
Stump := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.03, 0.42);

FindColorsTolerance(StumpTPA, 5670819, MSX1, MSY1, MSX2, MSY2, 6);

SetColorToleranceSpeed(Stump);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(StumpTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(StumpTPA[r].x, StumpTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 3, lets go to position 4!');
Result := True
end;

function RockFound: Boolean;
var
Rock, i, l, r, T: integer;
RockTPA: TPointArray;
begin
Rock := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.31, 0.07);

FindColorsTolerance(RockTPA, 7566457, MSX1, MSY1, MSX2, MSY2, 9);

SetColorToleranceSpeed(Rock);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(RockTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(RockTPA[r].x, RockTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 4, lets go to position 5!');
Result := True
end;

function BlueFlagFound: Boolean;
var
BlueFlag, i, l, r, T: integer;
FlagTPA: TPointArray;
begin
BlueFlag := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.02, 0.91);

FindColorsTolerance(FlagTPA, 12738604, MSX1, MSY1, MSX2, MSY2, 12);

SetColorToleranceSpeed(BlueFlag);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(FlagTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(FlagTPA[r].x, FlagTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 4, lets go to position 5!');
Result := True
end;

function HayandGrainFound: Boolean;
var
HayandGrain, i, l, r, T: integer;
HayandGrainTPA: TPointArray;
begin
HayandGrain := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.11, 2.34);

FindColorsTolerance(HayandGrainTPA, 8108508, MSX1, MSY1, MSX2, MSY2, 16);

SetColorToleranceSpeed(HayandGrain);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(HayandGrainTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(HayandGrainTPA[r].x, HayandGrainTPA[r].y, 2, 2);
if IsUpTextMultiCustom(['alk', 'earch']) then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 5, lets go to position 6!');
Result := True
end;

function WheelBarrelPlantFound: Boolean;
var
WheelBarrelPlant, i, l, r, T: integer;
WheelBarrelPlantTPA: TPointArray;
begin
WheelBarrelPlant := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.05, 1.81);

FindColorsTolerance(WheelBarrelPlantTPA, 2315332, MSX1, MSY1, MSX2, MSY2, 7);

SetColorToleranceSpeed(WheelBarrelPlant);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(WheelBarrelPlantTPA)
Marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(WheelBarrelPlantTPA[r].x, WheelBarrelPlantTPA[r].y, 2, 2);
if IsUpText('alk') then
Break;
if timefrommark(T) > 3000 then
begin
ClearDebug;
writeln('Still trying to find vines at position 1');
Result := False;
end;
end;
ClearDebug;
writeln('We are at position 6, lets check to see if the gate is open!');
Result := True
end;

function RoadColor1: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.14, 0.14);

FindColorsSpiralTolerance(MMCX, MMCY, arP, 5790813, MMX1, MMY1, MMX2, MMY2, 14);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 3.80) and (X <= 19.47) and (Y >= 3.96) and (Y <= 20.53) and (Z >= 4.17) and (Z <= 21.36) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

procedure WalkToChickens;
var
T: Integer;
begin
repeat
MarkTime(T);
Writeln('RadialWalk1');
RadialWalkTolerance(5594207, 70, 80, 70, -1, 0, 34);
wait(RandomRange(1000,1500));
until ((VinesFound = True) or (TimeFromMark (T) > 10000));
repeat
MarkTime(T);
Writeln('RadialWalk2');
RadialWalkTolerance(5594207, 45, 55, 55, - 1, 0, 34);
until ((LightPostFound = True) or (TimeFromMark (T) > 10000));
repeat
MarkTime(T);
Writeln('RadialWalk3');
RadialWalkTolerance(5594207, 330, 350, 75, - 1, 0, 34);
until ((StumpFound = True) or (TimeFromMark (T) > 10000));
repeat
MarkTime(T);
Writeln('RadialWalk4');
RadialWalkTolerance(5594207, 330, 350, 80, - 1, 0, 34);
until ((BlueFlagFound = True) or (TimeFromMark (T) > 10000));
//repeat
// MarkTime(T);
// Writeln('RadialWalk5');
// RadialWalkTolerance(5594207, 350, 359, 20, - 1, 0, 34);
//until ((RockFound = True) or (TimeFromMark (T) > 10000));
repeat
MarkTime(T);
Writeln('RadialWalk6');
RadialWalkTolerance(5594207, 300, 355, 70, - 1, 0, 34);
until ((HayandGrainFound = True) or (TimeFromMark (T) > 10000));
repeat
MarkTime(T);
Writeln('RadialWalk7');
RadialWalkTolerance(5594207, 350, 355, 63, - 1, 0, 34);
until ((WheelBarrelPlantFound = True) or (TimeFromMark (T) > 10000));
Wait(RandomRange(1500,2000));
end;

procedure OpenGateIfClosed;

var MMx, MMy, x, y: Integer;
MainScreenPointConverted: TPoint;

begin
WaitNotMoving(true);
Writeln('Looking for gate on MiniMap');
FindColorSpiral(MMx, MMy, (197874 or 3951706), MMCX, MMCY, MMCX + -25, MMCY + -25);
MainScreenPointConverted := MMToMS(Point(MMx, MMy));
if FindObj(MMx, MMy, 'pen', 3951706, 7) then
begin
Writeln('1');
MMouse(MMx, MMy, 0, 0);
Writeln('2');
if IsUpText('pen') then
Writeln('3');
begin
ClickMouse2(2);
Writeln('4');
ChooseOption('pen');
Writeln('5');
wait(RandomRange(400,600));
Writeln('6');
MMouse(80, 186, 10, 10);
Writeln('7');
wait(RandomRange(100,150));
Writeln('8');
Mouse(x, y, 2, 2, true);
Writeln('9');
end;
end
else
begin
Writeln('10');
if FindObj(MMx, MMy, 'lose', 3951706, 7) then
begin
Writeln('11');
MMouse(MMx, MMy, 0, 0);
Writeln('12');
if IsUpText('lose') then
begin
Writeln('13');
MMouse(80, 186, 10, 10);
Writeln('14');
wait(RandomRange(100,150));
Writeln('15');
Mouse(x, y, 2, 2, true);
Writeln('16');
end;
end;
end;
end;

procedure MainLoop;
begin
TeleHome;
WalkToChickens;
OpenGateIfClosed;
end;

Begin
Setup;
MainLoop;
End.

EDIT: I re-positioned my initial MMouse and IsUpText functions to be directly after the FindObj function and it now correctly clicks to open the closed gate to detect that it is already open, no I just need to figure out why the simple clicking procedure is working for walking him inside the chicken pen.

procedure OpenGateIfClosed;

var MMx, MMy, x, y: Integer;
MainScreenPointConverted: TPoint;

begin
WaitNotMoving(true);
Writeln('Looking for gate on MiniMap');
FindColorSpiral(MMx, MMy, (197874 or 3951706), MMCX, MMCY, MMCX + -25, MMCY + -25);
MainScreenPointConverted := MMToMS(Point(MMx, MMy));
FindObj(MMx, MMy, 'pen', 3951706, 7);
MMouse(MMx, MMy, 0, 0);
if WaitUptext('pen', RandomRange(400,650)) then
begin
ClickMouse2(1);
Writeln('4');
wait(RandomRange(400,600));
Writeln('6');
MMouse(80, 186, 10, 10);
Writeln('7');
wait(RandomRange(100,150));
Writeln('8');
Mouse(x, y, 2, 2, true);
Writeln('9');
end
else
if WaitUptext('lose', 500) then
begin
Writeln('13');
MMouse(80, 186, 10, 10);
Writeln('14');
wait(RandomRange(100,150));
Writeln('15');
Mouse(x, y, 2, 2, true);
Writeln('16');
end;
end;