SRL Archive - OSR Help

Simple, silly function question


Roflme

2012-07-09 23:10:32

Before I test it, just wanted to see if I could get a faster response here.

Basically I'm working on a fletching script and am trying to add stringing to it at the moment. I just wanted to know if a function could give results on two things?

Function NoBow: Boolean;
begin
Result := not FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2);
end;

Function NoBow2: Boolean;
begin
Result := not FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2);
end;

Is there any way to combine these functions into one? Have the function look for both results? Or can i just have it do (after it's clicked to begin stringing the bows):

repeat
Antiban
WaitFunc(@NoBow, 10, 2000);
WaitFunc(@NoBow2, 10, 2000);
until NoBow and NoBow2;

^If that worked, it wouldn't matter if I was fletching long or shortbows since it'd be checking for both at the same time.

Going to test it if nobody replies anyways, but a quick reply will save me some time/guide me in the right direction.

bolshak25

2012-07-09 23:16:39

Function NoBow: Boolean;
var
Shortbow,Longbow:Integer;
begin
Result:=True;
Shortbow:=blah;
Longbow:=blah;
If FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2) then
Result:=False;
If FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2) then
Result:=False;
FreeDTM(ShortBow);
FreeDTM(LongBow);
end;

should work?

Frement

2012-07-09 23:19:39

function NoBow: Boolean;
Result := (not FindDTM(FirstDTM)) or (not FindDTM(SecondDTM));
end;

Works for both :)

Roflme

2012-07-09 23:36:41

From: bolshak25
Function NoBow: Boolean;
var
Shortbow,Longbow:Integer;
begin
Result:=True;
Shortbow:=blah;
Longbow:=blah;
If FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2) then
Result:=False;
If FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2) then
Result:=False;
FreeDTM(ShortBow);
FreeDTM(LongBow);
end;

should work?

Will try this out first :p

From: Frement
function NoBow: Boolean;
Result := (not FindDTM(FirstDTM)) or (not FindDTM(SecondDTM));
end;

Works for both :)


Will try this out second lol. Would replacing the "or" with "and" work? Or is the "or" acting as an and in this case. (Will the function come back as true if it can find one but not the other, fooling the script into continuing?).

Frement

2012-07-09 23:39:56

If it finds either of those, then it will return true, in all other scenarios it will return false.

Runaway

2012-07-09 23:40:54

Just another variation:


function NoBow: Boolean;
var
BowDTM: TIntegerArray;
c, i, x, y: Integer;
begin
BowDTM := [Shortbow, Longbow];
for i := 0 to High(BowDTM) do
begin
if FindDTM(BowDTM[i], x, y, MIX1, MIY1, MIX2, MIY2) then
Inc(c);
end;
Result := (c < 1);
end;

Not necessarily very useful for only two variables, but it's usefulness increases exponentially when more variables are needed.

Roflme

2012-07-09 23:44:49

Strange, wasn't getting any "The following DTMs were not freed: [2, 3, 4]" message until now :( both functions are causing the message. I have a FreeDTMZ procedure, going to try to add it to the functions utilizing DTMs and see if that fixes it.


From: Runaway
Just another variation:


function NoBow: Boolean;
var
BowDTM: TIntegerArray;
c, i, x, y: Integer;
begin
BowDTM := [Shortbow, Longbow];
for i := 0 to High(BowDTM) do
begin
if FindDTM(BowDTM[i], x, y, MIX1, MIY1, MIX2, MIY2) then
Inc(c);
end;
Result := (c < 1);
end;

Not necessarily very useful for only two variables, but it's usefulness increases exponentially when more variables are needed.



Going to stare at that for a few minutes to see if I can comprehend what is being done there :( :p lol

So i is going to act as the Longbow or Shortbow DTM? (it gets replaced by what is in the brackets [Longbow, Shortbow]?)

I'm just lost at the end. What is the purpose of c exactly? Why increase it but have the result as less than 1?

EDIT: Still getting DTMs not freed. No need to read the full script it's just makes it easier for me to compare what I have to what was suggested.

program RoflmeFletcher;


{$DEFINE SMART}
{$i SRL\SRL.simba}
{$i SRL\SRL\Misc\Debug.simba}


// Thank you for using my script.
// Read thread for instructions and details.
// Also post any issues on the thread.

const
//CASE SENSITIVE (At least for me while testing)

FletchType = 'string';
//'bow' for unfinished bows,
//'string' for complete bows,
//'arrow' for arrows,
//'bolt' for bolts,
//'dart' for darts
//ONLY BOW AND STRING WORK FOR NOW

BowType = '';
//'shortbow' for shortbows,
//'longbow' for longbows
//only fill out if making unfinished bows

var

x, y, Log, Longbow, Shortbow, LogsCut, BowsStrung, t: Integer;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
With Players[0] do
begin
Name := '';
Pass := '';
Pin := '';

Active := true;
end;
end;


Procedure AntiBan;
begin
Case Random(800) of
1: RandomRClick;
2: RandomMovement;
3..10: BoredHuman;
11..20: PickUpMouse;
21..800: Wait(500);
end;
SetAngle(SRL_ANGLE_HIGH);
Wait(350+Random(200));
end;

Procedure SetDTMs;
begin
Log := DTMFromString('mlwAAAHicY2dgYJjBxMAwAYinA/FCIF4KxLOAeDIQPwXK3wHi21D6BRC/A+IPQGykww8kmbDi/wy4ASMeDAUARmYMBQ==');
Longbow := DTMFromString('mQwAAAHicY2ZgYAhjYmBIAmJXII5iZGDIBmJ/IC5ITQTKMkExAjAiYSAAAJ8NA1s=');
Shortbow := DTMFromString('mQwAAAHicY2ZgYBACYlkGCOCD0uJAXJSWDCSZoBgBGJEwEAAAQj4Bmg==');
end;


procedure FreeDTMZ;
begin
FreeDTM(Log);
FreeDTM(Longbow);
FreeDTM(Shortbow);
end;

Procedure Bank;
begin
begin
repeat
OpenBankChest(SRL_BANK_SW);
until BankSCreen or PinScreen;
end;

if PinScreen then
begin
repeat
InPin(Players[0].Pin);
until BankScreen
end;

if BankScreen then
begin
DepositAll;
Case FletchType of
'bow':
begin
Withdraw(0,0,28);
end;
'string':
begin
Withdraw(0,0,14);
Wait(200+Random(100));
Withdraw(1,0,14);
end;
end;
Wait(100);
Closebank;
repeat
wait(10);
until InvCount > 0;
end;
end;

Function GetDaText(var cx, cy: Integer; TextHere: String): Boolean;
begin
Result := FindText(cx, cy, TextHere, StatChars, MCX1, MCY1, MCX2, MCY2);
end;

Function NoLogs: Boolean;
begin
Result := not FindDTM(Log, x, y, MIX1, MIY1, MIX2, MIY2);
end;

Function NoBow: Boolean;
begin
Result := (not FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2)) or (not FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2));
end;

Function OptionsAppeared: Boolean;
begin
Result := CountColorTolerance(2070783, MCX1, MCY1, MCX2, MCY2, 14) > 50;
end;

Function Cut: Boolean;
begin
MarkTime(t);
if FindDTM(Log, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
MouseItem(RandomRange(1,28), mouse_left);
wait(200+random(50));
repeat
wait(100);
if TimeFromMark(t) > 10000 then
begin
TerminateScript;
end;
until(OptionsAppeared);
Result := True
end else
begin
TerminateScript;
end;
end;

Procedure FletchBow;
begin
if GetDaText(x, y, 'nife') then
begin
Mouse(x, y, 5, 5, mouse_left);
repeat
wait(100);
until GetDaText(x, y, 'bow')
end;

Case BowType of
'longbow':
begin
if GetDaTExt(x, y, 'ongb') then
begin
Mouse(x, y, 5, 5, mouse_left);
end;
end;

'shortbow':
begin
if GetDaTExt(x, y, 'ortb') then
begin
Mouse(x, y, 5, 5, mouse_left);
end;
end;
end;

Repeat
AntiBan;
WaitFunc(@NoLogs, 10, 5000);
Until NoLogs;
LogsCut := LogsCut + InvCount
end;


Function StringBow: Boolean;
begin
MarkTime(t)
if FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2) or
FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
Writeln('Found unstrung bows, stringing them')
MouseItem(14,mouse_left);
MouseItem(15,mouse_left);
repeat
wait(200);
if TimeFromMark(t) > 10000 then
begin
TerminateScript;
end;
until OptionsAppeared
Result := True
Writeln('Found Option Color');
end else
begin
TerminateScript;
end;

if GetDaText(x, y, 'bow') then
begin
Mouse(x, y, 5, 5, mouse_left);
repeat
AntiBan;
WaitFunc(@NoBow, 10, 5000);
until NoBow;
end else
begin
TerminateScript;
end;
end;



procedure Report;
begin
ClearDebug;
Case FletchType of
'bow':
begin
Writeln('Roflme''s Fletcher');
Writeln('Logs cut:' + IntToStr(LogsCut));
Writeln('Script has run for ' + TimeRunning);
end;
'string':
begin
Writeln('Roflme''s Fletcher');
Writeln('Bows strung:' + IntToStr(BowsStrung));
Writeln('Script has run for ' + TimeRunning);
end;
end;
end;


procedure MainLoop;
begin
Bank;
case FletchType of
'bow':
begin
Cut;
FletchBow;
end;
'string':
begin
StringBow;
end;
end;
Report;
end;


begin
Cleardebug;
DeclarePlayers;
Smart_Server := 1;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
SetupSRL;
SmartSetRefresh(70);
LoginPlayer;
SetAngle(SRL_ANGLE_HIGH);
SetDTMs;
repeat
MainLoop;
until(false);
FreeDTMZ;
end.

Although I'm looking at
Function StringBow: Boolean;
begin
MarkTime(t)
if FindDTM(Longbow, x, y, MIX1, MIY1, MIX2, MIY2) or
FindDTM(Shortbow, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
Writeln('Found unstrung bows, stringing them')
MouseItem(14,mouse_left);
MouseItem(15,mouse_left);
repeat
wait(200);
if TimeFromMark(t) > 10000 then
begin
TerminateScript;
end;
until OptionsAppeared
Result := True
Writeln('Found Option Color');
end else
begin
TerminateScript;
end;

if GetDaText(x, y, 'bow') then
begin
Mouse(x, y, 5, 5, mouse_left);
repeat
AntiBan;
WaitFunc(@NoBow, 10, 5000);
until NoBow;
end else
begin
TerminateScript;
end;
end;

I'm guessing the first if then is wrong because that's where it gets stuck. It won't write the "found unstrung bows" piece. :(


EDIT: And when I take that out, the NoBow function isn't working properly. As soon as it begins stringing it will go to bank.

Noob King

2012-07-12 04:22:59

You need to add this


Addonterminate('FreeDTMZ');

Just put it under where you call SetDTMs

That way no matter how the script is stopped it will free the dtms.

bolshak25

2012-07-12 10:32:00

yeah, the reason it was saying dtms werent freed was because either you clicked stop or it got into one of your terminate scripts. either of those would just stop it right there, and it wouldnt ever get to the last line of freedtmz

Runaway

2012-07-12 12:41:45

From: Roflme
Going to stare at that for a few minutes to see if I can comprehend what is being done there :( :p lol

So i is going to act as the Longbow or Shortbow DTM? (it gets replaced by what is in the brackets [Longbow, Shortbow]?)

I'm just lost at the end. What is the purpose of c exactly? Why increase it but have the result as less than 1?


Sorry, I guess I jumped the gun a bit :p I'll comment it step-by-step for you:


function NoBow: Boolean;
var
BowDTM: TIntegerArray; // array of Integers.
c, i, x, y: Integer;
begin
BowDTM := [Shortbow, Longbow]; { [] denotes an array. Each value stored in the array
is given a location. BowDTM[0] refers to the first value stored in the BowDTM array. Whereas
BowDTM[1] refers to the second value. Note that arrays start at 0; so their length is always
one greater than the maximum location value. }
for i := 0 to High(BowDTM) do { This loops through the following begin/end, increasing the
value of i by 1 every time it starts over. It stops looping once i reaches the maximum set value,
which is High(BowDTM) in this case. High(BowDTM) is 1 since the highest location value in the
BowDTM array is 1 (0 = Shortbow, 1 = Longbow). }
begin
if FindDTM(BowDTM[i], x, y, MIX1, MIY1, MIX2, MIY2) then
Inc(c); // if the current BowDTM (since i is either 0 or 1) is found, c is then increased by 1.
end;
Result := (c < 1); { The result is True when the value of c is less than 1. Meaning: if none of
the DTMs in the BowDTM array were found (which would increase the value of c), then c = 0 and
the result is True. If c is anything greater than 0 (meaning at least one of the DTMs were found),
then the result would be False. }
end;

Hopefully that helps :)

P1ng

2012-07-14 00:49:58

Runaway's looks like the shortest and most efficient way to go about this. I would recommend to add a FreeDTM line after it has searched for each DTM just to save memory and not have it clog up, especially if you have it search for alot of DTMs (in other cases where a similar function would be used)

function NoBow: Boolean;
var
BowDTM: TIntegerArray;
c, i, x, y: Integer;
begin
BowDTM := [Shortbow, Longbow];
for i := 0 to High(BowDTM) do
begin
if FindDTM(BowDTM[i], x, y, MIX1, MIY1, MIX2, MIY2) then
Inc(c);
FreeDTM(BowDTM[i]);
end;
Result := (c < 1);
end;