SRL Archive - RS3 Help

Need help with Timers


stu

2014-04-17 05:56:46

Hey guys,
I'm currently trying to make a script that powerchops arctic pines.

I want it to cut the trees, then burn/drop the inventory of logs (using the action bar) when the invent is full.

However I've barely even attempted a simba script since I wrote a couple of basic ones in 2011, and can't figure out what's wrong with mine. I want it to start a timer when it clicks a tree, and for that timer to reset every time the backpack fills up by 1 (log), and if it goes 10 seconds without a new log it will click a tree again. but mine just clicks a tree every 10 seconds regardless of how many logs I get, and if i remove the second "logTimer.start()" then it just spam clicks the trees.
It's probably something really obvious but I can't figure it out :(

procedure cutSomeLogs;
var
x, y, plusOne, logCounter:integer;
logTimer:TTimeMarker;
begin
begin
plusOne := tabBackpack.count() + 1;
if (mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
end;
begin
logTimer.start();
if (tabBackpack.count() = plusOne) then
logTimer.start();
repeat
until (logTimer.getTime() > 10000 + random(1000)) or (tabBackpack.isFull);
end;
end;


Also, this is my drop procedure (mostly taken from KeepBotting's powerminer)


procedure dropThoseLogs;
var
timesTried:integer;
begin
repeat
typeSend('2', false);
wait(randomRange(100, 300));
until chatbox.findAnyText(['have any lef']) or chatbox.findAnyText(['fire her'])
end;


I was trying to use keydown(2)…keyup(2) in the procedure, but that didn't seem to work. However what I currently have seems to press the 2 key every couple of seconds instead of holding it down, which isn't fast enough, and doesnt seem to know when to stop.
How would you fix this?

Any help would be greatly appreciated

Stu.

DemiseScythe

2014-04-17 06:26:31

You need a double loop with a check.

Function X: Boolean;
T, I: Integer;
begin
repeat
T := GetSystemTime;
I := Invcount;
//cut log code here
repeat
Wait(50);
until (InvCount > I) or ((GetSystemTime - T) > 10000) or (not(LoggedIn));
until (InvCount = 28) or (not(LoggedIn));
Result := (InvCount = 28);
end;

KeyDown(vk_2);
Wait(10 + Random(50));
KeyUp(vk_2);

stu

2014-04-17 06:53:51

From: DemiseScythe
You need a double loop with a check.

Function X: Boolean;
T, I: Integer;
begin
repeat
T := GetSystemTime;
I := Invcount;
//cut log code here
repeat
Wait(50);
until (InvCount > I) or ((GetSystemTime - T) > 10000) or (not(LoggedIn));
until (InvCount = 28) or (not(LoggedIn));
Result := (InvCount = 28);
end;

KeyDown(vk_2);
Wait(10 + Random(50));
KeyUp(vk_2);


If I use that, it says block expected at line 82 column 1 (before the T in your second line).
Been trying to figure out what I'm missing but I don't understand

P1ng

2014-04-17 07:21:38

Some what confusing although I fixed everything up and it compiles and 'theoretically' should work.
Demise had a few different bits and pieces for OSR and would not work with the SRL-6 include and RS3.
Also the block expected was that Demise forgot to add in "var" before declaring variables.

Now for the dropping function, it was quite a pain to figure out and mostly just trial and error. But the simba docs say that '32' is the key code for the '2' key. However upon trial I discovered that 32 corresponds to space (' ').
Tried a few different combinations and it turns out '50' is the code for the '2' key.

function cutSomeLogs: Boolean;
var //block expected @line...
I: Integer;
T: TTimeMarker;
begin
repeat
T.startTime;
I := tabBackPack.count;
//cut log code here
repeat
Wait(50);
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn));
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;

procedure actionDrop;
var
T, CT: TTimeMarker;
begin
CT.startTime;

while CT.getTime < randomRange(3000, 4000) do
begin
Wait(500);
if conversationBox.findChat(['any more','any']) then
begin
typeByte(VK_ESCAPE);
wait(randomRange(500, 1000));
break;
end;
end;

keyDown(50); //key code for 2 is '50'
T.startTime;
while T.getTime < randomRange(5000, 10000) do
begin
wait(randomRange(50, 100));
if tabBackPack.isEmpty() then
break;
end;
keyUp(50);
end;

stu

2014-04-17 07:26:10

From: P1ng
Some what confusing although I fixed everything up and it compiles and 'theoretically' should work.
Demise had a few different bits and pieces for OSR and would not work with the SRL-6 include and RS3.
Also the block expected was that Demise forgot to add in "var" before declaring variables.

Now for the dropping function, it was quite a pain to figure out and mostly just trial and error. But the simba docs say that '32' is the key code for the '2' key. However upon trial I discovered that 32 corresponds to space (' ').
Tried a few different combinations and it turns out '50' is the code for the '2' key.

function cutSomeLogs: Boolean;
var //block expected @line...
I: Integer;
T: TTimeMarker;
begin
repeat
T.startTime;
I := tabBackPack.count;
//cut log code here
repeat
Wait(50);
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn));
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;

procedure actionDrop;
var
T, CT: TTimeMarker;
begin
CT.startTime;

while CT.getTime < randomRange(3000, 4000) do
begin
Wait(500);
if conversationBox.findChat(['any more','any']) then
begin
typeByte(VK_ESCAPE);
wait(randomRange(500, 1000));
break;
end;
end;

keyDown(50); //key code for 2 is '50'
T.startTime;
while T.getTime > randomRange(5000, 10000) do
begin
wait(randomRange(50, 100));
if tabBackPack.count() = 1 then
break;
end;
keyUp(50);
end;


ahhh okay, I did try putting "var" but that just caused other problems, I probably should have specified it was for RS3 not OSR.
Ill give yours a try and let you know how it goes. Thanks for the help guys :)

P1ng

2014-04-17 07:30:34

Those other errors would have been for things like InvCount and LoggedIn which were valid pre-SRL6. They've since been replaced with things like tabBackPack.count and isLoggedIn.

Anywho, I did some slight alterations to my post because there were a couple things that carried over from my fly fishing script which didn't work into what you're using it for. If you copy the simba code now it should work for you.

The Mayor

2014-04-17 07:33:45

I'll just chuck some ideas here too


function has28Logs(): boolean;
begin
repeat

mainscreen.findObject(x, y, 5464913... etc

repeat
wait(50);
until tabBackPack.waitForShift(10000) or (not isLoggedIn());

until tabBackPack.isFull() or (not isLoggedIn());

result := tabBackPack.isFull();
end;

procedure dropLogs();
var
timer: TTimeMarker;
begin
if has28Logs() then
begin
timer.start();
repeat
sendKeys('2', 250, 55);
wait(randomRange(100, 300));
until tabBackPack.isEmpty() or (timer.getTime > 30000) or (not isLoggedIn());
end;
end;

DemiseScythe

2014-04-17 07:44:26

From: P1ng
Those other errors would have been for things like InvCount and LoggedIn which were valid pre-SRL6. They've since been replaced with things like tabBackPack.count and isLoggedIn.

Anywho, I did some slight alterations to my post because there were a couple things that carried over from my fly fishing script which didn't work into what you're using it for. If you copy the simba code now it should work for you.


Yes, I don't really use SRL6 but from what I wrote, he should have realized which are the matching SRL6 functions which he already had in his original script. I wasn't expecting him to just copy and paste the code.

Also vk_2 should work for TypeByte and Key 2. It is a constant declared in Simba, I believe. vk stands for virtual key and works for all numbers and letters. Anything else you need the appropiate byte code which can be found in the Simba manual at: http://docs.villavu.com/simba/scriptref/mouseandkeyboard.html

Keyboard Virtual Keys
•UNKNOWN: 0
•LBUTTON: 1
•RBUTTON: 2
•CANCEL: 3
•MBUTTON: 4
•XBUTTON1: 5
•XBUTTON2: 6
•BACK: 8
•TAB: 9
•CLEAR: 12
•RETURN: 13
•SHIFT: 16
•CONTROL: 17
•MENU: 18
•PAUSE: 19
•CAPITAL: 20
•KANA: 21
•HANGUL: 21
•JUNJA: 23
•FINAL: 24
•HANJA: 25
•KANJI: 25
•ESCAPE: 27
•CONVERT: 28
•NONCONVERT: 29
•ACCEPT: 30
•MODECHANGE: 31
•SPACE: 32
•PRIOR: 33
•NEXT: 34
•END: 35
•HOME: 36
•LEFT: 37
•UP: 38
•RIGHT: 39
•DOWN: 40
•SELECT: 41
•PRINT: 42
•EXECUTE: 43
•SNAPSHOT: 44
•INSERT: 45
•DELETE: 46
•HELP: 47
•0: 30
•1: 31
•2: 32
•3: 33
•4: 34
•5: 35
•6: 36
•7: 37
•8: 38
•9: 39
•A: 41
•B: 42
•C: 43
•D: 44
•E: 45
•F: 46
•G: 47
•H: 48
•I: 49
•J: 4A
•K: 4B
•L: 4C
•M: 4D
•N: 4E
•O: 4F
•P: 50
•Q: 51
•R: 52
•S: 53
•T: 54
•U: 55
•V: 56
•W: 57
•X: 58
•Y: 59
•Z: 5A
•LWIN: 5B
•RWIN: 5C
•APPS: 5D
•SLEEP: 5F
•NUMPAD0: 96
•NUMPAD1: 97
•NUMPAD2: 98
•NUMPAD3: 99
•NUMPAD4: 100
•NUMPAD5: 101
•NUMPAD6: 102
•NUMPAD7: 103
•NUMPAD8: 104
•NUMPAD9: 105
•MULTIPLY: 106
•ADD: 107
•SEPARATOR: 108
•SUBTRACT: 109
•DECIMAL: 110
•DIVIDE: 111
•F1: 112
•F2: 113
•F3: 114
•F4: 115
•F5: 116
•F6: 117
•F7: 118
•F8: 119
•F9: 120
•F10: 121
•F11: 122
•F12: 123
•F13: 124
•F14: 125
•F15: 126
•F16: 127
•F17: 128
•F18: 129
•F19: 130
•F20: 131
•F21: 132
•F22: 133
•F23: 134
•F24: 135
•NUMLOCK: 90
•SCROLL: 91
•LSHIFT: A0
•RSHIFT: A1
•LCONTROL: A2
•RCONTROL: A3
•LMENU: A4
•RMENU: A5
•BROWSER_BACK: A6
•BROWSER_FORWARD: A7
•BROWSER_REFRESH: A8
•BROWSER_STOP: A9
•BROWSER_SEARCH: AA
•BROWSER_FAVORITES: AB
•BROWSER_HOME: AC
•VOLUME_MUTE: AD
•VOLUME_DOWN: AE
•VOLUME_UP: AF
•MEDIA_NEXT_TRACK: B0
•MEDIA_PREV_TRACK: B1
•MEDIA_STOP: B2
•MEDIA_PLAY_PAUSE: B3
•LAUNCH_MAIL: B4
•LAUNCH_MEDIA_SELECT: B5
•LAUNCH_APP1: B6
•LAUNCH_APP2: B7
•OEM_1: BA
•OEM_PLUS: BB
•OEM_COMMA: BC
•OEM_MINUS: BD
•OEM_PERIOD: BE
•OEM_2: BF
•OEM_3: C0
•OEM_4: DB
•OEM_5: DC
•OEM_6: DD
•OEM_7: DE
•OEM_8: DF
•OEM_102: E2
•PROCESSKEY: E7
•ATTN: F6
•CRSEL: F7
•EXSEL: F8
•EREOF: F9
•PLAY: FA
•ZOOM: FB
•NONAME: FC
•PA1: FD
•OEM_CLEAR: FE
•HIGHESTVALUE: FE
•UNDEFINED: FF

Still weird it says 32, vk_2 should always work though.

stu

2014-04-17 07:54:29

From: P1ng
Those other errors would have been for things like InvCount and LoggedIn which were valid pre-SRL6. They've since been replaced with things like tabBackPack.count and isLoggedIn.

Anywho, I did some slight alterations to my post because there were a couple things that carried over from my fly fishing script which didn't work into what you're using it for. If you copy the simba code now it should work for you.


I've tried putting my cutlogs code into what you sent me, and it still just spam clicks the trees. I don't understand why, as surely it should just click the tree then move on to the next loop.
Here's what that section looks like

var
x, y, plusOne, logCounter, I: Integer;
T: TTimeMarker;
begin
repeat
T.startTime;
I := tabBackPack.count;
(mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT));
repeat
Wait(50);
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn));
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;


And Mayor, I'll have a play with yours once I have this working to see which works best. Thanks for all the help everyone :)

P1ng

2014-04-17 07:54:31

Just tested it and VK_2 works for keyDown and keyUp (don't know how I got it in my head that it didn't…)
never the less the link you posted - http://docs.villavu.com/simba/script...dkeyboard.html with the list of virtual keys is incorrect. I had a look at it and you will note that there are repetitions (namely, SPACE: 32 and 2: 32).

I tested it using notepad as my target client and the result was that '50' pressed the 2 key and '32' pressed the space bar. Whereas the doc's suggest 50 would press "P"

EDIT: have a go at using some if..then statements and some begin..ends to that code and it should work. Check out the beginner's tutorial section for more information regarding their use and the logic surrounding them.

stu

2014-04-17 07:58:35

From: DemiseScythe
Yes, I don't really use SRL6 but from what I wrote, he should have realized which are the matching SRL6 functions which he already had in his original script. I wasn't expecting him to just copy and paste the code.


I didn't just directly copy and paste the code, but I have literally no scripting knowledge to know what I need to change. and I am trying to do revision for my uni exams next month, so I don't have a lot of time to try to learn everything myself. That's why I'm asking these questions, so I can get a working script while I revise, then clean it up and release it when I have more time post-exams

stu

2014-04-17 08:00:11

From: P1ng

EDIT: have a go at using some if..then statements and some begin..ends to that code and it should work. Check out the beginner's tutorial section for more information regarding their use and the logic surrounding them.


I originally had an if…then before/after my cutlogs script and it didn't help, but I'll have another play with it to see if i can get it working

stu

2014-04-17 08:24:34


repeat //begin the loop
T.startTime;
I := tabBackPack.count;
begin //dont think this is necessary, but added it to check something
if (mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then //-find tree&click. if successful, move on to next part
end; //again, don't think it's necessary.
repeat //begin the second loop
Wait(50); //wait 0.05s
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn)); //repeat the wait until a log is received (Just noticed this needs to be changed, as it means it will click a tree every time a log is received [I think]) or it has been 10s+ or logged out
until (tabBackPack.count = 28) or (not(isLoggedIn)); //repeat until full backpack or logged out
Result := (tabBackPack.count = 28);
End; //end the loop


Ok here's the code as I understand it. clearly I'm misunderstanding something here or it wouldn't just be spam clicking trees every 0.05s (or whatever the Wait time is set to). I'm going to do some revision now, but can someone try to explain to me what I'm misunderstanding?

Thanks a lot guys.

Stu.

Foundry

2014-04-17 11:31:27

I made sure this was RS3 this time :)

I don't really know why it would be looping like that. One of the conditions must be true… Try this:

repeat //begin the loop
T.startTime;
I := tabBackPack.count;
writeLn('I is ' + toStr(I) + 'at the start');
// no begin is needed here.
if (mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
begin // if we find the tree then...
repeat //begin the second loop
Wait(50); //wait 0.05s
writeLn(I);
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn)); // This looks fine.
end; //This ends what will happen if we clicked the tree.
until ((tabBackPack.count = 28) or (not(isLoggedIn))); //repeat until full backpack or logged out
Result := (tabBackPack.count = 28); // Returns true if our backpack is full
End; //end the loop

Also, try debugging what I is and all of the other conditions.

stu

2014-04-17 11:40:54

From: Foundry
I made sure this was RS3 this time :)

repeat //begin the loop
T.startTime;
I := tabBackPack.count;
// no begin is needed here.
if (mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
// The end here was causing it to end prematurely?
begin // if we find the tree then...
repeat //begin the second loop
Wait(50); //wait 0.05s
until (tabbackPack.count > I) or ((t.getTime) > 10000) or (not(isLoggedIn)); // This looks fine.
end; //This ends what will happen if we clicked the tree.
until (tabBackPack.count = 28) or (not(isLoggedIn)); //repeat until full backpack or logged out
Result := (tabBackPack.count = 28); // Returns true if our backpack is full
End; //end the loop


That looks at first glance exactly like another variation I tried which also kept spam clicking the tree (i tried it 3 or 4 different ways), but I'll test it in a minute and see.

Thanks in advance if it works!

Foundry

2014-04-17 11:44:21

From: stu
That looks at first glance exactly like another variation I tried which also kept spam clicking the tree (i tried it 3 or 4 different ways), but I'll test it in a minute and see.

Thanks in advance if it works!

@stu; I edited my post with another idea.

DemiseScythe

2014-04-17 12:10:29

Those fancy timer functions don't work. The part I wrote for the GetSystemTime can still be used. Except may be defined T as a cardinal.

var
x, y, I: Integer;
T: Cardinal;
begin
repeat
T := GetSystemTime;
I := tabBackPack.count;
if mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
begin
repeat
Wait(50);
until (tabbackPack.count > I) or ((GetSystemTime - T) > 10000) or (not(isLoggedIn));
end;
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;
should work.

GetSystemTime is a simba function, not SRL6 one.

stu

2014-04-17 12:49:47

Ok I've got it working now, thanks to the help from you guys :D

But there's still that part that I said needed to be changed, and I'm not really sure how to fix it (it was sort of what I was trying to find out originally).

Basically, the fixes you guys all sent me have it so that it clicks the tree whenever I get a log in the invent. I mentioned it in the code i uploaded with all the notes on. I don't want this to happen as you can get 10+ logs from a single tree, so it's pretty bot-like to click a tree every time you get a log.

I wanted the script to do this: (or an equivalent method not using "fancy" timers if they're not very good)
click a tree > start a timer > reset timer every time I get a new log (until backpack is full) > and have some way of knowing if the tree is gone (for example 10-15 seconds without any new logs or (an even better, new idea) the "chop down arctic pine" text disappears).

I'm assuming theres a way to know if the text disappears, the same way there's a way to detect that the text is there in the first place?


But the thing I was originally most struggling with was a way to reset the timer every time I got a new log. Thats why I had
begin
logTimer.start();
if (tabBackpack.count() = plusOne) then
repeat

In there originally, but that didn't work.

So thanks everyone for getting me a script that I can run, now I just need to make the final tweaks to make it a decent script that I can trust not to get me banned :)

DemiseScythe

2014-04-17 14:35:34

From: stu
Ok I've got it working now, thanks to the help from you guys :D

But there's still that part that I said needed to be changed, and I'm not really sure how to fix it (it was sort of what I was trying to find out originally).

Basically, the fixes you guys all sent me have it so that it clicks the tree whenever I get a log in the invent. I mentioned it in the code i uploaded with all the notes on. I don't want this to happen as you can get 10+ logs from a single tree, so it's pretty bot-like to click a tree every time you get a log.

I wanted the script to do this: (or an equivalent method not using "fancy" timers if they're not very good)
click a tree > start a timer > reset timer every time I get a new log (until backpack is full) > and have some way of knowing if the tree is gone (for example 10-15 seconds without any new logs or (an even better, new idea) the "chop down arctic pine" text disappears).

I'm assuming theres a way to know if the text disappears, the same way there's a way to detect that the text is there in the first place?


But the thing I was originally most struggling with was a way to reset the timer every time I got a new log. Thats why I had
begin
logTimer.start();
if (tabBackpack.count() = plusOne) then
repeat

In there originally, but that didn't work.

So thanks everyone for getting me a script that I can run, now I just need to make the final tweaks to make it a decent script that I can trust not to get me banned :)


var
x, y, I: Integer;
T: Cardinal;
begin
repeat
T := GetSystemTime;
I := tabBackPack.count;
if mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
begin
repeat
Wait(50);
if (tabbackPack.count > I) then
begin
T := GetSystemTime;
I := tabBackPack.count;
end;
until (tabBackPack.count = 28) or ((GetSystemTime - T) > 10000) or (not(isLoggedIn));
end;
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;

stu

2014-04-17 17:28:49

From: DemiseScythe
var
x, y, I: Integer;
T: Cardinal;
begin
repeat
T := GetSystemTime;
I := tabBackPack.count;
if mainscreen.findObject(x, y, 5464913, 23, colorSetting(2, 0.07, 0.15), mainscreen.playerPoint, 30, 50, 50, ['rctic', 'pine'], MOUSE_LEFT)) then
begin
repeat
Wait(50);
if (tabbackPack.count > I) then
begin
T := GetSystemTime;
I := tabBackPack.count;
end;
until (tabBackPack.count = 28) or ((GetSystemTime - T) > 10000) or (not(isLoggedIn));
end;
until (tabBackPack.count = 28) or (not(isLoggedIn));
Result := (tabBackPack.count = 28);
end;


Ugh I was being stupid. I tried moving the Click Tree part up there, but I didn't think to add the

begin
T := GetSystemTime;
I := tabBackPack.count;
end;

part. I'll test tomorrow, thanks a lot :)