SRL Archive - Jr. Member General Help and Discussion

Just learned about records, have I used them properly?


GetHyper

2015-06-17 19:22:23

Here is my fletching script, I have ran for a while at Lumby chest and it works as it should.

I am wondering if I have utilised the record process properly?

Also is there anyway I can improve it?

Thank you people!


program HyperFletch;

{$DEFINE SMART}
{$i srl-6/srl.simba}
{$i sps/lib/sps-rs3.simba}
{$i srl-6/lib/misc/srlplayerform.simba}

type demBanks = record
Name: String;
Colour: TColorData;
OverText: TStringArray;
end;

var
i, x, y, S, C, TO_CUT, ACTION_BAR, logsC, bowsS,
logsPH, bowsPH : integer;
bankT, bankT2, progT, progT2, progT3 : TTimeMarker;
TPA : TPointArray;
ATPA : T2DPointArray;
DUEL_CHEST, LUMBY_CHEST, SHANTAY_CHEST, NPC_BLUE : demBanks;

procedure initPlayerForm();
begin
with playerForm do
begin
name := 'HyperFletch';
scriptHelpThread := ' ';
editBoxLabels := ['Number to cut/string', 'Action bar slot'];
editBoxDefaults := ['1000', '2'];
comboBoxLabels := ['Action', 'Bank', 'Length'];
comboBoxDefaults := ['Cut', 'DUEL_CHEST', 'Long'];
setLength(comboBoxItems, length(comboBoxLabels));
comboBoxItems[0] := ['Cut', 'String', 'Shaft'];
comboBoxItems[1] := ['DUEL_CHEST', 'LUMBY_CHEST', 'SHANTAY_CHEST', 'NPC_BLUE'];
comboBoxItems[2] := ['Long', 'Short'];
end;
end;

procedure declarePlayers();
begin
players.setup(playerForm.players);
currentPlayer := 0;

for i := 0 to high(players) do
with players[i] do

begin
TO_CUT := strToInt(playerForm.players[i].settings[0]); //number to cut
ACTION_BAR := strToInt(playerForm.players[i].settings[1]); //actionbarslot
strings[1] := playerForm.players[i].settings[2]; //action
strings[2] := playerForm.players[i].settings[3]; //location
strings[3] := playerForm.players[i].settings[4]; //length
end;
end;

procedure antiban();
begin
case random(100) of
1..5 : case random(25) of
5..15 : hoverSkill(SKILL_FLETCHING);
11 : wait(randomRange(1000, 2500));
25..55 : mouseOffClient(OFF_CLIENT_RANDOM);
66 : pickUpMouse();
69 : case random(50) of
10 : randomGameTab(true);
end
77 : case random(10) of
7 : randomRClickItem();
end;
99 : wait(randomRange(3000, 4500));
end;
end;
end;

procedure loaddemBanks(); //color, tol, cts, hue, sat, sens
begin
DUEL_CHEST.Init('DUEL_CHEST', [10063735, 7, [2, [0.39, 0.09, 0.00]]], ['ank', 'hest']);
LUMBY_CHEST.init('LUMBY_CHEST', [9865599, 10, [2, [0.25, 0.42, 0.00]]], ['ank', 'hest']);
SHANTAY_CHEST.init('SHANTAY_CHEST', [3811380, 4, [2, [0.24, 0.90, 0.00]]], ['hantay', 'hest']);
NPC_BLUE.Init('NPC_BLUE', [5319225, 8, [2, [0.20, 0.77, 0.00]]], ['ank', 'anker']);
end;

procedure demBanks.Init(_Name: String; _Colour: TColorData; _OverText: TStringArray);
begin
Self.Name := _Name; // The procedure parameters start with '_' to differentiate them from the record fields
Self.Colour := _Colour;
Self.OverText := _OverText;
end;

function demBanks.Find(): Boolean;
var
i: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
//writeLn('Searching for: ' + Self.Name); // Prints the TMSObject's name
if Self.Colour.gatherIn(TPA, mainScreen.getBounds()) then // A TColourData method. Puts matching colours into 'TPA'
begin
ATPA := TPA.toATPA(20, 20);
ATPA.filterBetween(0, 10);
ATPA.sortFromMidPoint(mainScreen.playerPoint);
if (length(ATPA) < 1) then exit(false);

for i := 0 to high(ATPA) do
begin
mouse(ATPA[i].getBounds().getRandomPoint());
if isMouseOverText(Self.OverText) then // The TMSObject's OverText
begin
fastClick(MOUSE_LEFT);
break;
end;
end;
end;
end;

function chooseBank: string;
begin
case (players[currentPlayer].strings[2]) of
'DUEL_CHEST' : DUEL_CHEST.Find;
'LUMBY_CHEST' : LUMBY_CHEST.Find;
'SHANTAY_CHEST' : SHANTAY_CHEST.Find;
'NPC_BLUE' : NPC_BLUE.Find;
end;
end;

function noBank: boolean; Forward;
procedure letsGoFletch; Forward;

procedure letsGoBank();
begin
if not isLoggedIn then
exit;

writeln('Let us bank, I am off to find it');
if bankScreen.isOpen then
bankScreen.close else
bankT.start;
repeat
chooseBank;
wait(gaussRangeInt(1000,1200));
until (bankScreen.isOpen) or (not isLoggedIn) or (bankT.getTime > 10000);
if (bankT.getTime > 10000) then
noBank else
if bankScreen.isOpen then
writeln('Bank is open, getting items');
bankT2.start;
repeat
bankScreen.clickButton(3);
wait(randomRange(600, 800));
until (not bankScreen.isOpen) or (bankT2.getTime > 10000) or (not isLoggedIn);
end;

function noBank: boolean;
begin
writeln('Could not find bank, looking again');
if toolScreen.isOpen then
letsGoFletch else
if productionScreen.isOpen then
productionScreen.close else
if bankScreen.isOpen then
bankScreen.close;
minimap.clickCompass();
mainScreen.setAngle(MS_ANGLE_HIGH);
letsGoBank;
end;


function chooseLength: integer;
begin
case (players[currentPlayer].strings[3]) of
'Long' : 4;
'Short' : 2;
'Shaft' : 1;
end;
end;

procedure letsGoFletch();
begin
if not isLoggedIn() then
exit();

case (players[currentPlayer].strings[1]) of
'Cut':
begin
writeln('We have our items, lets cut');
progT.start;
repeat
actionBar.clickSlot(ACTION_BAR);
wait(randomRange(750, 1250));
until (toolScreen.isOpen) or (productionScreen.isOpen) or (progT.getTime > 10000);
progT2.start;
repeat
if toolScreen.isOpen then
toolScreen.select('Knife') else
if productionScreen.isOpen() then
productionScreen.selectBox(chooseLength);
if productionScreen._getSelectedBox(chooseLength) then
productionScreen.clickStart();
until (progressScreen.isOpen) or (progT2.getTime > 7000);
if progressScreen.isOpen() then
writeln('Just waiting and doing human things');
progT3.start;
repeat
wait(randomRange(1000, 1999));
antiban();
until (tabBackpack.waitSlotPixelChange(28, 2000)) or (not progressScreen.isOpen) or (not isLoggedIn) or (progT3.getTime > 60000);
inc(C);
end;

'String':
begin
writeln('We have our items, lets string');
if tabBackpack.isFull then
progT.start else
exit;
repeat
actionBar.clickSlot(ACTION_BAR);
wait(random(150));
until (productionScreen.isOpen) or (progT.getTime > 5000);
progT2.start;
if productionScreen.isOpen then
repeat
productionScreen.clickStart()
until (progressScreen.isOpen) or (progT2.getTime > 5000);
writeln('Just waiting and doing human things');
inc(S);
progT3.start;
repeat
wait(randomRange(1000, 1999));
antiban();
until (tabBackpack.waitSlotPixelChange(28, 2000)) or (not progressScreen.isOpen) or (progT3.getTime > 30000) or (not isLoggedIn);
wait(400 + random(200));
end;
end;
end;

procedure progressReport();
begin
if not isLoggedIn() then
exit;

logsC := C * 28;
bowsS := S * 14;
logsPH := round((logsC * 60) / (getTimeRunning() / 60000));
bowsPH := round((bowsS * 60) / (getTimeRunning() / 60000));

clearDebug();
writeln('HyperFletch V2.0');
writeln('Time Running: ' + timeRunning());
writeln('Bows Strung: ' + intToStr(bowsS) + ' (p/h: )' + intToStr(bowsPH));
writeln('Logs Cut: ' + intToStr(logsC) + ' (p/h: )' + intToStr(logsPH));

end;

begin
clearDebug();
disableSRLDebug := true;
initPlayerForm();
runPlayerForm();
loaddemBanks();
if not playerForm.isScriptReady then
exit();
declarePlayers();
setupSRL();

if not isLoggedIn() then
begin
players[currentPlayer].login();
exitTreasure();
writeln('Just setting up, be done soon');
wait(gaussRangeInt(500,1000));
minimap.clickCompass();
wait(gaussRangeInt(200,400));
mainScreen.setAngle(MS_ANGLE_HIGH);
end;

repeat
letsGoBank;
letsGoFletch;
progressReport();
until (not isLoggedIn()) or (TO_CUT = (S * 14)) or (TO_CUT = (C * 28));
writeln('We are done, logging out');
players[currentPlayer].logout();
end.

adc

2015-06-17 19:36:08

As far as I can tell, you used it correctly (assuming it works like you said it does). All a record does is allow you to create your own variable type. This is similar to creating a new class file to create a new Object in Java, if you have experience in that language.

The question is whether there's a reason to. In this case, there is no reason to do this, as SRL-6 contains banking functions for most of the popular bank types. You can dig through the documentation (http://docs.villavu.com/srl-6/index.html) for more info; BankScreen is what you're looking for in this case.

GetHyper

2015-06-17 20:34:03

Ok thanks, I do know there are already things in place for banking but some places don't work 100% such as Shantay chest so I have put my own colours in instead.

Turpinator

2015-06-17 21:12:08

Just a neat little trick as you seem to define 'Name' as just a string of the variable…
  Self.Name := GetGlobalName(@self);
(completely really unrelated, but neat)

J_R

2015-06-17 22:24:05

Wow, I didn't know you could actually do OOP (Object Oriented Programming) in pascalscript/lape! You've definitely used it right if that code works; however, just like adc I also believe it's probably not necessary to use it the way you did.

In other languages, I generally use OOP when there are multiple objects (classes) active at the same time, when I need some sort of encapsulation/security/interface/other property of classes, or when I need a completely new data structure(or where I'd have like 10000 variables that would be a pain to sift through, see TomTuff's Master divination or S1n or C0h3n's superheaters for examples of this scenario :P). I don't think any of these apply to your case.

It would be more 'correct' (from a CS perspective) to simply make a banking function take in (or use from the global scope) the name, color, and overtext and set them upon starting since there are only like 3 things you have to set anyway.

GetHyper

2015-06-18 05:40:59

From: Turpinator
Just a neat little trick as you seem to define 'Name' as just a string of the variable…
  Self.Name := GetGlobalName(@self);
(completely really unrelated, but neat)

Ok, thanks :)

From: J_R
Wow, I didn't know you could actually do OOP (Object Oriented Programming) in pascalscript/lape! You've definitely used it right if that code works; however, just like adc I also believe it's probably not necessary to use it the way you did.

In other languages, I generally use OOP when there are multiple objects (classes) active at the same time, when I need some sort of encapsulation/security/interface/other property of classes, or when I need a completely new data structure(or where I'd have like 10000 variables that would be a pain to sift through, see TomTuff's Master divination or S1n or C0h3n's superheaters for examples of this scenario :P). I don't think any of these apply to your case.

It would be more 'correct' (from a CS perspective) to simply make a banking function take in (or use from the global scope) the name, color, and overtext and set them upon starting since there are only like 3 things you have to set anyway.


It does work, so all good. I will have a look through there scripts to get an idea.

Sorry (maybe just cause early morning and I can't help but sit watching films until silly o'clock) but what do you mean by the banking function take in?
The reason I have done it is - just to learn really and also add colors to chests that sometimes do not work (such as Shantay)

adc

2015-06-18 10:40:33

From: GetHyper
Ok, thanks :)



It does work, so all good. I will have a look through there scripts to get an idea.

Sorry (maybe just cause early morning and I can't help but sit watching films until silly o'clock) but what do you mean by the banking function take in?
The reason I have done it is - just to learn really and also add colors to chests that sometimes do not work (such as Shantay)


function openBank(color : integer; name, uptext : String) : boolean;
begin
//Open bank based on the given parameters
end;

Removes the need to make your own variable type, and gives just as much flexibility.

J_R

2015-06-18 16:10:44

From: GetHyper
Ok, thanks :)



It does work, so all good. I will have a look through there scripts to get an idea.

Sorry (maybe just cause early morning and I can't help but sit watching films until silly o'clock) but what do you mean by the banking function take in?
The reason I have done it is - just to learn really and also add colors to chests that sometimes do not work (such as Shantay)


I mean precisely as done in the above post. You can provide arguments to a function that the function can then use. something like

function addnumbers(x,y : integer) : integer;
begin
result := (x + y);
exit;
end
instead of

function addnumbers() : integer;
begin
result := (x + y);
exit;
end
which relies on x and y being global and can't be used again without copying the code if I wanted to add u and v instead of x and y, while in the first one I'd just call add(u,v)